Search in sources :

Example 31 with ParameterDefinition

use of org.hl7.fhir.r4b.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);
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) FhirContext(ca.uhn.fhir.context.FhirContext) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Range(org.hl7.fhir.r4.model.Range) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser)

Example 32 with ParameterDefinition

use of org.hl7.fhir.r4b.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());
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_VALUE_URL) Range(org.hl7.fhir.r4.model.Range) StringUtils(org.apache.commons.lang3.StringUtils) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) InvalidOperatorArgument(org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) HumanName(org.hl7.fhir.r4.model.HumanName) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Map(java.util.Map) StringType(org.hl7.fhir.r4.model.StringType) Assert.fail(org.junit.Assert.fail) ParseException(java.text.ParseException) IntegerType(org.hl7.fhir.r4.model.IntegerType) Patient(org.hl7.fhir.r4.model.Patient) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) DateType(org.hl7.fhir.r4.model.DateType) TimeZone(java.util.TimeZone) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Period(org.hl7.fhir.r4.model.Period) MEASURE_PARAMETER_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_URL) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) PARAMETER_DEFAULT_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_DEFAULT_URL) TimeType(org.hl7.fhir.r4.model.TimeType) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Extension(org.hl7.fhir.r4.model.Extension) UriType(org.hl7.fhir.r4.model.UriType) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) Address(org.hl7.fhir.r4.model.Address) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) MEASURE_PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_VALUE_URL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Ratio(org.hl7.fhir.r4.model.Ratio) MeasureSupplementalDataEvaluation(com.ibm.cohort.engine.cqfruler.MeasureSupplementalDataEvaluation) DecimalType(org.hl7.fhir.r4.model.DecimalType) Before(org.junit.Before) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ListResource(org.hl7.fhir.r4.model.ListResource) Library(org.hl7.fhir.r4.model.Library) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) CDMConstants(com.ibm.cohort.engine.cdm.CDMConstants) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 33 with ParameterDefinition

use of org.hl7.fhir.r4b.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));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_VALUE_URL) Range(org.hl7.fhir.r4.model.Range) StringUtils(org.apache.commons.lang3.StringUtils) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) InvalidOperatorArgument(org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) HumanName(org.hl7.fhir.r4.model.HumanName) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Map(java.util.Map) StringType(org.hl7.fhir.r4.model.StringType) Assert.fail(org.junit.Assert.fail) ParseException(java.text.ParseException) IntegerType(org.hl7.fhir.r4.model.IntegerType) Patient(org.hl7.fhir.r4.model.Patient) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) DateType(org.hl7.fhir.r4.model.DateType) TimeZone(java.util.TimeZone) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Period(org.hl7.fhir.r4.model.Period) MEASURE_PARAMETER_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_URL) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) PARAMETER_DEFAULT_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_DEFAULT_URL) TimeType(org.hl7.fhir.r4.model.TimeType) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Extension(org.hl7.fhir.r4.model.Extension) UriType(org.hl7.fhir.r4.model.UriType) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) Address(org.hl7.fhir.r4.model.Address) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) MEASURE_PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_VALUE_URL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Ratio(org.hl7.fhir.r4.model.Ratio) MeasureSupplementalDataEvaluation(com.ibm.cohort.engine.cqfruler.MeasureSupplementalDataEvaluation) DecimalType(org.hl7.fhir.r4.model.DecimalType) Before(org.junit.Before) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ListResource(org.hl7.fhir.r4.model.ListResource) Library(org.hl7.fhir.r4.model.Library) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) CDMConstants(com.ibm.cohort.engine.cdm.CDMConstants) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Assert.assertEquals(org.junit.Assert.assertEquals) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) HashMap(java.util.HashMap) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) Library(org.hl7.fhir.r4.model.Library) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Test(org.junit.Test)

Example 34 with ParameterDefinition

use of org.hl7.fhir.r4b.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);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition)

Example 35 with ParameterDefinition

use of org.hl7.fhir.r4b.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());
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_VALUE_URL) Range(org.hl7.fhir.r4.model.Range) StringUtils(org.apache.commons.lang3.StringUtils) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) InvalidOperatorArgument(org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) HumanName(org.hl7.fhir.r4.model.HumanName) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Map(java.util.Map) StringType(org.hl7.fhir.r4.model.StringType) Assert.fail(org.junit.Assert.fail) ParseException(java.text.ParseException) IntegerType(org.hl7.fhir.r4.model.IntegerType) Patient(org.hl7.fhir.r4.model.Patient) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) DateType(org.hl7.fhir.r4.model.DateType) TimeZone(java.util.TimeZone) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Period(org.hl7.fhir.r4.model.Period) MEASURE_PARAMETER_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_URL) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) PARAMETER_DEFAULT_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_DEFAULT_URL) TimeType(org.hl7.fhir.r4.model.TimeType) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Extension(org.hl7.fhir.r4.model.Extension) UriType(org.hl7.fhir.r4.model.UriType) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) Address(org.hl7.fhir.r4.model.Address) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) MEASURE_PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_VALUE_URL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Ratio(org.hl7.fhir.r4.model.Ratio) MeasureSupplementalDataEvaluation(com.ibm.cohort.engine.cqfruler.MeasureSupplementalDataEvaluation) DecimalType(org.hl7.fhir.r4.model.DecimalType) Before(org.junit.Before) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ListResource(org.hl7.fhir.r4.model.ListResource) Library(org.hl7.fhir.r4.model.Library) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) CDMConstants(com.ibm.cohort.engine.cdm.CDMConstants) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Assert.assertEquals(org.junit.Assert.assertEquals) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) IntegerType(org.hl7.fhir.r4.model.IntegerType) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) UriType(org.hl7.fhir.r4.model.UriType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Library(org.hl7.fhir.r4.model.Library) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Test(org.junit.Test)

Aggregations

ParameterDefinition (org.hl7.fhir.r4.model.ParameterDefinition)32 Test (org.junit.Test)26 Extension (org.hl7.fhir.r4.model.Extension)14 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)9 ArrayList (java.util.ArrayList)9 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)9 QuantityParameter (com.ibm.cohort.cql.evaluation.parameters.QuantityParameter)8 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)8 Quantity (org.hl7.fhir.r4.model.Quantity)8 Range (org.hl7.fhir.r4.model.Range)8 CodeParameter (com.ibm.cohort.cql.evaluation.parameters.CodeParameter)7 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)7 Period (org.hl7.fhir.r4.model.Period)7 BooleanParameter (com.ibm.cohort.cql.evaluation.parameters.BooleanParameter)6 ConceptParameter (com.ibm.cohort.cql.evaluation.parameters.ConceptParameter)6 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)6 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)6 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)6 RatioParameter (com.ibm.cohort.cql.evaluation.parameters.RatioParameter)6 TimeParameter (com.ibm.cohort.cql.evaluation.parameters.TimeParameter)6