Search in sources :

Example 21 with FhirServerConfig

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

the class CqlTemporalTests method confirmCanFindEventWithExistenceOfThirdEvent.

@Test
public void confirmCanFindEventWithExistenceOfThirdEvent() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    Observation observation = new Observation();
    DateTimeType observationEffective = new DateTimeType(new Date());
    observationEffective.setYear(2015);
    observationEffective.setMonth(0);
    observationEffective.setDay(5);
    observation.setEffective(observationEffective);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
    mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observation, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "ObservationWithin30DaysOfCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test2", "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 : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) HashMap(java.util.HashMap) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 22 with FhirServerConfig

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

the class CqlTemporalTests method anEventDoesFollow.

@Test
public void anEventDoesFollow() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "NotFollowedByCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test4", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, false);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : HashMap(java.util.HashMap) 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)

Example 23 with FhirServerConfig

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

the class CohortCLITest method testMainZippedLibrariesMultiFolderWithExtraEntriesFiltered.

@Test
public void testMainZippedLibrariesMultiFolderWithExtraEntriesFiltered() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    IParser encoder = getFhirParser();
    mockFhirResourceRetrieval("/metadata?_format=json", encoder, getCapabilityStatement(), fhirConfig);
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, 65);
    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", "--filter", "cohorts/ci_colorectal_cancer_screening_v1_0_0_cql", "-l", "CI_Colorectal-Cancer", "-v", "Screening", "-e", "Individuals 50-75 years of age", "-c", "123", "-s", "CQL" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(output, 4, 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 24 with FhirServerConfig

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

the class CohortCLITest method testMainZippedLibrariesMultiFolderWithExtraEntriesFilteredNoneFound.

@Test(expected = IllegalArgumentException.class)
public void testMainZippedLibrariesMultiFolderWithExtraEntriesFilteredNoneFound() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    IParser encoder = getFhirParser();
    mockFhirResourceRetrieval("/metadata?_format=json", encoder, getCapabilityStatement(), fhirConfig);
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, 65);
    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", "--filter", "does-not-exist", "-l", "CI_Colorectal-Cancer", "-v", "Screening", "-e", "Individuals 50-75 years of age", "-c", "123", "-s", "CQL" });
            fail("Execution should not reach this point");
        } finally {
            System.setOut(originalOut);
        }
    } 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 25 with FhirServerConfig

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

the class CohortCLITest method testMainZippedLibrariesWithCompilation.

@Test
public void testMainZippedLibrariesWithCompilation() throws Exception {
    FhirServerConfig fhirConfig = getFhirServerConfig();
    IParser encoder = getFhirParser();
    mockFhirResourceRetrieval("/metadata?_format=json", encoder, getCapabilityStatement(), fhirConfig);
    Patient justRight = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
    mockFhirResourceRetrieval(justRight);
    Patient tooOld = getPatient("456", Enumerations.AdministrativeGender.FEMALE, "1900-08-01");
    mockFhirResourceRetrieval(tooOld);
    Patient tooManly = getPatient("789", Enumerations.AdministrativeGender.MALE, "1978-05-06");
    mockFhirResourceRetrieval(tooManly);
    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/breast_cancer_screening_v1_0_0_cql.zip", "-l", "Breast-Cancer", "-v", "Screening", "-e", "Female", "-e", "40-65 years of age", "-e", "MeetsInclusionCriteria", "-c", "123", "-c", "456", "-c", "789", "-s", "CQL" });
        } finally {
            System.setOut(originalOut);
        }
        String output = new String(baos.toByteArray());
        String[] lines = output.split("\r?\n");
        assertEquals(output, 16, lines.length);
        System.out.println(output);
        verify(1, getRequestedFor(urlEqualTo("/Patient/123?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Patient/456?_format=json")));
        verify(1, getRequestedFor(urlEqualTo("/Patient/789?_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)

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