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);
}
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;
}
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")));
}
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());
}
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));
}
Aggregations