Cascade queries
Every query cascade-vocabulary publishes, by kind: what it is for, as its file says, its text, the terms it reads, and, for a named question or a view, its rows on Alex Rivera's example pod. The queries are read from queries/.
Named questions · Views · Labels · Matcher rules · Derivations · Lenses · Tables
Named questions
What a person asks of a pod, by the kind of thing the question is about. Each is answered from the views alone.
About the entry
- What it shows What each entry shows: every value its view states of it and every value its members' current versions state of the fields the view shows, each with From, the member whose current version states it, and Lead, whether that member is the entry's lead (cascade:leadMember), whose values come first.
- What needs review Entries a person should look at, and why: its members disagree on how severe an allergy is, the matcher joined it for two different reasons, two records judged different are still joined in it, a matcher's Same of two records now in two entries has lapsed (an open adopted newer tables or rules and did not file it again, so the pair it joined is apart until a person judges it), a finding of the matcher judgments a rule list version no longer reaches names a lapsed matcher judgment of two records now in two entries (listed as one line, the finding, expanding to its pairs, each with the matcher judgment of least IRI that names it, until a person judges the pair, or files an acknowledgement of that kind naming both its records and no other, which takes the pair off; a lapsed Same such a finding names is listed with it, never alone), or two of its conditions, in two entries, carry one code and their dates cannot tell whether they are one condition: either has no onset, or one has an unknown end (no abatement that is a date ending on or after its onset begins, and no status that keeps it going: active, recurrence or relapse) and its onset begins on or before the other's end, the other's period counted as the matcher's rule R8 counts it, each date read as the days its precision covers.
- Where it came from For each member of an entry: when its current revision arrived, the import that brought it, and the document it was derived from, with each hospital that wrote or keeps that document and when it was retrieved.
About the judgment
- What needs review Each judgment that may no longer hold, or that a person made and someone else took back or replaced.
- Whether it counts Each judgment has one row saying whether it counts under the lens the pod was built with, and one more row for each thing that happened to it: a later judgment replaced it, a retraction invalidated it or one of its assertions, the reference table it was made with has a newer version whose rows do not join its members as its rule reads them (M7), or the rule list its matcher judgment was asserted under has a current version whose rule runs another query, the version naming what did it.
- Who judged what Everything each judgment says: when a person made it, by whom and in what role, its verdict, what it names, the reason given, any judgment it replaces, and, for a matcher judgment, each rule list version it is asserted under, since a matcher judgment carries no time; and each person's retraction, an activity, with the judgment it invalidated and no verdict.
About the pod
- How many judgments count The lens decides which judgments count, and only those shape the views.
- How many of each kind How many things of each type the pod's files state.
- My active allergies Read from the view alone, as an app would: each entry whose status is active, or that no document gives a status (its status then reads "not stated"), with its code, its criticality, its category and onset as its lead states them, else as the members chosen for them do, how many records it joins, what each record states of the reaction, and each record it joins, with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it.
- My active conditions Read from the view alone, as an app would: each entry whose status is active and not ruled out, so not one whose status was taken from a refuted record (`pod/My condition history` lists those), with its codes, its onset, each entry of a medication, procedure or vaccination a record of which was given for one of its records, once, as "<entry>, <name>" (the entry IRI alone when it has no name; the entry IRI holds no ", ", so the first ", " ends it and the name, which may hold anything, is the rest; none when no record names one; not an entry of a medication its source marked entered in error), in code point order of name (an entry with no name first), then entry, how many records it joins, and each record with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it.
- My active medications Read from the view alone, as an app would: each entry whose status is of the active lifecycle class (rule L1), so not one on hold, stopped, not taken or without a status, with its RxNorm code, when it started, the day its prescription was written, how many records it joins, each record's own status and the day it ended, the dosage text each record states with the day its prescription was written where it states one, in order of that day and the records stating none last (none when no record states one; a record that states a written day and no dosage text is not in it), the text each record's source wrote for it, such as a note beside the row (none when no record has one), what each record was given for: each condition it names, by the condition's entry and name, and each code of its reason, as "<record> for <entry>, <name>", "<record> for <code IRI>" and, for a code in a system the vocabulary lists none of, "<record> for <system IRI> <code>" (none when no record gives a reason, and no condition whose record is in no entry).
- My condition history Read from the view alone, as an app would: each condition entry whatever its status, with its codes, its status, when it started and when it ended, each record's own status, each entry given for it as `pod/My active conditions` lists them ("<entry>, <name>", the entry IRI alone when it has no name, in code point order of name, then entry, and with a medication entered in error left out), how many records it joins, and each record with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it.
- My genetic variants Read from the view alone, as an app would: one row for each variant entry and each code it states, the codes a page looks a variant up by. ?variant is the entry's IRI, as the other pod questions give theirs; ?gene, ?hgvs and ?variation are the literals as the entry states them, an HGVS expression or a ClinVar VariationID on a row of its own.
- My immunizations Read from the view alone, as an app would, newest first by the date as written, so a year follows its months and days, with how many records each entry joins, each CVX code the entry states, a row for each, and each record it joins with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it, in order, separated by U+001F, its own parts by ", ".
- My lab results Read from the view alone, as an app would, newest first, with the interpretation flags its source gave each entry, each the code of HL7's ObservationInterpretation, its reference range as text and each bound as written, with its unit, the text each record's source wrote for it, such as a label beside the value (none when no record has one), how many records each entry joins, and each record it joins, with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it.
- My medication history Read from the view alone, as an app would: each medication entry whatever its status, with its RxNorm code, its status, the lifecycle class of that status (rule L1), when it started, the day its prescription was written, when it ended, each record's own status and the day it ended, so a stop one record states is shown beside another's "active" whichever the entry took, the dosage text each record states with the day its prescription was written where it states one, in order of that day and the records stating none last, so a dose changed reads in the order it was written (none when no record states one; a record that states a written day and no dosage text is not in it), the text each record's source wrote for it, such as a stop reason (none when no record has one), what each record was given for, as `pod/My active medications` gives it: "<record> for <entry>, <name>" for a condition (an entry with no name gives "<record> for <entry>"), "<record> for <code IRI>" for a code in a listed system and "<record> for <system IRI> <code>" for a code in another system, each read from the token after "for " up to the first space, never from the text: a pod IRI then "," is a condition entry; otherwise a pod IRI alone is a condition entry with no name, an IRI that is not the pod's alone is a code in a listed system, and an IRI followed by a space and more text is a system IRI and its code, in code point order of the name or code, then the entry or system, then the record (none when no record gives a reason), how many records it joins, and each record with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it.
- My procedures Read from the view alone, as an app would, newest first by the date as written, so a year follows its months and days, with how many records each entry joins, its code IRI, the first in code point order when it states several, the text each record's source wrote for it, such as the finding beside a screening (none when no record has one), and each record it joins with the document it was derived from, when that was retrieved, and the hospitals that wrote it and that keep it, in order, separated by U+001F, its own parts by ", ".
- 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.
- 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.
- What each folder holds A file's folder is its address after the storage root the owner's profile names, and GRAPH ?file reads one file at a time.
- What each import brought in An import is one run of the Bridge over one download, or one session of the person entering things.
- What each report says of a variant Read from the view as an app would: one row for each interpretation entry that names the variant it interprets, newest first within a variant. ?report is the interpretation's entry and ?variant the variant's entry, each as the other pod questions give an entry's IRI; ?classification is the cascade: IRI of the ACMG value the report states, none for a report whose answer is not one of the five, and ?date the day it was issued, or its year or month where the source wrote no day, ordered by the date as written. ?lab is the organization record the view attributes the report to, none for a report that names no lab, and ?labName that record's current name.
- What everything is called The name of every thing that has one.
- What was seen more than once Each entry that holds more than one record, once for each place its records came from: how many of its records came from that place, and from how many places they came.
- Which file states each thing The store loads each file twice: into the default graph, which the other questions read, and into a graph named by its address, which GRAPH ?file reads.
- Which files are out of place A file is out of place when it holds a thing that the pod's layout, read beside it with the pod's root as its base, files somewhere else.
- Which reference versions are current The matcher compares codes using reference tables, and each table comes in versions.
- Which view lists each kind An app finds a Solid pod's data through its type index: each registration names a type and the file that lists things of that type.
About the profile
- What needs review Each patient profile whose records are hidden until a person answers whose it is: one a record's current version names, other than the subject, that no counting About or NotAbout names; and one held back, a counting NotAbout and a person's About standing against it, which it does unless a counting NotAbout of the same maker was made after it.
- Which judgments name it An About or a NotAbout judgment names a patient profile as its member and says whether it is the subject's; until an About counts that no counting NotAbout outranks, the records that name the profile are in no view.
- Which records name it A record names its patient through its current version's cascade:patient.
- Whose it is counted as About judgments say whose a patient profile is, and only one that counts is believed, while no counting NotAbout over the profile for that subject outranks it.
About the record
- Its revisions, in the order they arrived A revision is one arrival: it carries a version, which is the content, and names the document it was derived from.
- What each version says A version is named by a hash of its content, so two arrivals saying the same thing share one version.
- What needs review Records whose current revision the source's change time did not decide, for a person to look at: the confession that current is derived and never stored.
- Where each record a statement names is now A statement is a judgment a matcher did not make: a person's, or a model's.
- Which entry shows it A record is shown in at most one entry, in the view of its kind.
- Which judgments name it A judgment names records as its members: that two are the same, that they differ, or that one is wrong.
- Why it is in no view A record no entry joins is hidden, never deleted.
Views
The queries that make each view file of a pod, which an app reads without the records behind it.
- allergies Each entry takes the allergen, code, reactions and severity of its lead, its category and onset from its lead, and from the members the derivations chose for them (cascade:allergyCategoryFrom, cascade:onsetDateFrom) when its lead states none, the status of the member chosen for status, and the highest criticality any member states.
- conditions Each entry takes the name and codes of its lead, the clinical status, verification status and abatement date of the member chosen for status, and the onset of the member chosen for the date.
- immunizations Each entry takes the vaccine and code of its lead, the status of the member chosen for status, and the date of the member chosen for the date.
- lab-results Each entry takes the test, code, value, unit, time and text of its lead, so a value is never shown at another member's time, and the status of the member chosen for status.
- medication-dispenses Each entry takes the name, every RxNorm code, every NDC code, every code in another system and the code the source chose of its lead, the times it was prepared and handed over, and the entry of each prescription the lead names: its version names medication records, and each prescription's entry is the one that record is in, none when the record is in no entry.
- medications Each entry takes the name, every RxNorm code, every NDC code, the code the source chose, the status and end date of the member chosen for status, the start of use and the day the prescription was written of the members chosen for each, the dosage text of its lead, and every intent a member states, so an entry joining a prescription and a list entry says both.
- notes-and-documents Each entry takes the type, type name, title, date, content status, text and organization of its lead and the status of the member chosen for status.
- patient-profile One entry for the person, joining every patient profile a counting About judgment ties to them and no counting NotAbout over it for them outranks, named as every entry is, from its least member.
- procedures Each entry takes the name, code and text of its lead, the status of the member chosen for status, and the date of the member chosen for the date.
- reports Each entry takes the name, codes, categories, time, time issued, conclusion, conclusion codes, text and organization of its lead, the status of the member chosen for status, and the entry of each result the lead names: its version names result records, and each result's entry is the one that record is in, none when the record is in no entry.
- variant-interpretations Each entry takes the classification, date and lab of its lead, the status of the member chosen for status, and the entry of the variant the lead interprets: its version names a variant record, and the entry is the one that record is in, none when the record is in no entry.
- variants Each entry takes every member's gene symbol, HGVS expressions and ClinVar IDs, since codes are identity and nothing is chosen among them, and the status of the member chosen for status.
Labels
The query that gives every record, entry and judgment a name.
- 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.
Matcher rules
The query each rule of the matcher runs to say when two records match.
allergy or intolerance · 2 rules
- same-active-ingredient-key-joined-first Two records of one kind match when their current versions give two different allergen codes that one version of a product ingredient table maps to one ingredient.
- same-code-key-joined-first Two records of one kind match when their current versions share a code under one property: an allergen's code, or a procedure's or a condition's SNOMED CT code.
clinical note or document · 3 rules
- same-note-or-document-master-identifier Two notes match when their current versions carry one master identifier, the identifier of one version of one document, as FHIR's DocumentReference.masterIdentifier and a C-CDA document's ClinicalDocument/id give it: an unstructured document imported as C-CDA and pulled as a DocumentReference to it is one note, whatever the two are typed and whether either holds text.
- same-note-type-and-text Two notes match when their current versions share a note type, a LOINC code, or a code of another system when neither has a LOINC code, and give one text once every run of white space in it is one space and its two ends are trimmed (cascade:narrativeTextAsTrimmedLines, its lines joined by a space), so line breaks and indentation, which two adapters write differently, are not compared; whatever their sources: a hospital's note sent again in a clinic's summary, or pulled from its server, is one note with two copies.
- same-note-type-and-text-grown-within-one-organization Two notes match when their current versions share a note type, a LOINC code, or a code of another system when neither has a LOINC code, the documents their revisions come from name, as custodian or author, one organization record, or two that are currently the same organization, and the shorter one's text begins or ends the longer one's as whole lines, or is the longer one's first lines and last lines with whole lines between them, the first lines at most 20: a note its source sends again as it grows, as a clinic's plan of treatment that keeps every visit's paragraph and adds the latest after them, or before them, newest first, or a table that adds each new row after its header lines.
genetic variant finding · 2 rules
- same-variation-key-joined-first Two records of one kind match when their current versions share a ClinVar VariationID.
- same-variation-through-current-tables-key-joined-first Two records of one kind match when their current versions find one row of one version of a variant classifications table.
laboratory test result · 5 rules
- same-business-identifier-and-test-code-within-one-organization-bound-per-side Two records match when their current versions carry one business identifier, one test code and one clinically relevant time, or one of them no time, and the documents their revisions come from name, as custodian or author, one organization record, or two that are currently the same organization.
- same-code-day-or-padded-time-value-and-unit-others-by-code-and-day Two records of one kind match when their current versions give one test code, one day, and one value of one kind in one unit, and at least one of the two times is no instant: a day with no time, or a time its source wrote to the hour or the minute and the version holds padded (cascade:PaddedDateTime), which is its clinically relevant time, the one time a lab result holds.
- same-code-instant-to-the-second-different-units-others-by-code-and-instant Two records of one kind give a finding when their current versions give one test code, one instant, and values of one kind other than text and coded, both holding a number in one place, the first (a quantity, a numerator, a low bound) or the second (a denominator, a high bound), in units that differ: mmol/L and mg/dL may measure one draw, and no rule converts one into the other.
- same-code-instant-to-the-second-different-values-others-by-code-and-instant Two records of one kind give a finding when their current versions give one test code, one instant, and values that differ: values of two kinds, text included; or values of one kind other than text, in one unit, that differ: two quantities of two numbers, compared by value, or of one number with different comparators; two ratios or two ranges differing in a part or a bound, or one holding a bound the other lacks; two coded values sharing no code, of which some two codes are of one code system, the stem of their IRIs.
- same-code-instant-to-the-second-value-and-unit-others-by-code-and-instant Two records of one kind match when their current versions give one test code, one instant, and one value of one kind in one unit.
medical procedure · 1 rule
- same-code-key-joined-first Two records of one kind match when their current versions share a code under one property: an allergen's code, or a procedure's or a condition's SNOMED CT code.
prescribed or reported medication · 3 rules
- same-brand-generic-and-overlapping-exposure-periods Two records of one kind match when their current versions give two different RxNorm codes that one version of a brand generics table joins, a brand and its generic, either way round, or two brands of one generic, and their exposure periods share at least one day, so a brand taken in one year and its generic years later stay two medications (decisions/medication-matching.md).
- same-ndc-code-and-overlapping-exposure-periods Two records of one kind match when their current versions share an NDC and their exposure periods share at least one day, so two courses of one product years apart stay two medications (decisions/medication-matching.md).
- same-product-code-in-current-tables-and-overlapping-exposure-periods Two records of one kind match when their current versions share an RxNorm code that a version of a drug products table lists, so the code names one drug product (SCD, SBD, GPCK or BPCK), and their exposure periods share at least one day, so two courses of one product years apart stay two medications (decisions/medication-matching.md).
problem or diagnosis · 2 rules
- same-code-and-period-read-as-ranges Two conditions match when their current versions share a condition code and their periods overlap, bounds included.
- same-one-to-one-conversion-key-joined-first Two records of one kind match when one version of a code conversion table converts an ICD-10-CM code of one's current version to a different ICD-10-CM code of the other's, either way round, by a dct:isReplacedBy row whose cardinality is 1:1.
server · 1 rule
- same-self-asserted-base-url-and-authorization-endpoint-on-one-host Two servers match when a version of each, written by connects made with one client id, reports one self-asserted base URL and one authorization endpoint, as the servers wrote them, and the base URLs the client used name one host, its port aside.
vaccination · 2 rules
- same-code-and-day-or-exact-time-key-joined-first Two records of one kind match when their current versions give one vaccine code and one date, each the same term, and that date is a day or a time its source wrote to the second: a year or a month is a span, and a time the version holds padded (cascade:PaddedDateTime) was written to the hour or the minute, so two of either may be two events.
- same-vaccine-group-and-day-or-exact-time-key-joined-first Two records of one kind match when their current versions give two different vaccine codes that one version of a vaccine group table puts in one group, and one date, the same term, that is a day or a time its source wrote to the second: a year or a month is a span, and a time the version holds padded (cascade:PaddedDateTime) was written to the hour or the minute, so two of either may be two events.
Derivations
The queries that derive statements from a pod's records, for the questions and views to read.
- candidates-ordered-by-ancestry Of two candidates for a record's current revision from two live pulls of one source, the one whose act's snapshot descends from the other's is the later, whatever their clocks say.
- current-reference-versions A reference table's current version is the one no newer version revises.
- current-revision-candidates The ladder's first three steps over a record's revisions.
- current-revisions The ladder's last two steps pick a record's current revision from its candidates, and its version is the record's current version.
- date-sources An entry takes its date 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.
- different-pairs Two records named together by a counting Different judgment are currently different, unless no person made the Different and a person's counting Same names both: a person outranks every machine, so the pair stays joined.
- entries Records of one kind, not left out, that are currently the same, directly or through each other, make one entry.
- excluded-at-source A record whose current version its source marks entered in error is left out of every view, and so is an allergy it marks refuted: by its verification status, or, for an immunization, a lab result, a procedure, a variant, a variant interpretation, a report, a note or document or a medication dispense, which state entered in error as their status, by its workflow status, and a note or document also by the status of its content.
- excluded-by-judgment A record named by a counting Erroneous judgment is left out of every view, because of that judgment; so is a record every revision of which an Erroneous that stands names, since it has no current state, because of each of those judgments.
- excluded-for-their-patient A record about no one known to be the subject is left out of every view, and the reason rests on the patient profile its current version names: a person's About stands against a counting NotAbout over the profile, which holds it back for review; or a counting NotAbout names the profile; or no counting About ties the profile to the subject.
- excluded-with-their-activity Every record whose current revision an import brought is left out of every view when a counting Erroneous judgment names that import, because of that judgment.
- lapsed-sames A matcher's judgment has lapsed when it does not count, nothing retracts it, no judgment not itself retracted replaces it, and a newer version stopped it counting: a reference version it used has a newer current one whose rows do not join its members (M7), or no current version of a rule list has a row for its rule with the query hash of that rule's row in a version it is asserted under.
- lead-member-candidates The lead of an entry is chosen from its members' current revisions as a record's current revision is from its revisions.
- lead-members An entry's lead is the candidate whose current revision has the greatest cascade:observedAsOf, beside every candidate whose current revision a ClockDiscounted leaves carrying none, then the least IRI.
- medication-dispense-lifecycles The status of each medication dispense's current version is classed by runtime rule L2, and an entry has the class of the record it takes its status from, or unknown when no member gives one.
- medication-exposure-periods Each medication record in an entry is given the exposure its own current version shows, as the eCQM library CumulativeMedicationDuration 4.1.000 gives a medication's period: from its start of use, else its one dosage's bounds' start, else the day its prescription was written, else the start of its dispensing window; to its end of use, else its start plus its supply times one plus its repeats, less a day, in whole days, else its one dosage's bounds' end (the library reads what the copy states, and a rule filters intent and status, as the library's callers do).
- medication-lifecycles The status of each medication record's current version, however its source wrote it, is classed by the first step of runtime rule L1 that holds, and the step is recorded; an entry has the class and step of the record it takes its status from, and one no member gives a status to is unknown at step 2.
- narrative-texts-as-trimmed-lines The current version of each note, document or report with a narrative text gives its text as trimmed lines: each run of spaces, tabs and carriage returns in a line one space, each line trimmed, and blank lines dropped.
- records The first table is the one place that says which types are records and, for each kind, the word for it and whether its status comes only from documents; the tables after it give, by kind, the properties that hold a version's name and date.
- revision-judgments The judgments the ladder reads before the lens: a Before or an Erroneous over revisions is a person's, and stands while no activity invalidates it and no judgment that stands replaces it, as every lens counts a person's judgment.
- same-organizations Two organization records named together by a counting Same judgment are currently the same organization, unless they are also currently different.
- same-pairs Two records named together by a counting Same judgment are currently the same, unless they are also currently different: a Different judgment wins.
- same-records-under-same-servers Two servers that are currently the same, directly or through other servers, have one record wherever each has a record of one type and id.
- 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.
- subjects A record is about the subject when its current version names a patient profile a counting About judgment ties to them and no counting NotAbout over it for them outranks, or names the subject directly.
- top-criticalities An entry shows the highest criticality any member states: high over low over unable to assess.
Lenses
The queries that decide which judgments count.
- everyday The lens decides which judgments count, and is the one step of the build that can be swapped.
- export A stricter lens, for records sent elsewhere: a person's judgment counts unless retracted or replaced, and a matcher judgment only when the Cascade matcher made it resting on the same code, or code and date, or code and period, made with current reference versions, and asserted under a version whose row for its rule has the query hash of the current rule list version's row for it, by an assertion no retraction invalidates.
Tables
The queries that read the reference tables an app holds against a pod's entries.
- agreement Each report that states an ACMG classification, the one row of a version of a variant classifications table that the variant it interprets finds, and one verdict on how the report stands to the row.
- joined-by The reference table versions that joined each entry's records.
- medication-classes Each class of each active medication entry, by the drug class rows of the tables an app holds.
- medication-classes-of-every-medication-record Each class of each medication record in an entry, whatever its lifecycle: the three steps of medication-classes-through-precise-ingredients.rq over the codes of the record's current version, so a medication stopped, paused or entered in error is classed as an active one is, and an entry joining two records gives each its own rows. ?record is the record, ?entry the entry it is in, and the rest are as in that query: ?class, ?relation, ?origin, ?through and ?stated.
- medication-classes-through-precise-ingredients Each class of each active medication entry, by the drug class rows of the tables an app holds, told apart by the precise ingredient a code holds.
- 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.
Read from cascade-vocabulary at https://github.com/the-cascade-protocol/cascade-vocabulary/tree/c2d3ad17d0e4de9427a9cdfc3db0a8753a624993/; the example pod may have been built from another commit.