Search in sources :

Example 91 with Quantity

use of org.hl7.fhir.dstu2.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method processDataType.

private void processDataType(StructureDefinition profile, QuestionnaireItemComponent group, ElementDefinition element, String path, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, List<ElementDefinition> parents) throws FHIRException {
    String tc = t.getWorkingCode();
    if (tc.equals("code"))
        addCodeQuestions(group, element, path, answerGroups);
    else if (Utilities.existsInList(tc, "string", "id", "oid", "uuid", "markdown"))
        addStringQuestions(group, element, path, answerGroups);
    else if (Utilities.existsInList(tc, "uri", "url", "canonical"))
        addUriQuestions(group, element, path, answerGroups);
    else if (tc.equals("boolean"))
        addBooleanQuestions(group, element, path, answerGroups);
    else if (tc.equals("decimal"))
        addDecimalQuestions(group, element, path, answerGroups);
    else if (tc.equals("dateTime") || tc.equals("date"))
        addDateTimeQuestions(group, element, path, answerGroups);
    else if (tc.equals("instant"))
        addInstantQuestions(group, element, path, answerGroups);
    else if (tc.equals("time"))
        addTimeQuestions(group, element, path, answerGroups);
    else if (tc.equals("CodeableConcept"))
        addCodeableConceptQuestions(group, element, path, answerGroups);
    else if (tc.equals("Period"))
        addPeriodQuestions(group, element, path, answerGroups);
    else if (tc.equals("Ratio"))
        addRatioQuestions(group, element, path, answerGroups);
    else if (tc.equals("HumanName"))
        addHumanNameQuestions(group, element, path, answerGroups);
    else if (tc.equals("Address"))
        addAddressQuestions(group, element, path, answerGroups);
    else if (tc.equals("ContactPoint"))
        addContactPointQuestions(group, element, path, answerGroups);
    else if (tc.equals("Identifier"))
        addIdentifierQuestions(group, element, path, answerGroups);
    else if (tc.equals("integer") || tc.equals("positiveInt") || tc.equals("unsignedInt"))
        addIntegerQuestions(group, element, path, answerGroups);
    else if (tc.equals("Coding"))
        addCodingQuestions(group, element, path, answerGroups);
    else if (Utilities.existsInList(tc, "Quantity", "Count", "Age", "Duration", "Distance", "Money"))
        addQuantityQuestions(group, element, path, answerGroups);
    else if (tc.equals("Money"))
        addMoneyQuestions(group, element, path, answerGroups);
    else if (tc.equals("Reference"))
        addReferenceQuestions(group, element, path, t.getTargetProfile(), answerGroups);
    else if (tc.equals("Duration"))
        addDurationQuestions(group, element, path, answerGroups);
    else if (tc.equals("base64Binary"))
        addBinaryQuestions(group, element, path, answerGroups);
    else if (tc.equals("Attachment"))
        addAttachmentQuestions(group, element, path, answerGroups);
    else if (tc.equals("Age"))
        addAgeQuestions(group, element, path, answerGroups);
    else if (tc.equals("Range"))
        addRangeQuestions(group, element, path, answerGroups);
    else if (tc.equals("Timing"))
        addTimingQuestions(group, element, path, answerGroups);
    else if (tc.equals("Annotation"))
        addAnnotationQuestions(group, element, path, answerGroups);
    else if (tc.equals("SampledData"))
        addSampledDataQuestions(group, element, path, answerGroups);
    else if (tc.equals("Extension")) {
        if (t.hasProfile())
            addExtensionQuestions(profile, group, element, path, t.getProfile().get(0).getValue(), answerGroups, parents);
    } else if (tc.equals("SampledData"))
        addSampledDataQuestions(group, element, path, answerGroups);
    else if (!tc.equals("Narrative") && !tc.equals("Resource") && !tc.equals("Meta") && !tc.equals("Signature")) {
        StructureDefinition sd = context.fetchTypeDefinition(tc);
        if (sd == null)
            throw new NotImplementedException("Unhandled Data Type: " + tc + " on element " + element.getPath());
        buildGroup(group, sd, sd.getSnapshot().getElementFirstRep(), parents, answerGroups);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 92 with Quantity

use of org.hl7.fhir.dstu2.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseTransform.

private TypeDetails analyseTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, VariableForProfiling var, VariablesForProfiling vars) throws FHIRException {
    switch(tgt.getTransform()) {
        case CREATE:
            String p = getParamString(vars, tgt.getParameter().get(0));
            return new TypeDetails(CollectionStatus.SINGLETON, p);
        case COPY:
            return getParam(vars, tgt.getParameter().get(0));
        case EVALUATE:
            ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
            if (expr == null) {
                expr = fpe.parse(getParamString(vars, tgt.getParameter().get(tgt.getParameter().size() - 1)));
                tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
            }
            return fpe.check(vars, null, expr);
        case TRANSLATE:
            return new TypeDetails(CollectionStatus.SINGLETON, "CodeableConcept");
        case CC:
            ProfiledType res = new ProfiledType("CodeableConcept");
            if (tgt.getParameter().size() >= 2 && isParamId(vars, tgt.getParameter().get(1))) {
                TypeDetails td = vars.get(null, getParamId(vars, tgt.getParameter().get(1))).getProperty().getTypes();
                if (td != null && td.hasBinding())
                    // todo: do we need to check that there's no implicit translation her? I don't think we do...
                    res.addBinding(td.getBinding());
            }
            return new TypeDetails(CollectionStatus.SINGLETON, res);
        case C:
            return new TypeDetails(CollectionStatus.SINGLETON, "Coding");
        case QTY:
            return new TypeDetails(CollectionStatus.SINGLETON, "Quantity");
        case REFERENCE:
            VariableForProfiling vrs = vars.get(VariableMode.OUTPUT, getParamId(vars, tgt.getParameterFirstRep()));
            if (vrs == null)
                throw new FHIRException("Unable to resolve variable \"" + getParamId(vars, tgt.getParameterFirstRep()) + "\"");
            String profile = vrs.getProperty().getProfileProperty().getStructure().getUrl();
            TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
            td.addType("Reference", profile);
            return td;
        default:
            throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
    }
}
Also used : ProfiledType(org.hl7.fhir.r4b.model.TypeDetails.ProfiledType) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 93 with Quantity

use of org.hl7.fhir.dstu2.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class Element method getAsICoding.

public ICoding getAsICoding() throws FHIRException {
    if ("code".equals(fhirType())) {
        if (property.getDefinition().getBinding().getStrength() != BindingStrength.REQUIRED)
            return null;
        ICodingImpl c = new ICodingImpl(true, true, false, false);
        c.code = primitiveValue();
        ValueSetExpansionOutcome vse = property.getContext().expandVS(property.getDefinition().getBinding(), true, false);
        if (vse.getValueset() == null)
            return null;
        for (ValueSetExpansionContainsComponent cc : vse.getValueset().getExpansion().getContains()) {
            if (cc.getCode().equals(c.code)) {
                c.system = cc.getSystem();
                if (cc.hasVersion()) {
                    c.doesVersion = true;
                    c.version = cc.getVersion();
                }
                if (cc.hasDisplay()) {
                    c.doesDisplay = true;
                    c.display = cc.getDisplay();
                }
            }
        }
        if (c.system == null)
            return null;
        return c;
    } else if ("Coding".equals(fhirType())) {
        ICodingImpl c = new ICodingImpl(true, true, true, true);
        c.system = getNamedChildValue("system");
        c.code = getNamedChildValue("code");
        c.display = getNamedChildValue("display");
        c.version = getNamedChildValue("version");
        return c;
    } else if ("Quantity".equals(fhirType())) {
        ICodingImpl c = new ICodingImpl(true, true, false, false);
        c.system = getNamedChildValue("system");
        c.code = getNamedChildValue("code");
        return c;
    } else
        return null;
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionOutcome(org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome)

Example 94 with Quantity

use of org.hl7.fhir.dstu2.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opGreaterOrEqual.

private List<Base> opGreaterOrEqual(List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
    if (left.size() == 0 || right.size() == 0) {
        return new ArrayList<Base>();
    }
    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(FHIR_TYPES_STRING) && r.hasType(FHIR_TYPES_STRING)) {
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) >= 0);
        } else if ((l.hasType("integer", "decimal", "unsignedInt", "positiveInt")) && (r.hasType("integer", "decimal", "unsignedInt", "positiveInt"))) {
            return makeBoolean(new Double(l.primitiveValue()) >= new Double(r.primitiveValue()));
        } else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant"))) {
            Integer i = compareDateTimeElements(l, r, false);
            if (i == null) {
                return makeNull();
            } else {
                return makeBoolean(i >= 0);
            }
        } else if ((l.hasType("time")) && (r.hasType("time"))) {
            Integer i = compareTimeElements(l, r, false);
            if (i == null) {
                return makeNull();
            } else {
                return makeBoolean(i >= 0);
            }
        } else {
            throw makeException(expr, I18nConstants.FHIRPATH_CANT_COMPARE, l.fhirType(), r.fhirType());
        }
    } 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 opGreaterOrEqual(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"), expr);
        } else {
            if (worker.getUcumService() == null) {
                return makeBoolean(false);
            } else {
                List<Base> dl = new ArrayList<Base>();
                dl.add(qtyToCanonicalDecimal((Quantity) left.get(0)));
                List<Base> dr = new ArrayList<Base>();
                dr.add(qtyToCanonicalDecimal((Quantity) right.get(0)));
                return opGreaterOrEqual(dl, dr, expr);
            }
        }
    }
    return new ArrayList<Base>();
}
Also used : ArrayList(java.util.ArrayList) MergedList(org.hl7.fhir.utilities.MergedList) List(java.util.List) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r5.model.Base)

Example 95 with Quantity

use of org.hl7.fhir.dstu2.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opDiv.

private List<Base> opDiv(List<Base> left, List<Base> right, ExpressionNode expr) throws PathEngineException {
    if (left.size() == 0 || right.size() == 0) {
        return new ArrayList<Base>();
    }
    if (left.size() > 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_PLURAL, "div");
    }
    if (!left.get(0).isPrimitive() && !(left.get(0) instanceof Quantity)) {
        throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_WRONG_TYPE, "div", left.get(0).fhirType());
    }
    if (right.size() > 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_PLURAL, "div");
    }
    if (!right.get(0).isPrimitive() && !(right.get(0) instanceof Quantity)) {
        throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_WRONG_TYPE, "div", right.get(0).fhirType());
    }
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType("integer") && r.hasType("integer")) {
        int divisor = Integer.parseInt(r.primitiveValue());
        if (divisor != 0) {
            result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) / divisor));
        }
    } else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer")) {
        Decimal d1;
        try {
            d1 = new Decimal(l.primitiveValue());
            Decimal d2 = new Decimal(r.primitiveValue());
            result.add(new IntegerType(d1.divInt(d2).asDecimal()));
        } catch (UcumException e) {
        // just return nothing
        }
    } else {
        throw makeException(expr, I18nConstants.FHIRPATH_OP_INCOMPATIBLE, "div", left.get(0).fhirType(), right.get(0).fhirType());
    }
    return result;
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) BigDecimal(java.math.BigDecimal) Decimal(org.fhir.ucum.Decimal) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r5.model.Quantity) UcumException(org.fhir.ucum.UcumException) Base(org.hl7.fhir.r5.model.Base)

Aggregations

Quantity (org.hl7.fhir.r4.model.Quantity)58 ArrayList (java.util.ArrayList)47 Test (org.junit.jupiter.api.Test)40 BigDecimal (java.math.BigDecimal)39 Quantity (org.hl7.fhir.dstu3.model.Quantity)39 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37 Test (org.junit.Test)25 List (java.util.List)24 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)23 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)23 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)18 Observation (org.hl7.fhir.r4.model.Observation)18 UcumException (org.fhir.ucum.UcumException)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)16 Resource (org.hl7.fhir.r4.model.Resource)16 Quantity (org.hl7.fhir.r5.model.Quantity)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Coding (org.hl7.fhir.r4.model.Coding)13