Search in sources :

Example 96 with BooleanType

use of org.hl7.fhir.r4.model.BooleanType in project clinical_quality_language by cqframework.

the class DataRequirementsProcessor method toFhirValue.

private DataType toFhirValue(ElmRequirementsContext context, Expression value) {
    if (value == null) {
        return null;
    }
    if (value instanceof Interval) {
        // TODO: Handle lowclosed/highclosed
        return new Period().setStartElement(toFhirDateTimeValue(context, ((Interval) value).getLow())).setEndElement(toFhirDateTimeValue(context, ((Interval) value).getHigh()));
    } else if (value instanceof Literal) {
        if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
            return new DateTimeType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isDateType(value.getResultType())) {
            return new DateType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
            return new IntegerType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
            return new DecimalType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isStringType(value.getResultType())) {
            return new StringType(((Literal) value).getValue());
        }
    } else if (value instanceof DateTime) {
        DateTime dateTime = (DateTime) value;
        return new DateTimeType(toDateTimeString(toFhirValue(context, dateTime.getYear()), toFhirValue(context, dateTime.getMonth()), toFhirValue(context, dateTime.getDay()), toFhirValue(context, dateTime.getHour()), toFhirValue(context, dateTime.getMinute()), toFhirValue(context, dateTime.getSecond()), toFhirValue(context, dateTime.getMillisecond()), toFhirValue(context, dateTime.getTimezoneOffset())));
    } else if (value instanceof org.hl7.elm.r1.Date) {
        org.hl7.elm.r1.Date date = (org.hl7.elm.r1.Date) value;
        return new DateType(toDateString(toFhirValue(context, date.getYear()), toFhirValue(context, date.getMonth()), toFhirValue(context, date.getDay())));
    } else if (value instanceof Start) {
        DataType operand = toFhirValue(context, ((Start) value).getOperand());
        if (operand != null) {
            Period period = (Period) operand;
            return period.getStartElement();
        }
    } else if (value instanceof End) {
        DataType operand = toFhirValue(context, ((End) value).getOperand());
        if (operand != null) {
            Period period = (Period) operand;
            return period.getEndElement();
        }
    } else if (value instanceof ParameterRef) {
        if (context.getTypeResolver().isIntervalType(value.getResultType())) {
            Extension e = toExpression(context, (ParameterRef) value);
            org.hl7.cql.model.DataType pointType = ((IntervalType) value.getResultType()).getPointType();
            if (context.getTypeResolver().isDateTimeType(pointType) || context.getTypeResolver().isDateType(pointType)) {
                Period period = new Period();
                period.addExtension(e);
                return period;
            } else if (context.getTypeResolver().isQuantityType(pointType) || context.getTypeResolver().isIntegerType(pointType) || context.getTypeResolver().isDecimalType(pointType)) {
                Range range = new Range();
                range.addExtension(e);
                return range;
            } else {
                throw new IllegalArgumentException(String.format("toFhirValue not implemented for interval of %s", pointType.toString()));
            }
        } else // Boolean, Integer, Decimal, String, Quantity, Date, DateTime, Time, Coding, CodeableConcept
        if (context.getTypeResolver().isBooleanType(value.getResultType())) {
            BooleanType result = new BooleanType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
            IntegerType result = new IntegerType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
            DecimalType result = new DecimalType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isQuantityType(value.getResultType())) {
            Quantity result = new Quantity();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isCodeType(value.getResultType())) {
            Coding result = new Coding();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isConceptType(value.getResultType())) {
            CodeableConcept result = new CodeableConcept();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDateType(value.getResultType())) {
            DateType result = new DateType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
            DateTimeType result = new DateTimeType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isTimeType(value.getResultType())) {
            TimeType result = new TimeType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else {
            throw new IllegalArgumentException(String.format("toFhirValue not implemented for parameter of type %s", value.getResultType().toString()));
        }
    }
    throw new IllegalArgumentException(String.format("toFhirValue not implemented for %s", value.getClass().getSimpleName()));
}
Also used : IntervalType(org.hl7.cql.model.IntervalType) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) Quantity(org.hl7.fhir.r5.model.Quantity) org.hl7.elm.r1(org.hl7.elm.r1)

Example 97 with BooleanType

use of org.hl7.fhir.r4.model.BooleanType in project cqf-ruler by DBCG.

the class CqlExecutionProviderIT method testDataBundleCqlExecutionProviderWithSubject.

@Test
public void testDataBundleCqlExecutionProviderWithSubject() throws Exception {
    Parameters params = new Parameters();
    Parameters libraryParameter = new Parameters();
    params.addParameter().setName("subject").setValue(new StringType("Patient/SimplePatient"));
    libraryParameter.addParameter().setName("url").setValue(new CanonicalType(this.getClient().getServerBase() + "Library/SimpleR4Library"));
    libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleR4Library"));
    params.addParameter().setName("library").setResource(libraryParameter);
    params.addParameter().setName("expression").setValue(new StringType("SimpleR4Library.\"observationRetrieve\""));
    String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/";
    loadResource(packagePrefix + "SimpleR4Library.json");
    loadResource(packagePrefix + "SimplePatient.json");
    Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json");
    params.addParameter().setName("data").setResource(data);
    params.addParameter().setName("useServerData").setValue(new BooleanType(false));
    Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
    assertTrue(results.getParameter().get(0).getResource() instanceof Bundle);
    assertTrue(((Bundle) results.getParameter().get(0).getResource()).getEntry().get(0).getResource() instanceof Observation);
    assertTrue(results.getParameter("resultType") instanceof StringType);
    assertTrue(((StringType) results.getParameter("resultType")).asStringValue().equals("List"));
    logger.debug("Results: ", results);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) BooleanType(org.hl7.fhir.r4.model.BooleanType) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 98 with BooleanType

use of org.hl7.fhir.r4.model.BooleanType in project cqf-ruler by DBCG.

the class CqlExecutionProviderIT method testDataBundleCqlExecutionProvider.

@Test
public void testDataBundleCqlExecutionProvider() throws Exception {
    Parameters params = new Parameters();
    Parameters libraryParameter = new Parameters();
    libraryParameter.addParameter().setName("url").setValue(new CanonicalType(this.getClient().getServerBase() + "Library/SimpleR4Library"));
    libraryParameter.addParameter().setName("name").setValue(new StringType("SimpleR4Library"));
    params.addParameter().setName("library").setResource(libraryParameter);
    params.addParameter().setName("expression").setValue(new StringType("SimpleR4Library.\"observationRetrieve\""));
    String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/";
    loadResource(packagePrefix + "SimpleR4Library.json");
    loadResource(packagePrefix + "SimplePatient.json");
    Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json");
    params.addParameter().setName("data").setResource(data);
    params.addParameter().setName("useServerData").setValue(new BooleanType(false));
    Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
    assertTrue(results.getParameter().get(0).getResource() instanceof Bundle);
    assertTrue(((Bundle) results.getParameter().get(0).getResource()).getEntry().get(0).getResource() instanceof Observation);
    assertTrue(results.getParameter("resultType") instanceof StringType);
    assertTrue(((StringType) results.getParameter("resultType")).asStringValue().equals("List"));
    logger.debug("Results: ", results);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) BooleanType(org.hl7.fhir.r4.model.BooleanType) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 99 with BooleanType

use of org.hl7.fhir.r4.model.BooleanType in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveActivityDefinition.

// For library use
public Resource resolveActivityDefinition(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId, RequestDetails theRequest) throws FHIRException {
    Resource result = newResource(activityDefinition.getKind().toCode());
    switch(result.fhirType()) {
        case "ProcedureRequest":
            result = resolveProcedureRequest(activityDefinition, patientId, practitionerId, organizationId);
            break;
        case "MedicationRequest":
            result = resolveMedicationRequest(activityDefinition, patientId);
            break;
        case "SupplyRequest":
            result = resolveSupplyRequest(activityDefinition, practitionerId, organizationId);
            break;
        case "Procedure":
            result = resolveProcedure(activityDefinition, patientId);
            break;
        case "DiagnosticReport":
            result = resolveDiagnosticReport(activityDefinition, patientId);
            break;
        case "Communication":
            result = resolveCommunication(activityDefinition, patientId);
            break;
        case "CommunicationRequest":
            result = resolveCommunicationRequest(activityDefinition, patientId);
            break;
    }
    for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
        if (dynamicValue.getExpression() != null) {
            Boolean aliasedExpression = null;
            if (dynamicValue.hasLanguage()) {
                String language = dynamicValue.getLanguage();
                if (language.equals("text/cql.identifier") || language.equals("text/cql-identifier") || language.equals("text/cql.name") || language.equals("text/cql-name")) {
                    aliasedExpression = true;
                } else {
                    aliasedExpression = false;
                }
            } else {
                aliasedExpression = false;
            }
            /*
				 * TODO: Passing the activityDefinition as context here because that's what will
				 * have the libraries, but perhaps the "context" here should be the result
				 * resource?
				 */
            Object value = expressionEvaluation.evaluateInContext(activityDefinition, dynamicValue.getExpression(), aliasedExpression, patientId, theRequest);
            // TODO need to verify type... yay
            if (value instanceof Boolean) {
                value = new BooleanType((Boolean) value);
            }
            this.modelResolver.setValue(result, dynamicValue.getPath(), value);
        }
    }
    return result;
}
Also used : Resource(org.hl7.fhir.dstu3.model.Resource) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) ActivityDefinition(org.hl7.fhir.dstu3.model.ActivityDefinition)

Example 100 with BooleanType

use of org.hl7.fhir.r4.model.BooleanType in project cqf-ruler by DBCG.

the class ExtractProvider method createObservationFromItemAnswer.

private Bundle.BundleEntryComponent createObservationFromItemAnswer(QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, String linkId, Date authored, QuestionnaireResponse questionnaireResponse, Map<String, Coding> questionnaireCodeMap) {
    Observation obs = new Observation();
    obs.setEffective(new DateTimeType(authored));
    obs.setStatus(Observation.ObservationStatus.FINAL);
    obs.setSubject(questionnaireResponse.getSubject());
    Coding qrCategoryCoding = new Coding();
    qrCategoryCoding.setCode("survey");
    qrCategoryCoding.setSystem("http://hl7.org/fhir/observation-category");
    obs.setCategory(Collections.singletonList(new CodeableConcept().addCoding(qrCategoryCoding)));
    obs.setCode(new CodeableConcept().addCoding(questionnaireCodeMap.get(linkId)));
    obs.setId("qr" + questionnaireResponse.getIdElement().getIdPart() + "." + linkId);
    switch(answer.getValue().fhirType()) {
        case "string":
            obs.setValue(new StringType(answer.getValueStringType().getValue()));
            break;
        case "Coding":
            obs.setValue(new CodeableConcept().addCoding(answer.getValueCoding()));
            break;
        case "boolean":
            obs.setValue(new BooleanType(answer.getValueBooleanType().booleanValue()));
            break;
    }
    Reference questionnaireResponseReference = new Reference();
    questionnaireResponseReference.setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart());
    Observation.ObservationRelatedComponent related = new Observation.ObservationRelatedComponent().setType(Observation.ObservationRelationshipType.DERIVEDFROM).setTarget(questionnaireResponseReference);
    obs.setRelated(Collections.singletonList(related));
    Extension linkIdExtension = new Extension();
    linkIdExtension.setUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/derivedFromLinkId");
    Extension innerLinkIdExtension = new Extension();
    innerLinkIdExtension.setUrl("text");
    innerLinkIdExtension.setValue(new StringType(linkId));
    linkIdExtension.setExtension(Collections.singletonList(innerLinkIdExtension));
    obs.addExtension(linkIdExtension);
    Bundle.BundleEntryRequestComponent berc = new Bundle.BundleEntryRequestComponent();
    berc.setMethod(Bundle.HTTPVerb.PUT);
    berc.setUrl("Observation/" + obs.getId());
    Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
    bec.setResource(obs);
    bec.setRequest(berc);
    return bec;
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) Bundle(org.hl7.fhir.dstu3.model.Bundle) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Coding(org.hl7.fhir.dstu3.model.Coding) Observation(org.hl7.fhir.dstu3.model.Observation) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Aggregations

ArrayList (java.util.ArrayList)59 BooleanType (org.hl7.fhir.r5.model.BooleanType)38 BooleanType (org.hl7.fhir.r4.model.BooleanType)37 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 BooleanType (org.hl7.fhir.r4b.model.BooleanType)27 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)18 Base (org.hl7.fhir.r5.model.Base)17 Test (org.junit.Test)16 StringType (org.hl7.fhir.r4.model.StringType)15 Base (org.hl7.fhir.r4b.model.Base)15 BooleanType (org.hl7.fhir.dstu2016may.model.BooleanType)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)11 Base (org.hl7.fhir.dstu2.model.Base)10 StringType (org.hl7.fhir.dstu3.model.StringType)10 StringType (org.hl7.fhir.r5.model.StringType)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 Coding (org.hl7.fhir.r4.model.Coding)9