Search in sources :

Example 26 with Measure

use of org.hl7.fhir.r5.model.Measure 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)

Example 27 with Measure

use of org.hl7.fhir.r5.model.Measure 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 28 with Measure

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

the class MeasureSupplementalDataEvaluationTest method testProcessAccumulators_notSDESex.

@Test
public void testProcessAccumulators_notSDESex() {
    /* 
		 * Jill - I don't like how this part of the code works.  The code grabs everything after (and including) the "-", 
		 * and then looks for that to exist as an extension on the Patient resource.  This works for race and ethnicity 
		 * on the US-core patient profile, but since we already calculated this in the populate SDE accumulator method
		 * the only reason it's "recalculating" is because the system and display aren't on the passed in map.
		 * Plus, it's coded assuming there is a list of extensions within the extension (which is how US-Core handles race and eth) 
		 * and it magically grabs the first one... so if you have multiple this doesn't match all of them.
		*/
    Code white = new Code();
    white.setCode(WHITE_CODE);
    Map<String, Map<String, Integer>> sdeAccumulators = getSDEAccumulators(SDE_RACE, null, white, new HashMap<>());
    MeasureReport report = new MeasureReport();
    Patient mockPatient = mockPatient();
    Extension raceExtension = new Extension();
    // This can be anything as long as it includes "-race"
    raceExtension.setUrl("something-race");
    // This example was stolen from https://www.hl7.org/fhir/us/core/Patient-example.xml.html
    Extension valueExtension = new Extension();
    valueExtension.setUrl("ombCategory");
    valueExtension.setValue(getWhiteCoding());
    raceExtension.setExtension(Arrays.asList(valueExtension));
    Mockito.when(mockPatient.getExtension()).thenReturn(Arrays.asList(raceExtension));
    MeasureSupplementalDataEvaluation.processAccumulators(report, sdeAccumulators, true, Arrays.asList(mockPatient));
    assertNotNull(report);
    // EvaluatedResource should contain a reference to an observation record created for supplemental data
    assertEquals(1, report.getEvaluatedResource().size());
    // The observation record mentioned previously should exist within the contained resources of the measure report
    assertEquals(1, report.getContained().size());
    assertTrue(report.getContained().get(0) instanceof Observation);
    Observation obs = (Observation) report.getContained().get(0);
    // For a single patient, the code of the observation should be the supplemental data text
    assertEquals(SDE_RACE, obs.getCode().getText());
    // For a single patient, the value of the observation should be the result of the appropriate define
    assertTrue(obs.getValue() instanceof CodeableConcept);
    assertEquals(WHITE_CODE, ((CodeableConcept) obs.getValue()).getCoding().get(0).getCode());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Code(org.opencds.cqf.cql.engine.runtime.Code) HashMap(java.util.HashMap) Map(java.util.Map) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 29 with Measure

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

the class MeasureSupplementalDataEvaluationTest method testProcessAccumulators.

@Test
public void testProcessAccumulators() {
    Map<String, Map<String, Integer>> sdeAccumulators = getSexSDEAccumulators();
    MeasureReport report = new MeasureReport();
    MeasureSupplementalDataEvaluation.processAccumulators(report, sdeAccumulators, true, new ArrayList<>());
    assertNotNull(report);
    // EvaluatedResource should contain a reference to an observation record created for supplemental data
    assertEquals(1, report.getEvaluatedResource().size());
    // The observation record mentioned previously should exist within the contained resources of the measure report
    assertEquals(1, report.getContained().size());
    assertTrue(report.getContained().get(0) instanceof Observation);
    Observation obs = (Observation) report.getContained().get(0);
    // For a single patient, the code of the observation should be the supplemental data text
    assertEquals(MeasureSupplementalDataEvaluation.SDE_SEX, obs.getCode().getText());
    // For a single patient, the value of the observation should be the result of the appropriate define
    assertTrue(obs.getValue() instanceof CodeableConcept);
    assertEquals(MALE_CODE, ((CodeableConcept) obs.getValue()).getCoding().get(0).getCode());
    // Within the observation, there should be 1 extension, with two further nested extensions
    Extension obsExt = obs.getExtensionByUrl(MeasureSupplementalDataEvaluation.CQF_MEASUREINFO_URL);
    assertNotNull(obsExt);
    assertEquals(2, obsExt.getExtension().size());
    Extension measureNestedExt = obsExt.getExtensionByUrl(MeasureSupplementalDataEvaluation.MEASURE);
    assertTrue(measureNestedExt.getValue() instanceof CanonicalType);
    assertEquals(MeasureSupplementalDataEvaluation.CQFMEASURES_URL + report.getMeasure(), ((CanonicalType) measureNestedExt.getValue()).asStringValue());
    Extension populationNestedExt = obsExt.getExtensionByUrl(MeasureSupplementalDataEvaluation.POPULATION_ID);
    assertEquals(MeasureSupplementalDataEvaluation.SDE_SEX, ((StringType) populationNestedExt.getValue()).asStringValue());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Observation(org.hl7.fhir.r4.model.Observation) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) HashMap(java.util.HashMap) Map(java.util.Map) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 30 with Measure

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

the class CDMMeasureEvaluationTest method testSetReportMeasureToMeasureId__measureFromBundleWithoutMetaVersion__onlyMeasurePortionWithoutHistoryOnReport.

@Test
public void testSetReportMeasureToMeasureId__measureFromBundleWithoutMetaVersion__onlyMeasurePortionWithoutHistoryOnReport() {
    MeasureReport report = new MeasureReport();
    String bundleInput = "{\"resourceType\":\"Bundle\",\"id\":\"98765\",\"entry\":[{\"fullUrl\":\"https://full-url-to/fhir-server/api/v4/Measure/id1\",\"resource\":{\"resourceType\":\"Measure\",\"id\":\"id1\"}}]}";
    Measure measure = (Measure) fhirParser.parseResource(Bundle.class, bundleInput).getEntryFirstRep().getResource();
    CDMMeasureEvaluation.setReportMeasureToMeasureId(report, measure);
    assertEquals("Measure/id1", report.getMeasure());
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Measure(org.hl7.fhir.r4.model.Measure) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.Test)

Aggregations

Measure (org.hl7.fhir.r4.model.Measure)119 Test (org.junit.Test)97 Library (org.hl7.fhir.r4.model.Library)61 Patient (org.hl7.fhir.r4.model.Patient)45 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)44 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)23 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)22 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)22 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)22 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 MeasureEvidenceOptions (com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions)20 CapabilityStatement (org.hl7.fhir.r4.model.CapabilityStatement)20 Test (org.junit.jupiter.api.Test)18 Extension (org.hl7.fhir.r4.model.Extension)15 StringType (org.hl7.fhir.r4.model.StringType)15 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)14 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)14 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)14