Search in sources :

Example 21 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method describeTransformCCorC.

@SuppressWarnings("rawtypes")
private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
    if (tgt.getParameter().size() < 2)
        return null;
    DataType p1 = tgt.getParameter().get(0).getValue();
    DataType p2 = tgt.getParameter().get(1).getValue();
    if (p1 instanceof IdType || p2 instanceof IdType)
        return null;
    if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType))
        return null;
    String uri = ((PrimitiveType) p1).asStringValue();
    String code = ((PrimitiveType) p2).asStringValue();
    if (Utilities.noString(uri))
        throw new FHIRException("Describe Transform, but the uri is blank");
    if (Utilities.noString(code))
        throw new FHIRException("Describe Transform, but the code is blank");
    Coding c = buildCoding(uri, code);
    return TerminologyRenderer.describeSystem(c.getSystem()) + "#" + c.getCode() + (c.hasDisplay() ? "(" + c.getDisplay() + ")" : "");
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 22 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method describeCoded.

private Piece describeCoded(HierarchicalTableGenerator gen, DataType fixed) {
    if (fixed instanceof Coding) {
        Coding c = (Coding) fixed;
        ValidationResult vr = context.validateCode(terminologyServiceOptions, c.getSystem(), c.getVersion(), c.getCode(), c.getDisplay());
        if (vr.getDisplay() != null)
            return gen.new Piece(null, " (" + vr.getDisplay() + ")", null).addStyle("color: darkgreen");
    } else if (fixed instanceof CodeableConcept) {
        CodeableConcept cc = (CodeableConcept) fixed;
        for (Coding c : cc.getCoding()) {
            ValidationResult vr = context.validateCode(terminologyServiceOptions, c.getSystem(), c.getVersion(), c.getCode(), c.getDisplay());
            if (vr.getDisplay() != null)
                return gen.new Piece(null, " (" + vr.getDisplay() + ")", null).addStyle("color: darkgreen");
        }
    }
    return null;
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 23 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class EnableWhenEvaluator method evaluateCondition.

protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition, QuestionnaireItemComponent qitem, QStack qstack) {
    List<Element> answerItems = findQuestionAnswers(qstack, qitem, enableCondition);
    QuestionnaireItemOperator operator = enableCondition.getOperator();
    if (operator == QuestionnaireItemOperator.EXISTS) {
        DataType answer = enableCondition.getAnswer();
        if (!(answer instanceof BooleanType)) {
            throw new UnprocessableEntityException("Exists-operator requires answerBoolean");
        }
        return new EnableWhenResult(((BooleanType) answer).booleanValue() != answerItems.isEmpty(), enableCondition);
    }
    boolean result = false;
    for (Element answer : answerItems) {
        result = result || evaluateAnswer(answer, enableCondition.getAnswer(), enableCondition.getOperator());
    }
    return new EnableWhenResult(result, enableCondition);
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) Element(org.hl7.fhir.r5.elementmodel.Element) BooleanType(org.hl7.fhir.r5.model.BooleanType) QuestionnaireItemOperator(org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemOperator) DataType(org.hl7.fhir.r5.model.DataType)

Example 24 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class DiagnosticReportRenderer method addObservationToTable.

private void addObservationToTable(XhtmlNode tr, ResourceWrapper obs, int i, String ref, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
    // code (+bodysite)
    XhtmlNode td = tr.td();
    PropertyWrapper pw = getProperty(obs, "code");
    if (valued(pw)) {
        render(td.ah(ref), pw.value());
    }
    pw = getProperty(obs, "bodySite");
    if (valued(pw)) {
        td.tx(" (");
        render(td, pw.value());
        td.tx(")");
    }
    // value / dataAbsentReason (in red)
    td = tr.td();
    pw = getProperty(obs, "value[x]");
    if (valued(pw)) {
        render(td, pw.value());
    } else {
        pw = getProperty(obs, "dataAbsentReason");
        if (valued(pw)) {
            XhtmlNode span = td.span("color: maroon", "Error");
            span.tx("Error: ");
            render(span.b(), pw.value());
        }
    }
    if (refRange) {
        // reference range
        td = tr.td();
        pw = getProperty(obs, "referenceRange");
        if (valued(pw)) {
            boolean first = true;
            for (BaseWrapper v : pw.getValues()) {
                if (first)
                    first = false;
                else
                    td.br();
                PropertyWrapper pwr = getProperty(v, "type");
                if (valued(pwr)) {
                    render(td, pwr.value());
                    td.tx(": ");
                }
                PropertyWrapper pwt = getProperty(v, "text");
                if (valued(pwt)) {
                    render(td, pwt.value());
                } else {
                    PropertyWrapper pwl = getProperty(v, "low");
                    PropertyWrapper pwh = getProperty(v, "high");
                    if (valued(pwl) && valued(pwh)) {
                        render(td, pwl.value());
                        td.tx(" - ");
                        render(td, pwh.value());
                    } else if (valued(pwl)) {
                        td.tx(">");
                        render(td, pwl.value());
                    } else if (valued(pwh)) {
                        td.tx("<");
                        render(td, pwh.value());
                    } else {
                        td.tx("??");
                    }
                }
                pwr = getProperty(v, "appliesTo");
                PropertyWrapper pwrA = getProperty(v, "age");
                if (valued(pwr) || valued(pwrA)) {
                    boolean firstA = true;
                    td.tx(" for ");
                    if (valued(pwr)) {
                        for (BaseWrapper va : pwr.getValues()) {
                            if (firstA)
                                firstA = false;
                            else
                                td.tx(", ");
                            render(td, va);
                        }
                    }
                    if (valued(pwrA)) {
                        if (firstA)
                            firstA = false;
                        else
                            td.tx(", ");
                        td.tx("Age ");
                        render(td, pwrA.value());
                    }
                }
            }
        }
    }
    if (flags) {
        // flags (status other than F, interpretation, )
        td = tr.td();
        boolean first = true;
        pw = getProperty(obs, "status");
        if (valued(pw)) {
            if (!pw.value().getBase().primitiveValue().equals("final")) {
                if (first)
                    first = false;
                else
                    td.br();
                render(td, pw.value());
            }
        }
        pw = getProperty(obs, "interpretation");
        if (valued(pw)) {
            for (BaseWrapper v : pw.getValues()) {
                if (first)
                    first = false;
                else
                    td.br();
                render(td, v);
            }
        }
    }
    if (note) {
        td = tr.td();
        pw = getProperty(obs, "note");
        if (valued(pw)) {
            render(td, pw.value());
        }
    }
    if (effectiveTime) {
        // effective if different to DR
        td = tr.td();
        pw = getProperty(obs, "effective[x]");
        if (valued(pw)) {
            if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
                render(td, pw.value());
            }
        }
    }
    if (issued) {
        // issued if different to DR
        td = tr.td();
        pw = getProperty(obs, "issued");
        if (valued(pw)) {
            if (!Base.compareDeep(pw.value().getBase(), eff, true)) {
                render(td, pw.value());
            }
        }
    }
}
Also used : PropertyWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.PropertyWrapper) BaseWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 25 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class DiagnosticReportRenderer method buildObservationsTable.

private void buildObservationsTable(XhtmlNode root, List<ObservationNode> observations, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
    XhtmlNode tbl = root.table("grid");
    boolean refRange = scanObsForRefRange(observations);
    boolean flags = scanObsForFlags(observations);
    boolean note = scanObsForNote(observations);
    boolean effectiveTime = scanObsForEffective(observations, eff);
    boolean issued = scanObsForIssued(observations, iss);
    int cs = 2;
    if (refRange)
        cs++;
    if (flags)
        cs++;
    if (note)
        cs++;
    if (issued)
        cs++;
    if (effectiveTime)
        cs++;
    XhtmlNode tr = tbl.tr();
    tr.td().b().tx("Code");
    tr.td().b().tx("Value");
    if (refRange) {
        tr.td().b().tx("Reference Range");
    }
    if (flags) {
        tr.td().b().tx("Flags");
    }
    if (note) {
        tr.td().b().tx("Note");
    }
    if (effectiveTime) {
        tr.td().b().tx("When For");
    }
    if (issued) {
        tr.td().b().tx("Reported");
    }
    for (ObservationNode o : observations) {
        addObservationToTable(tbl, o, 0, Integer.toString(cs), refRange, flags, note, effectiveTime, issued, eff, iss);
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

DataType (org.hl7.fhir.r5.model.DataType)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 Collectors (java.util.stream.Collectors)6 DataType (org.hl7.cql.model.DataType)6 ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 ArrayList (java.util.ArrayList)5 StructType (org.apache.spark.sql.types.StructType)5 BooleanType (org.hl7.fhir.r5.model.BooleanType)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 Arrays (java.util.Arrays)4 QName (javax.xml.namespace.QName)4 DataType (org.hl7.fhir.r4b.model.DataType)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3