Search in sources :

Example 1 with PrimitiveType

use of org.hl7.fhir.r4.model.PrimitiveType in project kindling by HL7.

the class Publisher method genPrimitiveTypeProfile.

private void genPrimitiveTypeProfile(PrimitiveType t) throws Exception {
    StructureDefinition profile = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(t);
    if (page.getProfiles().has(profile.getUrl()))
        throw new Exception("Duplicate Profile URL " + profile.getUrl());
    page.getProfiles().see(profile, page.packageInfo());
    t.setProfile(profile);
// DataTypeTableGenerator dtg = new DataTypeTableGenerator(page.getFolders().dstDir, page, t.getCode(), true);
// t.setProfile(profile);
// t.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
// t.getProfile().getText().getDiv().getChildNodes().add(dtg.generate(t));
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with PrimitiveType

use of org.hl7.fhir.r4.model.PrimitiveType in project kindling by HL7.

the class Publisher method processProfiles.

@SuppressWarnings("unchecked")
private void processProfiles() throws Exception {
    page.log(" ...process profiles (base)", LogMessageType.Process);
    // first, for each type and resource, we build it's master profile
    for (DefinedCode t : page.getDefinitions().getPrimitives().values()) {
        if (t instanceof PrimitiveType)
            genPrimitiveTypeProfile((PrimitiveType) t);
        else
            genPrimitiveTypeProfile((DefinedStringPattern) t);
    }
    genXhtmlProfile();
    for (TypeDefn t : page.getDefinitions().getTypes().values()) genTypeProfile(t);
    for (TypeDefn t : page.getDefinitions().getInfrastructure().values()) genTypeProfile(t);
    page.log(" ...process profiles (resources)", LogMessageType.Process);
    for (ResourceDefn r : page.getDefinitions().getBaseResources().values()) {
        r.setConformancePack(makeConformancePack(r));
        r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
        if (page.getProfiles().has(r.getProfile().getUrl()))
            throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
        page.getProfiles().see(r.getProfile(), page.packageInfo());
        ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
        r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
    }
    for (String rn : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn r = page.getDefinitions().getResourceByName(rn);
        r.setConformancePack(makeConformancePack(r));
        r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", false));
        if (page.getProfiles().has(r.getProfile().getUrl()))
            throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
        page.getProfiles().see(r.getProfile(), page.packageInfo());
        ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
        r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", false));
    }
    for (ResourceDefn r : page.getDefinitions().getResourceTemplates().values()) {
        r.setConformancePack(makeConformancePack(r));
        r.setProfile(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(r.getConformancePack(), r, "core", true));
        ResourceTableGenerator rtg = new ResourceTableGenerator(page.getFolders().dstDir, page, null, true, page.getVersion());
        r.getProfile().getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
        r.getProfile().getText().getDiv().getChildNodes().add(rtg.generate(r, "", true));
        if (page.getProfiles().has(r.getProfile().getUrl()))
            throw new Exception("Duplicate Profile URL " + r.getProfile().getUrl());
        page.getProfiles().see(r.getProfile(), page.packageInfo());
    }
    for (ProfiledType pt : page.getDefinitions().getConstraints().values()) {
        genProfiledTypeProfile(pt);
    }
    page.log(" ...process profiles (extensions)", LogMessageType.Process);
    for (StructureDefinition ex : page.getWorkerContext().getExtensionDefinitions()) processExtension(ex);
    for (ResourceDefn r : page.getDefinitions().getResources().values()) {
        // boolean logged = false;
        for (Profile ap : r.getConformancePackages()) {
            // logged = true;
            for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), r);
        }
    }
    page.log(" ...process profiles (packs)", LogMessageType.Process);
    // we have profiles scoped by resources, and stand alone profiles
    for (Profile ap : page.getDefinitions().getPackList()) {
        // page.log(" ...  pack "+ap.getId(), LogMessageType.Process);
        for (ConstraintStructure p : ap.getProfiles()) processProfile(ap, p, ap.getId(), null);
    }
    page.log(" ...process logical models", LogMessageType.Process);
    for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
        for (LogicalModel lm : ig.getLogicalModels()) {
            page.log(" ...process logical model " + lm.getId(), LogMessageType.Process);
            if (lm.getDefinition() == null)
                lm.setDefinition(new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generateLogicalModel(ig, lm.getResource()));
        }
    }
    // now, validate the profiles
    for (Profile ap : page.getDefinitions().getPackList()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
    for (ResourceDefn r : page.getDefinitions().getResources().values()) for (Profile ap : r.getConformancePackages()) for (ConstraintStructure p : ap.getProfiles()) validateProfile(p);
    page.log(" ...Check FHIR Path Expressions", LogMessageType.Process);
    StringBuilder b = new StringBuilder();
    FHIRPathEngine fp = new FHIRPathEngine(page.getWorkerContext());
    fp.setHostServices(page.getExpressionResolver());
    for (FHIRPathUsage p : fpUsages) {
        checkExpression(b, fp, p);
    }
    TextFile.stringToFile(b.toString(), Utilities.path(page.getFolders().dstDir, "fhirpaths.txt"));
    checkAllOk();
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) ResourceTableGenerator(org.hl7.fhir.definitions.generators.specification.ResourceTableGenerator) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Profile(org.hl7.fhir.definitions.model.Profile) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) LogicalModel(org.hl7.fhir.definitions.model.LogicalModel) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) FHIRPathUsage(org.hl7.fhir.definitions.validation.FHIRPathUsage) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Example 3 with PrimitiveType

use of org.hl7.fhir.r4.model.PrimitiveType in project kindling by HL7.

the class PageProcessor method genDataTypeMappings.

private String genDataTypeMappings(String name) throws Exception {
    if (name.equals("primitives")) {
        StringBuilder b = new StringBuilder();
        b.append("<table class=\"grid\">\r\n");
        b.append("<tr>");
        b.append("<td><b>Data Type</b></td>");
        b.append("<td><b>V2</b></td>");
        b.append("<td><b>RIM</b></td>");
        b.append("</tr>");
        List<String> names = new ArrayList<String>();
        names.addAll(definitions.getPrimitives().keySet());
        Collections.sort(names);
        for (String n : names) {
            DefinedCode dc = definitions.getPrimitives().get(n);
            if (dc instanceof PrimitiveType) {
                PrimitiveType pt = (PrimitiveType) dc;
                b.append("<tr>");
                b.append("<td>").append(n).append("</td>");
                b.append("<td>").append(pt.getV2()).append("</td>");
                b.append("<td>").append(pt.getV3()).append("</td>");
                b.append("</tr>");
            }
        }
        b.append("</table>\r\n");
        return b.toString();
    } else {
        List<ElementDefn> list = new ArrayList<ElementDefn>();
        // list.addAll(definitions.getStructures().values());
        // list.addAll(definitions.getTypes().values());
        // list.addAll(definitions.getInfrastructure().values());
        list.add(definitions.getElementDefn(name));
        MappingsGenerator maps = new MappingsGenerator(definitions);
        maps.generate(list);
        return maps.getMappings();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ArrayList(java.util.ArrayList) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) MappingsGenerator(org.hl7.fhir.definitions.generators.specification.MappingsGenerator)

Example 4 with PrimitiveType

use of org.hl7.fhir.r4.model.PrimitiveType in project kindling by HL7.

the class SvgGenerator method drawClass.

private ClassItem drawClass(XMLWriter xml, ElementDefn e, boolean isRoot, ResourceDefn resource, boolean link, String path, DefinedCode primitive, StandardsStatus status) throws Exception {
    ClassItem item = classes.get(e);
    String tn = e.getName();
    if (!definitions.hasPrimitiveType(tn) && !tn.equals("xhtml")) {
        tn = Utilities.capitalize(tn);
    }
    ResourceDefn r = definitions.hasResource(tn) ? definitions.getResourceByName(tn) : null;
    if (r == null) {
        r = definitions.getBaseResources().get(tn);
    }
    xml.attribute("id", "n" + (++nc));
    xml.enter("g");
    xml.attribute("x", Double.toString(item.left));
    xml.attribute("y", Double.toString(item.top));
    xml.attribute("rx", "4");
    xml.attribute("ry", "4");
    xml.attribute("width", Double.toString(item.width));
    xml.attribute("height", Double.toString(item.height));
    xml.attribute("filter", "url(#shadow" + id + ")");
    if (r != null) {
        xml.attribute("style", "fill:" + r.getStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = r.getStatus();
    } else if (e == null || e.getStandardsStatus() == null)
        xml.attribute("style", "fill:" + (status == null ? "#ffffff" : status.getColorSvg()) + ";stroke:black;stroke-width:1");
    else {
        xml.attribute("style", "fill:" + e.getStandardsStatus().getColorSvg() + ";stroke:black;stroke-width:1");
        status = e.getStandardsStatus();
    }
    if (!makeTargets)
        xml.attribute("id", "n" + (++nc));
    else
        xml.attribute("id", item.getId());
    xml.element("rect", null);
    xml.attribute("x1", Double.toString(item.left));
    xml.attribute("y1", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("x2", Double.toString(item.left + item.width));
    xml.attribute("y2", Double.toString(item.top + HEADER_HEIGHT + GAP_HEIGHT * 2));
    xml.attribute("style", "stroke:dimgrey;stroke-width:1");
    xml.attribute("id", "n" + (++nc));
    xml.element("line", null);
    xml.attribute("x", Double.toString(item.left + item.width / 2));
    xml.attribute("y", Double.toString(item.top + HEADER_HEIGHT));
    xml.attribute("fill", "black");
    if (isRoot)
        xml.attribute("class", "diagram-class-title  diagram-class-resource");
    else
        xml.attribute("class", "diagram-class-title");
    if (link) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.attribute("xlink:href", makeRel(definitions.getSrcFile(tn) + ".html#" + tn));
        xml.attribute("id", "n" + (++nc));
        xml.enter("a");
        xml.text(tn);
        xml.exit("a");
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (isRoot) {
        xml.attribute("id", "n" + (++nc));
        if (e.isAbstractType()) {
            xml.attribute("style", "font-style: italic");
        }
        xml.enter("text");
        xml.text(tn);
        if (Utilities.noString(e.typeCode())) {
            xml.text(" \u00ABResource\u00BB");
        } else {
            xml.attribute("class", "diagram-class-title-link");
            xml.enter("tspan");
            xml.text(" (");
            if ("Logical".equals(e.typeCode()))
                xml.attribute("xlink:href", prefix + definitions.getBaseLink());
            else
                xml.attribute("xlink:href", prefix + definitions.getSrcFile(e.typeCode()) + ".html#" + e.typeCode());
            xml.attribute("class", "diagram-class-reference");
            xml.attribute("id", "n" + (++nc));
            xml.attribute("style", "font-style: italic");
            if ("Logical".equals(e.typeCode())) {
                xml.element("a", "Base");
            } else {
                xml.element("a", e.typeCode());
            }
            xml.text(")");
            xml.exit("tspan");
        }
        if ("Logical".equals(e.typeCode())) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#pattern"));
            xml.enter("a");
            xml.text("«Pattern»");
            xml.exit("a");
        }
        if (definitions.getBaseResources().containsKey(e.getName()) && definitions.getBaseResources().get(e.getName()).isInterface()) {
            xml.text(" ");
            xml.attribute("xlink:href", makeRel("uml.html#interface"));
            xml.enter("a");
            xml.text("«Interface»");
            xml.exit("a");
        }
        xml.exit("text");
    } else if (e.hasStatedType()) {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", e.getStatedType());
    } else {
        xml.attribute("id", "n" + (++nc));
        xml.element("text", tn);
    }
    if (attributes) {
        if (primitive != null) {
            if (primitive instanceof PrimitiveType)
                addValueAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT, getXsi(primitive).split("\\|"));
        } else {
            int i = 0;
            for (ElementDefn c : e.getElements()) {
                if (isAttribute(c)) {
                    i++;
                    addAttribute(xml, item.left, item.top + HEADER_HEIGHT + GAP_HEIGHT * 2 + LINE_HEIGHT * i, c, path, LINE_HEIGHT, item.width);
                    String[] texts = textForAttribute(c);
                    i = i + texts.length - 1;
                }
            }
        }
    }
    xml.exit("g");
    if (attributes) {
        for (ElementDefn c : e.getElements()) {
            if (!isAttribute(c)) {
                if (Utilities.noString(c.typeCode()) || !c.typeCode().startsWith("@")) {
                    links.add(new Link(item, drawClass(xml, c, false, resource, false, path + "." + c.getName(), null, status), LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                } else {
                    ClassItem target = getItemForPath(resource, c.typeCode().substring(1));
                    links.add(new Link(item, target, LinkType.COMPOSITION, c.getName(), c.describeCardinality(), PointKind.unknown, baseUrl(path) + path + "." + c.getName(), c.getEnhancedDefinition()));
                }
            }
        }
    }
    return item;
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 5 with PrimitiveType

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

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)18 EqualsBuilder (org.apache.commons.lang3.builder.EqualsBuilder)12 IPrimitiveType (org.hl7.fhir.instance.model.api.IPrimitiveType)12 IOException (java.io.IOException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 PrimitiveType (org.hl7.fhir.r5.model.PrimitiveType)8 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)8 URISyntaxException (java.net.URISyntaxException)6 PrimitiveType (org.hl7.fhir.definitions.model.PrimitiveType)6 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 PrimitiveType (org.hl7.fhir.dstu3.model.PrimitiveType)5 PrimitiveType (org.hl7.fhir.r4b.model.PrimitiveType)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 URI (java.net.URI)4 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)4 StringType (org.hl7.fhir.dstu3.model.StringType)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3