Search in sources :

Example 11 with TypeRefComponent

use of org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent in project kindling by HL7.

the class DictHTMLGenerator method describeTypes.

private String describeTypes(List<TypeRefComponent> types) throws Exception {
    if (types.isEmpty())
        return "";
    StringBuilder b = new StringBuilder();
    if (types.size() == 1)
        describeType(b, types.get(0));
    else {
        boolean first = true;
        b.append("Choice of: ");
        for (TypeRefComponent t : types) {
            if (first)
                first = false;
            else
                b.append(", ");
            describeType(b, t);
        }
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)

Example 12 with TypeRefComponent

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

the class SpecDifferenceEvaluator method analyseTypes.

private void analyseTypes(JsonObject element, ElementDefinition rev, ElementDefinition orig) {
    JsonArray oa = new JsonArray();
    JsonArray ra = new JsonArray();
    if (rev.getType().size() == 1 && orig.getType().size() == 1) {
        String r = describeType(rev.getType().get(0));
        if (Utilities.noString(r) && Utilities.existsInList(rev.getId(), "Element.id", "Extension.url"))
            r = "string";
        String o = describeType(orig.getType().get(0));
        if (Utilities.noString(o) && Utilities.existsInList(orig.getId(), "Element.id", "Extension.url"))
            o = "string";
        if (!o.equals(r)) {
            oa.add(new JsonPrimitive(o));
            ra.add(new JsonPrimitive(r));
        }
    } else {
        for (TypeRefComponent tr : orig.getType()) {
            if (!hasType(rev.getType(), tr))
                oa.add(new JsonPrimitive(describeType(tr)));
        }
        for (TypeRefComponent tr : rev.getType()) {
            if (!hasType(orig.getType(), tr) && !isAbstractType(tr.getWorkingCode()))
                ra.add(new JsonPrimitive(describeType(tr)));
        }
        for (TypeRefComponent tr : rev.getType()) {
            TypeRefComponent tm = getType(rev.getType(), tr);
            if (tm != null) {
                compareParameters(element, tr, tm);
            }
        }
    }
    if (oa.size() > 0)
        element.add("removed-types", oa);
    if (ra.size() > 0)
        element.add("added-types", ra);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)

Example 13 with TypeRefComponent

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

the class SpecDifferenceEvaluator method hasType.

private boolean hasType(List<TypeRefComponent> types, TypeRefComponent tr) {
    for (TypeRefComponent t : types) {
        if (t.getWorkingCode().equals(tr.getWorkingCode())) {
            if ((!t.hasProfile() && !tr.hasProfile())) {
                return true;
            }
            boolean found = true;
            for (CanonicalType t1 : tr.getProfile()) {
                boolean ok = false;
                for (CanonicalType t2 : t.getProfile()) {
                    ok = ok || t2.getValue().equals(t1.getValue());
                }
                found = found && ok;
            }
            return found;
        }
    }
    return false;
}
Also used : TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)

Example 14 with TypeRefComponent

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

the class DefinitionNavigator method loadTypedChildren.

private void loadTypedChildren(TypeRefComponent type) throws DefinitionException {
    typeOfChildren = null;
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, type.hasProfile() ? type.getProfile().get(0).getValue() : type.getCode());
    if (sd != null) {
        DefinitionNavigator dn = new DefinitionNavigator(context, sd, 0, path, names, sd.getConstrainedType());
        typeChildren = dn.children();
    } else
        throw new DefinitionException("Unable to find definition for " + type.getCode() + (type.hasProfile() ? "(" + type.getProfile() + ")" : ""));
    typeOfChildren = type;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 15 with TypeRefComponent

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

the class FHIRPathEngine method getChildTypesByName.

private void getChildTypesByName(String type, String name, TypeDetails result) throws PathEngineException, DefinitionException {
    if (Utilities.noString(type))
        throw new PathEngineException("No type provided in BuildToolPathEvaluator.getChildTypesByName");
    if (type.equals("xhtml"))
        return;
    String url = null;
    if (type.contains(".")) {
        url = "http://hl7.org/fhir/StructureDefinition/" + type.substring(0, type.indexOf("."));
    } else {
        url = "http://hl7.org/fhir/StructureDefinition/" + type;
    }
    String tail = "";
    StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
    if (sd == null)
        // this really is an error, because we can only get to here if the internal infrastrucgture is wrong
        throw new DefinitionException("Unknown type " + type);
    List<StructureDefinition> sdl = new ArrayList<StructureDefinition>();
    ElementDefinitionMatch m = null;
    if (type.contains("."))
        m = getElementDefinition(sd, type, false);
    if (m != null && hasDataType(m.definition)) {
        if (m.fixedType != null) {
            StructureDefinition dt = worker.fetchTypeDefinition(m.fixedType);
            if (dt == null)
                throw new DefinitionException("unknown data type " + m.fixedType);
            sdl.add(dt);
        } else
            for (TypeRefComponent t : m.definition.getType()) {
                StructureDefinition dt = worker.fetchTypeDefinition(t.getCode());
                if (dt == null)
                    throw new DefinitionException("unknown data type " + t.getCode());
                sdl.add(dt);
            }
    } else {
        sdl.add(sd);
        if (type.contains("."))
            tail = type.substring(type.indexOf("."));
    }
    for (StructureDefinition sdi : sdl) {
        String path = sdi.getSnapshot().getElement().get(0).getPath() + tail + ".";
        if (name.equals("**")) {
            assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
            for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
                if (ed.getPath().startsWith(path))
                    for (TypeRefComponent t : ed.getType()) {
                        if (t.hasCode() && t.getCodeElement().hasValue()) {
                            String tn = null;
                            if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                                tn = ed.getPath();
                            else
                                tn = t.getCode();
                            if (t.getCode().equals("Resource")) {
                                for (String rn : worker.getResourceNames()) {
                                    if (!result.hasType(worker, rn)) {
                                        result.addType(rn);
                                        getChildTypesByName(rn, "**", result);
                                    }
                                }
                            } else if (!result.hasType(worker, tn)) {
                                result.addType(tn);
                                getChildTypesByName(tn, "**", result);
                            }
                        }
                    }
            }
        } else if (name.equals("*")) {
            assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
            for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
                if (ed.getPath().startsWith(path) && !ed.getPath().substring(path.length()).contains("."))
                    for (TypeRefComponent t : ed.getType()) {
                        if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                            result.addType(ed.getPath());
                        else if (t.getCode().equals("Resource"))
                            result.addTypes(worker.getResourceNames());
                        else
                            result.addType(t.getCode());
                    }
            }
        } else {
            path = sdi.getSnapshot().getElement().get(0).getPath() + tail + "." + name;
            ElementDefinitionMatch ed = getElementDefinition(sdi, path, false);
            if (ed != null) {
                if (!Utilities.noString(ed.getFixedType()))
                    result.addType(ed.getFixedType());
                else
                    for (TypeRefComponent t : ed.getDefinition().getType()) {
                        if (Utilities.noString(t.getCode()))
                            // throw new PathEngineException("Illegal reference to primitive value attribute @ "+path);
                            break;
                        if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                            result.addType(path);
                        else if (t.getCode().equals("Resource"))
                            result.addTypes(worker.getResourceNames());
                        else
                            result.addType(t.getCode());
                    }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) PathEngineException(org.hl7.fhir.exceptions.PathEngineException)

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