use of org.hl7.fhir.dstu2016may.model.Extension 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.dstu2016may.model.Extension in project quality-measure-and-cohort-service by Alvearie.
the class CDMMeasureEvaluationTest method testDefinesOnMeasureReport.
@Test
public void testDefinesOnMeasureReport() {
MeasureReport report = new MeasureReport();
Map<VersionedIdentifier, Map<String, Object>> expectedResults = setupTestExpectedResultsContext();
CDMContext defineContext = setupTestDefineContext(expectedResults);
CDMMeasureEvaluation.addDefineEvaluationToReport(report, defineContext, DefineReturnOptions.ALL);
assertEquals(5, report.getExtension().size());
int index = 0;
for (Entry<VersionedIdentifier, Map<String, Object>> expectedLibraryResults : expectedResults.entrySet()) {
for (Entry<String, Object> defineResult : expectedLibraryResults.getValue().entrySet()) {
Extension extension = report.getExtension().get(index++);
assertEquals(MeasureEvidenceHelper.createEvidenceKey(expectedLibraryResults.getKey(), defineResult.getKey()), extension.getExtensionByUrl(CDMConstants.EVIDENCE_TEXT_URL).getValue().primitiveValue());
// hack because Type does not return equals for 2 identical objects :(
Type returnType = extension.getExtensionByUrl(CDMConstants.EVIDENCE_VALUE_URL).getValue();
if (defineResult.getValue() instanceof Boolean) {
assertTrue(returnType.isBooleanPrimitive());
assertEquals(defineResult.getValue(), ((BooleanType) returnType).booleanValue());
} else if (defineResult.getValue() instanceof String) {
assertTrue(returnType.isPrimitive());
assertEquals(defineResult.getValue(), returnType.primitiveValue());
} else if (defineResult.getValue() instanceof DomainResource) {
assertTrue(returnType instanceof Reference);
}
}
}
}
use of org.hl7.fhir.dstu2016may.model.Extension 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.dstu2016may.model.Extension in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method in_populations_defines_returned.
@Test
public void in_populations_defines_returned() throws Exception {
CapabilityStatement metadata = getCapabilityStatement();
mockFhirResourceRetrieval("/metadata?_format=json", metadata);
Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
// Add 2 names to test list
HumanName name1 = new HumanName();
name1.setFamily("Jones");
HumanName name2 = new HumanName();
name2.setFamily("Smith");
patient.setName(Arrays.asList(name1, name2));
// Add marital status to test codeable concept
CodeableConcept maritalStatus = new CodeableConcept();
Coding maritalCoding = new Coding();
maritalCoding.setCode("M");
maritalCoding.setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus");
maritalCoding.setDisplay("Married");
maritalStatus.setCoding(Arrays.asList(maritalCoding));
maritalStatus.setText("Married");
patient.setMaritalStatus(maritalStatus);
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(true, DefineReturnOptions.ALL));
assertNotNull(report);
assertFalse(report.getEvaluatedResource().isEmpty());
List<Extension> returnedExtensions = report.getExtensionsByUrl(CDMConstants.EVIDENCE_URL);
assertFalse(returnedExtensions.isEmpty());
assertEquals(30, returnedExtensions.size());
}
use of org.hl7.fhir.dstu2016may.model.Extension 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;
}
Aggregations