cqframework / clinical_quality_language

Clinical Quality Language (CQL) is an HL7 specification for the expression of clinical knowledge that can be used within both the Clinical Decision Support (CDS) and Clinical Quality Measurement (CQM) domains. This repository contains complementary tooling in support of that specification.
https://confluence.hl7.org/display/CDS/Clinical+Quality+Language
Apache License 2.0
266 stars 124 forks source link

[Question] Does CqlEngine support running with USCore? #938

Closed msargentibm closed 4 years ago

msargentibm commented 4 years ago

((If there is a better forum for questions about the engine, I am happy to move discussion elsewhere.))

Does the CqlEngine currently support running with USCore? I saw this closed issue (https://github.com/DBCG/cql_engine/issues/232) and I wasn't sure what that meant for support for USCore currently.

I'm initially trying to run a very simple ELM to get started:

<?xml version="1.0" encoding="UTF-8"?>
<library xmlns="urn:hl7-org:elm:r1" xmlns:t="urn:hl7-org:elm-types:r1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fhir="http://hl7.org/fhir" xmlns:qdm43="urn:healthit-go
v:qdm:v4_3" xmlns:qdm53="urn:healthit-gov:qdm:v5_3" xmlns:a="urn:hl7-org:cql-annotations:r1">
   <annotation translatorOptions="" xsi:type="a:CqlToElmInfo"/>
   <identifier id="Test" version="1.0.0"/>
   <schemaIdentifier id="urn:hl7-org:elm" version="r1"/>
   <usings>
      <def localIdentifier="System" uri="urn:hl7-org:elm-types:r1"/>
      <def localIdentifier="USCore" uri="http://hl7.org/fhir/us/core" version="3.1.0"/>
   </usings>
   <contexts>
      <def name="Patient"/>
   </contexts>
   <statements>
      <def name="Patient" context="Patient">
         <expression xsi:type="SingletonFrom">
            <operand xmlns:ns0="http://hl7.org/fhir/us/core" dataType="ns0:PatientProfile" templateId="http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient" xsi:type="Retrieve"/>
         </expression>
      </def>
   </statements>
</library>

However, I am getting the following error: ca.uhn.fhir.parser.DataFormatException: Unknown resource name "PatientProfile" (this name is not known in FHIR version "R4").

I think this stems from using the R4FhirModelResolver class in a CompositeDataProvider I am passing to the CqlEngine since its FHIRContext only contains information in the base FHIR spec. Based on the closed issue I linked to, I was not sure if I needed a custom ModelResolver or DataProvider, or if running with USCore should be possible using existing code in this project.

I would appreciate any guidance that can be offered. Thank you!

JPercival commented 4 years ago

USCore is not supported directly by the cql-engine. The cql-translator project has a set of mappings call "modelinfos" that provide a way for it to emit ELM in terms of a FHIR model from CQL that's written in terms of USCore (or other FHIR-based models). In other words, when the issue you referenced was opened we were thinking of adding a "USCoreModelResolver" to support it directly and then the issue was closed when we decided to handle it in the cql-translator instead.

Does that answer your question?

msargentibm commented 4 years ago

Thanks for the response.

The strategy you described makes sense, but I am still a bit confused. The ELM I posted was a result of running the cql tranlsator on this CQL:

library "Test" version '1.0.0'
using "USCore" version '3.1.0'

context Patient

As far as I can tell, the translation is using the provided model info file for us core.

FWIW, I just modified the ELM by hand and changed PatientProfile to Patient. With that change the cql is successfully retrieving the USCore patient resource I was trying to retrieve.

Are there flags I need to use during translation to successfully pick up model information that maps from USCore to FHIR (PatientProfile to Patient in this case)?

msargentibm commented 4 years ago

It seems like maybe the model info changed recently?

https://github.com/cqframework/clinical_quality_language/commit/91af4f9dd87e85c1be264a55a7fe4a6f8d5dba98#diff-2866531ca569a1f18a985d1ded2cf46f1517557115d77132fcbdd14df9c4d528L1483

It looks like the model info for USCore no longer has a target included for the PatientProfile. Before:

<ns4:typeInfo xsi:type="ns4:ClassInfo" namespace="USCore" name="PatientProfile" target="Patient" identifier="http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient" label="US Core Patient Profile" retrievable="true" baseType="USCore.DomainResource">

After:

    <typeInfo baseType="USCore.DomainResource" namespace="USCore" name="PatientProfile" identifier="http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient" label="US Core Patient Profile" retrievable="true" xsi:type="ClassInfo">

Does the model info need fixed/updated?

msargentibm commented 4 years ago

I'm happy to close this issue and open up a separate issue in that project if that makes sense.

JPercival commented 4 years ago

Sorry, I wasn't clear. The work to emit the ELM in terms of a FHIR for FHIR-based models is ongoing. It's not yet complete. One of the first targets is actually QICore:

https://github.com/cqframework/clinical_quality_language/issues/507

msargentibm commented 4 years ago

Thanks again for the response. If you don't mind, I'll echo back my current understanding of the answer and if it seems correct then I can close this issue.

I guess I'm still wondering about the latest USCore model info change and why the PatientProfile dropped the target="Patient" portion of its defintion. It seemed that the translator understood that target in that case was a mapping back to the FHIR type to use when requesting a resource from the FHIR server. Although, I'm happy to open a separate issue in the correct project to ask about that change.

Thanks again for your responses! It certainly helps take away some of the guesswork involved in being new to working with all of the available cql tooling.

JPercival commented 4 years ago

The intention is to have the CQL to ELM translator take a model info, a CQL written against that model info, and create ELM that just references the base FHIR model.

Yes.

Mapping to FHIR is a work in progress. Using the USCore model info (or any arbitrary model info) offers no guarantees about the correctness of the ELM emitted by the translator.

Yes, and we are attempting to support USCore/QICore fully by generating the modelInfos ourselves.

Mapping QICore to base FHIR is being targeted specifically. Some of this work seems general enough where it would apply to an arbitrary IG/model info

The work we're doing should apply to any FHIR-based model. When generating the ModelInfos it looks at a profile and its dependencies recursively all the way down to the base FHIR spec. So, assuming the QICore generation works, so should USCore.

The code for the generation is located here (you'll note that both QICore and USCore are listed as examples) which works directly from the official StructureDefinitions

https://github.com/cqframework/cqf-tooling/blob/master/src/main/java/org/opencds/cqf/tooling/modelinfo/StructureDefinitionToModelInfo.java

I guess I'm still wondering about the latest USCore model info change and why the PatientProfile dropped the target="Patient" portion of its defintion.

I would file an issue on the https://github.com/cqframework/clinical_quality_language repo.

msargentibm commented 4 years ago

Thanks for your help addressing my questions.