Search in sources :

Example 91 with ElementDefn

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

the class MappingsGenerator method generate.

public void generate(List<ElementDefn> elements) {
    StringBuilder s = new StringBuilder();
    List<String> maps = new ArrayList<String>();
    for (ElementDefn e : elements) listKnownMappings(e, maps);
    Collections.sort(maps);
    StringBuilder list = new StringBuilder();
    for (String m : maps) {
        list.append("|" + definitions.getMapTypes().get(m).getTitle() + "#" + m);
        s.append("<a name=\"" + m + "\"> </a>\r\n");
        s.append("<a name=\"" + definitions.getMapTypes().get(m).getId() + "\"> </a>\r\n");
        s.append("<h3>" + definitions.getMapTypes().get(m).getTitle() + " (" + m + ")</h3>\r\n");
        s.append("<table class=\"grid\">\r\n");
        for (ElementDefn e : elements) if (elementHasMapping(e, m)) {
            genElement(s, 0, e, m, ALL, true, definitions.getMapTypes().get(m).isSparse());
        }
        s.append("</table>\r\n");
    }
    mappings = s.toString();
    if (list.toString().length() > 1)
        mappingsList = list.toString().substring(1);
    else
        mappingsList = list.toString();
}
Also used : ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 92 with ElementDefn

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

the class ProfileGenerator method createBaseDefinition.

private ElementDefinition createBaseDefinition(StructureDefinition p, String path, ElementDefn src) throws Exception {
    ElementDefinition ce = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    ce.setId(path + "." + src.getName());
    ce.setPath(path + "." + src.getName());
    ce.setShort(src.getShortDefn());
    ce.setDefinition(preProcessMarkdown(src.getDefinition(), "ELement Definition"));
    ce.setComment(preProcessMarkdown(src.getComments(), "Element Comments"));
    ce.setRequirements(preProcessMarkdown(src.getRequirements(), "Element Reqiurements"));
    for (String a : src.getAliases()) ce.addAlias(a);
    ce.setMin(src.getMinCardinality());
    if (src.getMaxCardinality() != null)
        ce.setMax(src.getMaxCardinality() == Integer.MAX_VALUE ? "*" : src.getMaxCardinality().toString());
    ce.getType(src.typeCode());
    // this one should never be used
    if (!Utilities.noString(src.getTypes().get(0).getProfile())) {
        if (ce.getType().equals("Reference") || ce.getType().equals("canonical") || ce.getType().equals("CodeableReference"))
            throw new Error("Should not happen");
        ce.getType().get(0).addProfile(src.getTypes().get(0).getProfile());
    }
    // todo? conditions, constraints, binding, mapping
    if (src.hasModifier())
        ce.setIsModifier(src.isModifier());
    if (ce.getIsModifier())
        ce.setIsModifierReason(src.getModifierReason());
    if (src.hasSummaryItem())
        ce.setIsSummaryElement(Factory.newBoolean(src.isSummary()));
    for (Invariant id : src.getStatedInvariants()) ce.addCondition(id.getId());
    return ce;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Example 93 with ElementDefn

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

the class DictHTMLGenerator method patternAnalysis.

private String patternAnalysis(ElementDefn e) {
    StringBuilder b = new StringBuilder();
    boolean first = true;
    for (TypeRef tr : e.getTypes()) {
        if (tr.getPatterns() != null) {
            if (first)
                first = false;
            else
                b.append("<br/>\r\n");
            if (tr.getPatterns().isEmpty())
                b.append(tr.summary() + ": No common pattern");
            else {
                CommaSeparatedStringBuilder cb = new CommaSeparatedStringBuilder();
                for (String s : tr.getPatterns()) {
                    cb.append("<a href=\"" + s.toLowerCase() + ".html#" + s + "\">" + s + "</a>");
                }
                if (tr.getPatterns().size() == 0)
                    b.append(tr.summary() + ": Common pattern = " + cb.toString());
                else
                    b.append(tr.summary() + ": Common patterns = " + cb.toString());
            }
        }
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRef(org.hl7.fhir.definitions.model.TypeRef) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 94 with ElementDefn

use of org.hl7.fhir.definitions.model.ElementDefn 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)

Example 95 with ElementDefn

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

the class JsonSpecGenerator method generateCoreElem.

private void generateCoreElem(ElementDefn elem, int indent, String rootName, String pathName, boolean backbone, boolean last) throws Exception {
    // base pattern: "name" : "value" // optionality documentation
    int width = 0;
    // If this is an unrolled element, show its profile name
    if (elem.getProfileName() != null && !elem.getProfileName().equals("")) {
        for (int i = 0; i < indent; i++) write("  ");
        write("<span style=\"color: Gray\">// </span><span style=\"color: blue\">\"" + elem.getProfileName() + "\":</span>\r\n");
    }
    if (elem.getMaxCardinality() != null && elem.getMaxCardinality() == 0)
        write("<span style=\"text-decoration: line-through\">");
    String en = elem.getName();
    if (en.contains("[x]") && elem.getTypes().size() == 1 && !elem.getTypes().get(0).isWildcardType())
        en = en.replace("[x]", elem.typeCode());
    if (en.contains("[x]")) {
        // 1. name
        for (int i = 0; i < indent; i++) {
            write("  ");
        }
        if (elem.getTypes().size() > 1) {
            write("<span style=\"color: Gray\">// " + en + ": <span style=\"color: navy; opacity: 0.8\">" + docPrefix(width, indent, elem) + Utilities.escapeXml(elem.getShortDefn()) + "</span>. One of these " + Integer.toString(elem.getTypes().size()) + ":</span>\r\n");
            for (TypeRef t : elem.getTypes()) generateCoreElemDetails(elem, indent, rootName, pathName, backbone, last, width, en.replace("[x]", nameForType(t.getName())), t, false);
        } else {
            List<WildcardInformation> tr = TypesUtilities.wildcards(version);
            write("<span style=\"color: Gray\">// " + en + ": <span style=\"color: navy; opacity: 0.8\">" + docPrefix(width, indent, elem) + Utilities.escapeXml(elem.getShortDefn()) + "</span>. One of these " + Integer.toString(tr.size()) + ":</span>\r\n");
            for (WildcardInformation t : tr) generateCoreElemDetails(elem, indent, rootName, pathName, backbone, last, width, en.replace("[x]", upFirst(t.getTypeName())), toTypeRef(t), false);
        }
    } else {
        generateCoreElemDetails(elem, indent, rootName, pathName, backbone, last, width, en, elem.getTypes().isEmpty() ? null : elem.getTypes().get(0), true);
    }
}
Also used : WildcardInformation(org.hl7.fhir.r5.utils.TypesUtilities.WildcardInformation) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Aggregations

ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)100 TypeRef (org.hl7.fhir.definitions.model.TypeRef)35 ArrayList (java.util.ArrayList)28 FHIRException (org.hl7.fhir.exceptions.FHIRException)28 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)21 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)19 Invariant (org.hl7.fhir.definitions.model.Invariant)16 IOException (java.io.IOException)14 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)11 FileNotFoundException (java.io.FileNotFoundException)10 URISyntaxException (java.net.URISyntaxException)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 TransformerException (javax.xml.transform.TransformerException)8 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 UcumException (org.fhir.ucum.UcumException)7 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7