-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for issues 1225 and 1226 (#1276)
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1225.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, r)); | ||
var result = engine.evaluate("Issue1225"); | ||
|
||
assertEquals("123", result.forExpression("Address Line 1").value()); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/Issue1226.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://hl7.org/fhir", | ||
new CompositeDataProvider(r4ModelResolver, r)); | ||
|
||
var result = engine.evaluate("Issue1226") | ||
.forExpression("Most Recent Medication Request reference") | ||
.value(); | ||
|
||
assertEquals("Medication/456", result); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1225.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
16 changes: 16 additions & 0 deletions
16
Src/java/engine-fhir/src/test/resources/org/opencds/cqf/cql/engine/fhir/data/Issue1226.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |