Search in sources :

Example 26 with FhirServerConfig

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

the class CohortCLITest method testMainNoParams.

@Test
public void testMainNoParams() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    setupTestFor(patient, fhirConfig, "cql.no-version");
    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/no-version", "-l", "Test", "-e", "Female", "-e", "Male", "-e", "Over the hill", "-c", "123" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(6, lines.length);
        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) Test(org.junit.Test)

Example 27 with FhirServerConfig

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

the class CohortCLITest method testMainFHIRLibrariesWithDependencies.

@Test
public void testMainFHIRLibrariesWithDependencies() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    mockFhirResourceRetrieval(patient);
    Library root = getLibrary("Breast-Cancer-Screening", DEFAULT_RESOURCE_VERSION, "cql/includes/Breast-Cancer-Screening.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" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(output, 12, lines.length);
        System.out.println(output);
        verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_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) Library(org.hl7.fhir.r4.model.Library) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 28 with FhirServerConfig

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

the class CohortCLITest method testMainWithParams.

@Test
public void testMainWithParams() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    setupTestFor(patient, fhirConfig, "cql.parameters");
    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/parameters", "-l", "test-with", "-v", "params", "-e", "Female", "-e", "Male", "-c", "123", "-p", "MaxAge:integer:40" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(5, lines.length);
        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) Test(org.junit.Test)

Example 29 with FhirServerConfig

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

the class CohortCLITest method testMainMultiFolder.

@Test
public void testMainMultiFolder() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    setupTestFor(patient, fhirConfig, "cql.multi-folder");
    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/multi-folder", "-l", "Cohort1", "-v", "1.0.0", "-c", "123" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(String.join("\n", lines), 5, lines.length);
        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) Test(org.junit.Test)

Example 30 with FhirServerConfig

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

the class CohortCLITest method testMainNoContext.

@Test
public void testMainNoContext() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    setupTestFor(patient, fhirConfig, "cql.unfiltered-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/unfiltered-context", "-l", "UnfilteredContext", "-v", "1.0.0", "-e", "ValidateMath" });
        } finally {
            System.setOut(originalOut);
        }
        String output = baos.toString();
        Assert.assertTrue(output.contains("Expression: \"ValidateMath\", Result: true"));
        verify(0, 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) 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