Search in sources :

Example 16 with BindingSpecification

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

the class ResourceDependencyGenerator method addBindingToAnalysis.

private void addBindingToAnalysis(HierarchicalTableGenerator gen, Row row, Cell dc, boolean req, StandardsStatus elementStatus, BindingSpecification binding) throws FHIRException {
    String tgtFMM = null;
    StandardsStatus tgtSS = null;
    ValueSet vs = binding.getValueSet();
    if (vs != null) {
        tgtFMM = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_FMM_LEVEL);
        tgtSS = ToolingExtensions.getStandardsStatus(vs);
    } else if (Utilities.existsInList(binding.getReference(), "http://www.rfc-editor.org/bcp/bcp13.txt")) {
        tgtFMM = "5";
        tgtSS = StandardsStatus.EXTERNAL;
    }
    if (elementStatus == null)
        elementStatus = sstatus;
    if (tgtFMM == null)
        addError(gen, row, dc, "Binding Error: Unable to resolve vs '" + binding.getReference() + "' to check dependencies", null);
    else {
        boolean ok = elementStatus.canDependOn(tgtSS);
        if (ok)
            ok = fmm.compareTo(tgtFMM) <= 0;
        if (ok)
            // addInfo(gen, row, dc, "Binding OK (ValueSet = FMM"+tgtFMM+"-"+tgtSS.toDisplay()+" vs. Element = FMM"+fmm+"-"+elementStatus.toDisplay()+")", null);
            ;
        else
            addError(gen, row, dc, "Binding Error: (ValueSet = FMM" + tgtFMM + "-" + tgtSS.toDisplay() + " vs. Element = FMM" + fmm + "-" + elementStatus.toDisplay() + ")", vs.getUserString("path"));
    }
}
Also used : StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 17 with BindingSpecification

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

the class ResourceValidator method check.

// private List<ValidationMessage> check(String n, BindingSpecification cd) throws Exception {
// List<ValidationMessage> errors = new ArrayList<ValidationMessage>();
// check(errors, n, cd);
// return errors;
// }
private void check(List<ValidationMessage> errors, String path, BindingSpecification cd, String sd, ElementDefn e) throws Exception {
    // basic integrity checks
    List<DefinedCode> ac = cd.getAllCodes(definitions.getCodeSystems(), definitions.getValuesets(), false);
    for (DefinedCode c : ac) {
        String d = c.getCode();
        if (Utilities.noString(d))
            d = c.getId();
        if (Utilities.noString(d))
            d = c.getDisplay();
        if (Utilities.noString(d))
            d = c.getDisplay();
        if (Utilities.noString(c.getSystem()))
            warning(errors, IssueType.STRUCTURE, "Binding @ " + path, !Utilities.noString(c.getDefinition()), "Code " + d + " must have a definition");
        rule(errors, IssueType.STRUCTURE, "Binding @ " + path, !(Utilities.noString(c.getId()) && Utilities.noString(c.getSystem())), "Code " + d + " must have a id or a system");
    }
    // trigger processing into a Heirachical set if necessary
    // rule(errors, IssueType.STRUCTURE, "Binding @ "+path, !cd.isHeirachical() || (cd.getChildCodes().size() < cd.getCodes().size()), "Logic error processing Hirachical code set");
    // now, rules for the source
    hint(errors, IssueType.STRUCTURE, "Binding @ " + path, cd.getBinding() != BindingMethod.Unbound, "Need to provide a binding");
    rule(errors, IssueType.STRUCTURE, "Binding @ " + path, Utilities.noString(cd.getDefinition()) || (cd.getDefinition().charAt(0) == cd.getDefinition().toUpperCase().charAt(0)), "Definition cannot start with a lowercase letter");
    if (cd.getBinding() == BindingMethod.CodeList || (cd.getBinding() == BindingMethod.ValueSet && cd.getStrength() == BindingStrength.REQUIRED && ac.size() > 0 && "code".equals(e.typeCode()))) {
        if (path.toLowerCase().endsWith("status")) {
            if (rule(errors, IssueType.STRUCTURE, path, definitions.getStatusCodes().containsKey(path), "Status element not registered in status-codes.xml")) {
                // rule(errors, IssueType.STRUCTURE, path, e.isModifier(), "Status elements that map to status-codes should be labelled as a modifier");
                ArrayList<String> list = definitions.getStatusCodes().get(path);
                for (DefinedCode c : ac) {
                    boolean ok = false;
                    for (String s : list) {
                        String[] parts = s.split("\\,");
                        for (String p : parts) if (p.trim().equals(c.getCode()))
                            ok = true;
                    }
                    rule(errors, IssueType.STRUCTURE, path, ok, "Status element code \"" + c.getCode() + "\" not found in status-codes.xml");
                }
                for (String s : list) {
                    String[] parts = s.split("\\,");
                    for (String p : parts) {
                        List<String> cl = new ArrayList<>();
                        if (!Utilities.noString(p)) {
                            boolean ok = false;
                            for (DefinedCode c : ac) {
                                cl.add(c.getCode());
                                if (p.trim().equals(c.getCode()))
                                    ok = true;
                            }
                            if (!ok)
                                rule(errors, IssueType.STRUCTURE, path, ok, "Status element code \"" + p + "\" found for " + path + " in status-codes.xml but has no matching code in the resource (codes = " + cl + ")");
                        }
                    }
                }
            }
        }
        StringBuilder b = new StringBuilder();
        for (DefinedCode c : ac) {
            if (!c.getAbstract())
                b.append(" | ").append(c.getCode());
        }
        if (sd.equals("*")) {
            e.setShortDefn(b.toString().substring(3));
            sd = b.toString().substring(3);
        }
        if (sd.contains("|")) {
            if (b.length() < 3)
                throw new Error("surprise");
            String esd = b.substring(3);
            rule(errors, IssueType.STRUCTURE, path, sd.startsWith(esd) || (sd.endsWith("+") && b.substring(3).startsWith(sd.substring(0, sd.length() - 1))), "The short description \"" + sd + "\" does not match the expected (\"" + b.substring(3) + "\")");
        } else {
            rule(errors, IssueType.STRUCTURE, path, cd.getStrength() != BindingStrength.REQUIRED || ac.size() > 12 || ac.size() <= 1 || !hasGoodCode(ac) || isExemptFromCodeList(path), "The short description of an element with a code list should have the format code | code | etc (is " + sd.toString() + ") (" + ac.size() + " codes = \"" + b.toString() + "\")");
        }
    }
    boolean isComplex = !e.typeCode().equals("code");
    if (isComplex && cd.getValueSet() != null && hasInternalReference(cd.getValueSet()) && cd.getStrength() != BindingStrength.EXAMPLE) {
        hint(errors, IssueType.BUSINESSRULE, path, false, "The value " + cd.getValueSet().getUrl() + " defines codes, but is used by a Coding/CodeableConcept @ " + path + ", so it should not use FHIR defined codes");
        cd.getValueSet().setUserData("vs-val-warned", true);
    }
    if (cd.getElementType() == ElementType.Unknown) {
        if (isComplex)
            cd.setElementType(ElementType.Complex);
        else
            cd.setElementType(ElementType.Simple);
    } else if (isComplex && !cd.hasMax())
        rule(errors, IssueType.STRUCTURE, path, cd.getElementType() == ElementType.Complex, "Cannot use a binding from both code and Coding/CodeableConcept elements");
    else
        rule(errors, IssueType.STRUCTURE, path, cd.getElementType() == ElementType.Simple, "Cannot use a binding from both code and Coding/CodeableConcept elements");
    if (isComplex && cd.getValueSet() != null) {
        for (ConceptSetComponent inc : cd.getValueSet().getCompose().getInclude()) if (inc.hasSystem())
            txurls.add(inc.getSystem());
    }
    rule(errors, IssueType.STRUCTURE, "Binding @ " + path, (cd.getElementType() != ElementType.Simple || cd.getStrength() == BindingStrength.REQUIRED || cd.hasMax()) || isExemptFromProperBindingRules(path), "Must be a required binding if bound to a code instead of a Coding/CodeableConcept");
    rule(errors, IssueType.STRUCTURE, "Binding @ " + path, cd.getElementType() != ElementType.Simple || cd.getBinding() != BindingMethod.Unbound, "Need to provide a binding for code elements");
    if (!isComplex && !externalException(path)) {
        ValueSet vs = cd.getValueSet();
        if (warning(errors, IssueType.REQUIRED, path, vs != null || cd.hasReference(), "Unable to resolve value set on 'code' Binding")) {
            hint(errors, IssueType.REQUIRED, path, noExternals(vs), "Bindings for code data types should only use internally defined codes (" + vs.getUrl() + ")");
        // don't disable this without discussion on Zulip
        }
    }
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 18 with BindingSpecification

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

the class JsonLDGenerator method generateElement.

private void generateElement(ElementDefn root, String name, ElementDefn e, JsonObject base, Set<String> types) throws Exception {
    if ((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");
        for (TypeRef tr : datatypes) {
            String tn = tr.getName();
            if (tn.equals("SimpleQuantity"))
                tn = "Quantity";
            else
                tn = Utilities.capitalize(tn);
            String en = e.getName().substring(0, e.getName().length() - 3) + tn;
            JsonObject property = new JsonObject();
            base.add(name + "." + en, property);
            property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + en);
        }
    // 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;
    // String en = e.getName().replace("[x]",  "");
    // props.add(en+upFirst(t.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 if (e.getName().endsWith("[x]")) {
        for (TypeRef tr : e.getTypes()) {
            String tn = tr.getName();
            if (tn.equals("SimpleQuantity"))
                tn = "Quantity";
            else
                tn = Utilities.capitalize(tn);
            String en = e.getName().substring(0, e.getName().length() - 3) + tn;
            JsonObject property = new JsonObject();
            base.add(name + "." + en, property);
            property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + en);
        }
    } else {
        JsonObject property = new JsonObject();
        base.add(name + "." + e.getName(), property);
        if (e.getPath() == null)
            property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + e.getName());
        else
            property.addProperty("@id", "http://hl7.org/fhir/" + e.getPath());
    // if we're using lists:
    // if (e.unbounded())
    // property.addProperty("@container", "@list");
    // property.addProperty("fhir-@type", "http://hl7.org/fhir/"+e.typeCode());
    // 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);
    // 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);
    // type=tn;
    // if (definitions.getPrimitives().containsKey(e.typeCode())) {
    // DefinedCode def = definitions.getPrimitives().get(e.typeCode());
    // type = def.getJsonType();
    // pattern = def.getRegex();
    // property_ = new JsonObject();
    // props.add("_"+e.getName(), property_);
    // property_.addProperty("description", "Extensions for "+e.getName());
    // tref = (relative ? "#" : "Element.schema.json#") +"/definitions/Element";
    // 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 {
    // 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 (e.unbounded()) {
    // property.addProperty("type", "array");
    // if (property_ != null) {
    // property_.addProperty("type", "array");
    // JsonObject items = new JsonObject();
    // property.add("items", items);
    // items.addProperty("type", type);
    // if (!Utilities.noString(pattern))
    // items.addProperty("pattern", pattern);
    // 
    // items = new JsonObject();
    // property_.add("items", items);
    // items.addProperty("$ref", tref);
    // } else {
    // JsonObject items = new JsonObject();
    // property.add("items", items);
    // items.addProperty("$ref", tref);
    // }
    // } else {
    // if (property_ != null) {
    // property.addProperty("type", type);
    // if (!Utilities.noString(pattern))
    // property.addProperty("pattern", pattern);
    // 
    // 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.getMinCardinality() > 0 && property_ == null)
    // required.add(e.getName());
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 19 with BindingSpecification

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

the class XSDBaseGenerator method generateEnum.

private void generateEnum(BindingSpecification bs) throws IOException {
    String en = bs.getValueSet().getName();
    if (genEnums.contains(en))
        return;
    write("  <xs:simpleType name=\"" + en + "-list\">\r\n");
    write("    <xs:restriction base=\"code-primitive\">\r\n");
    bs.getValueSet().setUserData(ToolResourceUtilities.NAME_VS_USE_MARKER, true);
    ValueSet ex = workerContext.expandVS(bs.getValueSet(), true, false).getValueset();
    if (ex == null)
        throw new Error("The expansion for " + bs.getName() + " is null");
    if (ex.getExpansion().getContains().isEmpty())
        throw new Error("The expansion for " + bs.getName() + " is empty");
    for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
        genIncludedCode(cc);
    }
    write("    </xs:restriction>\r\n");
    write("  </xs:simpleType>\r\n");
    write("  <xs:complexType name=\"" + en + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(enumDefs.get(en)) + "</xs:documentation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    write("    <xs:complexContent>\r\n");
    write("       <xs:extension base=\"Element\">\r\n");
    write("         <xs:attribute name=\"value\" type=\"" + en + "-list\" use=\"optional\"/>\r\n");
    write("       </xs:extension>\r\n");
    write("     </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
    genEnums.add(en);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 20 with BindingSpecification

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

the class ResourceDependencyGenerator method genElement.

protected Row genElement(ElementDefn e, HierarchicalTableGenerator gen, boolean resource, String path, boolean isProfile, String prefix, RenderMode mode, boolean isRoot) throws Exception {
    Row row = gen.new Row();
    row.setAnchor(path);
    // 1. Name
    Cell gc = gen.new Cell(null, dictLinks() ? pageName + "#" + path.replace("[", "_").replace("]", "_") : null, e.getName(), path + " : " + e.getDefinition(), null);
    row.getCells().add(gc);
    if (e.getStandardsStatus() != null) {
        gc.addPiece(gen.new Piece(null, " ", null));
        gc.addStyledText("Publication Status = " + e.getStandardsStatus().toDisplay(), e.getStandardsStatus().getAbbrev(), "black", e.getStandardsStatus().getColor(), prefix + "versions.html#std-process", true);
    }
    Cell dc;
    if (resource) {
        // card.
        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));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        } else {
            // type
            row.getCells().add(gen.new Cell(null, prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode(), e.typeCode(), null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell(null, null, path.contains(".") ? e.describeCardinality() : "", null, null));
        }
    } else {
        if (!e.getElements().isEmpty()) {
            // card.
            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("Element"))
                row.getCells().add(gen.new Cell(null, null, "n/a", null, null));
            else
                row.getCells().add(gen.new Cell(null, prefix + definitions.getBackboneLink(), "Element", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        } else if (e.getTypes().size() == 1) {
            // card.
            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);
                row.getCells().add(c = gen.new Cell("see ", "#" + t.substring(1), t.substring(t.lastIndexOf(".") + 1), t.substring(1), null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
            } else if (t.equals("Reference") || t.equals("canonical")) {
                row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
                row.getCells().add(c = gen.new Cell());
                c.getPieces().add(gen.new Piece(prefix + "references.html", t, null));
                c.getPieces().add(gen.new Piece(null, "(", null));
                boolean first = true;
                for (String rt : e.getTypes().get(0).getParams()) {
                    if (definitions.hasLogicalModel(rt)) {
                        for (String rtn : definitions.getLogicalModel(rt).getImplementations()) {
                            if (!first)
                                c.getPieces().add(gen.new Piece(null, " | ", null));
                            c.getPieces().add(gen.new Piece(prefix + findPage(rtn) + ".html", rtn, null));
                            first = false;
                        }
                    } else {
                        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;
                    }
                }
                c.getPieces().add(gen.new Piece(null, ")", null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                for (String rt : e.getTypes().get(0).getParams()) if (definitions.hasLogicalModel(rt)) {
                    for (String rtn : definitions.getLogicalModel(rt).getImplementations()) {
                        addTypeToAnalysis(gen, row, dc, true, e.getStandardsStatus(), rtn);
                    }
                } else
                    addTypeToAnalysis(gen, row, dc, true, e.getStandardsStatus(), rt);
            } else if (definitions.getPrimitives().containsKey(t)) {
                row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                row.getCells().add(c = gen.new Cell(null, prefix + "datatypes.html#" + t, t, null, null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, row, dc, false, e.getStandardsStatus(), e.typeCode());
            } 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);
                row.getCells().add(c = gen.new Cell(null, prefix + definitions.getSrcFile(t) + ".html#" + t.replace("*", "open"), t, null, null));
                // analysis
                row.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, row, dc, false, e.getStandardsStatus(), t);
            }
        } else {
            row.getCells().add(gen.new Cell(null, null, e.describeCardinality(), null, null));
            row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
            row.getCells().add(gen.new Cell(null, null, "", null, null));
            // analysis
            row.getCells().add(dc = gen.new Cell());
        }
    }
    if (e.hasBinding() && e.getBinding() != null && e.getBinding().getBinding() != BindingMethod.Unbound && (e.getBinding().getStrength() == BindingStrength.REQUIRED || e.getBinding().getStrength() == BindingStrength.EXTENSIBLE)) {
        addBindingToAnalysis(gen, row, dc, e.getBinding().getStrength() == BindingStrength.REQUIRED, e.getStandardsStatus(), e.getBinding());
    // 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().getName() : 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();
    // cc.getPieces().add(gen.new Piece(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));
    }
    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 (t.equals("Reference")) {
                choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", "Reference"), null, null));
                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);
                c.getPieces().add(gen.new Piece(prefix + "references.html", "Reference", null));
                c.getPieces().add(gen.new Piece(null, "(", null));
                boolean first = true;
                List<String> tt = new ArrayList<>();
                for (String rt : tr.getParams()) {
                    if (definitions.hasLogicalModel(rt))
                        tt.addAll(definitions.getLogicalModel(rt).getImplementations());
                    else
                        tt.add(rt);
                }
                Collections.sort(tt);
                for (String rt : tt) {
                    if (!first)
                        c.getPieces().add(gen.new Piece(null, " | ", null));
                    c.getPieces().add(gen.new Piece(prefix + findPage(rt) + ".html", rt, null));
                    first = false;
                }
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                for (String rt : tt) addTypeToAnalysis(gen, choicerow, dc, true, e.getStandardsStatus(), rt);
            } 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(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));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            } 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(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));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            } 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(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));
                // analysis
                choicerow.getCells().add(dc = gen.new Cell());
                addTypeToAnalysis(gen, choicerow, dc, false, e.getStandardsStatus(), t);
            }
            row.getSubRows().add(choicerow);
        }
    } else
        for (ElementDefn c : e.getElements()) row.getSubRows().add(genElement(c, gen, false, path + '.' + c.getName(), isProfile, prefix, mode, false));
    return row;
}
Also used : 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) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

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