Skip to content

Commit

Permalink
Tests for issues 1225 and 1226 (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Nov 9, 2023
1 parent 063dc4b commit a856e39
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Object> retrieve(String context, String contextPath, Object contextValue, String dataType,
String templateId, String codePath, Iterable<Code> 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:https://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, r));
var result = engine.evaluate("Issue1225");

assertEquals("123", result.forExpression("Address Line 1").value());
}

}
Original file line number Diff line number Diff line change
@@ -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<Object> retrieve(String context, String contextPath, Object contextValue, String dataType,
String templateId, String codePath, Iterable<Code> 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:https://hl7.org/fhir",
new CompositeDataProvider(r4ModelResolver, r));

var result = engine.evaluate("Issue1226")
.forExpression("Most Recent Medication Request reference")
.value();

assertEquals("Medication/456", result);
}

}
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a856e39

Please sign in to comment.