Search in sources :

Example 86 with Operation

use of org.hl7.fhir.utilities.graphql.Operation 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;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) BooleanType(org.hl7.fhir.r4.model.BooleanType) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Example 87 with Operation

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

Example 88 with Operation

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

Example 89 with Operation

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

Example 90 with Operation

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

Aggregations

Parameters (org.hl7.fhir.r4.model.Parameters)72 Test (org.junit.jupiter.api.Test)69 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)63 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)63 StringType (org.hl7.fhir.r4.model.StringType)62 ArrayList (java.util.ArrayList)60 IOException (java.io.IOException)54 List (java.util.List)54 Bundle (org.hl7.fhir.r4.model.Bundle)53 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)52 Collectors (java.util.stream.Collectors)51 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)50 RequestHeaders (gov.cms.bfd.server.war.commons.RequestHeaders)48 FileOutputStream (java.io.FileOutputStream)47 Collections (java.util.Collections)47 Optional (java.util.Optional)47 File (java.io.File)46 Arrays (java.util.Arrays)46 CommonHeaders (gov.cms.bfd.server.war.commons.CommonHeaders)45 TransformerConstants (gov.cms.bfd.server.war.commons.TransformerConstants)45