Search in sources :

Example 31 with Subject

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;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) URI(java.net.URI) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest)

Example 32 with Subject

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);
}
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 33 with Subject

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);
}
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 34 with Subject

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();
    }
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) PrintStream(java.io.PrintStream) Reference(org.hl7.fhir.r4.model.Reference) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Coding(org.hl7.fhir.r4.model.Coding) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 35 with Subject

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());
}
Also used : HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)124 Test (org.junit.jupiter.api.Test)68 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)64 Bundle (org.hl7.fhir.r4.model.Bundle)56 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)54 Parameters (org.hl7.fhir.r4.model.Parameters)46 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)43 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)42 StringType (org.hl7.fhir.r4.model.StringType)41 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)39 Observation (org.hl7.fhir.r4.model.Observation)38 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)37 Bundle (org.hl7.fhir.dstu3.model.Bundle)35 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)32 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)32 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)31 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)31 Patient (org.hl7.fhir.r4.model.Patient)30 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)30 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)29