From ceb446f9288a0dbe977b8bb8cb5200c4a6a8fcfd Mon Sep 17 00:00:00 2001 From: Elsa Date: Thu, 14 Dec 2023 11:29:14 -0500 Subject: [PATCH] Modified Not Equal unit test cql to not use literal false --- test/unit/ClauseResultsHelper.test.ts | 4 +- test/unit/fixtures/cql/NotEqual.cql | 16 +- test/unit/fixtures/elm/NotEqual.json | 494 ++++++++++++++++++++++++-- 3 files changed, 479 insertions(+), 35 deletions(-) diff --git a/test/unit/ClauseResultsHelper.test.ts b/test/unit/ClauseResultsHelper.test.ts index 808fce45..5c7a81f8 100644 --- a/test/unit/ClauseResultsHelper.test.ts +++ b/test/unit/ClauseResultsHelper.test.ts @@ -28,10 +28,10 @@ describe('ClauseResultsHelpers', () => { const localIds = ClauseResultsHelpers.findAllLocalIdsInStatementByName(libraryElm, statementName); // For the fixture loaded for this test it is known that the localId for the Equal statement - // is 100 and the localId for the Not expression is 5 but we want the Equal clause to take + // is 100 and the localId for the Not expression is 23 but we want the Equal clause to take // the result of the Not expression expect(localIds[100]).toBeDefined(); - expect(localIds[100]).toEqual({ localId: '100', sourceLocalId: '5' }); + expect(localIds[100]).toEqual({ localId: '100', sourceLocalId: '23' }); }); test('finds localIds for an ELM Binary Expression with a comparison operator with a literal', () => { diff --git a/test/unit/fixtures/cql/NotEqual.cql b/test/unit/fixtures/cql/NotEqual.cql index 8f582488..7ca26d7b 100644 --- a/test/unit/fixtures/cql/NotEqual.cql +++ b/test/unit/fixtures/cql/NotEqual.cql @@ -3,8 +3,22 @@ library Test using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' +include MATGlobalCommonFunctions version '5.0.000' called Global + +codesystem "EXAMPLE": 'http://example.com' +codesystem "EXAMPLE-2": 'http://example.com/2' +codesystem "ConditionClinicalStatusCodes": 'http://terminology.hl7.org/CodeSystem/condition-clinical' + +valueset "test-vs": 'http://example.com/test-vs' + +code "Active": 'active' from "ConditionClinicalStatusCodes" +code "Recurrence": 'recurrence' from "ConditionClinicalStatusCodes" +code "Relapse": 'relapse' from "ConditionClinicalStatusCodes" + +concept "Condition Active": { "Active", "Recurrence", "Relapse" } display 'Active' context Patient define "Not Equal Clause": - true != false \ No newline at end of file + [Condition: "test-vs"] C + where C.id != 'notId' \ No newline at end of file diff --git a/test/unit/fixtures/elm/NotEqual.json b/test/unit/fixtures/elm/NotEqual.json index 193880c0..a03b4e4c 100644 --- a/test/unit/fixtures/elm/NotEqual.json +++ b/test/unit/fixtures/elm/NotEqual.json @@ -6,10 +6,22 @@ "translatorOptions": "EnableAnnotations,EnableLocators", "type": "CqlToElmInfo" }, + { + "libraryId": "MATGlobalCommonFunctions", + "libraryVersion": "5.0.000", + "startLine": 277, + "startChar": 19, + "endLine": 277, + "endChar": 53, + "message": "Could not resolve membership operator for terminology target of the retrieve.", + "errorType": "semantic", + "errorSeverity": "warning", + "type": "CqlToElmError" + }, { "type": "Annotation", "s": { - "r": "6", + "r": "25", "s": [ { "value": ["", "library Test"] @@ -94,13 +106,314 @@ } } ] + }, + { + "localId": "3", + "locator": "6:1-6:64", + "localIdentifier": "Global", + "path": "MATGlobalCommonFunctions", + "version": "5.0.000", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "3", + "s": [ + { + "value": ["", "include "] + }, + { + "s": [ + { + "value": ["MATGlobalCommonFunctions"] + } + ] + }, + { + "value": [" version ", "'5.0.000'", " called ", "Global"] + } + ] + } + } + ] + } + ] + }, + "codeSystems": { + "def": [ + { + "localId": "4", + "locator": "8:1-8:42", + "name": "EXAMPLE", + "id": "http://example.com", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "4", + "s": [ + { + "value": ["", "codesystem ", "\"EXAMPLE\"", ": ", "'http://example.com'"] + } + ] + } + } + ] + }, + { + "localId": "5", + "locator": "9:1-9:46", + "name": "EXAMPLE-2", + "id": "http://example.com/2", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "5", + "s": [ + { + "value": ["", "codesystem ", "\"EXAMPLE-2\"", ": ", "'http://example.com/2'"] + } + ] + } + } + ] + }, + { + "localId": "6", + "locator": "10:1-10:101", + "name": "ConditionClinicalStatusCodes", + "id": "http://terminology.hl7.org/CodeSystem/condition-clinical", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "6", + "s": [ + { + "value": [ + "", + "codesystem ", + "\"ConditionClinicalStatusCodes\"", + ": ", + "'http://terminology.hl7.org/CodeSystem/condition-clinical'" + ] + } + ] + } + } + ] + } + ] + }, + "valueSets": { + "def": [ + { + "localId": "7", + "locator": "12:1-12:48", + "name": "test-vs", + "id": "http://example.com/test-vs", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "7", + "s": [ + { + "value": ["", "valueset ", "\"test-vs\"", ": ", "'http://example.com/test-vs'"] + } + ] + } + } + ] + } + ] + }, + "codes": { + "def": [ + { + "localId": "9", + "locator": "14:1-14:59", + "name": "Active", + "id": "active", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "9", + "s": [ + { + "value": ["", "code ", "\"Active\"", ": ", "'active'", " from "] + }, + { + "r": "8", + "s": [ + { + "value": ["\"ConditionClinicalStatusCodes\""] + } + ] + } + ] + } + } + ], + "codeSystem": { + "localId": "8", + "locator": "14:30-14:59", + "name": "ConditionClinicalStatusCodes" + } + }, + { + "localId": "11", + "locator": "15:1-15:67", + "name": "Recurrence", + "id": "recurrence", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "11", + "s": [ + { + "value": ["", "code ", "\"Recurrence\"", ": ", "'recurrence'", " from "] + }, + { + "r": "10", + "s": [ + { + "value": ["\"ConditionClinicalStatusCodes\""] + } + ] + } + ] + } + } + ], + "codeSystem": { + "localId": "10", + "locator": "15:38-15:67", + "name": "ConditionClinicalStatusCodes" + } + }, + { + "localId": "13", + "locator": "16:1-16:61", + "name": "Relapse", + "id": "relapse", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "13", + "s": [ + { + "value": ["", "code ", "\"Relapse\"", ": ", "'relapse'", " from "] + }, + { + "r": "12", + "s": [ + { + "value": ["\"ConditionClinicalStatusCodes\""] + } + ] + } + ] + } + } + ], + "codeSystem": { + "localId": "12", + "locator": "16:32-16:61", + "name": "ConditionClinicalStatusCodes" + } + } + ] + }, + "concepts": { + "def": [ + { + "localId": "17", + "locator": "18:1-18:82", + "name": "Condition Active", + "display": "Active", + "accessLevel": "Public", + "annotation": [ + { + "type": "Annotation", + "s": { + "r": "17", + "s": [ + { + "value": ["", "concept ", "\"Condition Active\"", ": { "] + }, + { + "r": "14", + "s": [ + { + "value": ["\"Active\""] + } + ] + }, + { + "value": [", "] + }, + { + "r": "15", + "s": [ + { + "value": ["\"Recurrence\""] + } + ] + }, + { + "value": [", "] + }, + { + "r": "16", + "s": [ + { + "value": ["\"Relapse\""] + } + ] + }, + { + "value": [" } display ", "'Active'"] + } + ] + } + } + ], + "code": [ + { + "localId": "14", + "locator": "18:31-18:38", + "name": "Active" + }, + { + "localId": "15", + "locator": "18:41-18:52", + "name": "Recurrence" + }, + { + "localId": "16", + "locator": "18:55-18:63", + "name": "Relapse" + } + ] } ] }, "contexts": { "def": [ { - "locator": "7:1-7:15", + "locator": "20:1-20:15", "name": "Patient" } ] @@ -108,13 +421,13 @@ "statements": { "def": [ { - "locator": "7:1-7:15", + "locator": "20:1-20:15", "name": "Patient", "context": "Patient", "expression": { "type": "SingletonFrom", "operand": { - "locator": "7:1-7:15", + "locator": "20:1-20:15", "dataType": "{http://hl7.org/fhir}Patient", "templateId": "http://hl7.org/fhir/StructureDefinition/Patient", "type": "Retrieve" @@ -122,8 +435,8 @@ } }, { - "localId": "6", - "locator": "9:1-10:17", + "localId": "25", + "locator": "22:1-24:29", "name": "Not Equal Clause", "context": "Patient", "accessLevel": "Public", @@ -131,17 +444,99 @@ { "type": "Annotation", "s": { - "r": "6", + "r": "25", "s": [ { "value": ["", "define ", "\"Not Equal Clause\"", ":\n "] }, { - "r": "5", + "r": "24", "s": [ { - "r": "3", - "value": ["true", " ", "!=", " ", "false"] + "s": [ + { + "r": "19", + "s": [ + { + "r": "18", + "s": [ + { + "r": "18", + "s": [ + { + "value": ["[", "Condition", ": "] + }, + { + "s": [ + { + "value": ["\"test-vs\""] + } + ] + }, + { + "value": ["]"] + } + ] + } + ] + }, + { + "value": [" ", "C"] + } + ] + } + ] + }, + { + "value": ["\n "] + }, + { + "r": "23", + "s": [ + { + "value": ["where "] + }, + { + "r": "23", + "s": [ + { + "r": "21", + "s": [ + { + "r": "20", + "s": [ + { + "value": ["C"] + } + ] + }, + { + "value": ["."] + }, + { + "r": "21", + "s": [ + { + "value": ["id"] + } + ] + } + ] + }, + { + "value": [" ", "!=", " "] + }, + { + "r": "22", + "s": [ + { + "value": ["'notId'"] + } + ] + } + ] + } + ] } ] } @@ -150,29 +545,64 @@ } ], "expression": { - "localId": "5", - "locator": "10:5-10:17", - "type": "Not", - "operand": { - "locator": "10:5-10:17", - "localId": "100", - "type": "Equal", - "operand": [ - { - "localId": "3", - "locator": "10:5-10:8", - "valueType": "{urn:hl7-org:elm-types:r1}Boolean", - "value": "true", - "type": "Literal" - }, - { - "localId": "4", - "locator": "10:13-10:17", - "valueType": "{urn:hl7-org:elm-types:r1}Boolean", - "value": "false", - "type": "Literal" + "localId": "24", + "locator": "23:5-24:29", + "type": "Query", + "source": [ + { + "localId": "19", + "locator": "23:5-23:28", + "alias": "C", + "expression": { + "localId": "18", + "locator": "23:5-23:26", + "dataType": "{http://hl7.org/fhir}Condition", + "templateId": "http://hl7.org/fhir/StructureDefinition/Condition", + "codeProperty": "code", + "codeComparator": "in", + "type": "Retrieve", + "codes": { + "locator": "23:17-23:25", + "name": "test-vs", + "preserve": true, + "type": "ValueSetRef" + } } - ] + } + ], + "relationship": [], + "where": { + "localId": "23", + "locator": "24:9-24:29", + "type": "Not", + "operand": { + "locator": "24:15-24:29", + "localId": "100", + "type": "Equal", + "operand": [ + { + "name": "ToString", + "libraryName": "FHIRHelpers", + "type": "FunctionRef", + "operand": [ + { + "localId": "21", + "locator": "24:15-24:18", + "path": "id", + "scope": "C", + "type": "Property" + } + ] + }, + { + "localId": "22", + "locator": "24:23-24:29", + "valueType": "{urn:hl7-org:elm-types:r1}String", + "value": "notId", + "type": "Literal" + } + ] + } } } }