Search in sources :

Example 6 with ProfiledType

use of org.hl7.fhir.r5.model.TypeDetails.ProfiledType in project kindling by HL7.

the class SourceParser method loadCompositeType.

private String loadCompositeType(String n, Map<String, org.hl7.fhir.definitions.model.TypeDefn> map, String fmm, boolean isAbstract) throws Exception {
    TypeParser tp = new TypeParser(version.toString());
    List<TypeRef> ts = tp.parse(n, false, null, context, true);
    definitions.getKnownTypes().addAll(ts);
    StandardsStatus status = loadStatus(n);
    String nv = loadNormativeVersion(n);
    try {
        TypeRef t = ts.get(0);
        File csv = new CSFile(dtDir + t.getName().toLowerCase() + ".xml");
        if (csv.exists()) {
            OldSpreadsheetParser p = new OldSpreadsheetParser("core", new CSFileInputStream(csv), csv.getName(), csv.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, true, ini, wg("fhir"), definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
            org.hl7.fhir.definitions.model.TypeDefn el = p.parseCompositeType();
            el.setFmmLevel(fmm);
            el.setStandardsStatus(status);
            el.setNormativeVersion(nv);
            map.put(t.getName(), el);
            genTypeProfile(el);
            errors.addAll(p.getErrors());
            return el.getName();
        } else {
            String p = ini.getStringProperty("types", n);
            csv = new CSFile(dtDir + p.toLowerCase() + ".xml");
            if (!csv.exists())
                throw new Exception("unable to find a definition for " + n + " in " + p);
            XLSXmlParser xls = new XLSXmlParser(new CSFileInputStream(csv), csv.getAbsolutePath());
            new XLSXmlNormaliser(csv.getAbsolutePath(), exceptionIfExcelNotNormalised).go();
            Sheet sheet = xls.getSheets().get("Restrictions");
            boolean found = false;
            for (int i = 0; i < sheet.rows.size(); i++) {
                if (sheet.getColumn(i, "Name").equals(n)) {
                    found = true;
                    Invariant inv = new Invariant();
                    inv.setId(n);
                    inv.setEnglish(sheet.getColumn(i, "Rules"));
                    inv.setOcl(sheet.getColumn(i, "OCL"));
                    inv.setXpath(sheet.getColumn(i, "XPath"));
                    inv.setExpression(sheet.getColumn(i, "Expression"));
                    inv.setExplanation(sheet.getColumn(i, "Explanation"));
                    inv.setTurtle(sheet.getColumn(i, "RDF"));
                    ProfiledType pt = new ProfiledType();
                    pt.setDefinition(sheet.getColumn(i, "Definition"));
                    pt.setDescription(sheet.getColumn(i, "Rules"));
                    String structure = sheet.getColumn(i, "Structure");
                    if (!Utilities.noString(structure)) {
                        String[] parts = structure.split("\\;");
                        for (String pp : parts) {
                            String[] words = pp.split("\\=");
                            pt.getRules().put(words[0], words[1]);
                        }
                    }
                    pt.setName(n);
                    pt.setBaseType(p);
                    pt.setInvariant(inv);
                    definitions.getConstraints().put(n, pt);
                }
            }
            if (!found)
                throw new Exception("Unable to find definition for " + n);
            return n;
        }
    } catch (Exception e) {
        throw new Exception("Unable to load " + n + ": " + e.getMessage(), e);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) XLSXmlNormaliser(org.hl7.fhir.utilities.xls.XLSXmlNormaliser) CSFile(org.hl7.fhir.utilities.CSFile) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 7 with ProfiledType

use of org.hl7.fhir.r5.model.TypeDetails.ProfiledType 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 8 with ProfiledType

use of org.hl7.fhir.r5.model.TypeDetails.ProfiledType in project kindling by HL7.

the class SvgGenerator method determineMetrics.

private Point determineMetrics(String[] classNames) throws Exception {
    double width = textWidth("Element") * 1.8;
    double height = HEADER_HEIGHT + GAP_HEIGHT * 2;
    // if ("true".equals(ini.getStringProperty("diagram", "element-attributes"))) {
    // height = height + LINE_HEIGHT + GAP_HEIGHT;
    // width = textWidth("extension : Extension 0..*");
    // }
    Point p = new Point(0, 0, PointKind.unknown);
    ClassItem item = new ClassItem(p.x, p.y, width, height, id);
    classes.put(null, item);
    double x = item.right() + MARGIN_X;
    double y = item.bottom() + MARGIN_Y;
    if (classNames != null) {
        for (String cn : classNames) {
            if (definitions.getPrimitives().containsKey(cn)) {
                DefinedCode cd = definitions.getPrimitives().get(cn);
                ElementDefn fake = new ElementDefn();
                fake.setName(cn);
                fakes.put(cn, fake);
                if (cd instanceof DefinedStringPattern)
                    p = determineMetrics(fake, classes.get(fakes.get(((DefinedStringPattern) cd).getBase())), cn, false, cd);
                else
                    p = determineMetrics(fake, item, cn, false, cd);
            } else if ("xhtml".equals(cn)) {
                ElementDefn fake = new ElementDefn();
                fake.setName("xhtml");
                fakes.put("xhtml", fake);
                DefinedCode cd = new DefinedCode("xhtml", "XHTML for resource narrative", null);
                p = determineMetrics(fake, item, cn, false, cd);
            } else if (definitions.getConstraints().containsKey(cn)) {
                ProfiledType cd = definitions.getConstraints().get(cn);
                ElementDefn ed = definitions.getElementDefn(cd.getBaseType());
                ClassItem parentClss = classes.get(ed);
                ElementDefn fake = new ElementDefn();
                fake.setName(cn);
                fakes.put(cn, fake);
                p = determineMetrics(fake, parentClss, cn, false, null);
            } else {
                ElementDefn c = definitions.getElementDefn(cn);
                p = determineMetrics(c, item, c.getName(), false, null);
            }
            x = Math.max(x, p.x + MARGIN_X);
            y = Math.max(y, p.y + MARGIN_Y);
        }
    }
    return new Point(x, y, PointKind.unknown);
}
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 9 with ProfiledType

use of org.hl7.fhir.r5.model.TypeDetails.ProfiledType in project kindling by HL7.

the class TurtleSpecGenerator method renderType.

private int renderType(int indent, int w, TypeRef t) throws IOException {
    if (t.isXhtml())
        write("fhir:value \"[escaped xhtml]\"^^xsd:string");
    else if (t.getName().startsWith("@"))
        write("<a href=\"#ttl-" + t.getName().substring(1) + "\"><span style=\"color: DarkViolet\">See " + t.getName().substring(1) + "</span></a>");
    else if (definitions.getConstraints().containsKey(t.getName())) {
        ProfiledType pt = definitions.getConstraints().get(t.getName());
        write("<a href=\"" + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
        w = w + pt.getBaseType().length() + 2;
        write("(<a style=\"color:navy\" href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
    } else
        write("<a href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
    if (t.hasParams()) {
        write("(");
        boolean firstp = true;
        List<String> ap = new ArrayList<>();
        for (String p : t.getParams()) {
            if (definitions.hasLogicalModel(p))
                ap.addAll(definitions.getLogicalModel(p).getImplementations());
            else
                ap.add(p);
        }
        Collections.sort(ap);
        for (String p : ap) {
            if (!firstp) {
                write("|");
                w++;
            }
            // again, p.length() could be wrong if this is an extension, but then it won't wrap
            if (w + p.length() > 80) {
                write("\r\n  ");
                for (int j = 0; j < indent; j++) write(" ");
                w = indent + 2;
            }
            w = w + p.length();
            // TODO: Display action and/or profile information
            if (p.equals("Any")) {
                write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
            } else if (t.getName().equals("Reference") && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
                write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
            else
                write("<a href=\"" + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
            firstp = false;
        }
        write(")");
        w++;
    }
    return w;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) ArrayList(java.util.ArrayList)

Example 10 with ProfiledType

use of org.hl7.fhir.r5.model.TypeDetails.ProfiledType in project kindling by HL7.

the class XmlSpecGenerator method writeTypeLinks.

private int writeTypeLinks(ElementDefn elem, int indent) throws Exception {
    write(" <span style=\"color: darkgreen\">");
    int i = 0;
    // this is wrong if the type is an attribute, but the wrapping concern shouldn't apply in this case, so this is ok
    int w = indent + 12 + elem.getName().length();
    for (TypeRef t : elem.getTypes()) {
        if (i > 0) {
            write("|");
            w++;
        }
        if (w + t.getName().length() > 80) {
            write("\r\n  ");
            for (int j = 0; j < indent; j++) write(" ");
            w = indent + 2;
        }
        // again, could be wrong if this is an extension, but then it won't wrap
        w = w + t.getName().length();
        if (t.isXhtml() || t.getName().equals("list"))
            write(t.getName());
        else if (t.getName().equals("Extension") && t.getParams().size() == 0 && !Utilities.noString(t.getProfile()))
            write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
        else if (definitions.getConstraints().containsKey(t.getName())) {
            ProfiledType pt = definitions.getConstraints().get(t.getName());
            write("<a href=\"" + (dtRoot + definitions.getSrcFile(pt.getBaseType()) + ".html#" + pt.getBaseType() + "\">" + pt.getBaseType()) + "</a>");
            w = w + pt.getBaseType().length() + 2;
            write("(<a style=\"color:navy\" href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>)");
        } else
            write("<a href=\"" + (dtRoot + definitions.getSrcFile(t.getName()) + ".html#" + t.getName() + "\">" + t.getName()) + "</a>");
        if (t.hasParams()) {
            write("(");
            boolean firstp = true;
            List<String> ap = new ArrayList<>();
            for (String p : t.getParams()) {
                if (definitions.hasLogicalModel(p))
                    ap.addAll(definitions.getLogicalModel(p).getImplementations());
                else
                    ap.add(p);
            }
            Collections.sort(ap);
            for (String p : ap) {
                if (!firstp) {
                    write("|");
                    w++;
                }
                // again, p.length() could be wrong if this is an extension, but then it won't wrap
                if (w + p.length() > 80) {
                    write("\r\n  ");
                    for (int j = 0; j < indent; j++) write(" ");
                    w = indent + 2;
                }
                w = w + p.length();
                // TODO: Display action and/or profile information
                if (p.equals("Any")) {
                    write("<a href=\"" + prefix + "resourcelist.html" + "\">" + p + "</a>");
                } else if (t.getName().equals("Reference") && t.getParams().size() == 1 && !Utilities.noString(t.getProfile()))
                    write("<a href=\"" + prefix + t.getProfile() + "\"><span style=\"color: DarkViolet\">@" + t.getProfile().substring(1) + "</span></a>");
                else
                    write("<a href=\"" + (dtRoot + definitions.getSrcFile(p) + ".html#" + p) + "\">" + p + "</a>");
                firstp = false;
            }
            write(")");
            w++;
        }
        i++;
    }
    write("</span>");
    return w;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)19 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)14 ArrayList (java.util.ArrayList)11 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)9 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 TypeRef (org.hl7.fhir.definitions.model.TypeRef)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 IOException (java.io.IOException)5 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)5 URISyntaxException (java.net.URISyntaxException)4 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)4 ProfiledType (org.hl7.fhir.r4.model.TypeDetails.ProfiledType)4 ProfiledType (org.hl7.fhir.r4b.model.TypeDetails.ProfiledType)4 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)4 ProfiledType (org.hl7.fhir.r5.model.TypeDetails.ProfiledType)4 FileNotFoundException (java.io.FileNotFoundException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 List (java.util.List)3 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)3