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

Library XML deserializer doesn't include annotations #931

Open JPercival opened 3 years ago

JPercival commented 3 years ago

When deserializing an XML ELM library the annotations are omitted and you get null instead. This makes it impossible to check for valid translator options on an XML ELM library, among other things.

There is schema in the project for cqlannotations here:

https://github.com/DBCG/cql_engine/blob/develop/engine/src/main/resources/cql-lm/schema/elm/cqlannotations.xsd

However, that schema is never run through code-gen and there no classes are generated for it:

https://github.com/DBCG/cql_engine/blob/develop/engine/pom.xml#L95

The JAXB deserializer is not configured to know how deserialize those nonexistent classes. The Jackson deseralizer automatically maps the annotations to a HashMap so it does preserve the annotations, albeit in a JSON-y format.

The ELM deseralizer regression suite only checks for exceptions and not the validity of the resulting libraries. There are no tests for the presence of annotations. The regression suite also does only a basic comparison of the results of the JSON and XML deseralizers, so the the fact that the JSON libraries are good and the XML libraries are bad is not detected:

https://github.com/DBCG/cql_engine/blob/develop/engine/src/test/java/org/opencds/cqf/cql/engine/execution/ElmTests.java#L137

So, we need to:

  1. Add code-gen for the cqlannotations.xsd
  2. Register those classes appropriately for the XML and JSON deserializers
  3. Add direct tests for annotations to the XML and JSON deserializer test suite
  4. Add comparison tests for XML and JSON annotations to the test suite
JPercival commented 3 years ago

The annotations work for JSON because of an opposite bug:

https://github.com/DBCG/cql_engine/issues/453

vitorpamplona commented 2 years ago

I noticed that in some cases Jackson generates an empty string as translatorOptions

    "annotation" : [ {
      "translatorOptions" : ""
    } ]

This breaks the expectations of the TranslatorOptionsUtil, triggering:

java.lang.IllegalArgumentException: No enum constant org.cqframework.cql.cql2elm.CqlTranslator.Options.
at java.lang.Enum.valueOf(Enum.java:257)
at org.cqframework.cql.cql2elm.CqlTranslator$Options.valueOf(CqlTranslator.java:38)
at org.opencds.cqf.cql.evaluator.engine.util.TranslatorOptionsUtil.parseTranslatorOptions(TranslatorOptionsUtil.java:117)
at org.opencds.cqf.cql.evaluator.engine.util.TranslatorOptionsUtil.getTranslatorOptions(TranslatorOptionsUtil.java:41)

The solution is perhaps to check for empty strings on TranslatorOptionsUtil.parseTranslatorOptions