Skip to content
Alpha: see what works today →
Menu

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.

allergenNamecodecriticalitystatuscategoryreactionsByRecordrecordsentrysourcesonset
Latexhttp://snomed.info/id/111088007lowactiveenvironmenturn:uuid:b28ee795-dd4b-8fae-95cb-fe95c9a908cd Contact dermatitis1Allergy entry · Latexurn:uuid:b28ee795-dd4b-8fae-95cb-fe95c9a908cd from ni:///sha-256;KhxSx-TIKeJLC0RLZBluu78zuUIk67LG7SRAjvIL3Bc, retrieved 2026-11-20T09:00:00Z, written by Meridian Health System
Peanutshighnot statedurn:uuid:1cf6cca9-1098-8ca1-9155-ad7048360146 Anaphylaxis1Allergy entry · Peanutsurn:uuid:1cf6cca9-1098-8ca1-9155-ad7048360146
Penicillinhttp://snomed.info/id/373270004highactivemedicationurn:uuid:0f282f2d-4ceb-897a-bdb8-750d6e25db2d Hives; urn:uuid:58e34d36-550a-882e-b43a-9225dbdce037 Hives; urn:uuid:69961a65-6383-84b7-96f1-0a88fb755c9c Hives3Allergy entry · Penicillinurn:uuid:0f282f2d-4ceb-897a-bdb8-750d6e25db2d from ni:///sha-256;QikKI44xZW8VbEs_UoN0xtF7wzhrF4TqXE2vwyoQTnw, retrieved 2026-10-14T15:40:00Z, written by Larkspur Valley Health; urn:uuid:58e34d36-550a-882e-b43a-9225dbdce037 from ni:///sha-256;PHGfdoVLMSugnCba9doA7_kfDyJ32abX9loelLpSZDQ, retrieved 2027-03-18T12:00:00Z, written by Larkspur Valley Health; urn:uuid:69961a65-6383-84b7-96f1-0a88fb755c9c from ni:///sha-256;KTBUa0_qvJ_3g2Vz7C4my_-C-9jkahpzl8IOoJ4Bchs, retrieved 2026-09-01T10:00:00Z, written by Meridian Health System2019-06-14
Sulfamethoxazolehttps://ns.cascadeprotocol.org/codes/rxnorm/10180highactivemedicationurn:uuid:5a16d5f4-34b0-8fb6-9f5c-59b37aa6d4dc Itching, Rash; urn:uuid:828f3452-da1d-83e7-9fd4-23f49d355848 Hives; urn:uuid:b0492421-a1b7-8de4-817e-8940bf97f7df Hives3Allergy entry · Sulfamethoxazoleurn:uuid:5a16d5f4-34b0-8fb6-9f5c-59b37aa6d4dc from ni:///sha-256;aR9fwxPZ7i91Kw5BYYU_04tPlRZ3tAGAF_hMLFE7vBY, retrieved 2026-11-20T09:00:00Z, written by Meridian Health System; urn:uuid:828f3452-da1d-83e7-9fd4-23f49d355848 from ni:///sha-256;4In_oVrmJrT2srA1AoevBN_tcXIim5nfwyGNV_erII8, retrieved 2027-03-18T12:00:00Z, written by Larkspur Valley Health; urn:uuid:b0492421-a1b7-8de4-817e-8940bf97f7df from ni:///sha-256;Nzy98Fl4yOkQKqm5dNA_GBNn1TAlLc98ehXPsXYwG8A, retrieved 2026-10-14T15:40:00Z, written by Larkspur Valley Health2022-05-03

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