Search in sources :

Example 41 with Library

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

the class MeasureCLITest method testProportionRatioMultiplePatients.

@Test
public void testProportionRatioMultiplePatients() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient1 = mockPatientRetrieval("123", AdministrativeGender.MALE, 30);
    Patient patient2 = mockPatientRetrieval("456", AdministrativeGender.MALE, 45);
    Patient patient3 = mockPatientRetrieval("789", AdministrativeGender.FEMALE, 45);
    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", patient1.getId(), "-c", patient2.getId(), "-c", patient3.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, 18, 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 42 with Library

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

the class FhirTestBase method getLibrary.

protected Library getLibrary(String name, String version, String... attachmentData) throws Exception {
    if (attachmentData == null || attachmentData.length == 0 || (attachmentData.length > 2) && ((attachmentData.length % 2) != 0)) {
        fail("Invalid attachment data. Data must consist of one or more pairs of resource path and content-type strings");
    }
    List<String> pairs = new ArrayList<>(Arrays.asList(attachmentData));
    if (pairs.size() == 1) {
        pairs.add("text/cql");
    }
    List<Attachment> attachments = new ArrayList<>();
    for (int i = 0; i < pairs.size(); i += 2) {
        String resource = pairs.get(i);
        String contentType = pairs.get(i + 1);
        try (InputStream is = ClassLoader.getSystemResourceAsStream(resource)) {
            assertNotNull(String.format("No such resource %s found in classpath", resource), is);
            String text = IOUtils.toString(is, StandardCharsets.UTF_8);
            Attachment attachment = new Attachment();
            attachment.setContentType(contentType);
            attachment.setData(text.getBytes());
            attachments.add(attachment);
        }
    }
    Library library = new Library();
    library.setId("library-" + name + "-" + version);
    library.setName(name);
    library.setUrl(IBM_PREFIX + "/Library/" + name);
    library.setVersion(version);
    library.setContent(attachments);
    return library;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attachment(org.hl7.fhir.r4.model.Attachment) Library(org.hl7.fhir.r4.model.Library)

Example 43 with Library

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

the class MeasureEvaluatorTest method id_based_library_link___successfully_loaded_and_evaluated.

@Test
public void id_based_library_link___successfully_loaded_and_evaluated() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("TestDummyPopulations", DEFAULT_VERSION, "cql/fhir-measure/test-dummy-populations.cql");
    Measure measure = getCareGapMeasure("IDBasedLibraryMeasure", library, expressionsByPopulationType, "CareGap1", "CareGap2");
    measure.setLibrary(Arrays.asList(new CanonicalType("Library/" + library.getId())));
    mockFhirResourceRetrieval(measure);
    Map<String, Parameter> passingParameters = new HashMap<>();
    passingParameters.put("InInitialPopulation", new BooleanParameter(true));
    List<MeasureContext> measureContexts = new ArrayList<>();
    measureContexts.add(new MeasureContext(measure.getId(), passingParameters));
    List<MeasureReport> reports = evaluator.evaluatePatientMeasures(patient.getId(), measureContexts);
    assertEquals(1, reports.size());
    MeasureReport report = reports.get(0);
    verifyStandardPopulationCounts(report);
    verify(1, getRequestedFor(urlEqualTo("/Library/" + library.getId() + "?_format=json")));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Measure(org.hl7.fhir.r4.model.Measure) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 44 with Library

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

the class MeasureEvaluatorTest method in_populations_evaluated_boolean_define_only_returned.

@Test
public void in_populations_evaluated_boolean_define_only_returned() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    Library library = setupDefineReturnLibrary();
    expressionsByPopulationType.clear();
    expressionsByPopulationType.put(MeasurePopulationType.INITIALPOPULATION, INITIAL_POPULATION);
    expressionsByPopulationType.put(MeasurePopulationType.DENOMINATOR, DENOMINATOR);
    expressionsByPopulationType.put(MeasurePopulationType.NUMERATOR, NUMERATOR);
    Measure measure = getProportionMeasure("ProportionMeasureName", library, expressionsByPopulationType);
    mockFhirResourceRetrieval(measure);
    MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null, new MeasureEvidenceOptions(false, DefineReturnOptions.BOOLEAN));
    assertNotNull(report);
    assertTrue(report.getEvaluatedResource().isEmpty());
    assertFalse(report.getExtensionsByUrl(CDMConstants.EVIDENCE_URL).isEmpty());
}
Also used : CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Library(org.hl7.fhir.r4.model.Library) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) Test(org.junit.Test)

Example 45 with Library

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

the class MeasureEvaluatorTest method in_initial_population_when_engine_run_in_utc__engine_defaults_to_utc.

@Test
public void in_initial_population_when_engine_run_in_utc__engine_defaults_to_utc() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    // Test CQL written to pass when engine run with a timezone of UTC
    // and should fail otherwise
    Library library = mockLibraryRetrieval("TestDatetimeDefaultTimezones", DEFAULT_VERSION, "cql/fhir-measure/test-datetime-default-timezones.cql", "text/cql");
    Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
    mockFhirResourceRetrieval(measure);
    MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null, new MeasureEvidenceOptions(false, DefineReturnOptions.BOOLEAN));
    assertNotNull(report);
    report.getExtension().stream().filter(x -> x.getUrl().equals(CDMConstants.EVIDENCE_URL)).forEach(x -> validateBooleanEvidence(x, true));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_VALUE_URL) Range(org.hl7.fhir.r4.model.Range) StringUtils(org.apache.commons.lang3.StringUtils) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) InvalidOperatorArgument(org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) HumanName(org.hl7.fhir.r4.model.HumanName) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Map(java.util.Map) StringType(org.hl7.fhir.r4.model.StringType) Assert.fail(org.junit.Assert.fail) ParseException(java.text.ParseException) IntegerType(org.hl7.fhir.r4.model.IntegerType) Patient(org.hl7.fhir.r4.model.Patient) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) DateType(org.hl7.fhir.r4.model.DateType) TimeZone(java.util.TimeZone) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Period(org.hl7.fhir.r4.model.Period) MEASURE_PARAMETER_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_URL) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) PARAMETER_DEFAULT_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_DEFAULT_URL) TimeType(org.hl7.fhir.r4.model.TimeType) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Extension(org.hl7.fhir.r4.model.Extension) UriType(org.hl7.fhir.r4.model.UriType) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) Address(org.hl7.fhir.r4.model.Address) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) MEASURE_PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_VALUE_URL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Ratio(org.hl7.fhir.r4.model.Ratio) MeasureSupplementalDataEvaluation(com.ibm.cohort.engine.cqfruler.MeasureSupplementalDataEvaluation) DecimalType(org.hl7.fhir.r4.model.DecimalType) Before(org.junit.Before) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ListResource(org.hl7.fhir.r4.model.ListResource) Library(org.hl7.fhir.r4.model.Library) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) CDMConstants(com.ibm.cohort.engine.cdm.CDMConstants) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Assert.assertEquals(org.junit.Assert.assertEquals) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Library(org.hl7.fhir.r4.model.Library) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) 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