use of org.hl7.fhir.r5.model.CanonicalType in project cqf-ruler by DBCG.
the class Session method resolveDefinition.
private Resource resolveDefinition(Session session, PlanDefinition.PlanDefinitionActionComponent action, RequestDetails theRequest) {
Resource result = null;
if (action.hasDefinition()) {
logger.debug("Resolving definition: {}", action.getDefinitionCanonicalType().getValue());
String definition = action.getDefinitionCanonicalType().getValue();
if (definition.contains(session.getPlanDefinition().fhirType())) {
IdType id = new IdType(definition);
CarePlan plan;
try {
plan = applyPlanDefinition(theRequest, id, session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), session.getUserType(), session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
if (plan.getId() == null) {
plan.setId(UUID.randomUUID().toString());
}
for (CanonicalType c : plan.getInstantiatesCanonical()) {
session.getCarePlanBuilder().buildInstantiatesCanonical(c.getValueAsString());
}
result = plan;
} catch (IOException e) {
e.printStackTrace();
logger.error("nested plan failed");
}
} else {
try {
if (action.getDefinitionCanonicalType().getValue().startsWith("#")) {
result = this.activityDefinitionApplyProvider.resolveActivityDefinition((ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinitionCanonicalType().getValue()), session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest);
} else {
result = this.activityDefinitionApplyProvider.apply(theRequest, new IdType(CanonicalHelper.getId(action.getDefinitionCanonicalType())), session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), null, session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
}
if (result.getId() == null) {
logger.warn("ActivityDefinition {} returned resource with no id, setting one", action.getDefinitionCanonicalType().getId());
result.setId(UUID.randomUUID().toString());
}
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition {} could not be applied and threw exception {}", action.getDefinition(), e.toString());
}
}
}
return result;
}
use of org.hl7.fhir.r5.model.CanonicalType 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 CanonicalType(this.getClient().getServerBase() + "Library/SimpleR4Library"));
libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleR4Library"));
params.addParameter().setName("library").setResource(libraryParameter);
params.addParameter().setName("expression").setValue(new StringType("SimpleR4Library.\"simpleBooleanExpression\""));
String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/";
loadResource(packagePrefix + "SimpleR4Library.json");
loadResource(packagePrefix + "SimplePatient.json");
Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
assertTrue(results.getParameter("value") instanceof StringType);
assertTrue(((StringType) results.getParameter("value")).asStringValue().equals("true"));
assertTrue(results.getParameter("resultType") instanceof StringType);
assertTrue(((StringType) results.getParameter("resultType")).asStringValue().equals("Boolean"));
logger.debug("Results: ", results);
}
use of org.hl7.fhir.r5.model.CanonicalType 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 CanonicalType(this.getClient().getServerBase() + "Library/SimpleR4Library"));
libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleR4Library"));
params.addParameter().setName("library").setResource(libraryParameter);
params.addParameter().setName("expression").setValue(new StringType("SimpleR4Library.\"observationRetrieve\""));
String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/";
loadResource(packagePrefix + "SimpleR4Library.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("resultType") instanceof StringType);
assertTrue(((StringType) results.getParameter("resultType")).asStringValue().equals("List"));
logger.debug("Results: ", results);
}
use of org.hl7.fhir.r5.model.CanonicalType 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 CanonicalType(this.getClient().getServerBase() + "Library/SimpleR4Library"));
libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleR4Library"));
params.addParameter().setName("library").setResource(libraryParameter);
params.addParameter().setName("expression").setValue(new StringType("SimpleR4Library.\"observationRetrieve\""));
String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/";
loadResource(packagePrefix + "SimpleR4Library.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("resultType") instanceof StringType);
assertTrue(((StringType) results.getParameter("resultType")).asStringValue().equals("List"));
logger.debug("Results: ", results);
}
use of org.hl7.fhir.r5.model.CanonicalType in project cqf-ruler by DBCG.
the class ExpressionEvaluation method getLibraryReferences.
private List<CanonicalType> getLibraryReferences(DomainResource instance, RequestDetails theRequest) {
List<CanonicalType> references = new ArrayList<>();
if (instance.hasContained()) {
for (Resource resource : instance.getContained()) {
if (resource instanceof Library) {
resource.setId(resource.getIdElement().getIdPart().replace("#", ""));
this.jpaFhirDalFactory.create(theRequest).update((Library) resource);
// getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(),
// getLibraryLoader().toElmLibrary((Library) resource));
}
}
}
if (instance instanceof ActivityDefinition) {
references.addAll(((ActivityDefinition) instance).getLibrary());
} else if (instance instanceof PlanDefinition) {
references.addAll(((PlanDefinition) instance).getLibrary());
} else if (instance instanceof Measure) {
references.addAll(((Measure) instance).getLibrary());
}
for (Extension extension : instance.getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/cqif-library")) {
Type value = extension.getValue();
if (value instanceof CanonicalType) {
references.add((CanonicalType) value);
} else {
throw new RuntimeException("Library extension does not have a value of type reference");
}
}
return cleanReferences(references);
}
Aggregations