Skip to content
Alpha: see what works today →
Menu

Named question about pod

My condition history

Read from the view alone, as an app would: each condition entry whatever its status, with its codes, its status, when it started and when it ended, each record's own status, each entry given for it as `pod/My active conditions` lists them ("<entry>, <name>", the entry IRI alone when it has no name, in code point order of name, then entry, and with a medication entered in error left out), 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. The status is "ruled out" when the record the entry took its status from is refuted, whatever its clinical status, so a condition that was considered and refuted is never read as one that resolved; otherwise it is that record's clinical status, or none when it states none, and an entry ruled out has no abatement day. The verification status is as the source writes it. The entries whose status is active and not ruled out are the ones `pod/My active conditions` lists. A record's own status is its clinical status, "ruled out" alone when it is refuted; the day it abated follows a clinical status, never "ruled out". A list holds its values in order, separated by U+001F; a value's own parts are ended 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 ?status ?verificationStatus ?onset ?abated ?statuses ?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(?statusText, "\u001F"); separator=""), "\u001F$", "") AS ?statuses)
    WHERE {
      { SELECT ?entry ?statusText
        WHERE {
          ?entry a cascade:ProblemOrDiagnosis ; cascade:memberCurrentValues ?values .
          ?values cascade:valuesOfMember ?member .
          OPTIONAL { ?values cascade:clinicalStatus ?memberClinicalStatus }
          OPTIONAL { ?values cascade:verificationStatus ?memberVerificationStatus }
          OPTIONAL { ?values cascade:abatementDate ?memberAbated }
          BIND (BOUND(?memberVerificationStatus) && ?memberVerificationStatus = "refuted" AS ?memberRuledOut)
          BIND (CONCAT(STR(?member), " ",
                       IF(?memberRuledOut, "ruled out", COALESCE(?memberClinicalStatus, "with no status")),
                       IF(?memberRuledOut, "", COALESCE(CONCAT(", abated ", STR(?memberAbated)), ""))) AS ?statusText)
        }
        ORDER BY ?entry ?statusText }
    }
    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: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:ProblemOrDiagnosis ; cascade:conditionName ?condition ; cascade:entryMember ?record .
  OPTIONAL { ?entry cascade:clinicalStatus ?clinicalStatus }
  OPTIONAL { ?entry cascade:verificationStatus ?verificationStatus }
  OPTIONAL {
    ?entry cascade:conditionCode ?conditionCode .
    FILTER NOT EXISTS {
      ?entry cascade:conditionCode ?earlier .
      FILTER (STR(?earlier) < STR(?conditionCode))
    }
  }
  OPTIONAL { ?entry cascade:onsetDate ?onset }
  OPTIONAL { ?entry cascade:abatementDate ?abated
             FILTER NOT EXISTS { ?entry cascade:verificationStatus "refuted" } }
  OPTIONAL { ?entry rdfs:label ?entryLabel }
  BIND (IF(BOUND(?verificationStatus) && ?verificationStatus = "refuted", "ruled out", ?clinicalStatus) AS ?status)
  BIND (IF(?forIt = "", ?nothing, ?forIt) AS ?entriesForIt)
}
GROUP BY ?entry ?condition ?conditionCode ?status ?verificationStatus ?onset ?abated ?entryLabel ?statuses ?entriesForIt ?sources
ORDER BY ?condition ?entry

Terms it reads

cascade:AuthorRole · cascade:CustodianRole · cascade:MedicationEnteredInError · cascade:ProblemOrDiagnosis · cascade:abatementDate · 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:valuesOfMember · 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

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

conditionconditionCodestatusverificationStatusonsetabatedstatusesrecordsentrysources
Acute bronchitishttp://snomed.info/id/10509002resolvedconfirmed2026-08-122026-09-20urn:uuid:427f6a98-faf9-8e37-bd5d-6dca2a812580 resolved, abated 2026-09-201Condition entry · Acute bronchitis · 2026-08-12urn:uuid:427f6a98-faf9-8e37-bd5d-6dca2a812580 from ni:///sha-256;bX2lWmFFhM9GXagC-zoAMoV_w_8c4PxXI2u3y35J8aI, retrieved 2026-11-20T09:00:00Z, written by Meridian Health System
Asthmahttp://snomed.info/id/195967001activeconfirmed2008-09-01urn:uuid:3719cb66-c5be-8fac-a0bf-a6db7573fe71 active; urn:uuid:fdf1589d-bc02-8c0f-8874-4d377574cc8d active2Condition 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/38341003activeconfirmed2021-04-02urn:uuid:173c9663-2406-8025-843b-5f9b19c1b9f3 active; urn:uuid:e3889c3a-faa3-8a4f-a9f6-84d1dd1d85a4 active; urn:uuid:fb6ea0ec-3fbb-865c-a044-01b708d547f1 active3Condition 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/279039007activeconfirmed2026-06-01urn:uuid:fc149b2f-bf16-816b-8beb-04ccaff3eade active1Condition 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 condition history.rq on GitHub ↗