Search in sources :

Example 51 with TypeDetails

use of org.hl7.fhir.r4.model.TypeDetails 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 52 with TypeDetails

use of org.hl7.fhir.r4.model.TypeDetails 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)

Example 53 with TypeDetails

use of org.hl7.fhir.r4.model.TypeDetails in project org.hl7.fhir.core by hapifhir.

the class Property method getChildProperties.

protected List<Property> getChildProperties(TypeDetails type) throws DefinitionException {
    ElementDefinition ed = definition;
    StructureDefinition sd = structure;
    List<ElementDefinition> children = profileUtilities.getChildMap(sd, ed);
    if (children.isEmpty()) {
        // ok, find the right definitions
        String t = null;
        if (ed.getType().size() == 1)
            t = ed.getType().get(0).getCode();
        else if (ed.getType().size() == 0)
            throw new Error("types == 0, and no children found");
        else {
            t = ed.getType().get(0).getCode();
            boolean all = true;
            for (TypeRefComponent tr : ed.getType()) {
                if (!tr.getCode().equals(t)) {
                    all = false;
                    break;
                }
            }
            if (!all) {
                // ok, it's polymorphic
                t = type.getType();
            }
        }
        if (!"xhtml".equals(t)) {
            sd = context.fetchResource(StructureDefinition.class, t);
            if (sd == null)
                throw new DefinitionException("Unable to find class '" + t + "' for name '" + ed.getPath() + "' on property " + definition.getPath());
            children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
        }
    }
    List<Property> properties = new ArrayList<Property>();
    for (ElementDefinition child : children) {
        properties.add(new Property(context, child, sd, this.profileUtilities));
    }
    return properties;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)18 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)18 FHIRException (org.hl7.fhir.exceptions.FHIRException)16 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 ArrayList (java.util.ArrayList)9 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)6 ProfiledType (org.hl7.fhir.r4.model.TypeDetails.ProfiledType)6 TypeDetails (org.hl7.fhir.dstu2016may.model.ExpressionNode.TypeDetails)5 TypeDetails (org.hl7.fhir.dstu2.model.ExpressionNode.TypeDetails)4 TypeDetails (org.hl7.fhir.dstu3.model.TypeDetails)4 TypeDetails (org.hl7.fhir.r4.model.TypeDetails)4 TypeDetails (org.hl7.fhir.r5.model.TypeDetails)4 NodeType (org.hl7.fhir.utilities.xhtml.NodeType)4 Property (org.hl7.fhir.dstu3.elementmodel.Property)3 TypeRefComponent (org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent)3 Property (org.hl7.fhir.r4b.elementmodel.Property)3 TypeRefComponent (org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent)3 TypeDetails (org.hl7.fhir.r4b.model.TypeDetails)3 ProfiledType (org.hl7.fhir.r4b.model.TypeDetails.ProfiledType)3 Property (org.hl7.fhir.r5.elementmodel.Property)3