Search in sources :

Example 6 with ElementDefinitionBindingComponent

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

the class ProfileGenerator method generateBinding.

private ElementDefinitionBindingComponent generateBinding(BindingSpecification src) throws Exception {
    if (src == null)
        return null;
    ElementDefinitionBindingComponent dst = new ElementDefinitionBindingComponent();
    dst.setDescription(src.getDescription());
    if (!Utilities.noString(src.getDefinition())) {
        dst.addExtension().setUrl(BuildExtensions.EXT_DEFINITION).setValue(new StringType(src.getDefinition()));
    }
    if (src.getBinding() != BindingMethod.Unbound) {
        dst.setStrength(src.getStrength());
        dst.setValueSet(buildValueSetReference(src));
        if (src.hasMax()) {
            dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet").setValue(new CanonicalType(src.getMaxReference() != null ? src.getMaxReference() : src.getMaxValueSet().getUrl()));
        }
    } else {
        dst.setStrength(BindingStrength.EXAMPLE);
    }
    dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName").setValue(new StringType(src.getName()));
    if (src.isShared())
        dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding").setValue(new BooleanType(true));
    return dst;
}
Also used : StringType(org.hl7.fhir.r5.model.StringType) BooleanType(org.hl7.fhir.r5.model.BooleanType) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 7 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class SpecDifferenceEvaluator method compareBindings.

private boolean compareBindings(JsonObject element, ElementDefinitionBindingComponent rev, ElementDefinitionBindingComponent orig) {
    boolean res = false;
    if (rev.getStrength() != orig.getStrength()) {
        element.addProperty("binding-strength-changed", true);
        res = true;
    }
    if (!Base.compareDeep(rev.getValueSet(), orig.getValueSet(), false)) {
        element.addProperty("binding-valueset-changed", true);
        res = true;
    }
    if (!maxValueSetsMatch(rev, orig)) {
        element.addProperty("max-valueset-changed", true);
        res = true;
    }
    if (rev.getStrength() == BindingStrength.REQUIRED && orig.getStrength() == BindingStrength.REQUIRED) {
        JsonArray oa = new JsonArray();
        JsonArray ra = new JsonArray();
        ValueSet vrev = getValueSet(rev.getValueSet(), revision.getExpansions());
        ValueSet vorig = getValueSet(rev.getValueSet(), original.getExpansions());
        if (vrev != null && vorig != null) {
            for (ValueSetExpansionContainsComponent cc : vorig.getExpansion().getContains()) {
                if (!hasCode(vrev, cc))
                    oa.add(new JsonPrimitive(cc.getCode()));
            }
            for (ValueSetExpansionContainsComponent cc : vrev.getExpansion().getContains()) {
                if (!hasCode(vorig, cc))
                    ra.add(new JsonPrimitive(cc.getCode()));
            }
        }
        if (oa.size() > 0 || ra.size() > 0) {
            element.addProperty("binding-codes-changed", true);
            res = true;
        }
        if (oa.size() > 0)
            element.add("removed-codes", oa);
        if (ra.size() > 0)
            element.add("added-codes", ra);
    }
    return res;
}
Also used : JsonArray(com.google.gson.JsonArray) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) JsonPrimitive(com.google.gson.JsonPrimitive)

Example 8 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method generateGridDescription.

private Cell generateGridDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, ElementDefinition valueDefn) throws IOException {
    Cell c = gen.new Cell();
    row.getCells().add(c);
    if (used) {
        if (definition.hasContentReference()) {
            ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
            if (ed == null)
                c.getPieces().add(gen.new Piece(null, "Unknown reference to " + definition.getContentReference(), null));
            else
                c.getPieces().add(gen.new Piece("#" + ed.getPath(), "See " + ed.getPath(), null));
        }
        if (definition.getPath().endsWith("url") && definition.hasFixed()) {
            c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
        } else {
            if (url != null) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                String fullUrl = url.startsWith("#") ? baseURL + url : url;
                StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
                String ref = null;
                if (ed != null) {
                    String p = ed.getUserString("path");
                    if (p != null) {
                        ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
                    }
                }
                c.getPieces().add(gen.new Piece(null, "URL: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(ref, fullUrl, null));
            }
            if (definition.hasSlicing()) {
                if (!c.getPieces().isEmpty())
                    c.addPiece(gen.new Piece("br"));
                c.getPieces().add(gen.new Piece(null, "Slice: ", null).addStyle("font-weight:bold"));
                c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
            }
            if (definition != null) {
                ElementDefinitionBindingComponent binding = null;
                if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
                    binding = valueDefn.getBinding();
                else if (definition.hasBinding())
                    binding = definition.getBinding();
                if (binding != null && !binding.isEmpty()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    BindingResolution br = pkp.resolveBinding(profile, binding, definition.getPath());
                    c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, "Binding: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
                    if (binding.hasStrength()) {
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, " (", null)));
                        c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), binding.getStrength().toCode(), binding.getStrength().getDefinition())));
                        c.getPieces().add(gen.new Piece(null, ")", null));
                    }
                }
                for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getHuman(), null)));
                }
                if (definition.hasFixed()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, buildJson(definition.getFixed()), null).addStyle("color: darkgreen")));
                } else if (definition.hasPattern()) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "Required Pattern: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
                } else if (definition.hasExample()) {
                    for (ElementDefinitionExampleComponent ex : definition.getExample()) {
                        if (!c.getPieces().isEmpty())
                            c.addPiece(gen.new Piece("br"));
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, "Example'" + ("".equals("General") ? "" : " " + ex.getLabel() + "'") + ": ", null).addStyle("font-weight:bold")));
                        c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
                    }
                }
                if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
                    c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
                }
                if (profile != null) {
                    for (StructureDefinitionMappingComponent md : profile.getMapping()) {
                        if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
                            ElementDefinitionMappingComponent map = null;
                            for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
                                map = m;
                            if (map != null) {
                                for (int i = 0; i < definition.getMapping().size(); i++) {
                                    c.addPiece(gen.new Piece("br"));
                                    c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
                                }
                            }
                        }
                    }
                }
                if (definition.getComment() != null) {
                    if (!c.getPieces().isEmpty())
                        c.addPiece(gen.new Piece("br"));
                    c.getPieces().add(gen.new Piece(null, "Comments: ", null).addStyle("font-weight:bold"));
                    c.addPiece(gen.new Piece("br"));
                    c.addMarkdown(definition.getComment());
                // c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), null)));
                }
            }
        }
    }
    return c;
}
Also used : ElementDefinitionExampleComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionExampleComponent) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) BindingResolution(org.hl7.fhir.dstu3.conformance.ProfileUtilities.ProfileKnowledgeProvider.BindingResolution) StructureDefinitionMappingComponent(org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionMappingComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ElementDefinitionBindingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionBindingComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionMappingComponent)

Example 9 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class Analyser method scanNestedTypes.

private void scanNestedTypes(Analysis analysis, TypeInfo type, String path, ElementDefinition e) throws Exception {
    String tn = null;
    if (e.typeSummary().equals("code") && e.hasBinding()) {
        ElementDefinitionBindingComponent cd = e.getBinding();
        if (isEnum(cd)) {
            ValueSet vs = definitions.getValuesets().get(cd.getValueSet());
            if (vs != null) {
                tn = getCodeListType(vs.getName());
                EnumInfo ei = analysis.getEnums().get(tn);
                if (ei == null) {
                    ei = new EnumInfo(tn);
                    analysis.getEnums().put(tn, ei);
                    ei.setValueSet(vs);
                }
                if (tn.equals("SubscriptionStatus")) {
                    // work around cause there's a Resource with the same name
                    tn = "org.hl7.fhir.r4b.model.Enumerations." + tn;
                }
                e.setUserData("java.type", "Enumeration<" + tn + ">");
                e.setUserData("java.enum", ei);
            }
        }
    }
    if (tn == null) {
        if (e.getType().size() > 0 && !e.hasContentReference() && (!Utilities.existsInList(e.getType().get(0).getCode(), "Element", "BackboneElement"))) {
            tn = getTypeName(e);
            if (e.typeSummary().equals("xml:lang"))
                tn = "CodeType";
            if (e.typeSummary().equals("xhtml"))
                tn = "XhtmlNode";
            else if (e.getType().size() > 1)
                tn = "DataType";
            else if (definitions.hasPrimitiveType(tn))
                tn = upFirst(tn) + "Type";
            e.setUserData("java.type", tn);
        } else {
            if (e.hasContentReference()) {
                ElementDefinition er = getElementForPath(analysis.getStructure(), e.getContentReference().substring(1));
                tn = er.getUserString("java.type");
                if (Utilities.noString(tn)) {
                    // have to resolve this later
                    e.setUserData("java.type", "@" + er.getPath());
                } else {
                    e.setUserData("java.type", tn);
                }
            } else {
                String cpath;
                if (e.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
                    tn = upFirst(e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) + "Component";
                    cpath = e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name");
                } else if (config.getIni().hasProperty("typenames", e.getPath())) {
                    tn = upFirst(config.getIni().getStringProperty("typenames", e.getPath())) + "Component";
                    cpath = config.getIni().getStringProperty("typenames", e.getPath());
                } else {
                    tn = path + upFirst(getTitle(e.getName())) + "Component";
                    cpath = path + getTitle(e.getName());
                }
                if (tn.equals("Element"))
                    tn = "Element_";
                if (analysis.getTypes().containsKey(tn)) {
                    char i = 'A';
                    while (analysis.getTypes().containsKey(tn + i)) {
                        i++;
                    }
                    tn = tn + i;
                }
                e.setUserData("java.type", tn);
                tn = upFirst(tn);
                TypeInfo ctype = new TypeInfo();
                ctype.setName(tn);
                analysis.getTypes().put(ctype.getName(), ctype);
                analysis.getTypeList().add(ctype);
                ctype.setDefn(e);
                ctype.setAncestorName(e.typeSummary());
                ctype.setChildren(filterChildren(new ProfileUtilities(null, null, null).getChildList(analysis.getStructure(), ctype.getDefn())));
                for (ElementDefinition c : ctype.getChildren()) {
                    scanNestedTypes(analysis, ctype, cpath, c);
                }
            }
        }
    }
}
Also used : ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 10 with ElementDefinitionBindingComponent

use of org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent in project org.hl7.fhir.core by hapifhir.

the class ProfileComparer method unionBindings.

private ElementDefinitionBindingComponent unionBindings(ElementDefinition ed, ProfileComparison outcome, String path, ElementDefinitionBindingComponent left, ElementDefinitionBindingComponent right) {
    ElementDefinitionBindingComponent union = new ElementDefinitionBindingComponent();
    if (left.getStrength().compareTo(right.getStrength()) < 0)
        union.setStrength(left.getStrength());
    else
        union.setStrength(right.getStrength());
    union.setDescription(mergeText(ed, outcome, path, "binding.description", left.getDescription(), right.getDescription()));
    if (Base.compareDeep(left.getValueSet(), right.getValueSet(), false))
        union.setValueSet(left.getValueSet());
    else {
        ValueSet lvs = resolveVS(outcome.left, left.getValueSet());
        ValueSet rvs = resolveVS(outcome.left, right.getValueSet());
        if (lvs != null && rvs != null)
            union.setValueSet(new Reference().setReference("#" + addValueSet(unite(ed, outcome, path, lvs, rvs))));
        else if (lvs != null)
            union.setValueSet(new Reference().setReference("#" + addValueSet(lvs)));
        else if (rvs != null)
            union.setValueSet(new Reference().setReference("#" + addValueSet(rvs)));
    }
    return union;
}
Also used : Reference(org.hl7.fhir.dstu2.model.Reference) ElementDefinitionBindingComponent(org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent) ValueSet(org.hl7.fhir.dstu2.model.ValueSet)

Aggregations

ElementDefinitionBindingComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent)18 ValueSet (org.hl7.fhir.r5.model.ValueSet)12 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)8 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)8 IOException (java.io.IOException)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)7 ElementDefinitionBindingComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionBindingComponent)6 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)6 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)6 ElementDefinitionBindingComponent (org.hl7.fhir.dstu3.model.ElementDefinition.ElementDefinitionBindingComponent)4 ElementDefinitionBindingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionBindingComponent)4 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)4 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)4 ArrayList (java.util.ArrayList)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 ValueSet (org.hl7.fhir.r4b.model.ValueSet)3 StringType (org.hl7.fhir.r5.model.StringType)3 ElementDefinitionBindingComponent (org.hl7.fhir.dstu2.model.ElementDefinition.ElementDefinitionBindingComponent)2 Reference (org.hl7.fhir.dstu2.model.Reference)2