Search in sources :

Example 81 with DataType

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

the class DiagnosticReportRenderer method addObservationToTable.

private void addObservationToTable(XhtmlNode tbl, ObservationNode o, int i, String cs, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
    XhtmlNode tr = tbl.tr();
    if (o.obs != null && o.obs.getReference() == null) {
        XhtmlNode td = tr.td().colspan(cs);
        td.i().tx("This Observation could not be resolved");
    } else {
        if (o.obs != null && o.obs.getResource() != null) {
            addObservationToTable(tr, o.obs.getResource(), i, o.obs.getReference(), refRange, flags, note, effectiveTime, issued, eff, iss);
        } else {
            XhtmlNode td = tr.td().colspan(cs);
            td.i().tx("Observation");
        }
        if (o.contained != null) {
            for (ObservationNode c : o.contained) {
                addObservationToTable(tbl, c, i + 1, cs, refRange, flags, note, effectiveTime, issued, eff, iss);
            }
        }
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 82 with DataType

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

the class StructureMapUtilities method getParam.

private Base getParam(Variables vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    DataType p = parameter.getValue();
    if (!(p instanceof IdType))
        return p;
    else {
        String n = ((IdType) p).asStringValue();
        Base b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b;
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 83 with DataType

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

the class StructureMapUtilities method analyseTarget.

private void analyseTarget(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt, String tv, TargetWriter tw, List<StructureDefinition> profiles, String sliceName) throws FHIRException {
    VariableForProfiling var = null;
    if (tgt.hasContext()) {
        var = vars.get(VariableMode.OUTPUT, tgt.getContext());
        if (var == null)
            throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
        if (!tgt.hasElement())
            throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
    }
    TypeDetails type = null;
    if (tgt.hasTransform()) {
        type = analyseTransform(context, map, tgt, var, vars);
    } else {
        Property vp = var.getProperty().getBaseProperty().getChild(tgt.getElement(), tgt.getElement());
        if (vp == null)
            throw new FHIRException("Unknown Property " + tgt.getElement() + " on " + var.getProperty().getPath());
        type = new TypeDetails(CollectionStatus.SINGLETON, vp.getType(tgt.getElement()));
    }
    if (tgt.getTransform() == StructureMapTransform.CREATE) {
        String s = getParamString(vars, tgt.getParameter().get(0));
        if (worker.getResourceNames().contains(s))
            tw.newResource(tgt.getVariable(), s);
    } else {
        boolean mapsSrc = false;
        for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) {
            DataType pr = p.getValue();
            if (pr instanceof IdType && ((IdType) pr).asStringValue().equals(tv))
                mapsSrc = true;
        }
        if (mapsSrc) {
            if (var == null)
                throw new Error("Rule \"" + ruleId + "\": Attempt to assign with no context");
            tw.valueAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + getTransformSuffix(tgt.getTransform()));
        } else if (tgt.hasContext()) {
            if (isSignificantElement(var.getProperty(), tgt.getElement())) {
                String td = describeTransform(tgt);
                if (td != null)
                    tw.keyAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + " = " + td);
            }
        }
    }
    DataType fixed = generateFixedValue(tgt);
    PropertyWithType prop = updateProfile(var, tgt.getElement(), type, map, profiles, sliceName, fixed, tgt);
    if (tgt.hasVariable())
        if (tgt.hasElement())
            vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
        else
            vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r4b.elementmodel.Property)

Example 84 with DataType

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

the class StructureMapUtilities method getParam.

private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    DataType p = parameter.getValue();
    if (!(p instanceof IdType))
        return new TypeDetails(CollectionStatus.SINGLETON, ProfileUtilities.sdNs(p.fhirType(), worker.getOverrideVersionNs()));
    else {
        String n = ((IdType) p).asStringValue();
        VariableForProfiling b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b.getProperty().getTypes();
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 85 with DataType

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

the class StructureMapUtilities method updateProfile.

private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, DataType fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
    if (var == null) {
        assert (Utilities.noString(element));
        // 1. start the new structure definition
        StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType());
        if (sdn == null)
            throw new FHIRException("Unable to find definition for " + type.getType());
        ElementDefinition edn = sdn.getSnapshot().getElementFirstRep();
        PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt);
        return pn;
    } else {
        assert (!Utilities.noString(element));
        Property pvb = var.getProperty().getBaseProperty();
        Property pvd = var.getProperty().getProfileProperty();
        Property pc = pvb.getChild(element, var.getProperty().getTypes());
        if (pc == null)
            throw new DefinitionException("Unable to find a definition for " + pvb.getDefinition().getPath() + "." + element);
        // the profile structure definition (derived)
        StructureDefinition sd = var.getProperty().getProfileProperty().getStructure();
        ElementDefinition ednew = sd.getDifferential().addElement();
        ednew.setPath(var.getProperty().getProfileProperty().getDefinition().getPath() + "." + pc.getName());
        ednew.setUserData("slice-name", sliceName);
        ednew.setFixed(fixed);
        for (ProfiledType pt : type.getProfiledTypes()) {
            if (pt.hasBindings())
                ednew.setBinding(pt.getBindings().get(0));
            if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = pt.getUri().substring(40);
                t = checkType(t, pc, pt.getProfiles());
                if (t != null) {
                    if (pt.hasProfiles()) {
                        for (String p : pt.getProfiles()) if (t.equals("Reference"))
                            ednew.getType(t).addTargetProfile(p);
                        else
                            ednew.getType(t).addProfile(p);
                    } else
                        ednew.getType(t);
                }
            }
        }
        return new PropertyWithType(var.getProperty().getPath() + "." + element, pc, new Property(worker, ednew, sd), type);
    }
}
Also used : ProfiledType(org.hl7.fhir.r4b.model.TypeDetails.ProfiledType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r4b.elementmodel.Property)

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