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
- C9. A condition its source refutes is an entry, ruled out, and an allergy so marked is still left out runtime/currency.feature
Its rows on Alex Rivera's pod
3 rows, as Alex Rivera's explorer shows them.
| condition | conditionCode | onset | records | entry | sources |
|---|---|---|---|---|---|
| Asthma | http:/ | 2008-09-01 | 2 | Condition entry · Asthma · 2008-09-01 | urn:uuid:3719cb66-c5be-8fac-a0bf-a6db7573fe71 from ni:/ |
| Essential hypertension | http:/ | 2021-04-02 | 3 | Condition entry · Essential hypertension · 2021-04-02 | urn:uuid:173c9663-2406-8025-843b-5f9b19c1b9f3 from ni:/ |
| Low back pain | http:/ | 2026-06-01 | 1 | Condition entry · Low back pain · 2026-06-01 | urn:uuid:fc149b2f-bf16-816b-8beb-04ccaff3eade from ni:/ |