Search in sources :

Example 61 with CanonicalType

use of org.hl7.fhir.r4.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;
}
Also used : CarePlan(org.hl7.fhir.r4.model.CarePlan) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) IOException(java.io.IOException) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.r4.model.IdType) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Example 62 with CanonicalType

use of org.hl7.fhir.r4.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);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 63 with CanonicalType

use of org.hl7.fhir.r4.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);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) BooleanType(org.hl7.fhir.r4.model.BooleanType) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 64 with CanonicalType

use of org.hl7.fhir.r4.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);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) BooleanType(org.hl7.fhir.r4.model.BooleanType) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 65 with CanonicalType

use of org.hl7.fhir.r4.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);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Type(org.hl7.fhir.r4.model.Type) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) IdType(org.hl7.fhir.r4.model.IdType) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) Measure(org.hl7.fhir.r4.model.Measure) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) Library(org.hl7.fhir.r4.model.Library) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)45 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)27 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Extension (org.hl7.fhir.r4.model.Extension)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 IdType (org.hl7.fhir.r4.model.IdType)5