use of org.hl7.fhir.r4.model.StringType in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testCQLTranslationCustomIGWithTargetUrl.
@Test
public void testCQLTranslationCustomIGWithTargetUrl() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
patient.addExtension(new Extension("http://fakeIg.com/fake-extension", new StringType("fakeValue")));
mockFhirResourceRetrieval(patient);
Library root = getLibrary("test", DEFAULT_RESOURCE_VERSION, "cql/ig-test/Test-1.0.0.cql");
Library helpers = getLibrary("FHIRHelpers", "4.0.0", "cql/fhir-helpers/FHIRHelpers.cql", "text/cql", "cql/fhir-helpers/FHIRHelpers.xml", "application/elm+json");
RelatedArtifact related = new RelatedArtifact();
related.setType(RelatedArtifactType.DEPENDSON);
related.setResource("/Library/" + helpers.getId());
root.addRelatedArtifact(related);
mockFhirResourceRetrieval(root);
mockFhirSingletonBundleRetrieval(helpers);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", root.getId(), "-l", root.getName(), "-v", root.getVersion(), "-c", patient.getId(), "-s", "CQL", "-i", "src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
System.out.println(output);
verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library?url=%2FLibrary%2F" + helpers.getId() + "&_format=json")));
} finally {
tmpFile.delete();
}
}
use of org.hl7.fhir.r4.model.StringType 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.r4.model.StringType in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method measure_report_generated___FHIR_measure_parameters_on_measure_report.
@Test
public void measure_report_generated___FHIR_measure_parameters_on_measure_report() throws Exception {
CapabilityStatement metadata = getCapabilityStatement();
mockFhirResourceRetrieval("/metadata?_format=json", metadata);
Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
mockFhirResourceRetrieval(patient);
Library library = mockLibraryRetrieval("TestDummyPopulations", DEFAULT_VERSION, "cql/fhir-measure/test-dummy-populations.xml", ELM_MIME_TYPE);
Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
Map<String, Type> measureParameters = new HashMap<>();
measureParameters.put("base64Param", new Base64BinaryType("AAA"));
measureParameters.put("booleanParam", new BooleanType(false));
measureParameters.put("dateParam", new DateType("2020-01-01"));
measureParameters.put("dateTimeParam", new DateTimeType("2020-01-01T12:00:00"));
measureParameters.put("decimalParam", new DecimalType(12.0));
measureParameters.put("instantParam", new InstantType("2020-01-01T12:00:00-04:00"));
measureParameters.put("integerParam", new IntegerType(1));
measureParameters.put("stringParam", new StringType("str"));
measureParameters.put("timeParam", new TimeType("05:30:00"));
measureParameters.put("uriParam", new UriType("abcde"));
measureParameters.put("codeableConceptParam", new CodeableConcept().setText("display").addCoding(new Coding().setCode("val").setSystem("sys").setDisplay("display")));
measureParameters.put("codingParam", new Coding().setCode("v").setSystem("s").setDisplay("d"));
measureParameters.put("periodParam", new Period().setStart(new Date(1)).setEnd(new Date(2)));
measureParameters.put("quantityParam", new Quantity().setValue(1).setUnit("g"));
measureParameters.put("rangeParam", new Range().setLow(new Quantity().setUnit("g").setValue(1)).setHigh(new Quantity().setUnit("g").setValue(5)));
measureParameters.put("ratioParam", new Ratio().setNumerator(new Quantity().setUnit("g").setValue(1)).setDenominator(new Quantity().setUnit("g").setValue(5)));
List<Extension> parameterExtensions = measureParameters.entrySet().stream().map(x -> createMeasureParameter(x.getKey(), x.getValue())).collect(Collectors.toList());
measure.setExtension(parameterExtensions);
mockFhirResourceRetrieval(measure);
MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null);
assertNotNull(report);
List<String> parameterNames = report.getExtension().stream().filter(x -> x.getUrl().equals(MEASURE_PARAMETER_VALUE_URL)).map(x -> (ParameterDefinition) x.getValue()).map(ParameterDefinition::getName).collect(Collectors.toList());
// Expected parameters are the ones listed above, plus the special parameters
// measurement period and product line
assertEquals(measureParameters.size() + 2, parameterNames.size());
assertTrue(parameterNames.containsAll(measureParameters.keySet()));
assertTrue(parameterNames.contains(CDMConstants.MEASUREMENT_PERIOD));
assertTrue(parameterNames.contains(CDMConstants.PRODUCT_LINE));
}
use of org.hl7.fhir.r4.model.StringType in project quality-measure-and-cohort-service by Alvearie.
the class MeasureSupplementalDataEvaluation method processAccumulators.
public static MeasureReport processAccumulators(MeasureReport report, Map<String, Map<String, Integer>> sdeAccumulators, boolean isSingle, List<Patient> patients) {
List<Reference> newRefList = new ArrayList<>();
sdeAccumulators.forEach((sdeKey, sdeAccumulator) -> {
sdeAccumulator.forEach((sdeAccumulatorKey, sdeAccumulatorValue) -> {
Observation obs = new Observation();
obs.setStatus(Observation.ObservationStatus.FINAL);
obs.setId(UUID.randomUUID().toString());
Coding valueCoding = new Coding();
if (sdeKey.equalsIgnoreCase(SDE_SEX)) {
valueCoding.setCode(sdeAccumulatorKey);
} else {
String coreCategory = sdeKey.substring(sdeKey.lastIndexOf('-'));
patients.forEach((pt) -> {
pt.getExtension().forEach((ptExt) -> {
if (ptExt.getUrl().contains(coreCategory)) {
String code = ((Coding) ptExt.getExtension().get(0).getValue()).getCode();
if (code.equalsIgnoreCase(sdeAccumulatorKey)) {
valueCoding.setSystem(((Coding) ptExt.getExtension().get(0).getValue()).getSystem());
valueCoding.setCode(code);
valueCoding.setDisplay(((Coding) ptExt.getExtension().get(0).getValue()).getDisplay());
}
}
});
});
}
CodeableConcept obsCodeableConcept = new CodeableConcept();
Extension obsExtension = new Extension().setUrl(CQF_MEASUREINFO_URL);
Extension extExtMeasure = new Extension().setUrl(MEASURE).setValue(new CanonicalType(CQFMEASURES_URL + report.getMeasure()));
obsExtension.addExtension(extExtMeasure);
Extension extExtPop = new Extension().setUrl(POPULATION_ID).setValue(new StringType(sdeKey));
obsExtension.addExtension(extExtPop);
obs.addExtension(obsExtension);
obs.setValue(new IntegerType(sdeAccumulatorValue));
if (!isSingle) {
valueCoding.setCode(sdeAccumulatorKey);
obsCodeableConcept.setCoding(Collections.singletonList(valueCoding));
obs.setCode(obsCodeableConcept);
} else {
obs.setCode(new CodeableConcept().setText(sdeKey));
obsCodeableConcept.setCoding(Collections.singletonList(valueCoding));
obs.setValue(obsCodeableConcept);
}
newRefList.add(new Reference("#" + obs.getId()));
report.addContained(obs);
});
});
newRefList.addAll(report.getEvaluatedResource());
report.setEvaluatedResource(newRefList);
return report;
}
use of org.hl7.fhir.r4.model.StringType in project quality-measure-and-cohort-service by Alvearie.
the class CDMMeasureEvaluation method addDefineEvaluationToReport.
protected static void addDefineEvaluationToReport(MeasureReport report, CDMContext defineContext, DefineReturnOptions defineOption) {
if (DefineReturnOptions.NONE == defineOption) {
return;
}
for (Entry<VersionedIdentifier, Map<String, Object>> libraryCache : defineContext.getEntriesInCache()) {
for (Entry<String, Object> defineResult : libraryCache.getValue().entrySet()) {
List<Type> values = MeasureEvidenceHelper.getFhirTypes(defineResult.getValue());
if (shouldAddDefineResult(defineOption, values)) {
Extension evidence = new Extension();
evidence.setUrl(CDMConstants.EVIDENCE_URL);
StringType key = new StringType(MeasureEvidenceHelper.createEvidenceKey(libraryCache.getKey(), defineResult.getKey()));
Extension textExtension = new Extension();
textExtension.setUrl(CDMConstants.EVIDENCE_TEXT_URL);
textExtension.setValue(key);
evidence.addExtension(textExtension);
for (Type value : values) {
Extension valueExtension = new Extension();
valueExtension.setUrl(CDMConstants.EVIDENCE_VALUE_URL);
valueExtension.setValue(value);
evidence.addExtension(valueExtension);
}
report.addExtension(evidence);
}
}
}
}
Aggregations