Matcher rule
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. Two texts are never compared, nor are coded values of two code systems, which a rule cannot tell apart from one answer coded twice; a pair whose units differ is a finding of its own, of different units, and is not given here. Two times with zones are one instant when they name one moment, two with none are one when written alike, and one of each never; a quantity's number is compared by value, so 6.8 and 6.80 are one; units are compared with their UCUM annotations dropped, a unit of annotations alone being 1, the litre's l and L one, and other case kept. A pair of one value in one unit is a match, so it is never given here. Each ordered pair is a row.
The query
PREFIX cascade: <https://ns.cascadeprotocol.org/cascade#>
PREFIX pav: <http://purl.org/pav/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?record ?other
WHERE {
{ SELECT ?record ?version ?code ?instant ?valueKind ?firstNumber ?firstComparator ?firstUnit ?secondNumber ?secondComparator ?secondUnit
# bound: ?record
WHERE {
?record pav:hasCurrentVersion ?version .
?version cascade:testCode ?code ; cascade:resultClinicallyRelevantTime ?time ;
cascade:resultValueKind ?valueKind .
FILTER (DATATYPE(?time) = xsd:dateTime)
MINUS { ?version cascade:paddedDateTime ?padded }
BIND (COALESCE(IF(TZ(?time) != "", STR(?time - "1970-01-01T00:00:00Z"^^xsd:dateTime),
CONCAT("local ", STR(?time - "1970-01-01T00:00:00"^^xsd:dateTime))), CONCAT("written ", STR(?time))) AS ?instant)
OPTIONAL { ?version cascade:resultQuantity ?firstQuantity . ?firstQuantity cascade:decimalValue ?firstQuantityNumber .
OPTIONAL { ?firstQuantity cascade:quantityComparator ?firstQuantityComparator }
OPTIONAL { ?firstQuantity cascade:ucumUnit ?firstQuantityUcum }
OPTIONAL { ?firstQuantity cascade:unitText ?firstQuantityText } }
OPTIONAL { ?version cascade:resultRatioNumerator ?firstNumerator . ?firstNumerator cascade:decimalValue ?firstNumeratorNumber .
OPTIONAL { ?firstNumerator cascade:quantityComparator ?firstNumeratorComparator }
OPTIONAL { ?firstNumerator cascade:ucumUnit ?firstNumeratorUcum }
OPTIONAL { ?firstNumerator cascade:unitText ?firstNumeratorText } }
OPTIONAL { ?version cascade:resultValueRangeLow ?firstLow . ?firstLow cascade:decimalValue ?firstLowNumber .
OPTIONAL { ?firstLow cascade:quantityComparator ?firstLowComparator }
OPTIONAL { ?firstLow cascade:ucumUnit ?firstLowUcum }
OPTIONAL { ?firstLow cascade:unitText ?firstLowText } }
OPTIONAL { ?version cascade:resultRatioDenominator ?secondDenominator . ?secondDenominator cascade:decimalValue ?secondDenominatorNumber .
OPTIONAL { ?secondDenominator cascade:quantityComparator ?secondDenominatorComparator }
OPTIONAL { ?secondDenominator cascade:ucumUnit ?secondDenominatorUcum }
OPTIONAL { ?secondDenominator cascade:unitText ?secondDenominatorText } }
OPTIONAL { ?version cascade:resultValueRangeHigh ?secondHigh . ?secondHigh cascade:decimalValue ?secondHighNumber .
OPTIONAL { ?secondHigh cascade:quantityComparator ?secondHighComparator }
OPTIONAL { ?secondHigh cascade:ucumUnit ?secondHighUcum }
OPTIONAL { ?secondHigh cascade:unitText ?secondHighText } }
BIND (COALESCE(?firstQuantityNumber, ?firstNumeratorNumber, ?firstLowNumber) AS ?firstNumber)
BIND (COALESCE(?firstQuantityComparator, ?firstNumeratorComparator, ?firstLowComparator) AS ?firstComparator)
BIND (COALESCE(?firstQuantityUcum, ?firstNumeratorUcum, ?firstLowUcum) AS ?firstUcum)
BIND (COALESCE(?firstQuantityText, ?firstNumeratorText, ?firstLowText) AS ?firstText)
BIND (COALESCE(?firstUcum, ?firstText, "") AS ?firstUnitWritten)
BIND (REPLACE(?firstUnitWritten, "\\{[^{}]*\\}", "") AS ?firstUnitBare)
BIND (REPLACE(REPLACE(REPLACE(?firstUnitBare, "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "\u0001", "L")
AS ?firstUnitFolded)
BIND (IF(?firstUnitFolded = "" && ?firstUnitWritten != "", "1", ?firstUnitFolded) AS ?firstUnit)
BIND (COALESCE(?secondDenominatorNumber, ?secondHighNumber) AS ?secondNumber)
BIND (COALESCE(?secondDenominatorComparator, ?secondHighComparator) AS ?secondComparator)
BIND (COALESCE(?secondDenominatorUcum, ?secondHighUcum) AS ?secondUcum)
BIND (COALESCE(?secondDenominatorText, ?secondHighText) AS ?secondText)
BIND (COALESCE(?secondUcum, ?secondText, "") AS ?secondUnitWritten)
BIND (REPLACE(?secondUnitWritten, "\\{[^{}]*\\}", "") AS ?secondUnitBare)
BIND (REPLACE(REPLACE(REPLACE(?secondUnitBare, "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "\u0001", "L")
AS ?secondUnitFolded)
BIND (IF(?secondUnitFolded = "" && ?secondUnitWritten != "", "1", ?secondUnitFolded) AS ?secondUnit)
} }
{ SELECT ?other ?otherVersion ?code ?instant ?otherInstant ?otherValueKind ?otherFirstNumber ?otherFirstComparator ?otherFirstUnit ?otherSecondNumber ?otherSecondComparator ?otherSecondUnit
WHERE {
{ SELECT DISTINCT ?code ?instant
# bound: ?record
WHERE { ?record pav:hasCurrentVersion ?version .
?version cascade:testCode ?code ; cascade:resultClinicallyRelevantTime ?time .
FILTER (DATATYPE(?time) = xsd:dateTime)
BIND (COALESCE(IF(TZ(?time) != "", STR(?time - "1970-01-01T00:00:00Z"^^xsd:dateTime),
CONCAT("local ", STR(?time - "1970-01-01T00:00:00"^^xsd:dateTime))), CONCAT("written ", STR(?time))) AS ?instant) } }
{ SELECT ?other ?otherVersion ?code ?instant ?otherTime ?otherValueKind
WHERE {
{ SELECT DISTINCT ?code
# bound: ?record
WHERE { ?record pav:hasCurrentVersion ?version . ?version cascade:testCode ?code } }
?other pav:hasCurrentVersion ?otherVersion .
?otherVersion cascade:testCode ?code ; cascade:resultClinicallyRelevantTime ?otherTime ;
cascade:resultValueKind ?otherValueKind .
FILTER (DATATYPE(?otherTime) = xsd:dateTime)
MINUS { ?otherVersion cascade:paddedDateTime ?otherPadded }
BIND (COALESCE(IF(TZ(?otherTime) != "", STR(?otherTime - "1970-01-01T00:00:00Z"^^xsd:dateTime),
CONCAT("local ", STR(?otherTime - "1970-01-01T00:00:00"^^xsd:dateTime))), CONCAT("written ", STR(?otherTime))) AS ?instant) } }
BIND (?instant AS ?otherInstant)
OPTIONAL { ?otherVersion cascade:resultQuantity ?otherFirstQuantity . ?otherFirstQuantity cascade:decimalValue ?otherFirstQuantityNumber .
OPTIONAL { ?otherFirstQuantity cascade:quantityComparator ?otherFirstQuantityComparator }
OPTIONAL { ?otherFirstQuantity cascade:ucumUnit ?otherFirstQuantityUcum }
OPTIONAL { ?otherFirstQuantity cascade:unitText ?otherFirstQuantityText } }
OPTIONAL { ?otherVersion cascade:resultRatioNumerator ?otherFirstNumerator . ?otherFirstNumerator cascade:decimalValue ?otherFirstNumeratorNumber .
OPTIONAL { ?otherFirstNumerator cascade:quantityComparator ?otherFirstNumeratorComparator }
OPTIONAL { ?otherFirstNumerator cascade:ucumUnit ?otherFirstNumeratorUcum }
OPTIONAL { ?otherFirstNumerator cascade:unitText ?otherFirstNumeratorText } }
OPTIONAL { ?otherVersion cascade:resultValueRangeLow ?otherFirstLow . ?otherFirstLow cascade:decimalValue ?otherFirstLowNumber .
OPTIONAL { ?otherFirstLow cascade:quantityComparator ?otherFirstLowComparator }
OPTIONAL { ?otherFirstLow cascade:ucumUnit ?otherFirstLowUcum }
OPTIONAL { ?otherFirstLow cascade:unitText ?otherFirstLowText } }
OPTIONAL { ?otherVersion cascade:resultRatioDenominator ?otherSecondDenominator . ?otherSecondDenominator cascade:decimalValue ?otherSecondDenominatorNumber .
OPTIONAL { ?otherSecondDenominator cascade:quantityComparator ?otherSecondDenominatorComparator }
OPTIONAL { ?otherSecondDenominator cascade:ucumUnit ?otherSecondDenominatorUcum }
OPTIONAL { ?otherSecondDenominator cascade:unitText ?otherSecondDenominatorText } }
OPTIONAL { ?otherVersion cascade:resultValueRangeHigh ?otherSecondHigh . ?otherSecondHigh cascade:decimalValue ?otherSecondHighNumber .
OPTIONAL { ?otherSecondHigh cascade:quantityComparator ?otherSecondHighComparator }
OPTIONAL { ?otherSecondHigh cascade:ucumUnit ?otherSecondHighUcum }
OPTIONAL { ?otherSecondHigh cascade:unitText ?otherSecondHighText } }
BIND (COALESCE(?otherFirstQuantityNumber, ?otherFirstNumeratorNumber, ?otherFirstLowNumber) AS ?otherFirstNumber)
BIND (COALESCE(?otherFirstQuantityComparator, ?otherFirstNumeratorComparator, ?otherFirstLowComparator) AS ?otherFirstComparator)
BIND (COALESCE(?otherFirstQuantityUcum, ?otherFirstNumeratorUcum, ?otherFirstLowUcum) AS ?otherFirstUcum)
BIND (COALESCE(?otherFirstQuantityText, ?otherFirstNumeratorText, ?otherFirstLowText) AS ?otherFirstText)
BIND (COALESCE(?otherFirstUcum, ?otherFirstText, "") AS ?otherFirstUnitWritten)
BIND (REPLACE(?otherFirstUnitWritten, "\\{[^{}]*\\}", "") AS ?otherFirstUnitBare)
BIND (REPLACE(REPLACE(REPLACE(?otherFirstUnitBare, "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "\u0001", "L")
AS ?otherFirstUnitFolded)
BIND (IF(?otherFirstUnitFolded = "" && ?otherFirstUnitWritten != "", "1", ?otherFirstUnitFolded) AS ?otherFirstUnit)
BIND (COALESCE(?otherSecondDenominatorNumber, ?otherSecondHighNumber) AS ?otherSecondNumber)
BIND (COALESCE(?otherSecondDenominatorComparator, ?otherSecondHighComparator) AS ?otherSecondComparator)
BIND (COALESCE(?otherSecondDenominatorUcum, ?otherSecondHighUcum) AS ?otherSecondUcum)
BIND (COALESCE(?otherSecondDenominatorText, ?otherSecondHighText) AS ?otherSecondText)
BIND (COALESCE(?otherSecondUcum, ?otherSecondText, "") AS ?otherSecondUnitWritten)
BIND (REPLACE(?otherSecondUnitWritten, "\\{[^{}]*\\}", "") AS ?otherSecondUnitBare)
BIND (REPLACE(REPLACE(REPLACE(?otherSecondUnitBare, "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "(^|[./(])(Y|Z|E|P|T|G|M|k|h|da|d|c|m|u|n|p|f|a|z|y)?l($|[./)0-9+-])", "$1$2\u0001$3"), "\u0001", "L")
AS ?otherSecondUnitFolded)
BIND (IF(?otherSecondUnitFolded = "" && ?otherSecondUnitWritten != "", "1", ?otherSecondUnitFolded) AS ?otherSecondUnit)
} }
?record pav:hasCurrentVersion ?version .
FILTER (?record != ?other && ?instant = ?otherInstant)
FILTER (?valueKind != ?otherValueKind
|| (?valueKind != cascade:TextResultValue
&& IF(?valueKind = cascade:CodedResultValue,
NOT EXISTS { ?version cascade:resultValueCode ?sharedCode . ?otherVersion cascade:resultValueCode ?sharedCode }
&& EXISTS { ?version cascade:resultValueCode ?answer . ?otherVersion cascade:resultValueCode ?otherAnswer .
FILTER (REPLACE(STR(?answer), "[^/]*$", "") = REPLACE(STR(?otherAnswer), "[^/]*$", "")) },
(BOUND(?firstNumber) || BOUND(?secondNumber)) && (BOUND(?otherFirstNumber) || BOUND(?otherSecondNumber))
&& (!BOUND(?firstNumber) || !BOUND(?otherFirstNumber) || ?firstUnit = ?otherFirstUnit)
&& (!BOUND(?secondNumber) || !BOUND(?otherSecondNumber) || ?secondUnit = ?otherSecondUnit)
&& !(BOUND(?firstNumber) = BOUND(?otherFirstNumber) && BOUND(?secondNumber) = BOUND(?otherSecondNumber)
&& (!BOUND(?firstNumber)
|| (?firstNumber = ?otherFirstNumber
&& COALESCE(?firstComparator, "") = COALESCE(?otherFirstComparator, "")))
&& (!BOUND(?secondNumber)
|| (?secondNumber = ?otherSecondNumber
&& COALESCE(?secondComparator, "") = COALESCE(?otherSecondComparator, "")))))))
}
Terms it reads
cascade:CodedResultValue · cascade:TextResultValue · cascade:decimalValue · cascade:paddedDateTime · cascade:quantityComparator · cascade:resultClinicallyRelevantTime · cascade:resultQuantity · cascade:resultRatioDenominator · cascade:resultRatioNumerator · cascade:resultValueCode · cascade:resultValueKind · cascade:resultValueRangeHigh · cascade:resultValueRangeLow · cascade:testCode · cascade:ucumUnit · cascade:unitText · pav:hasCurrentVersion