use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtils method complicatedTypeValueConstructor.
static String complicatedTypeValueConstructor(ParameterDefinition parameterDefinition) {
FhirContext context = FhirContext.forCached(FhirVersionEnum.R4);
IParser parser = context.newJsonParser();
String valueKey;
// In order to use the hapi parser, we cannot translate an extension by itself. The patient object wraps the extension
Patient patient = new Patient();
Extension extension = new Extension();
switch(parameterDefinition.getType()) {
case "Period":
Period period = (Period) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(period);
patient.addExtension(extension);
valueKey = "valuePeriod";
break;
case "Range":
Range range = (Range) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(range);
patient.addExtension(extension);
valueKey = "valueRange";
break;
case "Quantity":
Quantity quantity = (Quantity) parameterDefinition.getExtension().get(0).getValue();
extension.setValue(quantity);
patient.addExtension(extension);
valueKey = "valueQuantity";
break;
default:
throw new RuntimeException("Complicated Type" + parameterDefinition.getType() + " not yet implemented");
}
String intermediateValue = parser.encodeResourceToString(patient);
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode root = mapper.readTree(intermediateValue);
JsonNode nameNode = root.path("extension");
return nameNode.get(0).path(valueKey).toString();
} catch (JsonProcessingException e) {
throw new RuntimeException("There was an issue with json translation", e);
}
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method measure_report_generated___datetime_parameters_on_report_in_utc.
@Test
public void measure_report_generated___datetime_parameters_on_report_in_utc() 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);
String fhirDefaultDatetimeParamterName = "fhirDatetimeParamDefault";
String fhirTimezoneDatetimeParameterName = "fhirDatetimeParamGMTPlus4";
Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
measure.addExtension(createParameterExtension(fhirDefaultDatetimeParamterName, new DateTimeType("2020-04-04")));
measure.addExtension(createParameterExtension(fhirTimezoneDatetimeParameterName, new DateTimeType("2020-04-04T00:00:00.0+04:00")));
mockFhirResourceRetrieval(measure);
String javaDefaultDatetimeParamterName = "javaDatetimeParamDefault";
String javaTimezoneDatetimeParameterName = "javaDatetimeParamGMTPlus4";
Map<String, Parameter> parameterMap = new HashMap<>();
parameterMap.put(javaDefaultDatetimeParamterName, new DatetimeParameter("2020-01-01"));
parameterMap.put(javaTimezoneDatetimeParameterName, new DatetimeParameter("2020-01-01T00:00:00.0+04:00"));
MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), parameterMap);
assertNotNull(report);
Map<String, DateTimeType> parameterNames = report.getExtension().stream().filter(x -> x.getUrl().equals(MEASURE_PARAMETER_VALUE_URL)).map(x -> (ParameterDefinition) x.getValue()).filter(x -> x.getExtensionByUrl(PARAMETER_VALUE_URL).getValue() instanceof DateTimeType).collect(Collectors.toMap(ParameterDefinition::getName, x -> (DateTimeType) x.getExtensionByUrl(PARAMETER_VALUE_URL).getValue()));
DateTimeType javaDefaultResult = parameterNames.get(javaDefaultDatetimeParamterName);
DateTimeType javaTimezoneResult = parameterNames.get(javaTimezoneDatetimeParameterName);
assertTrue(new DateTimeType("2020-01-01T00:00:00.000Z").equalsUsingFhirPathRules(javaDefaultResult));
assertEquals(TimeZone.getTimeZone("UTC"), javaDefaultResult.getTimeZone());
assertTrue(new DateTimeType("2019-12-31T20:00:00.000Z").equalsUsingFhirPathRules(javaTimezoneResult));
assertEquals(TimeZone.getTimeZone("UTC"), javaTimezoneResult.getTimeZone());
DateTimeType fhirDefaultResult = parameterNames.get(fhirDefaultDatetimeParamterName);
DateTimeType fhirTimezoneResult = parameterNames.get(fhirTimezoneDatetimeParameterName);
assertTrue(new DateTimeType("2020-04-04T00:00:00.000Z").equalsUsingFhirPathRules(fhirDefaultResult));
assertEquals(TimeZone.getTimeZone("UTC"), fhirDefaultResult.getTimeZone());
assertTrue(new DateTimeType("2020-04-03T20:00:00.000Z").equalsUsingFhirPathRules(fhirTimezoneResult));
assertEquals(TimeZone.getTimeZone("UTC"), fhirTimezoneResult.getTimeZone());
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method measure_report_generated___named_parameters_on_measure_report.
@Test
public void measure_report_generated___named_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);
mockFhirResourceRetrieval(measure);
Map<String, Parameter> parameterMap = new HashMap<>();
parameterMap.put("integerParam", new IntegerParameter(1));
parameterMap.put("decimalParam", new DecimalParameter("1.0"));
parameterMap.put("stringParam", new StringParameter("1"));
parameterMap.put("booleanParam", new BooleanParameter(false));
parameterMap.put("datetimeParam", new DatetimeParameter("2020-01-01"));
parameterMap.put("dateParam", new DateParameter("2020-01-01"));
parameterMap.put("timeParam", new TimeParameter("01:00:00"));
parameterMap.put("quantityParam", new QuantityParameter("1.0", "ml"));
parameterMap.put("ratioParam", new RatioParameter(new QuantityParameter("1.0", "ml"), new QuantityParameter("2.0", "ml")));
parameterMap.put("codeParam", new CodeParameter("1", "2", "3", "4"));
parameterMap.put("conceptParam", new ConceptParameter("1", new CodeParameter("1", "2", "3", "4")));
parameterMap.put("datetimeIntervalParam", new IntervalParameter(new DatetimeParameter("2020-01-01"), true, new DatetimeParameter("2021-01-01"), true));
parameterMap.put("quantityIntervalParam", new IntervalParameter(new QuantityParameter("1.0", "ml"), true, new QuantityParameter("2.0", "ml"), true));
MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), parameterMap);
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(parameterMap.size() + 2, parameterNames.size());
assertTrue(parameterNames.containsAll(parameterMap.keySet()));
assertTrue(parameterNames.contains(CDMConstants.MEASUREMENT_PERIOD));
assertTrue(parameterNames.contains(CDMConstants.PRODUCT_LINE));
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method createParameterExtension.
private Extension createParameterExtension(String name, Type innerValue) {
ParameterDefinition parameterDefinition = new ParameterDefinition().setName(name).setUse(ParameterDefinition.ParameterUse.IN).setType(innerValue.fhirType());
parameterDefinition.addExtension(new Extension().setUrl(PARAMETER_DEFAULT_URL).setValue(innerValue));
return new Extension().setUrl(MEASURE_PARAMETER_URL).setValue(parameterDefinition);
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluatorTest method measure_report_generated___java_overrides_overwrite_measure_params.
@Test
public void measure_report_generated___java_overrides_overwrite_measure_params() 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);
String duplicateParamName = "duplicateParam";
int fhirMeasureIntValue = 10;
int javaParameterIntValue = 99;
measure.addExtension(createParameterExtension(duplicateParamName, new IntegerType(fhirMeasureIntValue)));
mockFhirResourceRetrieval(measure);
Map<String, Parameter> parameterMap = new HashMap<>();
parameterMap.put(duplicateParamName, new IntegerParameter(javaParameterIntValue));
MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), parameterMap);
assertNotNull(report);
// Make sure report only contained one entry for the duplicate parameter
List<Type> filteredReportParams = report.getExtension().stream().filter(x -> x.getUrl().equals(MEASURE_PARAMETER_VALUE_URL)).map(x -> (ParameterDefinition) x.getValue()).filter(x -> x.getName().equals(duplicateParamName)).map(x -> x.getExtensionByUrl(PARAMETER_VALUE_URL).getValue()).collect(Collectors.toList());
assertEquals(1, filteredReportParams.size());
// Sanity check input parameter values were different before checking for correct value
assertNotEquals(fhirMeasureIntValue, javaParameterIntValue);
assertEquals(javaParameterIntValue, ((IntegerType) filteredReportParams.get(0)).getValue().intValue());
}
Aggregations