Skip to content
Alpha: see what works today →
Menu

Named question about pod

My active conditions

Read from the view alone, as an app would: each entry whose status is active and not ruled out, so not one whose status was taken from a refuted record (`pod/My condition history` lists those), with its codes, its onset, each entry of a medication, procedure or vaccination a record of which was given for one of its records, once, as "<entry>, <name>" (the entry IRI alone when it has no name; the entry IRI holds no ", ", so the first ", " ends it and the name, which may hold anything, is the rest; none when no record names one; not an entry of a medication its source marked entered in error), in code point order of name (an entry with no name first), then entry, how many records it joins, and each record with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it. A list holds its values in order, separated by U+001F, a value's own parts by ", ". Its code is the code IRI the entry states, in whichever listed system, the first in code point order when it states several, so that each entry is one row.

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 ?condition ?conditionCode ?onset ?entriesForIt (COUNT(?record) AS ?records) ?entry ?entryLabel ?sources
WHERE {
  { SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT ?forLine; separator=""), "\u001F$", "") AS ?forIt)
    WHERE {
      { SELECT ?entry ?forLine
        WHERE {
          ?entry a cascade:ProblemOrDiagnosis ; cascade:entryMember ?conditionRecord .
          OPTIONAL { ?forValues cascade:reasonCondition ?conditionRecord .
                     ?forEntry cascade:memberCurrentValues ?forValues .
                     OPTIONAL { ?forEntry cascade:drugName ?drugName }
                     OPTIONAL { ?forEntry cascade:procedureName ?procedureName }
                     OPTIONAL { ?forEntry cascade:vaccineName ?vaccineName }
                     FILTER NOT EXISTS { ?forEntry cascade:lifecycle cascade:MedicationEnteredInError } }
          BIND (COALESCE(?drugName, ?procedureName, ?vaccineName) AS ?forName)
          BIND (IF(BOUND(?forEntry), CONCAT(STR(?forEntry), COALESCE(CONCAT(", ", ?forName), ""), "\u001F"), "") AS ?forLine)
        }
        ORDER BY ?entry ?forName ?forEntry }
    }
    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:ProblemOrDiagnosis ; cascade:clinicalStatus "active" ; cascade:entryMember ?sourceRecord .
                  FILTER NOT EXISTS { ?entry cascade:verificationStatus "refuted" }
                  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:ProblemOrDiagnosis ; cascade:clinicalStatus "active" ;
         cascade:conditionName ?condition ; cascade:entryMember ?record .
  FILTER NOT EXISTS { ?entry cascade:verificationStatus "refuted" }
  OPTIONAL {
    ?entry cascade:conditionCode ?conditionCode .
    FILTER NOT EXISTS {
      ?entry cascade:conditionCode ?earlier .
      FILTER (STR(?earlier) < STR(?conditionCode))
    }
  }
  OPTIONAL { ?entry cascade:onsetDate ?onset }
  OPTIONAL { ?entry rdfs:label ?entryLabel }
  BIND (IF(?forIt = "", ?nothing, ?forIt) AS ?entriesForIt)
}
GROUP BY ?entry ?condition ?conditionCode ?onset ?entriesForIt ?entryLabel ?sources
ORDER BY ?condition ?entry

Terms it reads

cascade:AuthorRole · cascade:CustodianRole · cascade:MedicationEnteredInError · cascade:ProblemOrDiagnosis · cascade:clinicalStatus · cascade:conditionCode · cascade:conditionName · cascade:currentRevision · cascade:drugName · cascade:entryMember · cascade:lifecycle · cascade:memberCurrentValues · cascade:onsetDate · cascade:procedureName · cascade:reasonCondition · cascade:vaccineName · cascade:verificationStatus · pav:hasCurrentVersion · pav:retrievedOn · prov:agent · prov:hadRole · prov:wasGeneratedBy · rdfs:label

Rules and decision notes that name it

Its rows on Alex Rivera's pod

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

conditionconditionCodeonsetrecordsentrysources
Asthmahttp://snomed.info/id/1959670012008-09-012Condition entry · Asthma · 2008-09-01urn:uuid:3719cb66-c5be-8fac-a0bf-a6db7573fe71 from ni:///sha-256;JrahuZoHwbTA6XHjL2ULjX9vetTQjTNZFxr4LLytgqg, retrieved 2026-10-14T15:40:00Z, written by Larkspur Valley Health; urn:uuid:fdf1589d-bc02-8c0f-8874-4d377574cc8d from ni:///sha-256;5kn5zMwKLefLlu2hz3EIBOHJv9XyGZvXlkp1ZH0pi5I, retrieved 2027-03-18T12:00:00Z, written by Larkspur Valley Health
Essential hypertensionhttp://snomed.info/id/383410032021-04-023Condition entry · Essential hypertension · 2021-04-02urn:uuid:173c9663-2406-8025-843b-5f9b19c1b9f3 from ni:///sha-256;qryk4MG3hAJwf6mUdbw9UDLh84cFcozYJ3uA8qJmdKU, retrieved 2027-03-18T12:00:00Z, written by Larkspur Valley Health; urn:uuid:e3889c3a-faa3-8a4f-a9f6-84d1dd1d85a4 from ni:///sha-256;aRA8S5IYHGF9i7_EnT7Z741PL7GXrlEpgr-uMxFK6jY, retrieved 2026-09-01T10:00:00Z, written by Meridian Health System; urn:uuid:fb6ea0ec-3fbb-865c-a044-01b708d547f1 from ni:///sha-256;Cz5MtRwIZdqPndcnbRHYmSyV0ifFlAvMwatkhsAD_ho, retrieved 2026-10-14T15:40:00Z, written by Larkspur Valley Health
Low back painhttp://snomed.info/id/2790390072026-06-011Condition entry · Low back pain · 2026-06-01urn:uuid:fc149b2f-bf16-816b-8beb-04ccaff3eade from ni:///sha-256;EFb7AR24q2Lv88l_MdKSLxswBox0YR9tZBjaCH9Rn8Q, retrieved 2027-08-20T08:00:00Z, written by Meridian Health System

queries/questions/pod/My active conditions.rq on GitHub ↗