Search in sources :

Example 91 with TypeRefComponent

use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method typeCode.

public static String typeCode(List<TypeRefComponent> types) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (TypeRefComponent type : types) {
        if (first)
            first = false;
        else
            b.append(", ");
        b.append(type.getWorkingCode());
        if (type.hasTargetProfile())
            b.append("{" + type.getTargetProfile() + "}");
        else if (type.hasProfile())
            b.append("{" + type.getProfile() + "}");
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent)

Example 92 with TypeRefComponent

use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genTargetLink.

public void genTargetLink(HierarchicalTableGenerator gen, String profileBaseFileName, String corePath, Cell c, TypeRefComponent t, String u) {
    if (u.startsWith("http://hl7.org/fhir/StructureDefinition/")) {
        StructureDefinition sd = context.fetchResource(StructureDefinition.class, u);
        if (sd != null) {
            String disp = sd.hasTitle() ? sd.getTitle() : sd.getName();
            c.addPiece(checkForNoChange(t, gen.new Piece(checkPrepend(corePath, sd.getUserString("path")), disp, null)));
        } else {
            String rn = u.substring(40);
            c.addPiece(checkForNoChange(t, gen.new Piece(pkp.getLinkFor(corePath, rn), rn, null)));
        }
    } else if (Utilities.isAbsoluteUrl(u)) {
        StructureDefinition sd = context.fetchResource(StructureDefinition.class, u);
        if (sd != null) {
            String disp = sd.hasTitle() ? sd.getTitle() : sd.getName();
            String ref = pkp.getLinkForProfile(null, sd.getUrl());
            if (ref.contains("|"))
                ref = ref.substring(0, ref.indexOf("|"));
            c.addPiece(checkForNoChange(t, gen.new Piece(ref, disp, null)));
        } else
            c.addPiece(checkForNoChange(t, gen.new Piece(null, u, null)));
    } else if (t.hasTargetProfile() && u.startsWith("#"))
        c.addPiece(checkForNoChange(t, gen.new Piece(corePath + profileBaseFileName + "." + u.substring(1).toLowerCase() + ".html", u, null)));
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)

Example 93 with TypeRefComponent

use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent 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));
    }
    return properties;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 94 with TypeRefComponent

use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.

the class Property method getType.

public String getType(String elementName) {
    if (!definition.getPath().contains("."))
        return definition.getPath();
    ElementDefinition ed = definition;
    if (definition.hasContentReference()) {
        if (!definition.getContentReference().startsWith("#"))
            throw new Error("not handled yet");
        boolean found = false;
        for (ElementDefinition d : structure.getSnapshot().getElement()) {
            if (d.hasId() && d.getId().equals(definition.getContentReference().substring(1))) {
                found = true;
                ed = d;
            }
        }
        if (!found)
            throw new Error("Unable to resolve " + definition.getContentReference() + " at " + definition.getPath() + " on " + structure.getUrl());
    }
    if (ed.getType().size() == 0)
        return null;
    else if (ed.getType().size() > 1) {
        String t = ed.getType().get(0).getCode();
        boolean all = true;
        for (TypeRefComponent tr : ed.getType()) {
            if (!t.equals(tr.getCode()))
                all = false;
        }
        if (all)
            return t;
        String tail = ed.getPath().substring(ed.getPath().lastIndexOf(".") + 1);
        if (tail.endsWith("[x]") && elementName != null && elementName.startsWith(tail.substring(0, tail.length() - 3))) {
            String name = elementName.substring(tail.length() - 3);
            return isPrimitive(lowFirst(name)) ? lowFirst(name) : name;
        } else
            throw new Error("logic error, gettype when types > 1, name mismatch for " + elementName + " on at " + ed.getPath());
    } else if (ed.getType().get(0).getCode() == null) {
        if (Utilities.existsInList(ed.getId(), "Element.id", "Extension.url"))
            return "string";
        else
            return structure.getId();
    } else
        return ed.getType().get(0).getWorkingCode();
}
Also used : TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition)

Example 95 with TypeRefComponent

use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project org.hl7.fhir.core by hapifhir.

the class Property method getChildProperties.

protected List<Property> getChildProperties(String elementName, String statedType) throws FHIRException {
    ElementDefinition ed = definition;
    StructureDefinition sd = structure;
    List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, ed);
    String url = null;
    if (children.isEmpty() || isElementWithOnlyExtension(ed, children)) {
        // ok, find the right definitions
        String t = null;
        if (ed.getType().size() == 1)
            t = ed.getType().get(0).getWorkingCode();
        else if (ed.getType().size() == 0)
            throw new Error("types == 0, and no children found on " + getDefinition().getPath());
        else {
            t = ed.getType().get(0).getWorkingCode();
            boolean all = true;
            for (TypeRefComponent tr : ed.getType()) {
                if (!tr.getWorkingCode().equals(t)) {
                    all = false;
                    break;
                }
            }
            if (!all) {
                // ok, it's polymorphic
                if (ed.hasRepresentation(PropertyRepresentation.TYPEATTR)) {
                    t = statedType;
                    if (t == null && ToolingExtensions.hasExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype"))
                        t = ToolingExtensions.readStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype");
                    boolean ok = false;
                    for (TypeRefComponent tr : ed.getType()) {
                        if (tr.getWorkingCode().equals(t))
                            ok = true;
                        if (Utilities.isAbsoluteUrl(tr.getWorkingCode())) {
                            StructureDefinition sdt = context.fetchResource(StructureDefinition.class, tr.getWorkingCode());
                            if (sdt != null && sdt.getType().equals(t)) {
                                url = tr.getWorkingCode();
                                ok = true;
                            }
                        }
                        if (ok)
                            break;
                    }
                    if (!ok)
                        throw new DefinitionException("Type '" + t + "' is not an acceptable type for '" + elementName + "' on property " + definition.getPath());
                } else {
                    t = elementName.substring(tail(ed.getPath()).length() - 3);
                    if (isPrimitive(lowFirst(t)))
                        t = lowFirst(t);
                }
            }
        }
        if (!"xhtml".equals(t)) {
            for (TypeRefComponent aType : ed.getType()) {
                if (aType.getWorkingCode().equals(t)) {
                    if (aType.hasProfile()) {
                        assert aType.getProfile().size() == 1;
                        url = aType.getProfile().get(0).getValue();
                    } else {
                        url = ProfileUtilities.sdNs(t, context.getOverrideVersionNs());
                    }
                    break;
                }
            }
            if (url == null)
                throw new FHIRException("Unable to find type " + t + " for element " + elementName + " with path " + ed.getPath());
            sd = context.fetchResource(StructureDefinition.class, url);
            if (sd == null)
                throw new DefinitionException("Unable to find type '" + t + "' for name '" + elementName + "' 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));
    }
    return properties;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)71 ArrayList (java.util.ArrayList)57 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)47 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)43 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)37 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)31 TypeRefComponent (org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent)30 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 TypeRefComponent (org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent)24 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)24 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)19 HashSet (java.util.HashSet)18 TypeRefComponent (org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent)18 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)18 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)17 UriType (org.hl7.fhir.r5.model.UriType)15 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)14 List (java.util.List)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)12 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)12