Skip to content
Alpha: see what works today →
Menu

Table query

panel-results

The lab results of the person in each LOINC panel that lists one of them, by the panel members rows of the tables an app holds, with the required members they have no result for. It reads the entries of the views, as the pod questions do, and the rows inside GRAPH ?origin, as a rule's query does. A lab result entry is one with a test code; its code is ?member. Nothing here says a result was drawn in a panel: a page asks of the one panel the person picked, by ?panel, and the rows are the panel's view of what the person has.

?panel reaches ?member through the row of ?via, which lists ?member at ?sequence and gives its ?required as LOINC writes it (R, O, C, R-a, Rflx or Rflx-a), unbound where LOINC gives none. ?via is ?panel itself or a panel nested in it at any depth, each nested panel being a member row of its parent. ?origin is the panel members version, and ?entry the person's entry for ?member. Every panel that lists one of the person's results, directly or through nesting, is returned.

A member is missing when the person has no entry for it, its row requires it (R), it is not itself a panel (its own members are listed instead), and every row on the way from ?panel down to ?via says R: a nested panel's members are required in its parent only when the parent's row for it says so. A row that gives O, C or no requirement passes nothing up, since LOINC saying nothing is not a requirement, so the electrolytes inside a comprehensive metabolic panel are missing only when the electrolytes panel is the one picked. A missing member is a row with ?entry unbound and ?required "R". R-a marks one of several alternatives, and the rows do not say which go together, so an alternative is never said to be missing; an optional member with no entry is no row.

The query

PREFIX cascade: <https://ns.cascadeprotocol.org/cascade#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT DISTINCT ?panel ?member ?sequence ?required ?via ?origin ?entry
WHERE {
  {
    ?entry cascade:testCode ?member ; cascade:leadMember ?lead .
    ?origin prov:specializationOf/cascade:tableKind cascade:PanelMembers .
    GRAPH ?origin {
      ?row owl:annotatedSource ?via ; owl:annotatedTarget ?member ; cascade:panelSequence ?sequence .
      OPTIONAL { ?row cascade:observationRequiredInPanel ?required }
      ?via (^owl:annotatedTarget/owl:annotatedSource)* ?panel .
    }
  } UNION {
    { SELECT DISTINCT ?panel ?origin
      WHERE {
        ?held cascade:testCode ?code ; cascade:leadMember ?last .
        ?origin prov:specializationOf/cascade:tableKind cascade:PanelMembers .
        GRAPH ?origin { ?listed owl:annotatedTarget ?code ; owl:annotatedSource ?lister .
                        ?lister (^owl:annotatedTarget/owl:annotatedSource)* ?panel }
      } }
    GRAPH ?origin {
      ?panel (^owl:annotatedSource/owl:annotatedTarget)* ?via .
      ?row owl:annotatedSource ?via ; owl:annotatedTarget ?member ; cascade:panelSequence ?sequence ;
           cascade:observationRequiredInPanel "R" .
      FILTER NOT EXISTS { ?nested owl:annotatedSource ?member }
      MINUS {
        ?link owl:annotatedSource ?above ; owl:annotatedTarget ?below .
        ?below (^owl:annotatedSource/owl:annotatedTarget)* ?via .
        ?above (^owl:annotatedTarget/owl:annotatedSource)* ?panel .
        FILTER NOT EXISTS { ?link cascade:observationRequiredInPanel "R" }
      }
    }
    FILTER NOT EXISTS { ?entry cascade:testCode ?member ; cascade:leadMember ?lead }
    BIND ("R" AS ?required)
  }
}
ORDER BY ?panel ?via ?sequence ?member ?entry

Terms it reads

cascade:PanelMembers · cascade:leadMember · cascade:observationRequiredInPanel · cascade:panelSequence · cascade:testCode · owl:annotatedSource · owl:annotatedTarget · prov:specializationOf

Rules and decision notes that name it

No rule or decision note writes its path.

queries/tables/panel-results.rq on GitHub ↗