Named question about pod
My active allergies
Read from the view alone, as an app would: each entry whose status is active, or that no document gives a status (its status then reads "not stated"), with its code, its criticality, its category and onset as its lead states them, else as the members chosen for them do, how many records it joins, what each record states of the reaction, 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. A record's reactions are its reaction texts, then its reaction codes in parentheses, then its severity, each as the record's current values state them, so a record that is not the entry's lead is read as much as the lead. A list holds its values in order, separated by U+001F, a record stating none of them is left out, and a list with nothing in it is unbound; a value's own parts are ended by ", ".
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 ?allergenName ?code ?criticality ?status ?category ?onset ?reactionsByRecord (COUNT(?record) AS ?records) ?entry ?entryLabel ?sources
WHERE {
{ SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?memberText, "\u001F"), ""); separator=""), "\u001F$", "") AS ?allReactions)
WHERE {
{ SELECT ?entry ?memberText
WHERE {
{ SELECT ?entry ?member (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?reactionText, ", "), ""); separator=""), ", $", "") AS ?texts)
WHERE {
{ SELECT ?entry ?member ?reactionText
WHERE {
?entry a cascade:AllergyOrIntolerance ; cascade:memberCurrentValues ?textValues .
FILTER NOT EXISTS { ?entry cascade:clinicalStatus ?other FILTER (?other != "active") }
?textValues cascade:valuesOfMember ?member .
OPTIONAL { ?textValues cascade:reactionManifestationText ?reactionText }
}
ORDER BY ?entry ?member ?reactionText }
}
GROUP BY ?entry ?member }
{ SELECT ?entry ?member (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(STR(?memberCode), ", "), ""); separator=""), ", $", "") AS ?codes)
WHERE {
{ SELECT ?entry ?member ?memberCode
WHERE {
?entry a cascade:AllergyOrIntolerance ; cascade:memberCurrentValues ?codeValues .
FILTER NOT EXISTS { ?entry cascade:clinicalStatus ?other FILTER (?other != "active") }
?codeValues cascade:valuesOfMember ?member .
OPTIONAL { ?codeValues cascade:reactionManifestationCode ?memberCode }
}
ORDER BY ?entry ?member ?memberCode }
}
GROUP BY ?entry ?member }
?entry cascade:memberCurrentValues ?severityValues .
?severityValues cascade:valuesOfMember ?member .
OPTIONAL { ?severityValues cascade:allergySeverity ?memberSeverity }
BIND (IF(?texts = "" && ?codes = "" && !BOUND(?memberSeverity), 1/0,
CONCAT(STR(?member),
IF(?texts = "", "", CONCAT(" ", ?texts)),
IF(?codes = "", "", CONCAT(" (", ?codes, ")")),
COALESCE(CONCAT(", ", ?memberSeverity), ""))) AS ?memberText)
}
ORDER BY ?entry ?memberText }
}
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:AllergyOrIntolerance ; cascade:entryMember ?sourceRecord .
FILTER NOT EXISTS { ?entry cascade:clinicalStatus ?other FILTER (?other != "active") }
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:AllergyOrIntolerance ;
cascade:allergenName ?allergenName ; cascade:entryMember ?record .
OPTIONAL { ?entry cascade:clinicalStatus ?stated }
FILTER (!BOUND(?stated) || ?stated = "active")
OPTIONAL { ?entry cascade:allergenCode ?code }
OPTIONAL { ?entry cascade:allergyCriticality ?criticality }
OPTIONAL { ?entry cascade:allergyCategory ?category }
OPTIONAL { ?entry cascade:onsetDate ?onset }
OPTIONAL { ?entry rdfs:label ?entryLabel }
BIND (COALESCE(?stated, "not stated") AS ?status)
BIND (IF(?allReactions = "", 1/0, ?allReactions) AS ?reactionsByRecord)
}
GROUP BY ?entry ?allergenName ?code ?criticality ?status ?category ?onset ?reactionsByRecord ?entryLabel ?sources
ORDER BY ?allergenName ?entry ?code
Terms it reads
cascade:AllergyOrIntolerance · cascade:AuthorRole · cascade:CustodianRole · cascade:allergenCode · cascade:allergenName · cascade:allergyCategory · cascade:allergyCriticality · cascade:allergySeverity · cascade:clinicalStatus · cascade:currentRevision · cascade:entryMember · cascade:memberCurrentValues · cascade:onsetDate · cascade:reactionManifestationCode · cascade:reactionManifestationText · cascade:valuesOfMember · 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
4 rows, as Alex Rivera's explorer shows them.
| allergenName | code | criticality | status | category | reactionsByRecord | records | entry | sources | onset |
|---|---|---|---|---|---|---|---|---|---|
| Latex | http:/ | low | active | environment | urn:uuid:b28ee795-dd4b-8fae-95cb-fe95c9a908cd Contact dermatitis | 1 | Allergy entry · Latex | urn:uuid:b28ee795-dd4b-8fae-95cb-fe95c9a908cd from ni:/ | |
| Peanuts | high | not stated | urn:uuid:1cf6cca9-1098-8ca1-9155-ad7048360146 Anaphylaxis | 1 | Allergy entry · Peanuts | urn:uuid:1cf6cca9-1098-8ca1-9155-ad7048360146 | |||
| Penicillin | http:/ | high | active | medication | urn:uuid:0f282f2d-4ceb-897a-bdb8-750d6e25db2d Hives; urn:uuid:58e34d36-550a-882e-b43a-9225dbdce037 Hives; urn:uuid:69961a65-6383-84b7-96f1-0a88fb755c9c Hives | 3 | Allergy entry · Penicillin | urn:uuid:0f282f2d-4ceb-897a-bdb8-750d6e25db2d from ni:/ | 2019-06-14 |
| Sulfamethoxazole | https:/ | high | active | medication | urn:uuid:5a16d5f4-34b0-8fb6-9f5c-59b37aa6d4dc Itching, Rash; urn:uuid:828f3452-da1d-83e7-9fd4-23f49d355848 Hives; urn:uuid:b0492421-a1b7-8de4-817e-8940bf97f7df Hives | 3 | Allergy entry · Sulfamethoxazole | urn:uuid:5a16d5f4-34b0-8fb6-9f5c-59b37aa6d4dc from ni:/ | 2022-05-03 |