Search in sources :

Example 71 with Quantity

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

the class NarrativeGenerator method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return;
    Base e = ew.getBase();
    if (e instanceof StringType)
        x.addText(((StringType) e).getValue());
    else if (e instanceof CodeType)
        x.addText(((CodeType) e).getValue());
    else if (e instanceof IdType)
        x.addText(((IdType) e).getValue());
    else if (e instanceof Extension)
        x.addText("Extensions: Todo");
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType)
        x.addText(((DateTimeType) e).toHumanDisplay());
    else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.dstu2016may.model.DateType)
        x.addText(((org.hl7.fhir.dstu2016may.model.DateType) e).toHumanDisplay());
    else if (e instanceof Enumeration) {
        Object ev = ((Enumeration<?>) e).getValue();
        // todo: look up a display name if there is one
        x.addText(ev == null ? "" : ev.toString());
    } else if (e instanceof BooleanType)
        x.addText(((BooleanType) e).getValue().toString());
    else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x);
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
    } else if (e instanceof org.hl7.fhir.dstu2016may.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu2016may.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu2016may.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu2016may.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
    } else if (e instanceof UriType) {
        renderUri((UriType) e, x);
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
    } else if (e instanceof Range) {
        renderRange((Range) e, x);
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.addText("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.addText(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        XhtmlNode c = x;
        ResourceWithReference tr = null;
        if (r.hasReferenceElement()) {
            tr = resolveReference(res, r.getReference());
            if (!r.getReference().startsWith("#")) {
                if (tr != null && tr.getReference() != null)
                    c = x.addTag("a").attribute("href", tr.getReference());
                else
                    c = x.addTag("a").attribute("href", r.getReference());
            }
        }
        // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
        if (r.hasDisplayElement()) {
            c.addText(r.getDisplay());
            if (tr != null) {
                c.addText(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
        } else {
            c.addText(r.getReference());
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof ElementDefinition) {
        x.addText("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
}
Also used : Meta(org.hl7.fhir.dstu2016may.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu2016may.model.Address) StringType(org.hl7.fhir.dstu2016may.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu2016may.model.Attachment) UriType(org.hl7.fhir.dstu2016may.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu2016may.model.HumanName) ContactPoint(org.hl7.fhir.dstu2016may.model.ContactPoint) Identifier(org.hl7.fhir.dstu2016may.model.Identifier) Coding(org.hl7.fhir.dstu2016may.model.Coding) Narrative(org.hl7.fhir.dstu2016may.model.Narrative) SampledData(org.hl7.fhir.dstu2016may.model.SampledData) Ratio(org.hl7.fhir.dstu2016may.model.Ratio) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) InstantType(org.hl7.fhir.dstu2016may.model.InstantType) Enumeration(org.hl7.fhir.dstu2016may.model.Enumeration) Reference(org.hl7.fhir.dstu2016may.model.Reference) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) Resource(org.hl7.fhir.dstu2016may.model.Resource) DomainResource(org.hl7.fhir.dstu2016may.model.DomainResource) Quantity(org.hl7.fhir.dstu2016may.model.Quantity) Period(org.hl7.fhir.dstu2016may.model.Period) Range(org.hl7.fhir.dstu2016may.model.Range) Base(org.hl7.fhir.dstu2016may.model.Base) Annotation(org.hl7.fhir.dstu2016may.model.Annotation) IdType(org.hl7.fhir.dstu2016may.model.IdType) Extension(org.hl7.fhir.dstu2016may.model.Extension) DateTimeType(org.hl7.fhir.dstu2016may.model.DateTimeType) CodeType(org.hl7.fhir.dstu2016may.model.CodeType) EventTiming(org.hl7.fhir.dstu2016may.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu2016may.model.Timing) Base64BinaryType(org.hl7.fhir.dstu2016may.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu2016may.model.CodeableConcept)

Example 72 with Quantity

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

the class NarrativeGenerator method displayQuantity.

private String displayQuantity(Quantity q) {
    StringBuilder s = new StringBuilder();
    s.append("(system = '").append(describeSystem(q.getSystem())).append("' code ").append(q.getCode()).append(" = '").append(lookupCode(q.getSystem(), q.getCode())).append("')");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 73 with Quantity

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

the class QuestionnaireBuilder method convertType.

@SuppressWarnings("unchecked")
private Type convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
    switch(af) {
        // simple cases
        case BOOLEAN:
            if (value instanceof BooleanType)
                return (Type) value;
        case DECIMAL:
            if (value instanceof DecimalType)
                return (Type) value;
        case INTEGER:
            if (value instanceof IntegerType)
                return (Type) value;
        case DATE:
            if (value instanceof DateType)
                return (Type) value;
        case DATETIME:
            if (value instanceof DateTimeType)
                return (Type) value;
        case INSTANT:
            if (value instanceof InstantType)
                return (Type) value;
        case TIME:
            if (value instanceof TimeType)
                return (Type) value;
        case STRING:
            if (value instanceof StringType)
                return (Type) value;
            else if (value instanceof UriType)
                return new StringType(((UriType) value).asStringValue());
        case TEXT:
            if (value instanceof StringType)
                return (Type) value;
        case QUANTITY:
            if (value instanceof Quantity)
                return (Type) value;
        // ? QuestionnaireItemTypeAttachment: ...?
        case CHOICE:
        case OPENCHOICE:
            if (value instanceof Coding)
                return (Type) value;
            else if (value instanceof Enumeration) {
                Coding cc = new Coding();
                cc.setCode(((Enumeration<Enum<?>>) value).asStringValue());
                cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
                return cc;
            } else if (value instanceof StringType) {
                Coding cc = new Coding();
                cc.setCode(((StringType) value).asStringValue());
                cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
                return cc;
            }
        case REFERENCE:
            if (value instanceof Reference)
                return (Type) value;
            else if (value instanceof StringType) {
                Reference r = new Reference();
                r.setReference(((StringType) value).asStringValue());
            }
    }
    throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
Also used : Enumeration(org.hl7.fhir.dstu2016may.model.Enumeration) StringType(org.hl7.fhir.dstu2016may.model.StringType) Reference(org.hl7.fhir.dstu2016may.model.Reference) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) Quantity(org.hl7.fhir.dstu2016may.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) DateTimeType(org.hl7.fhir.dstu2016may.model.DateTimeType) TimeType(org.hl7.fhir.dstu2016may.model.TimeType) UriType(org.hl7.fhir.dstu2016may.model.UriType) IntegerType(org.hl7.fhir.dstu2016may.model.IntegerType) DateTimeType(org.hl7.fhir.dstu2016may.model.DateTimeType) Coding(org.hl7.fhir.dstu2016may.model.Coding) DecimalType(org.hl7.fhir.dstu2016may.model.DecimalType) InstantType(org.hl7.fhir.dstu2016may.model.InstantType) DateType(org.hl7.fhir.dstu2016may.model.DateType)

Example 74 with Quantity

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

the class QuestionnaireBuilder method convertType.

@SuppressWarnings("unchecked")
private Type convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
    switch(af) {
        // simple cases
        case BOOLEAN:
            if (value instanceof BooleanType)
                return (Type) value;
        case DECIMAL:
            if (value instanceof DecimalType)
                return (Type) value;
        case INTEGER:
            if (value instanceof IntegerType)
                return (Type) value;
        case DATE:
            if (value instanceof DateType)
                return (Type) value;
        case DATETIME:
            if (value instanceof DateTimeType)
                return (Type) value;
        case TIME:
            if (value instanceof TimeType)
                return (Type) value;
        case STRING:
            if (value instanceof StringType)
                return (Type) value;
            else if (value instanceof UriType)
                return new StringType(((UriType) value).asStringValue());
        case TEXT:
            if (value instanceof StringType)
                return (Type) value;
        case QUANTITY:
            if (value instanceof Quantity)
                return (Type) value;
        // ? QuestionnaireItemTypeAttachment: ...?
        case CHOICE:
        case OPENCHOICE:
            if (value instanceof Coding)
                return (Type) value;
            else if (value instanceof Enumeration) {
                Coding cc = new Coding();
                cc.setCode(((Enumeration<Enum<?>>) value).asStringValue());
                cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
                return cc;
            } else if (value instanceof StringType) {
                Coding cc = new Coding();
                cc.setCode(((StringType) value).asStringValue());
                cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
                return cc;
            }
        case REFERENCE:
            if (value instanceof Reference)
                return (Type) value;
            else if (value instanceof StringType) {
                Reference r = new Reference();
                r.setReference(((StringType) value).asStringValue());
            }
    }
    throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
Also used : Enumeration(org.hl7.fhir.dstu3.model.Enumeration) StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Quantity(org.hl7.fhir.dstu3.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.dstu3.model.TimeType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) UriType(org.hl7.fhir.dstu3.model.UriType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Coding(org.hl7.fhir.dstu3.model.Coding) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) DateType(org.hl7.fhir.dstu3.model.DateType)

Example 75 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);
        // //  throw new Error("Transform "+tgt.getTransform().toCode()+" not supported yet");
        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))).property.types;
                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.property.getProfileProperty().getStructure().getUrl();
            TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
            td.addType("Reference", profile);
            return td;
        // //    throw new FHIRException("Transform engine cannot point at an element of type "+b.fhirType());
        default:
            throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
    }
}
Also used : TypeDetails(org.hl7.fhir.dstu3.model.TypeDetails) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException)

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