Skip to content
Alpha: see what works today →
Menu

Named question about pod

My reports, notes and documents

Read from the views as an app would, so a model reads what a report or a note says in its first answer: one row for each report and each note or document entry, newest first, never more, so its text is given once. Each row holds the entry's kind, date, time issued, name, title, status, content status, conclusion and text; every code it states, an IRI or, in another system, the code and its system; each attachment its records' current versions hold, by media type and title, a file the pod keeps but does not read, so a report sent only as a PDF says so; each result a report names, by its entry in the lab results view, with its test, value, unit, reference range and the interpretation flags its source gave it; and each record the entry joins, 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, and a list with nothing in it is unbound; a value's own parts are ended by ", ". A day and a time are not comparable, so entries are ordered by their day first, then by the time as written; an entry with no date by the time it was issued.

The query

PREFIX cascade: <https://ns.cascadeprotocol.org/cascade#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX obo: <http://purl.obolibrary.org/obo/>
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 ?date ?issued ?kind ?codes ?name ?title ?status ?contentStatus ?conclusion ?text ?attachments ?results ?entry
       ?entryLabel ?sources
WHERE {
  { SELECT ?entry ?entryLabel ?kind ?date ?issued ?name ?title ?status ?contentStatus ?conclusion ?text
           (REPLACE(CONCAT(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(STR(?reportCode), "\u001F"), ""); separator=""),
                           GROUP_CONCAT(DISTINCT COALESCE(CONCAT(STR(?reportOther), " in ", STR(DATATYPE(?reportOther)), "\u001F"), ""); separator=""),
                           GROUP_CONCAT(DISTINCT COALESCE(CONCAT(STR(?noteType), "\u001F"), ""); separator=""),
                           GROUP_CONCAT(DISTINCT COALESCE(CONCAT(STR(?noteOther), " in ", STR(DATATYPE(?noteOther)), "\u001F"), ""); separator="")),
                    "\u001F$", "") AS ?allCodes)
           (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?attachment, "\u001F"), ""); separator=""), "\u001F$", "") AS ?allAttachments)
    WHERE {
      { SELECT ?entry ?entryLabel ?kind ?date ?issued ?name ?title ?status ?contentStatus ?conclusion ?text ?reportCode ?reportOther
               ?noteType ?noteOther ?attachment
        WHERE {
          VALUES ?type { cascade:DiagnosticReport cascade:ClinicalNoteOrDocument }
          ?entry a ?type ; cascade:leadMember ?lead .
          ?lead cascade:recordKind ?kind .
          OPTIONAL { ?entry rdfs:label ?entryLabel }
          OPTIONAL { ?entry cascade:reportEffectiveTime ?reportDate }
          OPTIONAL { ?entry cascade:noteOrDocumentDate ?noteDate }
          BIND (COALESCE(?reportDate, ?noteDate) AS ?date)
          OPTIONAL { ?entry cascade:reportIssuedTime ?issued }
          OPTIONAL { ?entry cascade:reportName ?reportName }
          OPTIONAL { ?entry cascade:noteOrDocumentTypeName ?noteName }
          BIND (COALESCE(?reportName, ?noteName) AS ?name)
          OPTIONAL { ?entry cascade:noteOrDocumentTitle ?title }
          OPTIONAL { ?entry cascade:workflowStatus ?status }
          OPTIONAL { ?entry cascade:noteOrDocumentContentStatus ?contentStatus }
          OPTIONAL { ?entry cascade:reportConclusion ?conclusion }
          OPTIONAL { ?entry cascade:narrativeText ?text }
          OPTIONAL { ?entry cascade:reportCode ?reportCode }
          OPTIONAL { ?entry cascade:reportCodeInOtherSystem ?reportOther }
          OPTIONAL { ?entry cascade:noteOrDocumentTypeCode ?noteType }
          OPTIONAL { ?entry cascade:noteOrDocumentTypeCodeInOtherSystem ?noteOther }
          OPTIONAL { ?entry cascade:entryMember/pav:hasCurrentVersion/cascade:attachment ?attached .
                     ?attached cascade:attachmentContentType ?contentType .
                     OPTIONAL { ?attached cascade:attachmentTitle ?attachmentTitle }
                     BIND (CONCAT(?contentType, COALESCE(CONCAT(" ", ?attachmentTitle), "")) AS ?attachment) }
        }
        ORDER BY ?entry ?reportCode ?reportOther ?noteType ?noteOther ?attachment }
    }
    GROUP BY ?entry ?entryLabel ?kind ?date ?issued ?name ?title ?status ?contentStatus ?conclusion ?text }
  { SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?resultText, "\u001F"), ""); separator=""), "\u001F$", "") AS ?allResults)
    WHERE {
      { SELECT ?entry ?resultText
        WHERE {
          { SELECT ?entry ?result ?test ?value ?unit ?range
                   (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?flag, ", "), ""); separator=""), ", $", "") AS ?flags)
            WHERE {
              { SELECT ?entry ?result ?test ?value ?unit ?range ?flag
                WHERE {
                  VALUES ?type { cascade:DiagnosticReport cascade:ClinicalNoteOrDocument }
                  ?entry a ?type .
                  OPTIONAL { ?entry obo:RO_0002351 ?result .
                             OPTIONAL { ?result cascade:testName ?test }
                             OPTIONAL { ?result cascade:resultValueText ?value }
                             OPTIONAL { ?result cascade:resultUnitText ?unit }
                             OPTIONAL { ?result cascade:referenceRangeText ?range }
                             OPTIONAL { ?result cascade:resultInterpretationCode ?interpretation }
                             BIND (REPLACE(STR(?interpretation), "^.*/", "") AS ?flag) }
                }
                ORDER BY ?entry ?result ?flag }
            }
            GROUP BY ?entry ?result ?test ?value ?unit ?range }
          BIND (CONCAT(STR(?result), COALESCE(CONCAT(" ", ?test), ""), COALESCE(CONCAT(" ", ?value), ""),
                       COALESCE(CONCAT(" ", ?unit), ""), COALESCE(CONCAT(", reference range ", ?range), ""),
                       IF(?flags = "", "", CONCAT(", flagged ", ?flags))) AS ?resultText)
        }
        ORDER BY ?entry ?resultText }
    }
    GROUP BY ?entry }
  { SELECT ?entry (REPLACE(GROUP_CONCAT(DISTINCT CONCAT(?sourceText, "\u001F"); separator=""), "\u001F$", "") AS ?allSources)
    WHERE {
      { SELECT ?entry ?sourceText
        WHERE {
          { SELECT ?entry ?record ?document ?retrievedOn
                   (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?hospital, ", "), ""); separator=""), ", $", "") AS ?hospitals)
            WHERE {
              { SELECT ?entry ?record ?document ?retrievedOn ?hospital
                WHERE {
                  VALUES ?type { cascade:DiagnosticReport cascade:ClinicalNoteOrDocument }
                  ?entry a ?type ; cascade:entryMember ?record .
                  OPTIONAL { ?record 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 ?record ?document ?hospital }
            }
            GROUP BY ?entry ?record ?document ?retrievedOn }
          BIND (CONCAT(STR(?record), COALESCE(CONCAT(" from ", STR(?document)), ""),
                       COALESCE(CONCAT(", retrieved ", STR(?retrievedOn)), ""),
                       IF(?hospitals = "", "", CONCAT(", ", ?hospitals))) AS ?sourceText)
        }
        ORDER BY ?entry ?sourceText }
    }
    GROUP BY ?entry }
  BIND (IF(?allCodes = "", 1/0, ?allCodes) AS ?codes)
  BIND (IF(?allAttachments = "", 1/0, ?allAttachments) AS ?attachments)
  BIND (IF(?allResults = "", 1/0, ?allResults) AS ?results)
  BIND (?allSources AS ?sources)
}
ORDER BY DESC(COALESCE(SUBSTR(STR(COALESCE(?date, ?issued)), 1, 10), "")) DESC(COALESCE(STR(COALESCE(?date, ?issued)), "")) ?entry

Terms it reads

cascade:AuthorRole · cascade:ClinicalNoteOrDocument · cascade:CustodianRole · cascade:DiagnosticReport · cascade:attachmentContentType · cascade:attachmentTitle · cascade:currentRevision · cascade:entryMember · cascade:leadMember · cascade:narrativeText · cascade:noteOrDocumentContentStatus · cascade:noteOrDocumentDate · cascade:noteOrDocumentTitle · cascade:noteOrDocumentTypeCode · cascade:noteOrDocumentTypeCodeInOtherSystem · cascade:noteOrDocumentTypeName · cascade:recordKind · cascade:referenceRangeText · cascade:reportCode · cascade:reportCodeInOtherSystem · cascade:reportConclusion · cascade:reportEffectiveTime · cascade:reportIssuedTime · cascade:reportName · cascade:resultInterpretationCode · cascade:resultUnitText · cascade:resultValueText · cascade:testName · cascade:workflowStatus · obo:RO_0002351 · 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

Alex Rivera's pod gives this question no rows. Open it in Alex Rivera's explorer.

queries/questions/pod/My reports, notes and documents.rq on GitHub ↗