use of org.hl7.fhir.r4.model.StringType in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveActivityDefinition.
// For library use
public Resource resolveActivityDefinition(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId, RequestDetails theRequest) throws FHIRException {
Resource result = newResource(activityDefinition.getKind().toCode());
switch(result.fhirType()) {
case "ServiceRequest":
result = resolveServiceRequest(activityDefinition, patientId, practitionerId, organizationId);
break;
case "MedicationRequest":
result = resolveMedicationRequest(activityDefinition, patientId);
break;
case "SupplyRequest":
result = resolveSupplyRequest(activityDefinition, practitionerId, organizationId);
break;
case "Procedure":
result = resolveProcedure(activityDefinition, patientId);
break;
case "DiagnosticReport":
result = resolveDiagnosticReport(activityDefinition, patientId);
break;
case "Communication":
result = resolveCommunication(activityDefinition, patientId);
break;
case "CommunicationRequest":
result = resolveCommunicationRequest(activityDefinition, patientId);
break;
case "Task":
result = resolveTask(activityDefinition, patientId);
break;
}
for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
// ActivityDefinition apply operation does not fail.
try {
if (dynamicValue.getExpression() != null) {
// Special case for setting a Patient reference
if ("Patient".equals(dynamicValue.getExpression().getExpression())) {
this.modelResolver.setValue(result, dynamicValue.getPath(), new Reference(patientId));
} else {
/*
* TODO: Passing the activityDefinition as context here because that's what will
* have the libraries, but perhaps the "context" here should be the result
* resource?
*/
Object value = expressionEvaluation.evaluateInContext(activityDefinition, dynamicValue.getExpression().getExpression(), patientId, theRequest);
if (value != null) {
logger.debug("dynamicValue value: {}", value);
if (value instanceof Boolean) {
value = new BooleanType((Boolean) value);
} else if (value instanceof DateTime) {
value = Date.from(((DateTime) value).getDateTime().toInstant());
} else if (value instanceof String) {
value = new StringType((String) value);
}
this.modelResolver.setValue(result, dynamicValue.getPath(), value);
} else {
logger.warn("WARNING: ActivityDefinition has null value for path: {}", dynamicValue.getPath());
}
}
}
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition dynamicValue {} could not be applied and threw exception {}", dynamicValue.getPath(), e.toString());
logger.error(e.toString());
}
}
return result;
}
use of org.hl7.fhir.r4.model.StringType 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.r4.model.StringType in project cqf-ruler by DBCG.
the class CqlExecutionProviderIT method testDataBundleCqlExecutionProvider.
@Test
public void testDataBundleCqlExecutionProvider() throws Exception {
Parameters params = new Parameters();
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.\"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.r4.model.StringType 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.r4.model.StringType in project cqf-ruler by DBCG.
the class LibraryEvaluationProviderIT method testLibraryEvaluationValidationThrows.
@Test
public void testLibraryEvaluationValidationThrows() throws IOException {
Parameters params = new Parameters();
params.addParameter().setName("periodStart").setValue(new StringType("2021-01-01"));
params.addParameter().setName("periodEnd").setValue(new StringType("2021-12-31"));
params.addParameter().setName("patientId").setValue(null);
params.addParameter().setName("context").setValue(new StringType("Patient"));
String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/";
loadResource(packagePrefix + "ColorectalCancerScreeningsFHIR.json");
Library lib = getClient().read().resource(Library.class).withId("ColorectalCancerScreeningsFHIR").execute();
assertNotNull(lib);
assertThrows(InternalErrorException.class, () -> {
getClient().operation().onInstance(new IdType("Library", "ColorectalCancerScreeningsFHIR")).named("$evaluate").withParameters(params).returnResourceType(Bundle.class).execute();
});
}
Aggregations