clinical-reasoning icon indicating copy to clipboard operation
clinical-reasoning copied to clipboard

function overloading issue

Open revans2023 opened this issue 1 year ago • 0 comments

I have two functions in a CQL library with the same name but different argument types and this fails when I run the CQL evaluator. In the following small CQL unit test one of the "Get Coverage" function accepts a String patient ID whereas the other accepts an actual FHIR.Patient.

The CQL developer's guide implies this should work at: https://cql.hl7.org/03-developersguide.html#function-resolution

Java command: java -jar resources\evaluator.cli-2.4.0.jar cql --library-url . --library-name RCQLEvaulatorFunctionOverloadings1 --model-url .\input\tests\RCQLEvaulatorFunctionOverloadings1-1.0.0 --fhir-version R4 --context Patient --context-value RCQLEvaulatorFunctionOverloadings1

CQL unit test: library RCQLEvaulatorFunctionOverloadings1 version '1.0.0'

using FHIR version '4.0.1' include FHIRHelpers version '4.0.1' called FHIRHelpers

context Patient

define function "Refers To?"(obj DomainResource, ref Reference) returns Boolean: EndsWith(ref.reference, obj.id)

define function "Get Patient"(patId String) returns Patient: First([Patient] P where P.id = patId)

// fails to compile because of circular reference define function "Get Coverage"(patId String) returns List<Coverage>: "Get Coverage"("Get Patient"(patId))

define function "Get Coverage"(pat Patient) returns List<Coverage>: [Coverage] cov where "Refers To?"(pat, cov.beneficiary)

define TestIt1: "Get Coverage"(First([Patient]).id)

define TestIt2: "Get Coverage"(First([Patient]))

Example FHIR Bundle: { "resourceType": "Bundle", "type": "transaction", "entry": [ { "fullUrl": "urn:uuid:69f79aa7-a9e2-44f1-9944-6f8281fd56de", "request": { "method": "POST", "url": "Patient" }, "resource": { "resourceType": "Patient", "name": [ { "given": [ "Test" ], "family": "Patient", "use": "official" } ], "birthDate": "1945-05-07", "active": true, "gender": "male" } }, { "fullUrl": "urn:uuid:69c4ecc5-af3d-4ad7-b6cb-80151df32d7b", "request": { "method": "POST", "url": "Coverage" }, "resource": { "resourceType": "Coverage", "status": "active", "beneficiary": { "reference": "urn:uuid:69f79aa7-a9e2-44f1-9944-6f8281fd56de" }, "payor": [ { "reference": "urn:uuid:69f79aa7-a9e2-44f1-9944-6f8281fd56de" } ], "period": { "start": "2020-01-01T00:00:00+00:00" } } } ] }

Output from running the CQL evaluator: org.opencds.cqf.cql.engine.exception.CqlException: Translation of library RCQLEvaulatorFunctionOverloadings1 failed with the following message: Cannot resolve reference to expression or function Get Coverage() because it results in a circular reference. at org.opencds.cqf.cql.evaluator.engine.execution.TranslatingLibraryLoader.translate(TranslatingLibraryLoader.java:136) at org.opencds.cqf.cql.evaluator.engine.execution.TranslatingLibraryLoader.load(TranslatingLibraryLoader.java:78) at org.opencds.cqf.cql.evaluator.engine.execution.CacheAwareLibraryLoaderDecorator.load(CacheAwareLibraryLoaderDecorator.java:50) at org.opencds.cqf.cql.engine.execution.CqlEngine.loadAndValidate(CqlEngine.java:257) at org.opencds.cqf.cql.engine.execution.CqlEngine.evaluate(CqlEngine.java:159) at org.opencds.cqf.cql.engine.execution.CqlEngine.evaluate(CqlEngine.java:148) at org.opencds.cqf.cql.evaluator.CqlEvaluator.evaluate(CqlEvaluator.java:89) at org.opencds.cqf.cql.evaluator.CqlEvaluator.evaluate(CqlEvaluator.java:76) at org.opencds.cqf.cql.evaluator.cli.command.CqlCommand.call(CqlCommand.java:216) at org.opencds.cqf.cql.evaluator.cli.command.CqlCommand.call(CqlCommand.java:38) at picocli.CommandLine.executeUserObject(CommandLine.java:1953)

revans2023 avatar Jan 13 '23 15:01 revans2023