Search in sources :

Example 36 with DateType

use of org.hl7.fhir.r5.model.DateType in project synthea by synthetichealth.

the class FhirR4 method careGoal.

/**
 * Map the JsonObject into a FHIR Goal resource, and add it to the given Bundle.
 * @param rand Source of randomness to use when generating ids etc
 * @param bundle The Bundle to add to
 * @param goalStatus The GoalStatus
 * @param goal The JsonObject
 * @return The added Entry
 */
private static BundleEntryComponent careGoal(RandomNumberGenerator rand, Bundle bundle, BundleEntryComponent personEntry, long carePlanStart, CodeableConcept goalStatus, JsonObject goal) {
    String resourceID = rand.randUUID().toString();
    Goal goalResource = new Goal();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-goal");
        goalResource.setMeta(meta);
    }
    goalResource.setLifecycleStatus(GoalLifecycleStatus.ACCEPTED);
    goalResource.setAchievementStatus(goalStatus);
    goalResource.setId(resourceID);
    goalResource.setSubject(new Reference(personEntry.getFullUrl()));
    if (goal.has("text")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        descriptionCodeableConcept.setText(goal.get("text").getAsString());
        goalResource.setDescription(descriptionCodeableConcept);
    } else if (goal.has("codes")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        JsonObject code = goal.get("codes").getAsJsonArray().get(0).getAsJsonObject();
        descriptionCodeableConcept.addCoding().setSystem(LOINC_URI).setCode(code.get("code").getAsString()).setDisplay(code.get("display").getAsString());
        descriptionCodeableConcept.setText(code.get("display").getAsString());
        goalResource.setDescription(descriptionCodeableConcept);
    } else if (goal.has("observation")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        // build up our own text from the observation condition, similar to the graphviz logic
        JsonObject logic = goal.get("observation").getAsJsonObject();
        String[] text = { logic.get("codes").getAsJsonArray().get(0).getAsJsonObject().get("display").getAsString(), logic.get("operator").getAsString(), logic.get("value").getAsString() };
        descriptionCodeableConcept.setText(String.join(" ", text));
        goalResource.setDescription(descriptionCodeableConcept);
    }
    goalResource.addTarget().setMeasure(goalResource.getDescription()).setDue(new DateType(new Date(carePlanStart + Utilities.convertTime("days", 30))));
    if (goal.has("addresses")) {
        for (JsonElement reasonElement : goal.get("addresses").getAsJsonArray()) {
            if (reasonElement instanceof JsonObject) {
                JsonObject reasonObject = reasonElement.getAsJsonObject();
                String reasonCode = reasonObject.get("codes").getAsJsonObject().get("SNOMED-CT").getAsJsonArray().get(0).getAsString();
                for (BundleEntryComponent entry : bundle.getEntry()) {
                    if (entry.getResource().fhirType().equals("Condition")) {
                        Condition condition = (Condition) entry.getResource();
                        // Only one element in list
                        Coding coding = condition.getCode().getCoding().get(0);
                        if (reasonCode.equals(coding.getCode())) {
                            goalResource.addAddresses().setReference(entry.getFullUrl());
                        }
                    }
                }
            }
        }
    }
    return newEntry(rand, bundle, goalResource);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) Goal(org.hl7.fhir.r4.model.Goal) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) JsonElement(com.google.gson.JsonElement) DateType(org.hl7.fhir.r4.model.DateType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 37 with DateType

use of org.hl7.fhir.r5.model.DateType in project bunsen by cerner.

the class TestData method newBunsenTestProfilePatient.

/**
 * Returns a new Patient from Bunsen Test profile for testing.
 *
 * @return a FHIR Patient for testing.
 */
public static Patient newBunsenTestProfilePatient() {
    Patient patient = new Patient();
    patient.setId("test-bunsen-test-profile-patient");
    patient.setGender(AdministrativeGender.MALE);
    patient.setActive(true);
    patient.setMultipleBirth(new IntegerType(1));
    patient.setBirthDateElement(new DateType("1945-01-01"));
    // set extension field
    Extension booleanField = patient.addExtension();
    booleanField.setUrl(BUNSEN_TEST_BOOLEAN_FIELD);
    booleanField.setValue(new BooleanType(true));
    Extension integerField = patient.addExtension();
    integerField.setUrl(BUNSEN_TEST_INTEGER_FIELD);
    integerField.setValue(new IntegerType(45678));
    Extension integerArrayField1 = patient.addExtension();
    integerArrayField1.setUrl(BUNSEN_TEST_INTEGER_ARRAY_FIELD);
    integerArrayField1.setValue(new IntegerType(6666));
    Extension integerArrayField2 = patient.addExtension();
    integerArrayField2.setUrl(BUNSEN_TEST_INTEGER_ARRAY_FIELD);
    integerArrayField2.setValue(new IntegerType(9999));
    // add multiple nested extensions
    final Extension nestedExtension1 = patient.addExtension();
    nestedExtension1.setUrl(BUNSEN_TEST_NESTED_EXT_FIELD);
    nestedExtension1.setValue(null);
    final Extension nestedExtension2 = patient.addExtension();
    nestedExtension2.setUrl(BUNSEN_TEST_NESTED_EXT_FIELD);
    nestedExtension2.setValue(null);
    // add text as sub-extension to nestedExtension
    final Extension textExt1 = nestedExtension1.addExtension();
    textExt1.setUrl("text");
    textExt1.setValue(new StringType("Text1 Sub-extension of nestedExtension1 field"));
    final Extension textExt2 = nestedExtension1.addExtension();
    textExt2.setUrl("text");
    textExt2.setValue(new StringType("Text2 Sub-extension of nestedExtension1 field"));
    final Extension textExt3 = nestedExtension2.addExtension();
    textExt3.setUrl("text");
    textExt3.setValue(new StringType("Text3 Sub-extension of nestedExtension2 field"));
    // add multiple codeableConcept extensions to nestedExtension
    final CodeableConcept codeableconcept1 = new CodeableConcept();
    codeableconcept1.addCoding().setSystem("http://snomed.info/sct").setCode("CC1").setDisplay("CC1 - Codeable Concept Extension").setUserSelected(true);
    final CodeableConcept codeableconcept2 = new CodeableConcept();
    codeableconcept2.addCoding().setSystem("http://snomed.info/sct").setCode("CC2").setDisplay("CC2 - Codeable Concept Extension").setUserSelected(true);
    final CodeableConcept codeableconcept3 = new CodeableConcept();
    codeableconcept3.addCoding().setSystem("http://snomed.info/sct").setCode("CC3").setDisplay("CC3 - Codeable Concept Extension").setUserSelected(true);
    final Extension codeableConceptExt1 = nestedExtension1.addExtension();
    codeableConceptExt1.setUrl(BUNSEN_TEST_CODEABLE_CONCEPT_EXT_FIELD);
    codeableConceptExt1.setValue(codeableconcept1);
    final Extension codeableConceptExt2 = nestedExtension1.addExtension();
    codeableConceptExt2.setUrl(BUNSEN_TEST_CODEABLE_CONCEPT_EXT_FIELD);
    codeableConceptExt2.setValue(codeableconcept2);
    final Extension codeableConceptExt3 = nestedExtension2.addExtension();
    codeableConceptExt3.setUrl(BUNSEN_TEST_CODEABLE_CONCEPT_EXT_FIELD);
    codeableConceptExt3.setValue(codeableconcept3);
    // add multiple ModifierExtension fields
    Extension stringModifierExtension = patient.addModifierExtension();
    stringModifierExtension.setUrl(BUNSEN_TEST_STRING_MODIFIER_EXT_FIELD);
    stringModifierExtension.setValue(new StringType("test string modifier value"));
    CodeableConcept concept1 = new CodeableConcept();
    concept1.addCoding().setSystem("http://snomed.info/sct").setCode("C-1").setDisplay("C-1 Codeable Concept Modifier Extension").setUserSelected(true);
    Extension codeableConceptField = patient.addModifierExtension();
    codeableConceptField.setUrl(BUNSEN_TEST_CODEABLE_CONCEPT_MODIFIER_EXT_FIELD);
    codeableConceptField.setValue(concept1);
    CodeableConcept concept2 = new CodeableConcept();
    concept2.addCoding().setSystem("http://snomed.info/sct").setCode("C-2").setDisplay("C-2 Codeable Concept Modifier Extension").setUserSelected(true);
    Extension codeableConceptField2 = patient.addModifierExtension();
    codeableConceptField2.setUrl(BUNSEN_TEST_CODEABLE_CONCEPT_MODIFIER_EXT_FIELD);
    codeableConceptField2.setValue(concept2);
    return patient;
}
Also used : IntegerType(org.hl7.fhir.dstu3.model.IntegerType) Extension(org.hl7.fhir.dstu3.model.Extension) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Patient(org.hl7.fhir.dstu3.model.Patient) DateType(org.hl7.fhir.dstu3.model.DateType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 38 with DateType

use of org.hl7.fhir.r5.model.DateType 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 39 with DateType

use of org.hl7.fhir.r5.model.DateType in project cqf-ruler by DBCG.

the class CqlExecutionProviderIT method testSimpleParametersCqlExecutionProvider.

@Test
public void testSimpleParametersCqlExecutionProvider() throws Exception {
    Parameters params = new Parameters();
    params.addParameter().setName("expression").setValue(new StringType("year from %inputDate before 2020"));
    Parameters evaluationParams = new Parameters();
    evaluationParams.addParameter().setName("%inputDate").setValue(new DateType("2019-11-01"));
    params.addParameter().setName("parameters").setResource(evaluationParams);
    Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
    assertTrue(results.getParameter().get(0).getValue() instanceof StringType);
    assertTrue(((StringType) results.getParameter().get(0).getValue()).asStringValue().equals("true"));
    assertTrue(results.getParameter().get(1).getValue() instanceof StringType);
    assertTrue(((StringType) results.getParameter().get(1).getValue()).asStringValue().equals("Boolean"));
    logger.debug("Results: ", results);
}
Also used : Parameters(org.hl7.fhir.dstu3.model.Parameters) StringType(org.hl7.fhir.dstu3.model.StringType) DateType(org.hl7.fhir.dstu3.model.DateType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 40 with DateType

use of org.hl7.fhir.r5.model.DateType in project cqf-ruler by DBCG.

the class CqlExecutionProviderIT method testSimpleParametersCqlExecutionProvider.

@Test
public void testSimpleParametersCqlExecutionProvider() throws Exception {
    Parameters params = new Parameters();
    params.addParameter().setName("expression").setValue(new StringType("year from %inputDate before 2020"));
    Parameters evaluationParams = new Parameters();
    evaluationParams.addParameter().setName("%inputDate").setValue(new DateType("2019-11-01"));
    params.addParameter().setName("parameters").setResource(evaluationParams);
    Parameters results = getClient().operation().onServer().named("$cql").withParameters(params).execute();
    assertTrue(results.getParameter("value") instanceof StringType);
    assertTrue(((StringType) results.getParameter("value")).asStringValue().equals("true"));
    assertTrue(results.getParameter("resultType") instanceof StringType);
    assertTrue(((StringType) results.getParameter("resultType")).asStringValue().equals("Boolean"));
    logger.debug("Results: ", results);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) DateType(org.hl7.fhir.r4.model.DateType) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Aggregations

DateType (org.hl7.fhir.r4.model.DateType)36 Test (org.junit.jupiter.api.Test)21 Date (java.util.Date)17 Coding (org.hl7.fhir.r4.model.Coding)15 Test (org.junit.Test)11 SupportingInformationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent)10 DateType (org.hl7.fhir.r4b.model.DateType)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ArrayList (java.util.ArrayList)8 DateType (org.hl7.fhir.r5.model.DateType)8 DateType (org.hl7.fhir.dstu3.model.DateType)7 Extension (org.hl7.fhir.r4.model.Extension)6 Calendar (java.util.Calendar)5 DisplayName (org.junit.jupiter.api.DisplayName)5 InvalidRifValueException (gov.cms.bfd.model.rif.parse.InvalidRifValueException)4 DateType (org.hl7.fhir.dstu2016may.model.DateType)4 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)4 Patient (org.hl7.fhir.r4.model.Patient)4 Reference (org.hl7.fhir.r4.model.Reference)4