Skip to content
Alpha: see what works today →
Menu

Named question about pod

My procedures

Read from the view alone, as an app would, newest first by the date as written, so a year follows its months and days, with how many records each entry joins, its code IRI, the first in code point order when it states several, the text each record's source wrote for it, such as the finding beside a screening (none when no record has one), and each record it joins with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it, in order, separated by U+001F, its own parts by ", ". Times written with a zone are ordered by their wall time as written, not as instants: 23:00-05:00 sorts before 01:00Z the next day, though it is later.

The query

PREFIX cascade: <https://ns.cascadeprotocol.org/cascade#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX pav: <http://purl.org/pav/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?performed ?procedure ?procedureCode ?status ?narrativeTexts (COUNT(?record) AS ?records) ?entry ?entryLabel ?sources
WHERE {
  { SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT ?narrativeLine; separator=""), "\u001F$", "") AS ?said)
    WHERE {
      { SELECT ?entry ?narrativeLine
        WHERE {
          ?entry a cascade:MedicalProcedure ; cascade:memberCurrentValues ?values .
          ?values cascade:valuesOfMember ?member .
          OPTIONAL { ?values cascade:narrativeText ?memberNarrativeText }
          BIND (IF(BOUND(?memberNarrativeText), CONCAT(STR(?member), " ", ?memberNarrativeText, "\u001F"), "") AS ?narrativeLine)
        }
        ORDER BY ?entry ?narrativeLine }
    }
    GROUP BY ?entry }
  { SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT CONCAT(?sourceText, "\u001F"); separator=""), "\u001F$", "") AS ?sources)
    WHERE {
      { SELECT ?entry ?sourceText
        WHERE {
          { SELECT ?entry ?sourceRecord ?document ?retrievedOn
                   (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?hospital, ", "), ""); separator=""), ", $", "") AS ?hospitals)
            WHERE {
              { SELECT ?entry ?sourceRecord ?document ?retrievedOn ?hospital
                WHERE {
                  ?entry a cascade:MedicalProcedure ; cascade:entryMember ?sourceRecord .
                  OPTIONAL { ?sourceRecord cascade:currentRevision/prov:wasDerivedFrom ?document .
                             OPTIONAL { ?document pav:retrievedOn ?retrievedOn }
                             OPTIONAL { ?document prov:wasGeneratedBy/prov:qualifiedAssociation ?association .
                                        ?association prov:hadRole ?hospitalRole ; prov:agent ?agent
                                        FILTER (?hospitalRole IN (cascade:AuthorRole, cascade:CustodianRole))
                                        OPTIONAL { ?agent rdfs:label ?agentLabel }
                                        OPTIONAL { ?agent pav:hasCurrentVersion/foaf:name ?agentName }
                                        BIND (CONCAT(IF(?hospitalRole = cascade:AuthorRole, "written by ", "kept by "),
                                                     COALESCE(?agentLabel, ?agentName)) AS ?hospital) } }
                }
                ORDER BY ?entry ?sourceRecord ?document ?hospital }
            }
            GROUP BY ?entry ?sourceRecord ?document ?retrievedOn }
          BIND (CONCAT(STR(?sourceRecord), COALESCE(CONCAT(" from ", STR(?document)), ""),
                       COALESCE(CONCAT(", retrieved ", STR(?retrievedOn)), ""),
                       IF(?hospitals = "", "", CONCAT(", ", ?hospitals))) AS ?sourceText)
        }
        ORDER BY ?entry ?sourceText }
    }
    GROUP BY ?entry }
  ?entry a cascade:MedicalProcedure ; cascade:entryMember ?record .
  OPTIONAL { ?entry cascade:procedureDate ?performed }
  OPTIONAL { ?entry cascade:procedureName ?procedure }
  OPTIONAL {
    ?entry cascade:procedureCode ?procedureCode .
    FILTER NOT EXISTS {
      ?entry cascade:procedureCode ?earlier .
      FILTER (STR(?earlier) < STR(?procedureCode))
    }
  }
  OPTIONAL { ?entry cascade:workflowStatus ?status }
  OPTIONAL { ?entry rdfs:label ?entryLabel }
  BIND (IF(?said = "", ?nothing, ?said) AS ?narrativeTexts)
}
GROUP BY ?entry ?performed ?procedure ?procedureCode ?status ?narrativeTexts ?entryLabel ?sources
ORDER BY DESC(COALESCE(STR(?performed), "")) ?procedure ?entry

Terms it reads

cascade:AuthorRole · cascade:CustodianRole · cascade:MedicalProcedure · cascade:currentRevision · cascade:entryMember · cascade:memberCurrentValues · cascade:narrativeText · cascade:procedureCode · cascade:procedureDate · cascade:procedureName · cascade:valuesOfMember · cascade:workflowStatus · pav:hasCurrentVersion · pav:retrievedOn · prov:agent · prov:hadRole · prov:wasGeneratedBy · rdfs:label

Rules and decision notes that name it

No rule or decision note writes its path.

Its rows on Alex Rivera's pod

2 rows, as Alex Rivera's explorer shows them.

performedprocedureprocedureCodestatusrecordsentrysources
2026-08-19Colonoscopyhttp://snomed.info/id/73761001completed2Procedure entry · Colonoscopy · 2026-08-19urn:uuid:7a11ba0d-eaa3-881d-a511-1f2ee8b8b0e9 from ni:///sha-256;ltngd2O05L-Jeq4u_dBI2rxpRUzXYj-ZiNpjJO9doV0, retrieved 2026-10-14T15:40:00Z, written by Larkspur Valley Health; urn:uuid:cfe67786-af77-8fb0-8c99-3d9faedcf182 from ni:///sha-256;Kl2jU5ZSxb7vZ9IYZT4E7Cs6tP8AmSBqqKD8yXCICdM, retrieved 2027-03-18T12:00:00Z, written by Larkspur Valley Health
2025-02-18Colonoscopyhttp://snomed.info/id/73761001completed1Procedure entry · Colonoscopy · 2025-02-18urn:uuid:c6f34248-0b58-8e8a-8e52-f426d1a8be5c from ni:///sha-256;SPGEJSdaOinAgDgw_i4ycahIFdhqFfdqb9G_YFrU6RA, retrieved 2026-09-01T10:00:00Z, written by Meridian Health System

queries/questions/pod/My procedures.rq on GitHub ↗