Search in sources :

Example 26 with ElementDefinition

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

the class ExtensionDefinitionValidator method checkNoValueAndExtensions.

private void checkNoValueAndExtensions(StructureDefinition sd) throws FHIRException {
    boolean hasValue = false;
    for (ElementDefinition ed : sd.getSnapshot().getElement()) {
        if (ed.getPath().startsWith("Extension.value")) {
            if (!ed.getMax().equals("0")) {
                hasValue = true;
            }
        }
    }
    if (hasValue) {
        for (ElementDefinition ed : sd.getSnapshot().getElement()) {
            if (ed.getPath().equals("Extension.extension")) {
                ed.setMax("0");
            }
            if (ed.getPath().startsWith("Extension.extension.")) {
                throw new FHIRException("The extension " + sd.getUrl() + " has both value and extensions");
            }
        }
        boolean found = false;
        int ip = 0;
        for (ElementDefinition ed : sd.getDifferential().getElement()) {
            if (ed.getPath().equals("Extension.extension")) {
                ed.setMax("0");
                found = true;
            }
            if (ed.getPath().equals("Extension") || ed.getPath().equals("Extension.id"))
                ip++;
        }
        if (!found) {
            ElementDefinition ed = new ElementDefinition();
            ed.setPath("Extension.extension");
            ed.setMax("0");
            sd.getDifferential().getElement().add(ip, ed);
        }
    }
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 27 with ElementDefinition

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

the class ResourceParser method parseBinding.

public BindingSpecification parseBinding(ElementDefinitionBindingComponent binding) throws IOException {
    BindingSpecification bs = new BindingSpecification("core", binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName"), "true".equals(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding")));
    bs.setStrength(binding.getStrength());
    bs.setBindingMethod(BindingMethod.ValueSet);
    bs.setDescription(binding.getDescription());
    bs.setReference(binding.getValueSet());
    if (bs.hasReference()) {
        bs.setValueSet(loadValueSet(bs.getReference(), false));
    }
    if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")) {
        bs.setMaxReference(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"));
        bs.setMaxValueSet(loadValueSet(bs.getMaxReference(), false));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V2_MAP)) {
        bs.setV2Map(binding.getExtensionString(BuildExtensions.EXT_V2_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V3_MAP)) {
        bs.setV3Map(binding.getExtensionString(BuildExtensions.EXT_V3_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_DEFINITION)) {
        bs.setDefinition(binding.getExtensionString(BuildExtensions.EXT_DEFINITION));
    }
    if (binding.hasExtension(BuildExtensions.EXT_URI)) {
        bs.setUri(binding.getExtensionString(BuildExtensions.EXT_URI));
    }
    if (binding.hasExtension(BuildExtensions.EXT_WEBSITE)) {
        bs.setWebSite(binding.getExtensionString(BuildExtensions.EXT_WEBSITE));
    }
    if (binding.hasExtension(BuildExtensions.EXT_EMAIL)) {
        bs.setEmail(binding.getExtensionString(BuildExtensions.EXT_EMAIL));
    }
    if (binding.hasExtension(BuildExtensions.EXT_COPYRIGHT)) {
        bs.setCopyright(binding.getExtensionString(BuildExtensions.EXT_COPYRIGHT));
    }
    if (binding.hasExtension(BuildExtensions.EXT_CS_OID)) {
        bs.setCsOid(binding.getExtensionString(BuildExtensions.EXT_CS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_VS_OID)) {
        bs.setVsOid(binding.getExtensionString(BuildExtensions.EXT_VS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_STATUS)) {
        bs.setStatus(PublicationStatus.fromCode(binding.getExtensionString(BuildExtensions.EXT_STATUS)));
    }
    return bs;
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 28 with ElementDefinition

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

the class ResourceParser method parseED.

private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
    ed.setMinCardinality(focus.getMin());
    ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
    ed.setIsModifier(focus.getIsModifier());
    ed.setModifierReason(focus.getIsModifierReason());
    ed.setMustSupport(focus.getMustSupport());
    ed.setSummaryItem(focus.getIsSummary());
    ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
    ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
        ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
    }
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
        ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
        String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
        if (svg.contains("w=")) {
            ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
            svg = svg.substring(0, svg.indexOf(";"));
        }
        ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
        ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
    }
    ed.setName(tail(focus.getPath()));
    ed.setShortDefn(focus.getShort());
    ed.setDefinition(focus.getDefinition());
    ed.setRequirements(focus.getRequirements());
    ed.setComments(focus.getComment());
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
        ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
        ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
        ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
    }
    if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
        ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
    }
    for (StringType t : focus.getAlias()) {
        ed.getAliases().add(t.getValue());
    }
    if (focus.hasMaxLength()) {
        ed.setMaxLength(Integer.toString(focus.getMaxLength()));
    }
    ed.setExample(focus.getExampleFirstRep().getValue());
    ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
        ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
    }
    ed.setOrderMeaning(focus.getOrderMeaning());
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
        ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
        ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
    }
    for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
        Invariant inv = new Invariant();
        inv.setContext(focus.getPath());
        inv.setEnglish(cst.getHuman());
        if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
            inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
        }
        inv.setXpath(cst.getXpath());
        inv.setId(cst.getKey());
        if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
            inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
        }
        inv.setSeverity(cst.getSeverity().toCode());
        if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
            inv.setSeverity("best-practice");
        }
        if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
            inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
        }
        inv.setRequirements(cst.getRequirements());
        inv.setExpression(cst.getExpression());
        if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
            inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
        }
        ed.getInvariants().put(inv.getId(), inv);
        invariants.put(inv.getId(), inv);
    }
    for (IdType cnd : focus.getCondition()) {
        Invariant inv = invariants.get(cnd.primitiveValue());
        if (inv == null) {
            System.out.println("Unable to find invariant " + cnd.primitiveValue());
        } else {
            ed.getStatedInvariants().add(inv);
        }
    }
    for (ElementDefinitionMappingComponent map : focus.getMapping()) {
        String uri = getMappingUri(sd, map.getIdentity());
        if ("http://hl7.org/fhir/fivews".equals(uri)) {
            ed.setW5(reverseW5(map.getMap()));
        } else {
            ed.getMappings().put(uri, map.getMap());
        }
    }
    if (focus.hasContentReference()) {
        ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
    } else {
        for (TypeRefComponent tr : focus.getType()) {
            if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
                TypeRef t = new TypeRef();
                ed.getTypes().add(t);
                if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
                    t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
                } else {
                    t.setName(tr.getCode());
                }
                if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
                    ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
                }
                for (CanonicalType u : tr.getProfile()) {
                    t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
                }
                for (CanonicalType u : tr.getTargetProfile()) {
                    String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
                    if ("Resource".equals(s)) {
                        t.getParams().add("Any");
                    } else {
                        t.getParams().add(s);
                    }
                }
                if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
                    t.setName("SimpleQuantity");
                    t.setProfile(null);
                }
                if ("Resource".equals(t.getProfile())) {
                    t.setProfile("Any");
                }
                if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
                    t.getParams().clear();
                    t.getParams().add("Definition");
                }
            }
        }
        if (ed.getTypes().size() == STAR_TYPES_COUNT) {
            ed.getTypes().clear();
            ed.getTypes().add(new TypeRef("*"));
        }
    }
    String name = parentName + Utilities.capitalize(ed.getName());
    if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
        ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
        ed.setDeclaredTypeName(ed.getStatedType());
    } else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
        ed.setDeclaredTypeName(name + "Component");
    }
    if (focus.hasBinding()) {
        ed.setBinding(parseBinding(focus.getBinding()));
    }
    for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
        ElementDefn c = new ElementDefn();
        ed.getElements().add(c);
        parseED(pu, c, child, sd, name);
    }
// todo:
// private ElementDefinition derivation;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) StringType(org.hl7.fhir.r5.model.StringType) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) IdType(org.hl7.fhir.r5.model.IdType)

Example 29 with ElementDefinition

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

the class ResourceParser method parseBinding.

private BindingSpecification parseBinding(OperationDefinitionParameterBindingComponent binding) throws IOException {
    BindingSpecification bs = new BindingSpecification("core", binding.getExtensionString(BuildExtensions.EXT_BINDING_NAME), "true".equals(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding")));
    bs.setStrength(binding.getStrength());
    bs.setBindingMethod(BindingMethod.ValueSet);
    bs.setReference(binding.getValueSet());
    if (bs.hasReference()) {
        bs.setValueSet(loadValueSet(bs.getReference(), false));
    }
    if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet")) {
        bs.setMaxReference(binding.getExtensionString("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"));
        bs.setMaxValueSet(loadValueSet(bs.getMaxReference(), false));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V2_MAP)) {
        bs.setV2Map(binding.getExtensionString(BuildExtensions.EXT_V2_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_V3_MAP)) {
        bs.setV3Map(binding.getExtensionString(BuildExtensions.EXT_V3_MAP));
    }
    if (binding.hasExtension(BuildExtensions.EXT_DEFINITION)) {
        bs.setDefinition(binding.getExtensionString(BuildExtensions.EXT_DEFINITION));
    }
    if (binding.hasExtension(BuildExtensions.EXT_URI)) {
        bs.setUri(binding.getExtensionString(BuildExtensions.EXT_URI));
    }
    if (binding.hasExtension(BuildExtensions.EXT_WEBSITE)) {
        bs.setWebSite(binding.getExtensionString(BuildExtensions.EXT_WEBSITE));
    }
    if (binding.hasExtension(BuildExtensions.EXT_EMAIL)) {
        bs.setEmail(binding.getExtensionString(BuildExtensions.EXT_EMAIL));
    }
    if (binding.hasExtension(BuildExtensions.EXT_COPYRIGHT)) {
        bs.setCopyright(binding.getExtensionString(BuildExtensions.EXT_COPYRIGHT));
    }
    if (binding.hasExtension(BuildExtensions.EXT_CS_OID)) {
        bs.setCsOid(binding.getExtensionString(BuildExtensions.EXT_CS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_VS_OID)) {
        bs.setVsOid(binding.getExtensionString(BuildExtensions.EXT_VS_OID));
    }
    if (binding.hasExtension(BuildExtensions.EXT_STATUS)) {
        bs.setStatus(PublicationStatus.fromCode(binding.getExtensionString(BuildExtensions.EXT_STATUS)));
    }
    return bs;
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 30 with ElementDefinition

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

the class ResourceParser method parseTypeDefinition.

private TypeDefn parseTypeDefinition(ProfileUtilities pu, ElementDefinition focus, StructureDefinition sd) throws IOException {
    TypeDefn ed = new TypeDefn();
    parseED(pu, ed, focus, sd, "");
    return ed;
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37