Search in sources :

Example 6 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig 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 7 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CohortCLITest method testMainNonPatientContext.

@Test
public void testMainNonPatientContext() throws Exception {
    Encounter encounter = new Encounter();
    encounter.setId("123");
    encounter.setStatus(Encounter.EncounterStatus.FINISHED);
    Encounter otherEncounter = new Encounter();
    otherEncounter.setId("234");
    otherEncounter.setStatus(Encounter.EncounterStatus.FINISHED);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    String resourcePath = "/Encounter?_count=1000&_format=json";
    mockFhirResourceRetrieval(resourcePath, getFhirParser(), makeBundle(encounter, otherEncounter));
    setupTestFor(encounter, fhirConfig, "cql.encounter-context");
    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(), "-t", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/encounter-context", "-l", "EncounterContext", "-v", "1.0.0", "-e", "ValidEncounterCount", "-n", "Encounter" });
        } finally {
            System.setOut(originalOut);
        }
        String output = baos.toString();
        assertTrue(output.contains("Expression: \"ValidEncounterCount\", Result: 2"));
        verify(1, getRequestedFor(urlEqualTo(resourcePath)));
    } finally {
        tmpFile.delete();
    }
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Encounter(org.hl7.fhir.r4.model.Encounter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 8 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CohortCLITest method testCQLTranslationCustomIGWithTargetUrl.

@Test
public void testCQLTranslationCustomIGWithTargetUrl() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    patient.addExtension(new Extension("http://fakeIg.com/fake-extension", new StringType("fakeValue")));
    mockFhirResourceRetrieval(patient);
    Library root = getLibrary("test", DEFAULT_RESOURCE_VERSION, "cql/ig-test/Test-1.0.0.cql");
    Library helpers = getLibrary("FHIRHelpers", "4.0.0", "cql/fhir-helpers/FHIRHelpers.cql", "text/cql", "cql/fhir-helpers/FHIRHelpers.xml", "application/elm+json");
    RelatedArtifact related = new RelatedArtifact();
    related.setType(RelatedArtifactType.DEPENDSON);
    related.setResource("/Library/" + helpers.getId());
    root.addRelatedArtifact(related);
    mockFhirResourceRetrieval(root);
    mockFhirSingletonBundleRetrieval(helpers);
    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", root.getId(), "-l", root.getName(), "-v", root.getVersion(), "-c", patient.getId(), "-s", "CQL", "-i", "src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        System.out.println(output);
        verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Library?url=%2FLibrary%2F" + helpers.getId() + "&_format=json")));
    } finally {
        tmpFile.delete();
    }
}
Also used : PrintStream(java.io.PrintStream) StringType(org.hl7.fhir.r4.model.StringType) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Extension(org.hl7.fhir.r4.model.Extension) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 9 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class CohortCLITest method testMainZippedLibrariesMultiFolderWithExtraEntries.

@Test
public void testMainZippedLibrariesMultiFolderWithExtraEntries() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    IParser encoder = getFhirParser();
    mockFhirResourceRetrieval("/metadata?_format=json", encoder, getCapabilityStatement(), fhirConfig);
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    mockFhirResourceRetrieval(patient);
    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(), "-t", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/zip-with-folders/cohorts.zip", "-l", "Breast-Cancer", "-v", "Screening", "-e", "Female", "-e", "Ages 40 to 75", "-e", "MeetsInclusionCriteria", "-c", "123", "-s", "CQL" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(output, 6, lines.length);
        System.out.println(output);
        verify(1, getRequestedFor(urlEqualTo("/Patient/123?_format=json")));
    } finally {
        tmpFile.delete();
    }
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) IParser(ca.uhn.fhir.parser.IParser) Test(org.junit.Test)

Example 10 with FhirServerConfig

use of com.ibm.cohort.fhir.client.config.FhirServerConfig in project quality-measure-and-cohort-service by Alvearie.

the class FhirClientTimeoutTest method testDefaultFhirClientBuilder_requestTimesOut.

@Test(expected = FhirClientConnectionException.class)
public void testDefaultFhirClientBuilder_requestTimesOut() {
    FhirServerConfig fhirServerConfig = getFhirServerConfig();
    fhirServerConfig.setSocketTimeout(CONFIG_TIMEOUT_MILLIS);
    DefaultFhirClientBuilder builder = new DefaultFhirClientBuilder(fhirContext);
    IGenericClient client = builder.createFhirClient(fhirServerConfig);
    client.read().resource(Patient.class).withId(PATIENT_ID).execute();
}
Also used : DefaultFhirClientBuilder(com.ibm.cohort.fhir.client.config.DefaultFhirClientBuilder) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Test(org.junit.Test)

Aggregations

FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)63 Test (org.junit.Test)52 Patient (org.hl7.fhir.r4.model.Patient)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)36 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 HashMap (java.util.HashMap)21 File (java.io.File)18 IAttachment (com.ibm.websphere.jaxrs20.multipart.IAttachment)15 Response (javax.ws.rs.core.Response)15 CqlEvaluator (com.ibm.cohort.cql.evaluation.CqlEvaluator)14 CqlVersionedIdentifier (com.ibm.cohort.cql.library.CqlVersionedIdentifier)14 FileWriter (java.io.FileWriter)14 CqlEvaluationResult (com.ibm.cohort.cql.evaluation.CqlEvaluationResult)13 PrintStream (java.io.PrintStream)13 Writer (java.io.Writer)13 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)10 IMultipartBody (com.ibm.websphere.jaxrs20.multipart.IMultipartBody)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IParser (ca.uhn.fhir.parser.IParser)9