diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1225.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1225.java new file mode 100644 index 000000000..623f68912 --- /dev/null +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1225.java @@ -0,0 +1,43 @@ +package org.opencds.cqf.cql.engine.fhir.data; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; + +import org.hl7.fhir.r4.model.Address; +import org.hl7.fhir.r4.model.Patient; +import org.opencds.cqf.cql.engine.data.CompositeDataProvider; +import org.opencds.cqf.cql.engine.retrieve.RetrieveProvider; +import org.opencds.cqf.cql.engine.runtime.Code; +import org.opencds.cqf.cql.engine.runtime.Interval; +import org.testng.annotations.Test; + +// https://github.com/cqframework/clinical_quality_language/issues/1225 +public class Issue1225 extends FhirExecutionTestBase { + + @Test + public void addressResolvesWithoutError() { + var r = new RetrieveProvider() { + @Override + public Iterable retrieve(String context, String contextPath, Object contextValue, String dataType, + String templateId, String codePath, Iterable codes, String valueSet, String datePath, + String dateLowPath, String dateHighPath, Interval dateRange) { + + if (dataType != null && dataType.equals("Patient")) { + var p = new Patient(); + p.getAddress().add(new Address().addLine("123").addLine("456")); + return Collections.singletonList(p); + } + + return Collections.emptyList(); + } + }; + + var engine = getEngine(); + engine.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, r)); + var result = engine.evaluate("Issue1225"); + + assertEquals("123", result.forExpression("Address Line 1").value()); + } + +} diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1226.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1226.java new file mode 100644 index 000000000..b4b2918b9 --- /dev/null +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1226.java @@ -0,0 +1,53 @@ +package org.opencds.cqf.cql.engine.fhir.data; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; + +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.Reference; +import org.opencds.cqf.cql.engine.data.CompositeDataProvider; +import org.opencds.cqf.cql.engine.retrieve.RetrieveProvider; +import org.opencds.cqf.cql.engine.runtime.Code; +import org.opencds.cqf.cql.engine.runtime.Interval; +import org.testng.annotations.Test; + +// https://github.com/cqframework/clinical_quality_language/issues/1226 +public class Issue1226 extends FhirExecutionTestBase { + + @Test + public void medicationReferenceFound() { + var r = new RetrieveProvider() { + @Override + public Iterable retrieve(String context, String contextPath, Object contextValue, String dataType, + String templateId, String codePath, Iterable codes, String valueSet, String datePath, + String dateLowPath, String dateHighPath, Interval dateRange) { + + switch(dataType) { + case "Patient" : return Collections.singletonList(new Patient().setId("123")); + case "MedicationRequest": return Collections.singletonList( + new MedicationRequest() + .setMedication( + new Reference("Medication/456"))); + } + + return Collections.emptyList(); + } + }; + + var engine = getEngine(); + + engine.getState().getEnvironment() + .registerDataProvider( + "http://hl7.org/fhir", + new CompositeDataProvider(r4ModelResolver, r)); + + var result = engine.evaluate("Issue1226") + .forExpression("Most Recent Medication Request reference") + .value(); + + assertEquals("Medication/456", result); + } + +} diff --git a/Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1225.cql b/Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1225.cql new file mode 100644 index 000000000..17d14fc53 --- /dev/null +++ b/Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1225.cql @@ -0,0 +1,13 @@ +library Issue1225 + +using USCore version '3.1.1' + +include FHIRHelpers version '4.0.1' + +context Patient + +define "Address": + Patient.address.line + +define "Address Line 1": + Patient.address.line[0] \ No newline at end of file diff --git a/Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1226.cql b/Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1226.cql new file mode 100644 index 000000000..9cc155355 --- /dev/null +++ b/Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1226.cql @@ -0,0 +1,16 @@ +library Issue1226 + +using USCore version '3.1.1' + +include FHIRHelpers version '4.0.1' + +context Patient + +define "All Medication Requests": + ["MedicationRequestProfile"] + +define "Most Recent Medication Request": + First("All Medication Requests") + +define "Most Recent Medication Request reference": + "Most Recent Medication Request".medication.reference \ No newline at end of file