Search in sources :

Example 21 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class JsonGenerator method generateElement.

private void generateElement(ElementDefn root, ElementDefn e, Set<String> required, JsonObject props, boolean relative) throws Exception {
    if (e.getTypes().size() > 1 || (e.getTypes().size() == 1 && e.getTypes().get(0).isWildcardType())) {
        if (!e.getName().contains("[x]"))
            throw new Exception("Element " + e.getName() + " in " + root.getName() + " has multiple types as a choice doesn't have a [x] in the element name");
        if (e.getTypes().size() == 1)
            generateAny(root, e, e.getName().replace("[x]", ""), props, relative);
        else {
            for (TypeRef t : e.getTypes()) {
                JsonObject property = new JsonObject();
                JsonObject property_ = null;
                TypeDefn td = null;
                if (definitions.getConstraints().containsKey(t.getName()))
                    td = definitions.getElementDefn(definitions.getConstraints().get(t.getName()).getBaseType());
                else if (definitions.hasElementDefn(t.getName()))
                    td = definitions.getElementDefn(t.getName());
                String en = e.getName().replace("[x]", "");
                props.add(en + upFirst(td == null ? t.getName() : td.getName()), property);
                property.addProperty("description", e.getDefinition());
                String tref = null;
                String type = null;
                String pattern = null;
                if (definitions.getPrimitives().containsKey(t.getName())) {
                    DefinedCode def = definitions.getPrimitives().get(t.getName());
                    type = def.getJsonType();
                    pattern = def.getRegex();
                    if (!Utilities.noString(pattern))
                        property.addProperty("pattern", "^" + pattern + "$");
                    property.addProperty("type", type);
                    property_ = new JsonObject();
                    props.add("_" + en + upFirst(t.getName()), property_);
                    property_.addProperty("description", "Extensions for " + en + upFirst(t.getName()));
                    tref = (relative ? "#" : "Element.schema.json#") + "/definitions/Element";
                    property_.addProperty("$ref", tref);
                } else {
                    String tn = encodeType(e, t, true);
                    tref = (relative ? "#" : tn.replace(".", "_") + ".schema.json#") + "/definitions/" + tn.replace(".", "_");
                    property.addProperty("$ref", tref);
                }
            }
        }
    } else {
        JsonObject property = new JsonObject();
        JsonObject property_ = null;
        props.add(e.getName(), property);
        property.addProperty("description", e.getDefinition());
        String tref = null;
        String type = null;
        String pattern = null;
        if (e.usesCompositeType()) /* && types.containsKey(root.getElementByName(e.typeCode().substring(1)))*/
        {
            ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
            String rtn = types.get(ref);
            if (rtn == null)
                throw new Exception("logic error in schema generator (null composite reference in " + types.toString() + ")");
            if (rtn == "Type")
                rtn = "Element";
            type = rtn;
            tref = "#/definitions/" + rtn.replace(".", "_");
        } else if (e.getTypes().size() == 0 && e.getElements().size() > 0) {
            tref = "#/definitions/" + types.get(e).replace(".", "_");
            type = types.get(e).replace(".", "_");
        } else if (e.getTypes().size() == 1) {
            String tn = encodeType(e, e.getTypes().get(0), true);
            tref = "#/definitions/" + tn;
            if (definitions.getPrimitives().containsKey(e.typeCode())) {
                DefinedCode def = definitions.getPrimitives().get(e.typeCode());
                if (e.getName().equals("id")) {
                    tref = (relative ? "#" : tn.replace(".", "_") + ".schema.json#") + "/definitions/" + tn.replace(".", "_");
                    property.addProperty("$ref", tref);
                } else {
                    property_ = new JsonObject();
                    props.add("_" + e.getName(), property_);
                    property_.addProperty("description", "Extensions for " + e.getName());
                    BindingSpecification cd = e.getBinding();
                    if (cd != null && (cd.getBinding() == BindingSpecification.BindingMethod.CodeList)) {
                        ValueSet vs = cd.getValueSet();
                        if (vs != null) {
                            ValueSet ex = workerContext.expandVS(vs, true, false).getValueset();
                            JsonArray enums = new JsonArray();
                            for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
                                enums.add(new JsonPrimitive(cc.getCode()));
                            }
                            property.add("enum", enums);
                            pattern = null;
                        }
                    } else {
                        property.addProperty("$ref", tref);
                    }
                    tref = (relative ? "#" : "Element.schema.json#") + "/definitions/Element";
                }
            } else {
                tref = (relative ? "#" : tn.replace(".", "_") + ".schema.json#") + "/definitions/" + tn.replace(".", "_");
            }
        } else
            throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(e.getTypes().size()));
        if (property_ != null) {
            if (!Utilities.noString(type))
                property.addProperty("type", type);
            if (!Utilities.noString(pattern))
                property.addProperty("pattern", "^" + pattern + "$");
            if (!Utilities.noString(tref))
                property_.addProperty("$ref", tref);
        } else if ("div".equals(e.getName()) && "xhtml".equals(type)) {
            // Is there a better type, or ref for html?
            property.addProperty("type", "string");
        } else {
            property.addProperty("$ref", tref);
        }
        if (e.unbounded()) {
            makeArray(property);
            if (property_ != null)
                makeArray(property_);
        }
        if (e.getMinCardinality() > 0 && property_ == null)
            required.add(e.getName());
    }
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) JsonArray(com.google.gson.JsonArray) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) JsonPrimitive(com.google.gson.JsonPrimitive) TypeRef(org.hl7.fhir.definitions.model.TypeRef) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) JsonObject(com.google.gson.JsonObject) ValueSet(org.hl7.fhir.r5.model.ValueSet) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 22 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class TableGenerator method genElement.

protected Row genElement(ElementDefn e, HierarchicalTableGenerator gen, boolean resource, String path, boolean isProfile, String prefix, RenderMode mode, boolean isRoot, StandardsStatus rootStatus, boolean isAbstract, boolean isInterface) throws Exception {
    Row row = gen.new Row();
    row.setAnchor(path);
    boolean isProfiledExtension = isProfile && (e.getName().equals("extension") || e.getName().equals("modifierExtension"));
    row.getCells().add(gen.new Cell(null, dictLinks() ? pageName + "#" + path.replace("[", "_").replace("]", "_") : null, e.getName(), path + " : " + e.getDefinition(), null));
    Cell gc = gen.new Cell();
    row.getCells().add(gc);
    if (e.hasMustSupport() && e.isMustSupport()) {
        gc.addStyledText("This element must be supported", "S", "white", "red", prefix + "conformance-rules.html#mustSupport", false);
    }
    if (e.isModifier()) {
        gc.addStyledText("This element is a modifier element", "?!", null, null, prefix + "conformance-rules.html#isModifier", false);
    }
    if (e.isSummary()) {
        gc.addStyledText("This element is included in summaries", "\u03A3", null, null, prefix + "elementdefinition-definitions.html#ElementDefinition.isSummary", false);
    }
    if (!isRoot && (!e.getInvariants().isEmpty() || !e.getStatedInvariants().isEmpty())) {
        gc.addStyledText("This element has or is affected by some invariants", "I", null, null, prefix + "conformance-rules.html#constraints", false);
    }
    if (isInterface) {
        gc.addStyledText("This is an abstract type", "«A»", null, null, prefix + "uml.html#abstract", false);
    } else if (isAbstract) {
        gc.addStyledText("This is an interface resource", "«I»", null, null, prefix + "uml.html#interface", false);
    }
    if (rootStatus != null)
        gc.addStyledText("Standards Status = " + rootStatus.toDisplay(), rootStatus.getAbbrev(), "black", rootStatus.getColor(), prefix + "versions.html#std-process", true);
    else if (e.getStandardsStatus() != null)
        gc.addStyledText("Standards Status = " + e.getStandardsStatus().toDisplay(), e.getStandardsStatus().getAbbrev(), "black", e.getStandardsStatus().getColor(), prefix + "versions.html#std-process", true);
    if (resource) {
        row.getCells().add(gen.new Cell());
        row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
        if (Utilities.noString(e.typeCode()))
            row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
        else if ("Logical".equals(e.typeCode()))
            row.getCells().add(gen.new Cell(null, prefix + "structuredefinition.html#logical", e.typeCode(), null, null));
        else if ("Base".equals(e.typeCode()))
            row.getCells().add(gen.new Cell(null, prefix + definitions.getSrcFile("Base") + ".html#" + e.typeCode(), e.typeCode(), null, null));
        else
            row.getCells().add(gen.new Cell(null, prefix + e.typeCode().toLowerCase() + ".html", e.typeCode(), null, null));
    // todo: base elements
    } else {
        if (!e.getElements().isEmpty()) {
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
            if (mode == RenderMode.RESOURCE)
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "BackboneElement", null, null));
            else if (e.getName().equals("Type"))
                row.getCells().add(gen.new Cell(null, null, "", null, null));
            else if (e.getName().equals("Element")) {
                if (version.isR4B()) {
                    row.getCells().add(gen.new Cell(null, prefix + definitions.getElementLink(), "Element", null, null));
                } else {
                    row.getCells().add(gen.new Cell(null, prefix + definitions.getBaseLink(), "Base", null, null));
                }
            } else if (e.typeCode().equals("BackboneElement"))
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "BackBoneElement", null, null));
            else
                row.getCells().add(gen.new Cell(null, prefix + definitions.getElementLink(), "Element", null, null));
        } else if (e.getTypes().size() == 1) {
            row.getCells().add(gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
            String t = e.getTypes().get(0).getName();
            Cell c;
            if (t.startsWith("@")) {
                row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
                c = gen.new Cell("see ", "#" + t.substring(1), t.substring(t.lastIndexOf(".") + 1), t.substring(1), null);
            } else if (isReference(t)) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                c = gen.new Cell();
                if (ADD_REFERENCE_TO_TABLE) {
                    c.getPieces().add(gen.new Piece(prefix + definitions.getSrcFile(t) + ".html#" + t, t, null));
                    c.getPieces().add(gen.new Piece(null, "(", null));
                }
                boolean first = true;
                for (String rt : e.getTypes().get(0).getParams()) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    if (first && isProfile && e.getTypes().get(0).getProfile() != null)
                        c.getPieces().add(gen.new Piece(null, e.getTypes().get(0).getProfile(), null));
                    else
                        c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                if (ADD_REFERENCE_TO_TABLE)
                    c.getPieces().add(gen.new Piece(null, ")", null));
            } else if (definitions.getPrimitives().containsKey(t)) {
                row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                c = gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null);
            } else {
                if (t.equals("Extension"))
                    row.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION);
                else
                    row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                c = gen.new Cell(null, prefix + definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null);
            }
            row.getCells().add(c);
        } else {
            row.getCells().add(gen.new Cell(null, null, isRoot ? "" : e.describeCardinality(), null, null));
            row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
            row.getCells().add(gen.new Cell(null, null, "", null, null));
        }
    }
    Cell cc = gen.new Cell(null, e.getShortDefn() != null && Utilities.isURL(e.getShortDefn()) ? e.getShortDefn() : null, e.getShortDefn(), null, null);
    row.getCells().add(cc);
    // constraints
    if (isProfiledExtension) {
        cc.addPiece(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(null, e.getTypes().get(0).getProfile(), null));
    }
    if (e.hasBinding() && e.getBinding() != null && e.getBinding().getBinding() != BindingMethod.Unbound) {
        if (cc.getPieces().size() == 1)
            cc.addPiece(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(getBindingLink(prefix, e), e.getBinding().getValueSet() != null ? e.getBinding().getValueSet().present() : e.getBinding().getName(), e.getBinding().getDefinition()));
        cc.getPieces().add(gen.new Piece(null, " (", null));
        BindingSpecification b = e.getBinding();
        if (b.hasMax()) {
            cc.getPieces().add(gen.new Piece(prefix + "terminologies.html#" + b.getStrength().toCode(), b.getStrength().getDisplay(), b.getStrength().getDefinition()));
            cc.getPieces().add(gen.new Piece(null, " but limited to ", null));
            ValueSet vs = b.getMaxValueSet();
            if (vs == null)
                cc.getPieces().add(gen.new Piece(b.getMaxReference(), b.getMaxReference(), null));
            else
                cc.getPieces().add(gen.new Piece(vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path"), vs.getName(), null));
        } else
            cc.getPieces().add(gen.new Piece(prefix + "terminologies.html#" + b.getStrength().toCode(), b.getStrength().getDisplay(), b.getStrength().getDefinition()));
        cc.getPieces().add(gen.new Piece(null, ")", null));
    }
    List<String> invs = new ArrayList<String>(e.getInvariants().keySet());
    Collections.sort(invs, new ConstraintsSorter());
    for (String name : invs) {
        Invariant inv = e.getInvariants().get(name);
        cc.addPiece(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(null, "+ " + presentLevel(inv) + ": " + inv.getEnglish(), inv.getId()).setStyle("font-style: italic"));
    }
    if (e.unbounded() && !isRoot) {
        if (cc.getPieces().size() > 0)
            cc.addPiece(gen.new Piece("br"));
        if (Utilities.noString(e.getOrderMeaning())) {
        // don't show this, this it's important: cc.getPieces().add(gen.new Piece(null, "This repeating element has no defined order", null));
        } else {
            cc.getPieces().add(gen.new Piece(null, "This repeating element order: " + e.getOrderMeaning(), null));
        }
    }
    if (isRoot && !Utilities.noString(e.typeCode()) && !"Logical".equals(e.typeCode())) {
        List<ElementDefn> ancestors = new ArrayList<ElementDefn>();
        ElementDefn f = definitions.getElementDefn(e.typeCode());
        while (f != null) {
            ancestors.add(0, f);
            f = Utilities.noString(f.typeCode()) || "Logical".equals(f.typeCode()) ? null : definitions.getElementDefn(f.typeCode());
        }
        cc.getPieces().add(gen.new Piece("br"));
        cc.getPieces().add(gen.new Piece(null, "Elements defined in Ancestors: ", null));
        boolean first = true;
        for (ElementDefn fi : ancestors) {
            for (ElementDefn fc : fi.getElements()) {
                if (first)
                    first = false;
                else
                    cc.getPieces().add(gen.new Piece(null, ", ", null));
                cc.getPieces().add(gen.new Piece(definitions.getSrcFile(fi.getName()) + ".html#" + fi.getName(), fc.getName(), fc.getDefinition()));
            }
        }
    }
    if (mode == RenderMode.LOGICAL) {
        String logical = e.getMappings().get("http://hl7.org/fhir/logical");
        Cell c = gen.new Cell();
        row.getCells().add(c);
        if (logical != null)
            presentLogicalMapping(gen, c, logical, prefix);
    }
    if (e.getTypes().size() > 1) {
        // create a child for each choice
        for (TypeRef tr : e.getTypes()) {
            Row choicerow = gen.new Row();
            String t = tr.getName();
            if (isReference(t)) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), null, null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                Cell c = gen.new Cell();
                choicerow.getCells().add(c);
                if (ADD_REFERENCE_TO_TABLE) {
                    if (tr.getName().equals("canonical"))
                        c.getPieces().add(gen.new Piece(prefix + "datatypes.html#canonical", "canonical", null));
                    else
                        c.getPieces().add(gen.new Piece(prefix + "references.html#Reference", "Reference", null));
                    c.getPieces().add(gen.new Piece(null, "(", null));
                }
                boolean first = true;
                for (String rt : tr.getParams()) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                if (ADD_REFERENCE_TO_TABLE)
                    c.getPieces().add(gen.new Piece(null, ")", null));
            } else if (definitions.getPrimitives().containsKey(t)) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getPrimitives().get(t).getDefinition(), null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                choicerow.getCells().add(gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
            } else if (definitions.getConstraints().containsKey(t)) {
                ProfiledType pt = definitions.getConstraints().get(t);
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(pt.getBaseType())), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
            } else {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(t)), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
            }
            choicerow.getCells().add(gen.new Cell());
            // choicerow.getCells().add(gen.new Cell());
            row.getSubRows().add(choicerow);
        }
    } else
        for (ElementDefn c : e.getElements()) {
            row.getSubRows().add(genElement(c, gen, false, path + '.' + c.getName(), isProfile, prefix, mode, false, null, false, false));
        }
    return row;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 23 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class TerminologyNotesGenerator method describeBinding.

public static String describeBinding(String prefix, BindingSpecification cd, PageProcessor page) throws Exception {
    if (cd.getBinding() == BindingSpecification.BindingMethod.Unbound)
        return cd.getDefinition();
    if (cd.getBinding() == BindingSpecification.BindingMethod.Special) {
        if (cd.getValueSet().getName().equals("MessageEvent"))
            return "the <a href=\"" + prefix + "valueset-message-events.html\">Event List in the messaging framework</a>";
        else if (cd.getValueSet().getName().equals("ResourceType"))
            return "<a href=\"" + prefix + "valueset-resource-types.html\">Any defined Resource Type name</a>";
        else if (cd.getValueSet().getName().equals("DataType"))
            return "<a href=\"" + prefix + "valueset-data-types.html\">Any defined Data Type name</a>";
        else if (cd.getValueSet().getName().equals("FHIRDefinedType"))
            return "<a href=\"" + prefix + "valueset-defined-types.html\">Any defined Resource or Data Type name</a>";
        else if (cd.getValueSet().getName().equals("FHIRAllTypes"))
            return "<a href=\"" + prefix + "valueset-all-types.html\">Any defined Resource or Data Type name (including \"Any\" and \"Type\")</a>";
        else
            throw new Exception("Unknown special type " + cd.getValueSet().getName());
    }
    String mx = "";
    if (cd.hasMax()) {
        if (cd.getMaxValueSet() == null)
            mx = " but limited to ??";
        else {
            String pp = cd.getMaxValueSet().hasUserData("external.url") ? cd.getMaxValueSet().getUserString("external.url") : cd.getMaxValueSet().getUserString("path");
            mx = " but limited to <a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getMaxValueSet().present() + "</a>";
        }
    }
    String bs = "<a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>";
    if (cd.getValueSet() != null) {
        ValueSet vs = cd.getValueSet();
        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
        return "<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getValueSet().present() + "</a> (" + bs + mx + ")";
    } else if (cd.getBinding() == BindingSpecification.BindingMethod.ValueSet) {
        if (Utilities.noString(cd.getReference()))
            return cd.getDescription();
        else if (cd.getValueSet() == null)
            return bs + ": <a href=\"" + (cd.getReference().startsWith("http") ? cd.getReference() : prefix + cd.getReference() + ".html") + "\">See " + cd.getDescription() + "</a> (" + cd.getDefinition() + mx + ")";
        else
            return bs + ": <a href=\"" + prefix + cd.getReference() + ".html\">See " + cd.getValueSet().getUrl() + "</a> (" + cd.getDefinition() + mx + ")";
    } else if (cd.getBinding() == BindingSpecification.BindingMethod.CodeList) {
        if (Utilities.noString(cd.getReference()))
            return bs + ": " + cd.getDescription() + " (" + cd.getDefinition() + mx + ")";
        else
            return bs + ": <a href=\"" + prefix + "valueset-" + cd.getReference().substring(1) + ".html\">http://hl7.org/fhir/" + cd.getReference().substring(1) + "</a> (" + cd.getDefinition() + mx + ")";
    }
    return "??";
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 24 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class XSDBaseGenerator method genType.

private void genType(ElementDefn elem) throws Exception {
    enums.clear();
    enumDefs.clear();
    String name = elem.getName();
    write("  <xs:complexType name=\"" + name + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(elem.getDefinition()) + "</xs:documentation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have a value for at least one of the defined elements, an @id referenced from the Narrative, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    write("    <xs:complexContent>\r\n");
    write("      <xs:extension base=\"" + getParentType(elem) + "\">\r\n");
    write("        <xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (e.typeCode().equals("xml:lang")) {
        // do nothing here
        } else if (e.getName().equals("[type]"))
            generateAny(elem, e, null, null);
        else
            generateElement(elem, e, null, null);
    }
    write("        </xs:sequence>\r\n");
    for (ElementDefn e : elem.getElements()) {
        if (e.typeCode().equals("xml:lang")) {
            write("        <xs:attribute ref=\"xml:lang\"/>\r\n");
        }
    }
    write("      </xs:extension>\r\n");
    write("    </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
    // write("  <xs:complexType name=\""+name+"\">\r\n");
    // write("    <xs:complexContent>\r\n");
    // write("      <xs:extension base=\"Core"+name+"\">\r\n");
    // write("        <xs:attribute name=\"id\" type=\"id-primitive\"/>\r\n");
    // write("      </xs:extension>\r\n");
    // write("    </xs:complexContent>\r\n");
    // write("  </xs:complexType>\r\n");
    genRegex();
    while (!structures.isEmpty()) {
        String s = structures.keySet().iterator().next();
        generateType(elem, s, structures.get(s));
        structures.remove(s);
    }
    for (BindingSpecification en : enums) {
        generateEnum(en);
    }
    genRegex();
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Example 25 with BindingSpecification

use of org.hl7.fhir.definitions.model.BindingSpecification in project kindling by HL7.

the class DictHTMLGenerator method describeBinding.

private String describeBinding(String path, ElementDefn e) throws Exception {
    if (!e.hasBinding())
        return null;
    // name (description): [[ValueSet]], Strength = [[]]
    StringBuilder b = new StringBuilder();
    BindingSpecification cd = e.getBinding();
    if (cd.getValueSet() == null) {
        if (!Utilities.noString(cd.getReference()))
            b.append("<a href=\"" + prefix + cd.getReference() + "\">" + e.getBinding().getName() + "</a>: ");
        else
            b.append("<a href=\"" + prefix + "terminologies.html#unbound\">" + e.getBinding().getName() + "</a>: ");
    } else
        b.append(TerminologyNotesGenerator.describeBinding(prefix, cd, page));
    // "<a href=\"terminologies.html#conformance\">"+(cd.getBindingStrength() == null ? "--" : cd.getBindingStrength().toString().toLowerCase())+"</a>)");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification)

Aggregations

BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)20 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)10 ArrayList (java.util.ArrayList)8 TypeRef (org.hl7.fhir.definitions.model.TypeRef)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 IOException (java.io.IOException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 CodeType (org.hl7.fhir.r5.model.CodeType)4 FileNotFoundException (java.io.FileNotFoundException)3 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)3 CSFile (org.hl7.fhir.utilities.CSFile)3 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 TransformerException (javax.xml.transform.TransformerException)2 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)2 Invariant (org.hl7.fhir.definitions.model.Invariant)2 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2