use of org.hl7.fhir.r4b.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);
}
use of org.hl7.fhir.r4b.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);
}
use of org.hl7.fhir.r4b.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());
}
use of org.hl7.fhir.r4b.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());
}
use of org.hl7.fhir.r4b.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());
}
Aggregations