Ask the record by name.
A named question is a query an app or a model asks by name. Each row it returns cites the records behind it.
See it
pod/My active allergies
It returns one row for each allergy in Alex Rivera's pod that is active or has no stated status, however many hospitals sent it.
The rows it returns
| Allergen | Criticality | Status | Records | From |
|---|---|---|---|---|
| Latex | low | active | 1 | Meridian Health System |
| Peanuts | high | not stated | 1 | Alex, entered |
| Penicillin | high | active | 3 | Larkspur Valley Health (×2), Meridian Health System |
| Sulfamethoxazole | high | active | 3 | Meridian Health System, Larkspur Valley Health (×2) |
Read from the allergies view, where the penicillin records are one entry.
Show 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 ?allergen ?code ?criticality ?status ?reactionsByRecord (COUNT(?record) AS ?records) ?entry ?entryLabel ?sources
WHERE {
{ SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?memberText, "; "), ""); separator=""), "; $", "") 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, "; "); separator=""), "; $", "") 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:allergen ?allergen ; 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 rdfs:label ?entryLabel }
BIND (COALESCE(?stated, "not stated") AS ?status)
BIND (IF(?allReactions = "", 1/0, ?allReactions) AS ?reactionsByRecord)
}
GROUP BY ?entry ?allergen ?code ?criticality ?status ?reactionsByRecord ?entryLabel ?sources
ORDER BY ?allergen ?entry
Use it
Ask it from your app.
The same question, from the command line in an app made in Start building, or from code:
npm run ask -- --pod alex-rivera "pod/My active allergies"
const her = await openPod("pods/alex-rivera");
const rows = await her.ask("pod/My active allergies");
npm run ask with a name it doesn’t know lists every question. Guide: let an AI model ask them →
The two words
A view joins the records that say the same thing into one entry, so an allergy two hospitals both reported reads as one line.
A named question is a SPARQL query with a name; an app or a model asks it by name, and each row it returns cites its entry and its sources.