Search in sources :

Example 36 with Library

use of org.hl7.fhir.dstu3.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLITest method testCohortMeasureByURLSinglePatientCommandLineInput.

@Test
public void testCohortMeasureByURLSinglePatientCommandLineInput() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1592-14-03");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("Test", DEFAULT_RESOURCE_VERSION, "cql/basic/Test-1.0.0.cql");
    Measure measure = getCohortMeasure("Test", library, "Female");
    mockMeasureRetrieval(measure);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(getFhirServerConfig()));
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    try {
        MeasureCLI cli = new MeasureCLI();
        cli.runWithArgs(new String[] { "-d", tmpFile.getAbsolutePath(), "-p", "p1:interval:decimal,1.0,100.5", "-p", "p2:integer:1", "-r", CanonicalHelper.toCanonicalUrl(measure.getUrl(), measure.getVersion()), "-c", patient.getId() }, out);
    } finally {
        tmpFile.delete();
    }
    String output = new String(baos.toByteArray());
    String[] lines = output.split(System.getProperty("line.separator"));
    assertEquals(output, 4, lines.length);
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Library(org.hl7.fhir.r4.model.Library) 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 37 with Library

use of org.hl7.fhir.dstu3.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLITest method testProportionRatioSinglePatient.

@Test
public void testProportionRatioSinglePatient() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = new Patient();
    patient.setId("123");
    patient.setGender(AdministrativeGender.MALE);
    OffsetDateTime birthDate = OffsetDateTime.now().minusYears(30);
    patient.setBirthDate(Date.from(birthDate.toInstant()));
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("Test", DEFAULT_RESOURCE_VERSION, "cql/basic/Test-1.0.0.cql");
    expressionsByPopulationType.clear();
    expressionsByPopulationType.put(MeasurePopulationType.INITIALPOPULATION, "Male");
    expressionsByPopulationType.put(MeasurePopulationType.DENOMINATOR, "Male");
    expressionsByPopulationType.put(MeasurePopulationType.NUMERATOR, "Over the hill");
    expectationsByPopulationType.clear();
    expectationsByPopulationType.put(MeasurePopulationType.INITIALPOPULATION, 1);
    expectationsByPopulationType.put(MeasurePopulationType.DENOMINATOR, 1);
    expectationsByPopulationType.put(MeasurePopulationType.NUMERATOR, 0);
    Measure measure = getProportionMeasure("Test", library, expressionsByPopulationType);
    mockFhirResourceRetrieval(measure);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(getFhirServerConfig()));
    }
    File tmpMeasureConfigurationsFile = createTmpConfigurationsFileForSingleMeasure(measure.getId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    try {
        MeasureCLI cli = new MeasureCLI();
        cli.runWithArgs(new String[] { "-d", tmpFile.getAbsolutePath(), "-j", tmpMeasureConfigurationsFile.getAbsolutePath(), "-c", patient.getId() }, out);
    } finally {
        tmpFile.delete();
        tmpMeasureConfigurationsFile.delete();
    }
    String output = new String(baos.toByteArray());
    System.out.println(output);
    String[] lines = output.split(System.getProperty("line.separator"));
    assertEquals(output, 6, lines.length);
    assertTextPopulationExpectations(lines);
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OffsetDateTime(java.time.OffsetDateTime) Measure(org.hl7.fhir.r4.model.Measure) 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 38 with Library

use of org.hl7.fhir.dstu3.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLITest method testJsonFormattedOutput.

@Test
public void testJsonFormattedOutput() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1592-14-03");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("Test", DEFAULT_RESOURCE_VERSION, "cql/basic/Test-1.0.0.cql");
    Measure measure = getCohortMeasure("Test", library, "Male");
    mockFhirResourceRetrieval(measure);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(getFhirServerConfig()));
    }
    File tmpMeasureConfigurationsFile = createTmpConfigurationsFileForSingleMeasure(measure.getId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    try {
        MeasureCLI cli = new MeasureCLI();
        cli.runWithArgs(new String[] { "-d", tmpFile.getAbsolutePath(), "-j", tmpMeasureConfigurationsFile.getAbsolutePath(), "-c", patient.getId(), "-f", "JSON" }, out);
    } finally {
        tmpFile.delete();
        tmpMeasureConfigurationsFile.delete();
    }
    String output = new String(baos.toByteArray());
    System.out.println(output);
    assertTrue(output.contains("\"resourceType\": \"MeasureReport\""));
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Library(org.hl7.fhir.r4.model.Library) 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 39 with Library

use of org.hl7.fhir.dstu3.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLITest method testCohortMeasureSinglePatientJsonInputWithCacheDisabled.

@Test
public void testCohortMeasureSinglePatientJsonInputWithCacheDisabled() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1592-14-03");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("Test", DEFAULT_RESOURCE_VERSION, "cql/basic/Test-1.0.0.cql");
    Measure measure = getCohortMeasure("Test", library, "Female");
    mockFhirResourceRetrieval(measure);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(getFhirServerConfig()));
    }
    File tmpMeasureConfigurationsFile = createTmpConfigurationsFileForSingleMeasure(measure.getId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    try {
        MeasureCLI cli = new MeasureCLI();
        cli.runWithArgs(new String[] { "-d", tmpFile.getAbsolutePath(), "-j", tmpMeasureConfigurationsFile.getAbsolutePath(), "-c", patient.getId(), "--disable-retrieve-cache" }, out);
    } finally {
        tmpFile.delete();
        tmpMeasureConfigurationsFile.delete();
    }
    String output = new String(baos.toByteArray());
    String[] lines = output.split(System.lineSeparator());
    assertEquals(output, 4, lines.length);
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Library(org.hl7.fhir.r4.model.Library) 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 40 with Library

use of org.hl7.fhir.dstu3.model.Library in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLITest method testCohortMeasureByIDSinglePatientCommandLineInput.

@Test
public void testCohortMeasureByIDSinglePatientCommandLineInput() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1592-14-03");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("Test", DEFAULT_RESOURCE_VERSION, "cql/basic/Test-1.0.0.cql");
    Measure measure = getCohortMeasure("Test", library, "Female");
    mockFhirResourceRetrieval(measure);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(getFhirServerConfig()));
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    try {
        MeasureCLI cli = new MeasureCLI();
        cli.runWithArgs(new String[] { "-d", tmpFile.getAbsolutePath(), "-p", "p1:interval:decimal,1.0,100.5", "-p", "p2:integer:1", "-r", measure.getId(), "-c", patient.getId() }, out);
    } finally {
        tmpFile.delete();
    }
    String output = new String(baos.toByteArray());
    String[] lines = output.split(System.getProperty("line.separator"));
    assertEquals(output, 4, lines.length);
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Library(org.hl7.fhir.r4.model.Library) 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

Library (org.hl7.fhir.r4.model.Library)130 Test (org.junit.Test)85 Measure (org.hl7.fhir.r4.model.Measure)60 Patient (org.hl7.fhir.r4.model.Patient)41 HashMap (java.util.HashMap)36 Test (org.junit.jupiter.api.Test)34 ArrayList (java.util.ArrayList)32 Library (org.hl7.fhir.dstu3.model.Library)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)21 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)21 StringType (org.hl7.fhir.r4.model.StringType)21 IOException (java.io.IOException)20 VersionedIdentifier (org.cqframework.cql.elm.execution.VersionedIdentifier)20 FhirContext (ca.uhn.fhir.context.FhirContext)19 IParser (ca.uhn.fhir.parser.IParser)19 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)19 Bundle (org.hl7.fhir.r4.model.Bundle)19 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)18