Skip to content
Alpha: see what works today →
Menu

Labels query

labels

A name for every record, version, revision, document, judgment, retraction, reference version, entry and patient profile, made from what each says: its kind, its name, where it came from and when; a matcher judgment, which gives no time, by the start of its name instead. Names only help people read; nothing depends on them. An entry is labelled as the view holding it names it: a view is built before this file, and its graph holds each entry resolved against the view's address (N13), so the placeholder only the derived state holds is never labelled.

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#>

CONSTRUCT { ?thing rdfs:label ?label }
WHERE {
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing cascade:recordKind ?kind ; pav:hasCurrentVersion ?v ; cascade:currentRevision ?r .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?v cascade:displayName ?name }
      OPTIONAL { ?r prov:wasDerivedFrom ?doc }
      OPTIONAL { ?r prov:wasDerivedFrom/pav:retrievedFrom ?from }
      OPTIONAL { ?r prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?authorVia .
                 ?authorVia prov:hadRole ?authorRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?authorName
                 FILTER (?authorRole = cascade:AuthorRole) }
      OPTIONAL { ?r prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?custodianVia .
                 ?custodianVia prov:hadRole ?custodianRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?custodianName
                 FILTER (?custodianRole = cascade:CustodianRole) }
      BIND (COALESCE(?authorName, ?custodianName) AS ?author)
      OPTIONAL { ?r prov:generatedAtTime ?t }
      BIND (CONCAT(?kind, " · ", COALESCE(?name, "no name"), " · ",
                   COALESCE(CONCAT(?author, " · ", REPLACE(STR(?from), "^.*/", "")),
                            CONCAT(?author, " · received ", SUBSTR(STR(?t), 1, 10)),
                            ?author,
                            IF(BOUND(?doc), "unknown source", "own entry"))) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing prov:specializationOf/cascade:recordKind ?kind .
      ?revision cascade:version ?thing ; prov:generatedAtTime ?t .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?thing cascade:displayName ?name }
      OPTIONAL { ?thing cascade:clinicalStatus|cascade:workflowStatus ?status }
      OPTIONAL { ?thing cascade:verificationStatus ?verification }
      OPTIONAL { ?thing cascade:allergyCriticality ?c }
      OPTIONAL { ?thing cascade:displayDate ?date }
      OPTIONAL { ?revision prov:wasDerivedFrom ?doc }
      OPTIONAL { ?revision prov:wasDerivedFrom/pav:retrievedFrom ?from }
      OPTIONAL { ?revision prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?authorVia .
                 ?authorVia prov:hadRole ?authorRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?authorName
                 FILTER (?authorRole = cascade:AuthorRole) }
      OPTIONAL { ?revision prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?custodianVia .
                 ?custodianVia prov:hadRole ?custodianRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?custodianName
                 FILTER (?custodianRole = cascade:CustodianRole) }
      BIND (COALESCE(?authorName, ?custodianName) AS ?author)
      BIND (CONCAT(?kind, " version · ", COALESCE(?name, "no name"), " · ",
                   COALESCE(IF(?verification = "refuted", "ruled out", ?status), ?status, ?verification, CONCAT("criticality ", ?c), STR(?date), "nothing stated"), " · ",
                   COALESCE(REPLACE(STR(?from), "^.*/", ""), ?author, IF(BOUND(?doc), "unknown source", "own entry")),
                   " · first received ", SUBSTR(STR(?t), 1, 10)) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing a cascade:Revision ; cascade:version ?v ; prov:generatedAtTime ?t .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?v cascade:displayName ?name }
      OPTIONAL { ?thing prov:wasDerivedFrom ?doc }
      OPTIONAL { ?thing prov:wasDerivedFrom/pav:retrievedFrom ?from }
      OPTIONAL { ?thing prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?authorVia .
                 ?authorVia prov:hadRole ?authorRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?authorName
                 FILTER (?authorRole = cascade:AuthorRole) }
      OPTIONAL { ?thing prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?custodianVia .
                 ?custodianVia prov:hadRole ?custodianRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?custodianName
                 FILTER (?custodianRole = cascade:CustodianRole) }
      BIND (COALESCE(?authorName, ?custodianName) AS ?author)
      BIND (CONCAT("Revision · ", COALESCE(?name, "no name"), " · ",
                   COALESCE(REPLACE(STR(?from), "^.*/", ""), ?author, IF(BOUND(?doc), "unknown source", "own entry")),
                   " · received ", SUBSTR(STR(?t), 1, 10)) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      { SELECT DISTINCT ?thing WHERE { ?revision a cascade:Revision ; prov:wasDerivedFrom ?thing } }
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?thing prov:wasGeneratedBy/prov:qualifiedAssociation ?authorVia .
                 ?authorVia prov:hadRole ?authorRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?authorName
                 FILTER (?authorRole = cascade:AuthorRole) }
      OPTIONAL { ?thing prov:wasGeneratedBy/prov:qualifiedAssociation ?custodianVia .
                 ?custodianVia prov:hadRole ?custodianRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?custodianName
                 FILTER (?custodianRole = cascade:CustodianRole) }
      BIND (COALESCE(?authorName, ?custodianName) AS ?author)
      OPTIONAL { ?thing pav:retrievedFrom ?from }
      OPTIONAL { ?thing pav:retrievedOn ?on }
      BIND (CONCAT("Document · ", COALESCE(?author, "unknown source"),
                   COALESCE(CONCAT(" · ", REPLACE(STR(?from), "^.*/([^/]+/[^/]+)$", "$1")), ""),
                   COALESCE(CONCAT(" · retrieved ", SUBSTR(STR(?on), 1, 10)), "")) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing a prov:Entity .
      FILTER NOT EXISTS { ?thing prov:specializationOf [] }
      FILTER NOT EXISTS { ?thing a cascade:Revision }
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?thing prov:wasGeneratedBy/prov:qualifiedAssociation ?authorVia .
                 ?authorVia prov:hadRole ?authorRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?authorName
                 FILTER (?authorRole = cascade:AuthorRole) }
      OPTIONAL { ?thing prov:wasGeneratedBy/prov:qualifiedAssociation ?custodianVia .
                 ?custodianVia prov:hadRole ?custodianRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?custodianName
                 FILTER (?custodianRole = cascade:CustodianRole) }
      BIND (COALESCE(?authorName, ?custodianName) AS ?author)
      OPTIONAL { ?thing pav:retrievedFrom ?from }
      OPTIONAL { ?thing pav:retrievedOn ?on }
      BIND (CONCAT("Document · ", COALESCE(?author, "unknown source"),
                   COALESCE(CONCAT(" · ", REPLACE(STR(?from), "^.*/([^/]+/[^/]+)$", "$1")), ""),
                   COALESCE(CONCAT(" · retrieved ", SUBSTR(STR(?on), 1, 10)), "")) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      { SELECT ?who (MIN(?name) AS ?machine)
        WHERE {
          { SELECT DISTINCT ?who WHERE { ?judgment a cascade:Judgment ; prov:wasAttributedTo ?who } }
          OPTIONAL { ?who rdfs:label ?name }
        }
        GROUP BY ?who }
      ?thing a cascade:Judgment ; prov:wasAttributedTo ?who .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?thing prov:generatedAtTime ?t }
      OPTIONAL { ?thing cascade:verdict ?verdict }
      OPTIONAL { ?thing prov:wasGeneratedBy/prov:qualifiedAssociation [ prov:agent ?who ; prov:hadRole ?role ] }
      OPTIONAL { ?thing prov:hadMember/^prov:specializationOf/cascade:displayName ?about }
      BIND (CONCAT(REPLACE(STR(?verdict), "^.*#", ""), " · ",
                   COALESCE(?machine, IF(?role = cascade:PatientRole, "the patient", "a person")), " · ",
                   IF(BOUND(?t), SUBSTR(STR(?t), 1, 10), SUBSTR(REPLACE(STR(?thing), "^.*[:/#]", ""), 1, 8)), " · ",
                   COALESCE(?about, "a patient profile")) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing a prov:Activity ; prov:invalidated ?retracted .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?thing prov:wasAssociatedWith ?who
                 OPTIONAL { ?who rdfs:label ?named }
                 OPTIONAL { ?thing prov:qualifiedAssociation [ prov:agent ?who ; prov:hadRole ?role ] } }
      OPTIONAL { ?thing prov:startedAtTime ?t }
      OPTIONAL { ?retracted cascade:assertedJudgment?/cascade:verdict ?retractedVerdict }
      OPTIONAL { ?retracted cascade:assertedJudgment?/prov:hadMember/^prov:specializationOf/cascade:displayName ?retractedAbout }
      BIND (CONCAT("Retraction · ",
                   COALESCE(?named, IF(BOUND(?who), IF(BOUND(?role) && ?role = cascade:PatientRole, "the patient", "a person"), "a release")), " · ",
                   IF(BOUND(?t), SUBSTR(STR(?t), 1, 10), SUBSTR(REPLACE(STR(?thing), "^.*[:/#]", ""), 1, 8)), " · of ",
                   COALESCE(REPLACE(STR(?retractedVerdict), "^.*#", ""), "a judgment"), " · ",
                   COALESCE(?retractedAbout, "a patient profile")) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing prov:specializationOf ?series ; pav:version ?version .
      ?series a cascade:ReferenceSeries ; rdfs:label ?name .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      BIND (CONCAT(?name, " · ", ?version) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      GRAPH ?view { ?view a cascade:View . ?thing cascade:leadMember ?lead }
      ?lead cascade:recordKind ?kind .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?lead pav:hasCurrentVersion/cascade:displayName ?name }
      OPTIONAL { ?lead cascade:inEntry/cascade:dateFrom/pav:hasCurrentVersion/cascade:displayDate ?date }
      BIND (CONCAT(?kind, " entry", COALESCE(CONCAT(" · ", ?name), ""), COALESCE(CONCAT(" · ", STR(?date)), "")) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      GRAPH ?view { ?view a cascade:View . ?thing a cascade:PatientProfile ; cascade:entryMember [] }
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      BIND ("Patient entry" AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?version cascade:patient ?thing .
      ?revision cascade:version ?version ; prov:generatedAtTime ?t .
      FILTER NOT EXISTS { ?thing a cascade:Subject }
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      OPTIONAL { ?revision prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?authorVia .
                 ?authorVia prov:hadRole ?authorRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?authorName
                 FILTER (?authorRole = cascade:AuthorRole) }
      OPTIONAL { ?revision prov:wasDerivedFrom/prov:wasGeneratedBy/prov:qualifiedAssociation ?custodianVia .
                 ?custodianVia prov:hadRole ?custodianRole ; prov:agent/(rdfs:label|pav:hasCurrentVersion/foaf:name) ?custodianName
                 FILTER (?custodianRole = cascade:CustodianRole) }
      BIND (COALESCE(?authorName, ?custodianName) AS ?author)
      BIND (CONCAT("Patient profile · ", COALESCE(?author, "unknown source"),
                   " · first received ", SUBSTR(STR(?t), 1, 10)) AS ?l)
    }
    GROUP BY ?thing }
  UNION
  { SELECT ?thing (MIN(?l) AS ?label)
    WHERE {
      ?thing a cascade:Subject .
      FILTER NOT EXISTS { ?thing rdfs:label [] }
      BIND ("The person this pod is about" AS ?l)
    }
    GROUP BY ?thing }
}

Terms it reads

cascade:AuthorRole · cascade:CustodianRole · cascade:Judgment · cascade:PatientProfile · cascade:PatientRole · cascade:ReferenceSeries · cascade:Revision · cascade:Subject · cascade:View · cascade:allergyCriticality · cascade:assertedJudgment · cascade:clinicalStatus · cascade:currentRevision · cascade:displayDate · cascade:displayName · cascade:entryMember · cascade:inEntry · cascade:leadMember · cascade:patient · cascade:recordKind · cascade:verdict · cascade:verificationStatus · cascade:version · cascade:workflowStatus · pav:hasCurrentVersion · pav:retrievedFrom · pav:retrievedOn · pav:version · prov:Activity · prov:Entity · prov:agent · prov:generatedAtTime · prov:hadMember · prov:hadRole · prov:invalidated · prov:qualifiedAssociation · prov:specializationOf · prov:startedAtTime · prov:wasAssociatedWith · prov:wasAttributedTo · prov:wasDerivedFrom · 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 query no rows. Open it in Alex Rivera's explorer.

queries/labels.rq on GitHub ↗