Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for issues 1225 and 1226 #1276

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}

}
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);
}

}
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