Skip to content
Alpha: see what works today →
Menu

Matcher rule

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. A text of under 200 characters, such as "Return in 3 months.", is written alike in many notes of one type, so it joins nothing. A text that holds the other's and more is no match here, from one source or from two: a note of another organization that holds a note whole quotes it, and within one organization same-note-type-and-text-grown-within-one-organization.rq joins a note to the one it grew from. Each ordered pair is a row.

The query

PREFIX cascade: <https://ns.cascadeprotocol.org/cascade#>
PREFIX pav: <http://purl.org/pav/>

SELECT DISTINCT ?record ?other
WHERE {
  { SELECT ?record ?type ?text
    # bound: ?record
    WHERE {
      ?record pav:hasCurrentVersion ?version .
      ?version cascade:noteOrDocumentTypeCode|cascade:noteOrDocumentTypeCodeInOtherSystem ?type .
      FILTER (isIRI(?type) || NOT EXISTS { ?version cascade:noteOrDocumentTypeCode ?loincOfVersion })
      ?version cascade:narrativeTextAsTrimmedLines ?lines .
      BIND (COALESCE(REPLACE(?lines, "\n", " "), "") AS ?text)
      FILTER (STRLEN(?text) >= 200)
    } }
  { SELECT ?other ?type ?text
    WHERE {
      { SELECT DISTINCT ?type
        # bound: ?record
        WHERE { ?record pav:hasCurrentVersion ?runVersion .
                ?runVersion cascade:noteOrDocumentTypeCode|cascade:noteOrDocumentTypeCodeInOtherSystem ?type .
                FILTER (isIRI(?type) || NOT EXISTS { ?runVersion cascade:noteOrDocumentTypeCode ?loincOfRunVersion }) } }
      ?other pav:hasCurrentVersion ?otherVersion .
      ?otherVersion cascade:noteOrDocumentTypeCode|cascade:noteOrDocumentTypeCodeInOtherSystem ?type .
      FILTER (isIRI(?type) || NOT EXISTS { ?otherVersion cascade:noteOrDocumentTypeCode ?loincOfOtherVersion })
      ?otherVersion cascade:narrativeTextAsTrimmedLines ?otherLines .
      BIND (COALESCE(REPLACE(?otherLines, "\n", " "), "") AS ?text)
    } }
  ?record pav:hasCurrentVersion ?version .
  FILTER (?other != ?record)
}

Terms it reads

cascade:narrativeTextAsTrimmedLines · cascade:noteOrDocumentTypeCode · cascade:noteOrDocumentTypeCodeInOtherSystem · pav:hasCurrentVersion

Rules and decision notes that name it

queries/matcher/same-note-type-and-text.rq on GitHub ↗