use of org.hl7.fhir.utilities.turtle.Turtle.Subject in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveServiceRequest.
private ServiceRequest resolveServiceRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
// status, intent, code, and subject are required
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.DRAFT);
serviceRequest.setIntent(ServiceRequest.ServiceRequestIntent.PROPOSAL);
String patientReferenceString = patientId;
URI patientIdAsUri = URI.create(patientReferenceString);
if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
patientReferenceString = "Patient/" + patientId;
}
serviceRequest.setSubject(new Reference(patientReferenceString));
if (practitionerId != null) {
serviceRequest.setRequester(new Reference(practitionerId));
} else if (organizationId != null) {
serviceRequest.setRequester(new Reference(organizationId));
}
if (activityDefinition.hasExtension()) {
serviceRequest.setExtension(activityDefinition.getExtension());
}
if (activityDefinition.hasCode()) {
serviceRequest.setCode(activityDefinition.getCode());
} else // code can be set as a dynamicValue
if (!activityDefinition.hasCode() && !activityDefinition.hasDynamicValue()) {
throw new ActivityDefinitionApplyException("Missing required code property");
}
if (activityDefinition.hasBodySite()) {
serviceRequest.setBodySite(activityDefinition.getBodySite());
}
if (activityDefinition.hasProduct()) {
throw new ActivityDefinitionApplyException("Product does not map to " + activityDefinition.getKind());
}
if (activityDefinition.hasDosage()) {
throw new ActivityDefinitionApplyException("Dosage does not map to " + activityDefinition.getKind());
}
return serviceRequest;
}
use of org.hl7.fhir.utilities.turtle.Turtle.Subject in project cqf-ruler by DBCG.
the class CqlExecutionProviderIT method testDataBundleCqlExecutionProviderWithSubject.
@Test
public void testDataBundleCqlExecutionProviderWithSubject() throws Exception {
Parameters params = new Parameters();
Parameters libraryParameter = new Parameters();
params.addParameter().setName("subject").setValue(new StringType("Patient/SimplePatient"));
libraryParameter.addParameter().setName("url").setValue(new StringType(this.getClient().getServerBase() + "Library/SimpleDstu3Library"));
libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleDstu3Library"));
params.addParameter().setName("library").setResource(libraryParameter);
params.addParameter().setName("expression").setValue(new StringType("SimpleDstu3Library.\"observationRetrieve\""));
String packagePrefix = "org/opencds/cqf/ruler/cpg/dstu3/provider/";
loadResource(packagePrefix + "SimpleDstu3Library.json");
loadResource(packagePrefix + "SimplePatient.json");
Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json");
params.addParameter().setName("data").setResource(data);
params.addParameter().setName("useServerData").setValue(new BooleanType(false));
Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
assertTrue(results.getParameter().get(0).getResource() instanceof Bundle);
assertTrue(((Bundle) results.getParameter().get(0).getResource()).getEntry().get(0).getResource() instanceof Observation);
assertTrue(results.getParameter().get(1).getValue() instanceof StringType);
assertTrue(((StringType) results.getParameter().get(1).getValue()).asStringValue().equals("List"));
logger.debug("Results: ", results);
}
use of org.hl7.fhir.utilities.turtle.Turtle.Subject in project cqf-ruler by DBCG.
the class CqlExecutionProviderIT method testReferencedLibraryCqlExecutionProvider.
@Test
public void testReferencedLibraryCqlExecutionProvider() throws Exception {
Parameters params = new Parameters();
params.addParameter().setName("subject").setValue(new StringType("Patient/SimplePatient"));
Parameters libraryParameter = new Parameters();
libraryParameter.addParameter().setName("url").setValue(new StringType(this.getClient().getServerBase() + "Library/SimpleDstu3Library"));
libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleDstu3Library"));
params.addParameter().setName("library").setResource(libraryParameter);
params.addParameter().setName("expression").setValue(new StringType("SimpleDstu3Library.\"simpleBooleanExpression\""));
String packagePrefix = "org/opencds/cqf/ruler/cpg/dstu3/provider/";
loadResource(packagePrefix + "SimpleDstu3Library.json");
loadResource(packagePrefix + "SimplePatient.json");
Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
assertTrue(results.getParameter().get(0).getValue() instanceof StringType);
assertTrue(((StringType) results.getParameter().get(0).getValue()).asStringValue().equals("true"));
assertTrue(results.getParameter().get(1).getValue() instanceof StringType);
assertTrue(((StringType) results.getParameter().get(1).getValue()).asStringValue().equals("Boolean"));
logger.debug("Results: ", results);
}
use of org.hl7.fhir.utilities.turtle.Turtle.Subject in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainMultipleResultTypes.
@Test
public void testMainMultipleResultTypes() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
patient.setMaritalStatus(new CodeableConcept(new Coding("http://hl7.org/fhir/ValueSet/marital-status", "M", "Married")));
mockFhirResourceRetrieval(patient);
Condition condition = new Condition();
condition.setSubject(new Reference(patient.getId()));
condition.setCode(new CodeableConcept(new Coding("http://snomed.com/snomed/2020", "1234", "Dummy")));
mockFhirResourceRetrieval("/Condition?code%3Ain=http%3A%2F%2Fsome.io%2Fcondition&subject=Patient%2F" + patient.getId() + "&_count=500&_format=json", condition);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/result-types", "-l", "test_result_types", "-c", patient.getId(), "--enable-terminology-optimization", "--search-page-size", "500" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
assertTrue(output.contains("Collection: 1"));
assertTrue(output.contains("Patient/123"));
assertTrue(output.contains("false"));
assertTrue(output.contains("DateType[1978-05-06]"));
assertTrue(output.contains("Enumeration[female]"));
String[] lines = output.split("\r?\n");
assertEquals(output, 9, lines.length);
System.out.println(output);
} finally {
tmpFile.delete();
}
}
use of org.hl7.fhir.utilities.turtle.Turtle.Subject in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method canFindMultipleEncountersFollowingEachOther.
@Test
public void canFindMultipleEncountersFollowingEachOther() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
Bundle bundle = new Bundle();
Bundle.BundleEntryComponent firstEncounter = new Bundle.BundleEntryComponent();
firstEncounter.setResource(ENCOUNTER_1);
Bundle.BundleEntryComponent secondEncounter = new Bundle.BundleEntryComponent();
secondEncounter.setResource(ENCOUNTER_2);
bundle.addEntry(firstEncounter);
bundle.addEntry(secondEncounter);
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), bundle, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "ValidEncounters2";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test3", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
Aggregations