Search in sources :

Example 81 with StructureDefinition

use of org.hl7.fhir.dstu2016may.model.StructureDefinition in project kindling by HL7.

the class MappingsGenerator method generateExtension.

public void generateExtension(StructureDefinition ed) throws IOException {
    if (ed.getMapping().isEmpty())
        mappings = "<p>No Mappings</p>";
    else {
        StringBuilder s = new StringBuilder();
        for (StructureDefinitionMappingComponent map : ed.getMapping()) {
            s.append("<a name=\"" + map.getIdentity() + "\"> </a><h3>" + map.getName() + " (" + map.getUri() + ")</h3>");
            if (map.hasComment())
                s.append("<p>" + Utilities.escapeXml(map.getComment()) + "</p>");
            else if (definitions.getMapTypes().containsKey(map.getUri())) {
                XhtmlNode pre = definitions.getMapTypes().get(map.getUri()).getPreamble();
                if (pre != null)
                    s.append(new XhtmlComposer(XhtmlComposer.HTML).compose(pre));
            }
            s.append("<table class=\"grid\">\r\n");
            s.append(" <tr><td colspan=\"3\"><b>" + Utilities.escapeXml(ed.getName()) + "</b></td></tr>\r\n");
            String path = null;
            for (ElementDefinition e : ed.getSnapshot().getElement()) {
                if (path == null || !e.getPath().startsWith(path)) {
                    path = null;
                    if (e.hasMax() && e.getMax().equals("0")) {
                        path = e.getPath() + ".";
                    } else
                        genElement(s, e, map.getIdentity());
                }
            }
            s.append("</table>\r\n");
        }
        mappings = s.toString();
    }
}
Also used : StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 82 with StructureDefinition

use of org.hl7.fhir.dstu2016may.model.StructureDefinition in project kindling by HL7.

the class ProfileGenerator method generateLogicalModel.

public StructureDefinition generateLogicalModel(ImplementationGuideDefn igd, ResourceDefn r) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setId(r.getRoot().getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + r.getRoot().getName());
    p.setKind(StructureDefinitionKind.LOGICAL);
    p.setAbstract(false);
    p.setUserData("filename", r.getName().toLowerCase());
    p.setUserData("path", igd.getPrefix() + r.getName().toLowerCase() + ".html");
    p.setTitle(r.getName());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    p.setType(r.getRoot().getName());
    ToolingExtensions.setStandardsStatus(p, r.getStatus(), null);
    ToolResourceUtilities.updateUsage(p, igd.getCode());
    p.setName(r.getRoot().getName());
    p.setPublisher("Health Level Seven International" + (r.getWg() == null ? " " + igd.getCommittee() : " (" + r.getWg().getName() + ")"));
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    if (r.getWg() != null) {
        p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, r.getWg().getUrl()));
        ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, r.getWg().getCode());
    }
    p.setDescription("Logical Model: " + r.getDefinition());
    p.setPurpose(r.getRoot().getRequirements());
    if (!p.hasPurpose())
        p.setPurpose(r.getRoot().getRequirements());
    p.setDate(genDate.getTime());
    // DSTU
    p.setStatus(PublicationStatus.fromCode("draft"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    defineElement(null, p, p.getSnapshot().getElement(), r.getRoot(), r.getRoot().getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, "Element", "Element", true);
    addElementConstraintToSnapshot(p);
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    return p;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) HashSet(java.util.HashSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 83 with StructureDefinition

use of org.hl7.fhir.dstu2016may.model.StructureDefinition in project kindling by HL7.

the class ProfileGenerator method convertElements.

public void convertElements(ElementDefn src, StructureDefinition ed, String path) throws Exception {
    ElementDefinition dst = new ElementDefinition();
    if (!ed.hasDifferential())
        ed.setDifferential(new StructureDefinitionDifferentialComponent());
    ed.getDifferential().getElement().add(dst);
    String thisPath = path == null ? "Extension" : path;
    dst.setId(thisPath);
    dst.setPath(thisPath);
    if (!Utilities.noString(src.getProfileName()))
        dst.setSliceName(src.getProfileName());
    dst.setShort(src.getShortDefn());
    dst.setDefinition(preProcessMarkdown(src.getDefinition(), "Element Definition"));
    dst.setComment(preProcessMarkdown(src.getComments(), "Element Comments"));
    if (src.getMaxCardinality() != null) {
        if (src.getMaxCardinality() == Integer.MAX_VALUE)
            dst.setMax("*");
        else
            dst.setMax(src.getMaxCardinality().toString());
    }
    if (src.getMinCardinality() != null)
        dst.setMin(src.getMinCardinality());
    if (src.getFixed() != null)
        dst.setFixed(src.getFixed());
    if (src.hasMustSupport())
        dst.setMustSupport(src.isMustSupport());
    if (src.hasModifier())
        dst.setIsModifier(src.isModifier());
    if (dst.getIsModifier())
        dst.setIsModifierReason(src.getModifierReason());
    if (src.hasSummaryItem() && dst.getPath().contains("."))
        dst.setIsSummaryElement(Factory.newBoolean(src.isSummary()));
    for (Invariant id : src.getStatedInvariants()) dst.addCondition(id.getId());
    // dDst.
    for (TypeRef t : src.getTypes()) {
        if (t.hasParams()) {
            for (String tp : t.getParams()) {
                if (definitions.hasLogicalModel(tp)) {
                    for (String tpn : definitions.getLogicalModel(tp).getImplementations()) {
                        ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
                        String pr = "http://hl7.org/fhir/StructureDefinition/" + tpn;
                        type.addTargetProfile(pr);
                    }
                } else {
                    ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
                    String pr = t.hasProfile() ? t.getProfile() : // this should only happen if t.getParams().size() == 1
                    "http://hl7.org/fhir/StructureDefinition/" + (tp.equals("Any") ? "Resource" : tp);
                    if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference"))
                        type.addTargetProfile(pr);
                    else
                        type.addProfile(pr);
                }
            }
        } else if (t.isWildcardType()) {
            for (String n : TypesUtilities.wildcardTypes(version.toString())) dst.getType(n);
        } else {
            if (definitions != null && definitions.getConstraints().containsKey(t.getName())) {
                ProfiledType ct = definitions.getConstraints().get(t.getName());
                ElementDefinition.TypeRefComponent type = dst.getType(ct.getBaseType());
                type.addProfile("http://hl7.org/fhir/StructureDefinition/" + ct.getName());
            } else if ("Extension.url".equals(path)) {
            // juat don't populate it
            // ElementDefinition.TypeRefComponent tt = dst.addType();
            // tt.setCodeElement(new UriType());
            // tt.getFormatCommentsPre().add("Note: special primitive values do not have an assigned type. e.g. this is compiler magic. XML, JSON and RDF types provided by extension");
            // ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_JSON_TYPE, "string");
            // ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_XML_TYPE, "xs:anyURI");
            // ToolingExtensions.addStringExtension(tt.getCodeElement(), ToolingExtensions.EXT_RDF_TYPE, "xs:anyURI");
            } else {
                ElementDefinition.TypeRefComponent type = dst.getType(t.getName());
                if (t.hasProfile())
                    if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("CodeableReference"))
                        type.addTargetProfile(t.getProfile());
                    else
                        type.addProfile(t.getProfile());
            }
        }
    }
    if (definitions != null) {
        // igtodo - catch this
        for (String mu : definitions.getMapTypes().keySet()) {
            if (src.hasMapping(mu)) {
                addMapping(ed, dst, mu, src.getMapping(mu), null);
            }
        }
    }
    for (String in : src.getInvariants().keySet()) {
        ElementDefinitionConstraintComponent con = new ElementDefinitionConstraintComponent();
        Invariant inv = src.getInvariants().get(in);
        con.setKey(inv.getId());
        if (!con.hasKey()) {
            extensionCounter++;
            con.setKey("exd-" + Integer.toString(extensionCounter));
        }
        con.setRequirements(inv.getRequirements());
        if (Utilities.noString(inv.getSeverity()))
            con.setSeverity(ConstraintSeverity.ERROR);
        else
            con.setSeverity(ConstraintSeverity.fromCode(inv.getSeverity()));
        con.setHuman(inv.getEnglish());
        con.setXpath(inv.getXpath());
        if (!"n/a".equals(inv.getExpression()))
            con.setExpression(inv.getExpression());
        dst.getConstraint().add(con);
    }
    if (src.hasBinding())
        dst.setBinding(generateBinding(src.getBinding()));
    if (src.getElements().isEmpty()) {
        if (path == null)
            throw new Exception("?error parsing extension");
    } else {
        ElementDefn url = src.getElements().get(0);
        if (!url.getName().equals("url"))
            throw new Exception("first child of extension should be 'url', not " + url.getName() + " for structure definition " + ed.getUrl());
        convertElements(url, ed, thisPath + ".url");
        // this pair might leave elements out of order, but we're going to sort them later
        if (!hasValue(src)) {
            ElementDefn value = new ElementDefn();
            value.setName("value[x]");
            value.setMinCardinality(0);
            value.setMaxCardinality(0);
            convertElements(value, ed, thisPath + ".value[x]");
        } else {
            ElementDefn ext = new ElementDefn();
            // can't have an extension if you have a value
            ext.setName("extension");
            ext.setMaxCardinality(0);
            convertElements(ext, ed, thisPath + ".extension");
        }
        if (src.getElements().size() == 2 && src.getElements().get(0).getName().equals("url") && src.getElements().get(1).getName().equals("value[x]")) {
            ElementDefn value = src.getElements().get(1);
            value.setMinCardinality(1);
            convertElements(value, ed, thisPath + ".value[x]");
        } else {
            for (ElementDefn child : src.getElements()) {
                if (child != url) {
                    if (child.getName().startsWith("value") && !child.getName().startsWith("valueSet"))
                        convertElements(child, ed, thisPath + "." + child.getName());
                    else {
                        if (child.getElements().size() == 0 || !child.getElements().get(0).getName().equals("url")) {
                            ElementDefn childUrl = new ElementDefn();
                            childUrl.setName("url");
                            childUrl.setXmlAttribute(true);
                            childUrl.getTypes().add(new TypeRef("uri"));
                            childUrl.setFixed(new UriType(child.getName()));
                            child.getElements().add(0, childUrl);
                        }
                        if (!hasValue(child)) {
                            ElementDefn value = new ElementDefn();
                            value.setName("value[x]");
                            value.setMinCardinality(0);
                            value.setMaxCardinality(0);
                            child.getElements().add(value);
                        }
                        convertElements(child, ed, thisPath + ".extension");
                    }
                }
            }
        }
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) UriType(org.hl7.fhir.r5.model.UriType)

Example 84 with StructureDefinition

use of org.hl7.fhir.dstu2016may.model.StructureDefinition in project kindling by HL7.

the class ProfileGenerator method generate.

public StructureDefinition generate(TypeDefn t) throws Exception {
    genUml(t);
    StructureDefinition p = new StructureDefinition();
    p.setId(t.getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + t.getName());
    p.setKind(StructureDefinitionKind.COMPLEXTYPE);
    p.setAbstract(t.isAbstractType());
    p.setUserData("filename", t.getName().toLowerCase());
    p.setUserData("path", definitions.getSrcFile(t.getName()) + ".html#" + t.getName());
    assert !Utilities.noString(t.typeCode());
    String b = (t.typeCode().equals("Type") ? "Element" : t.typeCode().equals("Structure") ? "BackboneElement" : t.typeCode());
    if (!Utilities.noString(b)) {
        p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + b);
        p.setDerivation(TypeDerivationRule.SPECIALIZATION);
    }
    p.setType(t.getName());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, t.getStandardsStatus(), t.getNormativeVersion());
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName(t.getName());
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for " + t.getName() + " Type: " + t.getDefinition());
    p.setPurpose(t.getRequirements());
    p.setDate(genDate.getTime());
    p.setStatus(t.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    defineElement(null, p, p.getDifferential().getElement(), t, t.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, "Element", b, false);
    p.getDifferential().getElement().get(0).setIsSummaryElement(null);
    reset();
    // now. the snapshot
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    defineElement(null, p, p.getSnapshot().getElement(), t, t.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.DataType, true, "Element", b, true);
    for (ElementDefinition ed : p.getSnapshot().getElement()) if (ed.getBase().getPath().equals(ed.getPath()) && ed.getPath().contains("."))
        generateElementDefinition(p, ed, getParent(ed, p.getSnapshot().getElement()));
    containedSlices.clear();
    addElementConstraintToSnapshot(p);
    p.getDifferential().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).setIsSummaryElement(null);
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    checkHasTypes(p);
    return p;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 85 with StructureDefinition

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

Aggregations

ArrayList (java.util.ArrayList)307 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)226 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)158 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)144 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)105 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)98 IOException (java.io.IOException)91 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)91 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)87 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)83 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)70 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)69 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)67 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)58 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)56 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)50 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)49 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)46 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)46