Search in sources :

Example 6 with DateTime

use of org.hl7.elm.r1.DateTime in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluatorTest method in_initial_population_when_engine_run_in_utc__engine_defaults_to_utc.

@Test
public void in_initial_population_when_engine_run_in_utc__engine_defaults_to_utc() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    // Test CQL written to pass when engine run with a timezone of UTC
    // and should fail otherwise
    Library library = mockLibraryRetrieval("TestDatetimeDefaultTimezones", DEFAULT_VERSION, "cql/fhir-measure/test-datetime-default-timezones.cql", "text/cql");
    Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
    mockFhirResourceRetrieval(measure);
    MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null, new MeasureEvidenceOptions(false, DefineReturnOptions.BOOLEAN));
    assertNotNull(report);
    report.getExtension().stream().filter(x -> x.getUrl().equals(CDMConstants.EVIDENCE_URL)).forEach(x -> validateBooleanEvidence(x, true));
}
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) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Library(org.hl7.fhir.r4.model.Library) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) Test(org.junit.Test)

Example 7 with DateTime

use of org.hl7.elm.r1.DateTime in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelper method getFhirTypeForInterval.

private static IBaseDatatype getFhirTypeForInterval(Interval interval) {
    Object low = interval.getLow();
    Object high = interval.getHigh();
    if (low instanceof DateTime) {
        // Handle DateTime conversion to force UTC timezone
        Period period = new Period();
        period.setStartElement(createDateTimeType((DateTime) low));
        period.setEndElement(createDateTimeType((DateTime) high));
        return period;
    } else if (low instanceof Quantity) {
        return converter.toFhirRange(interval);
    } else {
        logger.warn("Support not implemented for Interval parameters of type {} on a MeasureReport", low.getClass());
        return null;
    }
}
Also used : Period(org.hl7.fhir.r4.model.Period) Quantity(org.opencds.cqf.cql.engine.runtime.Quantity) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime)

Example 8 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class Questionnaire10_50 method convertQuestionnaireQuestionType.

public static org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> convertQuestionnaireQuestionType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Questionnaire.AnswerFormat> src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemTypeEnumFactory());
    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
    tgt.addExtension(VersionConvertorConstants.EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL, new CodeType(src.getValueAsString()));
    switch(src.getValue()) {
        case BOOLEAN:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.BOOLEAN);
            break;
        case DECIMAL:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DECIMAL);
            break;
        case INTEGER:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.INTEGER);
            break;
        case DATE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATE);
            break;
        case DATETIME:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
            break;
        case INSTANT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.DATETIME);
            break;
        case TIME:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TIME);
            break;
        case STRING:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.STRING);
            break;
        case TEXT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.TEXT);
            break;
        case URL:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.URL);
            break;
        case CHOICE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
            break;
        case OPENCHOICE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.CODING);
            break;
        case ATTACHMENT:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.ATTACHMENT);
            break;
        case REFERENCE:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.REFERENCE);
            break;
        case QUANTITY:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.QUANTITY);
            break;
        default:
            tgt.setValue(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType.NULL);
            break;
    }
    return tgt;
}
Also used : CodeType(org.hl7.fhir.r5.model.CodeType)

Example 9 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opLessOrEqual.

private List<Base> opLessOrEqual(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
        Base l = left.get(0);
        Base r = right.get(0);
        if (l.hasType("string") && r.hasType("string"))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
        else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
            return makeBoolean(new Double(l.primitiveValue()) <= new Double(r.primitiveValue()));
        else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
        else if ((l.hasType("time")) && (r.hasType("time")))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
    } else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
        List<Base> lUnits = left.get(0).listChildrenByName("unit");
        String lunit = lUnits.size() == 1 ? lUnits.get(0).primitiveValue() : null;
        List<Base> rUnits = right.get(0).listChildrenByName("unit");
        String runit = rUnits.size() == 1 ? rUnits.get(0).primitiveValue() : null;
        if ((lunit == null && runit == null) || lunit.equals(runit)) {
            return opLessOrEqual(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
        } else {
            throw new PathEngineException("Canonical Comparison isn't done yet");
        }
    }
    return new ArrayList<Base>();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base)

Example 10 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opGreater.

private List<Base> opGreater(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
        Base l = left.get(0);
        Base r = right.get(0);
        if (l.hasType("string") && r.hasType("string"))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
        else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
            return makeBoolean(new Double(l.primitiveValue()) > new Double(r.primitiveValue()));
        else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
        else if ((l.hasType("time")) && (r.hasType("time")))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
    } else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
        List<Base> lUnit = left.get(0).listChildrenByName("unit");
        List<Base> rUnit = right.get(0).listChildrenByName("unit");
        if (Base.compareDeep(lUnit, rUnit, true)) {
            return opGreater(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
        } else {
            throw new PathEngineException("Canonical Comparison isn't done yet");
        }
    }
    return new ArrayList<Base>();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base)

Aggregations

ArrayList (java.util.ArrayList)30 List (java.util.List)21 LinkedHashSet (java.util.LinkedHashSet)20 Test (org.junit.Test)18 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)16 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 Before (org.junit.Before)11 Set (java.util.Set)10 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 Condition (org.hl7.fhir.r4.model.Condition)8 MergedList (org.hl7.fhir.utilities.MergedList)8 Date (java.util.Date)5 HashMap (java.util.HashMap)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 Period (org.hl7.fhir.r4.model.Period)4 Procedure (org.hl7.fhir.r4.model.Procedure)4 CodeType (org.hl7.fhir.r5.model.CodeType)4 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)4