Skip to content
Alpha: see what works today →
Menu

Named question about pod

The person this pod is about

Each hospital knows the person by a patient profile of its own, and About judgments tie those profiles to one subject, whom every record in a view is about. Read from the patient-profile view, as an app would: what each profile the view joins for the subject, a counting About tying it and no counting NotAbout outranking that, says of the person's date of birth, administrative gender, whether they have died and when, each value after the profile that states it, so sources that disagree are told apart and none is chosen; and each profile 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 ", ".

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 DISTINCT ?subject ?subjectLabel ?dateOfBirth ?administrativeGender ?deceased ?dateOfDeath ?sources
WHERE {
  { SELECT ?subject
           (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?birthText, "\u001F"), ""); separator=""), "\u001F$", "") AS ?births)
           (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?genderText, "\u001F"), ""); separator=""), "\u001F$", "") AS ?genders)
           (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?deceasedText, "\u001F"), ""); separator=""), "\u001F$", "") AS ?deaths)
           (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?deathDateText, "\u001F"), ""); separator=""), "\u001F$", "") AS ?deathDates)
    WHERE {
      { SELECT ?subject ?birthText ?genderText ?deceasedText ?deathDateText
        WHERE {
          ?subject a cascade:Subject .
          OPTIONAL {
            ?about cascade:countsUnderLens true ; cascade:verdict ?aboutVerdict ; prov:hadMember ?profile ;
                   cascade:subject ?subject .
            ?entry a ?entryKind ; cascade:memberCurrentValues ?values .
            ?values cascade:valuesOfMember ?profile .
            FILTER (?aboutVerdict = cascade:About && ?entryKind = cascade:PatientProfile)
            OPTIONAL { ?values cascade:dateOfBirth ?birth }
            OPTIONAL { ?values cascade:administrativeGender ?gender }
            OPTIONAL { ?values cascade:deceased ?dead }
            OPTIONAL { ?values cascade:dateOfDeath ?died }
          }
          BIND (CONCAT(STR(?profile), " ", STR(?birth)) AS ?birthText)
          BIND (CONCAT(STR(?profile), " ", ?gender) AS ?genderText)
          BIND (CONCAT(STR(?profile), " ", STR(?dead)) AS ?deceasedText)
          BIND (CONCAT(STR(?profile), " ", STR(?died)) AS ?deathDateText)
        }
        ORDER BY ?subject ?profile }
    }
    GROUP BY ?subject }
  { SELECT ?subject (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?sourceText, "\u001F"), ""); separator=""), "\u001F$", "")
                     AS ?allSources)
    WHERE {
      { SELECT ?subject ?sourceText
        WHERE {
          { SELECT ?subject ?sourceRecord ?document ?retrievedOn
                   (REPLACE(GROUP_CONCAT(DISTINCT COALESCE(CONCAT(?hospital, ", "), ""); separator=""), ", $", "") AS ?hospitals)
            WHERE {
              { SELECT ?subject ?sourceRecord ?document ?retrievedOn ?hospital
                WHERE {
                  ?subject a cascade:Subject .
                  OPTIONAL {
                    ?about cascade:countsUnderLens true ; cascade:verdict ?aboutVerdict ; prov:hadMember ?sourceRecord ;
                           cascade:subject ?subject .
                    ?entry a ?entryKind ; cascade:entryMember ?sourceRecord .
                    FILTER (?aboutVerdict = cascade:About && ?entryKind = cascade:PatientProfile)
                    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 ?subject ?sourceRecord ?document ?hospital }
            }
            GROUP BY ?subject ?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 ?subject ?sourceText }
    }
    GROUP BY ?subject }
  ?subject a cascade:Subject .
  OPTIONAL { ?subject rdfs:label ?subjectLabel }
  BIND (IF(?births = "", 1/0, ?births) AS ?dateOfBirth)
  BIND (IF(?genders = "", 1/0, ?genders) AS ?administrativeGender)
  BIND (IF(?deaths = "", 1/0, ?deaths) AS ?deceased)
  BIND (IF(?deathDates = "", 1/0, ?deathDates) AS ?dateOfDeath)
  BIND (IF(?allSources = "", 1/0, ?allSources) AS ?sources)
}
ORDER BY ?subject

Terms it reads

cascade:About · cascade:AuthorRole · cascade:CustodianRole · cascade:PatientProfile · cascade:Subject · cascade:administrativeGender · cascade:countsUnderLens · cascade:currentRevision · cascade:dateOfBirth · cascade:dateOfDeath · cascade:deceased · cascade:entryMember · cascade:memberCurrentValues · cascade:subject · cascade:valuesOfMember · cascade:verdict · pav:hasCurrentVersion · pav:retrievedOn · prov:agent · prov:hadMember · 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

1 row, as Alex Rivera's explorer shows them.

subjectsources
The person this pod is abouturn:uuid:5056e058-324f-8c70-b69b-fb27a061cdc5; urn:uuid:7883c5a4-6c61-837c-9bf7-dbe1b37d89ff; urn:uuid:d461e692-842c-8a30-a8ba-940a908c8cab

queries/questions/pod/The person this pod is about.rq on GitHub ↗