Search in sources :

Example 56 with StringType

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();
    }
}
Also used : PrintStream(java.io.PrintStream) StringType(org.hl7.fhir.r4.model.StringType) FileWriter(java.io.FileWriter) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Extension(org.hl7.fhir.r4.model.Extension) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 57 with StringType

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());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Observation(org.hl7.fhir.r4.model.Observation) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) HashMap(java.util.HashMap) Map(java.util.Map) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 58 with StringType

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));
}
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) StringType(org.hl7.fhir.r4.model.StringType) TimeType(org.hl7.fhir.r4.model.TimeType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) UriType(org.hl7.fhir.r4.model.UriType) Coding(org.hl7.fhir.r4.model.Coding) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Range(org.hl7.fhir.r4.model.Range) Date(java.util.Date) IntegerType(org.hl7.fhir.r4.model.IntegerType) Extension(org.hl7.fhir.r4.model.Extension) 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) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalType(org.hl7.fhir.r4.model.DecimalType) Library(org.hl7.fhir.r4.model.Library) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 59 with StringType

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;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) IntegerType(org.hl7.fhir.r4.model.IntegerType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 60 with StringType

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);
            }
        }
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Type(org.hl7.fhir.r4.model.Type) StringType(org.hl7.fhir.r4.model.StringType) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) BooleanType(org.hl7.fhir.r4.model.BooleanType) StringType(org.hl7.fhir.r4.model.StringType) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StringType (org.hl7.fhir.r4.model.StringType)158 ArrayList (java.util.ArrayList)77 Test (org.junit.jupiter.api.Test)77 StringType (org.hl7.fhir.dstu3.model.StringType)65 Parameters (org.hl7.fhir.r4.model.Parameters)62 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)62 StringType (org.hl7.fhir.r5.model.StringType)61 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)58 StringType (org.hl7.fhir.r4b.model.StringType)45 FHIRException (org.hl7.fhir.exceptions.FHIRException)43 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 HashMap (java.util.HashMap)28 StringType (org.hl7.fhir.dstu2.model.StringType)27 StringType (org.hl7.fhir.dstu2016may.model.StringType)26 Coding (org.hl7.fhir.r4.model.Coding)26 Extension (org.hl7.fhir.r4.model.Extension)25 Measure (org.hl7.fhir.r4.model.Measure)23 Test (org.junit.Test)23 Base (org.hl7.fhir.r5.model.Base)20 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19