Skip to content
Alpha: see what works today →
Menu

Derivation

status-sources

An entry takes its status from a member that states one, chosen as the lead is from the members' current revisions: of those at the latest source change time, with those carrying none, the greatest cascade:observedAsOf beside those a ClockDiscounted leaves carrying none, then the least IRI. A kind whose status comes only from documents, as an allergy's does, never takes it from a member the person entered. A member states a status by its clinical status or its workflow status, and also by a verification status of refuted, which rules the record out.

The query

PREFIX cascade: <https://ns.cascadeprotocol.org/cascade#>
PREFIX pav: <http://purl.org/pav/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

CONSTRUCT { ?entry cascade:statusFrom ?from }
WHERE {
  { SELECT ?entry (IRI(MIN(STR(?r))) AS ?from)
    WHERE {
      { SELECT ?entry ?latest (MAX(?seen1) AS ?seen)
        WHERE {
          { SELECT ?entry (MAX(COALESCE(?changed2, "0001-01-01T00:00:00Z"^^xsd:dateTime)) AS ?latest)
            WHERE {
              ?r2 cascade:inEntry ?entry ; cascade:statusOnlyFromDocuments ?documentsOnly2 ;
                  cascade:currentRevision ?rev2 ; pav:hasCurrentVersion ?version2 .
              OPTIONAL { ?version2 cascade:clinicalStatus|cascade:workflowStatus ?stated2 }
              OPTIONAL { ?version2 cascade:verificationStatus ?ruledOut2 FILTER (?ruledOut2 = "refuted") }
              FILTER (BOUND(?stated2) || BOUND(?ruledOut2))
              FILTER (!?documentsOnly2 || EXISTS { ?rev2 prov:wasDerivedFrom [] })
              OPTIONAL { ?rev2 pav:lastUpdateOn ?changed2 }
            }
            GROUP BY ?entry }
          ?r1 cascade:inEntry ?entry ; cascade:statusOnlyFromDocuments ?documentsOnly1 ;
              cascade:currentRevision ?rev1 ; pav:hasCurrentVersion ?version1 .
          OPTIONAL { ?version1 cascade:clinicalStatus|cascade:workflowStatus ?stated1 }
          OPTIONAL { ?version1 cascade:verificationStatus ?ruledOut1 FILTER (?ruledOut1 = "refuted") }
          FILTER (BOUND(?stated1) || BOUND(?ruledOut1))
          ?rev1 cascade:observedAsOf ?observed1 .
          OPTIONAL { ?rev1 cascade:observationTimeDiscountedBy ?discount1 }
          BIND (IF(BOUND(?discount1), "0001-01-01T00:00:00Z"^^xsd:dateTime, ?observed1) AS ?seen1)
          FILTER (!?documentsOnly1 || EXISTS { ?rev1 prov:wasDerivedFrom [] })
          OPTIONAL { ?rev1 pav:lastUpdateOn ?changed1 }
          FILTER (!BOUND(?changed1) || ?changed1 = ?latest)
        }
        GROUP BY ?entry ?latest }
      ?r cascade:inEntry ?entry ; cascade:statusOnlyFromDocuments ?documentsOnly ;
         cascade:currentRevision ?rev ; pav:hasCurrentVersion ?version .
      OPTIONAL { ?version cascade:clinicalStatus|cascade:workflowStatus ?stated }
      OPTIONAL { ?version cascade:verificationStatus ?ruledOut FILTER (?ruledOut = "refuted") }
      FILTER (BOUND(?stated) || BOUND(?ruledOut))
      ?rev cascade:observedAsOf ?observed .
      OPTIONAL { ?rev cascade:observationTimeDiscountedBy ?discount }
      FILTER (?observed = ?seen || BOUND(?discount))
      FILTER (!?documentsOnly || EXISTS { ?rev prov:wasDerivedFrom [] })
      OPTIONAL { ?rev pav:lastUpdateOn ?changed }
      FILTER (!BOUND(?changed) || ?changed = ?latest)
    }
    GROUP BY ?entry }
}

Terms it reads

cascade:clinicalStatus · cascade:currentRevision · cascade:inEntry · cascade:observationTimeDiscountedBy · cascade:observedAsOf · cascade:statusFrom · cascade:statusOnlyFromDocuments · cascade:verificationStatus · cascade:workflowStatus · pav:hasCurrentVersion · pav:lastUpdateOn · prov:wasDerivedFrom

Rules and decision notes that name it

queries/derivations/status-sources.rq on GitHub ↗