use of org.hl7.fhir.r4b.model.Measure in project quality-measure-and-cohort-service by Alvearie.
the class CohortEngineRestHandler method createMeasureEvaluator.
private MeasureEvaluator createMeasureEvaluator(InputStream inputStream, FhirServerConfig dataServerConfig, FhirServerConfig terminologyServerConfig, Boolean expandValueSets, Integer searchPageSize, RetrieveCacheContext retrieveCacheContext, FhirContext fhirContext) throws IOException {
FhirClientBuilder clientBuilder = FhirClientBuilderFactory.newInstance().newFhirClientBuilder(fhirContext);
IGenericClient dataClient = clientBuilder.createFhirClient(dataServerConfig);
IGenericClient terminologyClient = dataClient;
if (terminologyServerConfig != null) {
terminologyClient = clientBuilder.createFhirClient(terminologyServerConfig);
}
IParser parser = dataClient.getFhirContext().newJsonParser();
String[] searchPaths = new String[] { "fhirResources", "fhirResources/libraries" };
R4QualityMeasureResolverFactory resolverFactory = new R4QualityMeasureResolverFactory(parser);
R4QualityMeasureResolvers resolvers = resolverFactory.fromZipStream(new ZipInputStream(inputStream), searchPaths);
FhirResourceResolver<Library> libraryResolver = resolvers.getLibraryResolver();
FhirResourceResolver<Measure> measureResolver = resolvers.getMeasureResolver();
R4LibraryDependencyGatherer libraryDependencyGatherer = new R4LibraryDependencyGatherer(libraryResolver);
CqlTerminologyProvider terminologyProvider = new R4RestFhirTerminologyProvider(terminologyClient);
if (expandValueSets == null) {
expandValueSets = R4DataProviderFactory.DEFAULT_IS_EXPAND_VALUE_SETS;
}
if (searchPageSize == null) {
searchPageSize = R4DataProviderFactory.DEFAULT_PAGE_SIZE;
}
Map<String, CqlDataProvider> dataProviders = R4DataProviderFactory.createDataProviderMap(dataClient, terminologyProvider, retrieveCacheContext, R4FhirModelResolverFactory.createCachingResolver(), expandValueSets, searchPageSize);
return new MeasureEvaluator(measureResolver, libraryResolver, libraryDependencyGatherer, terminologyProvider, dataProviders);
}
use of org.hl7.fhir.r4b.model.Measure 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);
}
use of org.hl7.fhir.r4b.model.Measure 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);
}
use of org.hl7.fhir.r4b.model.Measure 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\""));
}
use of org.hl7.fhir.r4b.model.Measure 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);
}
Aggregations