Search in sources :

Example 1 with DataType

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

the class CDAGenerator method addCDExtensions.

private void addCDExtensions(List<ElementDefinition> list, String n) {
    ElementDefinition ed = new ElementDefinition();
    ed.setPath(n + ".valueSet");
    seePath(ed);
    ed.setMin(0);
    ed.setMax("1");
    ed.addType().setCode("string");
    ed.addRepresentation(PropertyRepresentation.XMLATTR);
    ed.setDefinition("The valueSet extension adds an attribute for elements with a CD dataType which indicates the particular value set constraining the coded concept");
    ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:sdtc"));
    ed = new ElementDefinition();
    ed.setPath(n + ".valueSetVersion");
    seePath(ed);
    ed.setMin(0);
    ed.setMax("1");
    ed.addType().setCode("string");
    ed.addRepresentation(PropertyRepresentation.XMLATTR);
    ed.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("urn:hl7-org:sdtc"));
    ed.setDefinition("The valueSetVersion extension adds an attribute for elements with a CD dataType which indicates the version of the particular value set constraining the coded concept.");
    list.add(ed);
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) UriType(org.hl7.fhir.r5.model.UriType)

Example 2 with DataType

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

the class SvgGenerator method drawElement.

private ClassItem drawElement(XMLWriter xml, String[] classNames) throws Exception {
    // classNames.length == 1 && classNames[0].equals("Base");
    boolean onlyElement = false;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = fakes.get(cn);
                if (cd instanceof DefinedStringPattern) {
                    links.add(new Link(classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                } else {
                    ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "PrimitiveType"));
                    if (parent == null) {
                        drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                    } else {
                        links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                    }
                }
            } else if ("xhtml".equals(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(version.isR4B() ? "Element" : "DataType"));
                if (parent == null) {
                    drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
                } else {
                    links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn fake = fakes.get(cn);
                ClassItem parent = classes.get(definitions.getElementDefn(cd.getBaseType()));
                links.add(new Link(parent, drawClass(xml, fake, false, null, true, null, null, StandardsStatus.NORMATIVE), LinkType.CONSTRAINT, null, null, PointKind.unknown, null, null));
            } else if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                ElementDefn fake = fakes.get(cn);
                // links.add(new Link(item,
                // , LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                drawClass(xml, fake, false, null, true, null, cd, StandardsStatus.NORMATIVE);
            } else if (!onlyElement) {
                ElementDefn e = definitions.getElementDefn(cn);
                ClassItem parent = Utilities.noString(e.typeCode()) ? null : classes.get(definitions.getElementDefn(e.typeCode()));
                if (parent == null) {
                    drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus());
                } else {
                    links.add(new Link(parent, drawClass(xml, e, false, null, true, cn, null, e.getStandardsStatus()), LinkType.SPECIALIZATION, null, null, PointKind.unknown, null, null));
                }
            }
        }
    }
    return null;
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 3 with DataType

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

the class TerminologyNotesGenerator method gen.

private void gen(String prefix, Map<BindingSpecification, List<CDUsage>> txusages2) throws Exception {
    List<BindingSpecification> cds = new ArrayList<BindingSpecification>();
    cds.addAll(txusages.keySet());
    if (cds.size() == 0)
        return;
    Collections.sort(cds, new MyCompare());
    if (noHeader)
        write("<p>\r\n<b>Terminology Bindings</b>\r\n</p>\r\n");
    else
        write("<h3>\r\nTerminology Bindings\r\n</h3>\r\n");
    // 1. new form
    write("<table class=\"grid\">\r\n");
    write(" <tr><th>Path</th><th>Definition</th><th>Type</th><th>Reference</th></tr>\r\n");
    for (BindingSpecification cd : cds) {
        String path;
        List<CDUsage> list = txusages.get(cd);
        for (int i = 2; i < list.size(); i++) {
            if (!matchesTypes(list.get(i).element.typeCodeNoParams(), list.get(1).element.typeCodeNoParams()))
                throw new Exception("Mixed types on one concept domain in one type - not yet supported by the build process for binding " + cd.getName() + " (" + list.get(i).element.typeCode() + " vs " + list.get(1).element.typeCode() + ")");
        }
        String name = cd.getValueSet() != null ? cd.getValueSet().present() : cd.getName();
        write(" <tr><td valign=\"top\" title=\"" + name + "\">");
        boolean first = true;
        for (int i = 1; i < list.size(); i++) {
            if (!first)
                write("<br/>");
            first = false;
            write(list.get(i).path);
        }
        write(" </td>");
        write("<td valign=\"top\">" + Utilities.escapeXml(cd.getDefinition()) + "</td>");
        if (cd.getBinding() == BindingMethod.Unbound)
            write("<td>Unknown</td><td valign=\"top\">No details provided yet</td>");
        else {
            if (cd.hasMax()) {
                ValueSet vs = cd.getMaxValueSet();
                if (vs == null) {
                    write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>, but limited to <a href=\"" + cd.getMaxReference() + "\">" + cd.getMaxReference() + "</a></td>");
                } else {
                    String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                    write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a>, but limited to <a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + vs.getName() + "</a></td>");
                }
            } else
                write("<td><a href=\"" + prefix + "terminologies.html#" + cd.getStrength().toCode() + "\">" + cd.getStrength().getDisplay() + "</a></td>");
            write("<td valign=\"top\">");
            if (cd.getBinding() == BindingSpecification.BindingMethod.Special) {
                if (name.equals("MessageEvent"))
                    write("<a href=\"" + prefix + "valueset-message-events.html\">Message Events</a>");
                else if (name.equals("ResourceType"))
                    write("<a href=\"" + prefix + "valueset-resource-types.html\">Resource Types</a>");
                else if (name.equals("DataType"))
                    write("<a href=\"" + prefix + "valueset-data-types.html\">Data Types</a>");
                else if (name.equals("FHIRDefinedType"))
                    write("<a href=\"" + prefix + "valueset-defined-types.html\">Defined Types</a>");
                else if (name.equals("FHIRAllTypes"))
                    write("<a href=\"" + prefix + "valueset-all-types.html\">All Types</a>");
                else
                    throw new Exception("Unknown special type " + name);
            } else if (cd.getValueSet() != null) {
                ValueSet vs = cd.getValueSet();
                String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                if (pp == null)
                    throw new Exception("unknown path on " + cd.getReference());
                write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + vs.getName() + "</a><!-- b -->");
            } else if (cd.getBinding() == BindingSpecification.BindingMethod.ValueSet) {
                if (Utilities.noString(cd.getReference()))
                    write("??");
                else if (cd.getReference().startsWith("valueset-"))
                    write("<a href=\"" + prefix + cd.getReference() + ".html\">http://hl7.org/fhir/ValueSet/" + cd.getReference().substring(9) + "</a><!-- a -->");
                else if (cd.getReference().startsWith("http://hl7.org/fhir")) {
                    if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v3-")) {
                        ValueSet vs = page.getValueSets().get(cd.getReference());
                        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                        if (pp == null)
                            throw new Exception("unknown path on " + cd.getReference());
                        write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getReference() + "</a><!-- b -->");
                    } else if (cd.getReference().startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
                        ValueSet vs = page.getValueSets().get(cd.getReference());
                        String pp = vs.hasUserData("external.url") ? vs.getUserString("external.url") : vs.getUserString("path");
                        write("<a href=\"" + prefix + pp.replace(File.separatorChar, '/') + "\">" + cd.getReference() + "</a><!-- c -->");
                    } else if (cd.getReference().startsWith("http://hl7.org/fhir/ValueSet/")) {
                        String ref = getBindingLink(cd);
                        write("<a href=\"" + prefix + ref + "\">" + cd.getReference() + "</a><!-- d -->");
                    // BindingSpecification bs1 = page.getDefinitions().getBindingByURL(cd.getReference());
                    // if (bs1 != null)
                    // write("<a href=\""+cd.getReference().substring(23)+".html\">"+cd.getReference()+"</a><!-- d -->");
                    // else
                    // write("<a href=\"valueset-"+cd.getReference().substring(23)+".html\">"+cd.getReference()+"</a><!-- d -->");
                    } else
                        throw new Exception("Internal reference " + cd.getReference() + " not handled yet");
                } else if (cd.getReference().startsWith("http:"))
                    write("<a href=\"" + cd.getReference() + "\">" + cd.getReference() + "</a><!-- e -->");
                else
                    write("<a href=\"" + prefix + "valueset-" + cd.getReference() + ".html\">http://hl7.org/fhir/" + cd.getReference() + "</a><!-- e -->");
            } else if (cd.getBinding() == BindingSpecification.BindingMethod.CodeList) {
                write("<a href=\"" + prefix + "valueset-" + cd.getReference().substring(1) + ".html\">http://hl7.org/fhir/" + cd.getReference().substring(1) + "</a><!-- f -->");
            }
            write("</td>");
        }
        write(" </tr>\r\n");
    }
    write("</table>\r\n<p> </p>\r\n");
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with DataType

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

the class XmlSpecGenerator method renderType.

private String renderType(int indent, DataType value) throws Exception {
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < indent - 2; i++) b.append(" ");
    String ind = b.toString();
    XmlParser xml = new XmlParser();
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    xml.setOutputStyle(OutputStyle.PRETTY);
    xml.compose(bs, null, value);
    bs.close();
    String[] result = bs.toString().split("\\r?\\n");
    b = new StringBuilder();
    for (String s : result) {
        if (// eliminate the wrapper content
        s.startsWith(" "))
            b.append("\r\n  " + ind + Utilities.escapeXml(s));
    }
    return b.toString() + "\r\n" + ind;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with DataType

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

the class ProfileGenerator method genUml.

private void genUml(TypeDefn t) {
    if (!uml.hasClass(t.getName())) {
        UMLClass c = new UMLClass(t.getName(), UMLClassType.Class);
        uml.getTypes().put(t.getName(), c);
    }
    UMLClass c = uml.getClassByName(t.getName());
    c.setDocumentation(t.getDefinition());
    if (!t.getTypes().isEmpty()) {
        c.setSpecialises(uml.getClassByName(t.typeCodeNoParams()));
    }
    if (!c.hasAttributes()) {
        for (ElementDefn e : t.getElements()) {
            UMLAttribute a = null;
            if (t.getTypes().isEmpty()) {
                a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("Base"));
            } else if (t.getTypes().size() == 1 && !isReference(t.getTypes().get(0).getName())) {
                a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate(e.typeCode()));
            } else {
                String tn = t.getTypes().get(0).getName();
                boolean allSame = true;
                for (int i = 1; i < t.getTypes().size(); i++) {
                    allSame = tn.equals(t.getTypes().get(i).getName());
                }
                if (allSame && isReference(tn)) {
                    a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate(tn));
                    for (TypeRef tr : t.getTypes()) {
                        for (String p : tr.getParams()) {
                            a.getTargets().add(p);
                        }
                    }
                } else {
                    boolean allPrimitive = true;
                    for (TypeRef tr : t.getTypes()) {
                        if (!definitions.hasPrimitiveType(tr.getName())) {
                            allPrimitive = false;
                        }
                    }
                    if (allPrimitive) {
                        a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("PrimitiveType"));
                    } else {
                        a = new UMLAttribute(e.getName(), Integer.toString(e.getMinCardinality()), Integer.toString(e.getMaxCardinality()), uml.getClassByNameCreate("DataType"));
                    }
                    for (TypeRef tr : t.getTypes()) {
                        a.getTypes().add(tr.getName());
                        for (String p : tr.getParams()) {
                            a.getTargets().add(p);
                        }
                    }
                }
            }
            c.getAttributes().add(a);
        }
    }
}
Also used : UMLClass(org.hl7.fhir.definitions.uml.UMLClass) UMLAttribute(org.hl7.fhir.definitions.uml.UMLAttribute) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Aggregations

DataType (org.hl7.fhir.r5.model.DataType)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 Collectors (java.util.stream.Collectors)6 DataType (org.hl7.cql.model.DataType)6 ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 ArrayList (java.util.ArrayList)5 StructType (org.apache.spark.sql.types.StructType)5 BooleanType (org.hl7.fhir.r5.model.BooleanType)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 Arrays (java.util.Arrays)4 QName (javax.xml.namespace.QName)4 DataType (org.hl7.fhir.r4b.model.DataType)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3