Search in sources :

Example 1 with Invariant

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

the class PageProcessor method genBestPracticeList.

private void genBestPracticeList(StringBuilder b, ElementDefn e) throws Exception {
    for (Invariant inv : e.getInvariants().values()) {
        if ("best-practice".equals(inv.getSeverity())) {
            b.append("<tr>");
            b.append("<td>");
            b.append(inv.getId());
            b.append("</td>");
            b.append("<td>");
            b.append(inv.getEnglish());
            b.append("</td>");
            b.append("<td>");
            b.append(processMarkdown("best-practice-list", inv.getExplanation(), ""));
            b.append("</td>");
            b.append("</tr>\r\n");
        }
    }
    for (ElementDefn c : e.getElements()) {
        genBestPracticeList(b, c);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 2 with Invariant

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

the class PageProcessor method generateConstraintsTable.

private void generateConstraintsTable(String path, ElementDefn e, Map<String, String> invs, boolean base, String prefix) throws Exception {
    for (Invariant inv : e.getInvariants().values()) {
        String s = "";
        if (base)
            s = "<tr><td><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>(base)</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>";
        else
            s = "<tr><td><b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b></td><td>" + presentLevel(inv) + "</td><td>" + path + "</td><td>" + Utilities.escapeXml(inv.getEnglish()) + "</td><td><span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>";
        if (!Utilities.noString(inv.getExplanation()))
            s = s + "<br/>This is (only) a best practice guideline because: <blockquote>" + processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>";
        s = s + "</td></tr>";
        invs.put(inv.getId(), s);
    }
    for (ElementDefn c : e.getElements()) {
        generateConstraintsTable(path + "." + c.getName(), c, invs, false, prefix);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 3 with Invariant

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

the class PageProcessor method generateConstraints.

private void generateConstraints(String path, ElementDefn e, Map<String, String> invs, boolean base, String prefix) throws Exception {
    for (Invariant inv : e.getInvariants().values()) {
        String s = "";
        if (base)
            s = "<li>" + presentLevel(inv) + " <b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b>: " + Utilities.escapeXml(inv.getEnglish()) + " (<a href=\"http://hl7.org/fhirpath\">expression</a>: <span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>)";
        else
            s = "<li>" + presentLevel(inv) + " <b title=\"Formal Invariant Identifier\">" + inv.getId() + "</b>: On " + path + ": " + Utilities.escapeXml(inv.getEnglish()) + " (<a href=\"http://hl7.org/fhirpath\">expression</a> on " + presentPath(path) + ": <span style=\"font-family: Courier New, monospace\">" + Utilities.escapeXml(inv.getExpression()) + "</span>)";
        if (!Utilities.noString(inv.getExplanation()))
            s = s + ". This is (only) a best practice guideline because: <blockquote>" + processMarkdown("best practice guideline", inv.getExplanation(), prefix) + "</blockquote>";
        invs.put(inv.getId(), s + "</li>");
    }
    for (ElementDefn c : e.getElements()) {
        generateConstraints(path + "." + c.getName(), c, invs, false, prefix);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 4 with Invariant

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

the class OldSpreadsheetParser method parseProfileSheet.

private ConstraintStructure parseProfileSheet(Definitions definitions, Profile ap, String n, List<String> namedSheets, boolean published, String usage, List<ValidationMessage> issues, WorkGroup wg, String fmm) throws Exception {
    Sheet sheet;
    ResourceDefn resource = new ResourceDefn();
    sheet = loadSheet(n + "-Inv");
    Map<String, Invariant> invariants = null;
    if (sheet != null) {
        invariants = readInvariants(sheet, n, n + "-Inv");
    } else {
        invariants = new HashMap<String, Invariant>();
    }
    sheet = loadSheet(n);
    if (sheet == null)
        throw new Exception("The StructureDefinition referred to a tab by the name of '" + n + "', but no tab by the name could be found");
    for (int row = 0; row < sheet.rows.size(); row++) {
        ElementDefn e = processLine(resource, sheet, row, invariants, true, ap, row == 0);
        if (e != null)
            for (TypeRef t : e.getTypes()) {
                if (t.getProfile() != null && !t.getName().equals("Extension") && t.getProfile().startsWith("#")) {
                    if (!namedSheets.contains(t.getProfile().substring(1)))
                        namedSheets.add(t.getProfile().substring(1));
                }
            }
    }
    sheet = loadSheet(n + "-Extensions");
    if (sheet != null) {
        int row = 0;
        while (row < sheet.rows.size()) {
            if (sheet.getColumn(row, "Code").startsWith("!"))
                row++;
            else
                row = processExtension(resource.getRoot().getElementByName(definitions, "extensions", true, false), sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
        }
    }
    sheet = loadSheet(n + "-Search");
    if (sheet != null) {
        readSearchParams(resource, sheet, true);
    }
    if (invariants != null) {
        for (Invariant inv : invariants.values()) {
            if (Utilities.noString(inv.getContext()))
                throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " has no context");
            else {
                ElementDefn ed = findContext(resource.getRoot(), inv.getContext(), "Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " Context");
                // TODO: Need to resolve context based on element name, not just path
                if (ed.getName().endsWith("[x]") && !inv.getContext().endsWith("[x]"))
                    inv.setFixedName(inv.getContext().substring(inv.getContext().lastIndexOf(".") + 1));
                ed.getInvariants().put(inv.getId(), inv);
                if (Utilities.noString(inv.getXpath())) {
                    throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") has no XPath statement");
                } else if (inv.getXpath().contains("\""))
                    throw new Exception("Type " + resource.getRoot().getName() + " Invariant " + inv.getId() + " (" + inv.getEnglish() + ") contains a \" character");
            // if (Utilities.noString(inv.getExpression()))
            // throw new Exception("Type "+resource.getRoot().getName()+" Invariant "+inv.getId()+" ("+inv.getEnglish()+") has no Expression statement (in FHIRPath format)");
            }
        }
    }
    resource.getRoot().setProfileName(n);
    if (n.toLowerCase().equals(ap.getId()))
        throw new Exception("Duplicate Profile Name: Package id " + ap.getId() + " and profile id " + n.toLowerCase() + " are the same");
    if (profileIds.containsKey(n.toLowerCase()))
        throw new Exception("Duplicate Profile Name: " + n.toLowerCase() + " in " + ap.getId() + ", already registered in " + profileIds.get(n.toLowerCase()).getOwner());
    ConstraintStructure p = new ConstraintStructure(n.toLowerCase(), resource.getRoot().getProfileName(), resource, ig != null ? ig : definitions.getUsageIG(usage, "Parsing " + name), wg, fmm, Utilities.existsInList(ap.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
    p.setOwner(ap.getId());
    profileIds.put(n.toLowerCase(), p);
    return p;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with Invariant

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

the class OldSpreadsheetParser method parseConformancePackage.

public void parseConformancePackage(Profile ap, Definitions definitions, String folder, String usage, List<ValidationMessage> issues, WorkGroup wg) throws Exception {
    try {
        isProfile = true;
        this.folder = folder;
        checkMappings(ap);
        Sheet sheet = loadSheet("Bindings");
        if (sheet != null)
            readBindings(sheet);
        sheet = loadSheet("Metadata");
        for (int row = 0; row < sheet.rows.size(); row++) {
            String n = sheet.getColumn(row, "Name");
            String v = sheet.getColumn(row, "Value");
            if (n != null && v != null) {
                if (ap.getMetadata().containsKey(n))
                    ap.getMetadata().get(n).add(v);
                else {
                    ArrayList<String> vl = new ArrayList<String>();
                    vl.add(v);
                    ap.getMetadata().put(n, vl);
                }
            }
        }
        if (!Utilities.noString(ap.metadata("category")))
            usage = ap.metadata("category");
        if (ap.hasMetadata("name"))
            ap.setTitle(ap.metadata("name"));
        if (ap.hasMetadata("introduction"))
            ap.setIntroduction(Utilities.path(folder, ap.metadata("introduction")));
        if (ap.hasMetadata("notes"))
            ap.setNotes(Utilities.path(folder, ap.metadata("notes")));
        if (!ap.hasMetadata("id"))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " no 'id' found in metadata");
        if (!ap.metadata("id").matches(FormatUtilities.ID_REGEX))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' is not a valid id");
        if (wg == null)
            wg = workgroups.get(ap.metadata("workgroup"));
        if (wg == null)
            wg = committee;
        if (wg == null)
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " : no workgroup value in the metadata");
        if (!ap.metadata("id").equals(ap.metadata("id").toLowerCase()))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' must be all lowercase");
        this.profileExtensionBase = ap.metadata("extension.uri");
        if (ig == null || ig.isCore()) {
            if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/") && !profileExtensionBase.startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
                throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/ for " + ap.getId());
        } else {
            if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
                throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "- for " + ap.getId());
        }
        Map<String, Invariant> invariants = null;
        sheet = loadSheet("Extensions-Inv");
        if (sheet != null) {
            invariants = readInvariants(sheet, "", "Extensions-Inv");
        }
        sheet = loadSheet("Extensions");
        if (sheet != null) {
            int row = 0;
            while (row < sheet.rows.size()) {
                if (sheet.getColumn(row, "Code").startsWith("!"))
                    row++;
                else
                    row = processExtension(null, sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
            }
        }
        List<String> namedSheets = new ArrayList<String>();
        if (ap.getMetadata().containsKey("published.structure")) {
            for (String n : ap.getMetadata().get("published.structure")) {
                if (!Utilities.noString(n)) {
                    if (ig != null && !ig.isCore() && !n.toLowerCase().startsWith(ig.getCode() + "-"))
                        throw new Exception("Error: published structure names must start with the implementation guide code (" + ig.getCode() + "-)");
                    String fmm = ap.metadata("fmm-" + n);
                    if (Utilities.noString(fmm))
                        fmm = ap.metadata("fmm");
                    if (Utilities.noString(fmm))
                        // default fmm value
                        fmm = "1";
                    ap.getProfiles().add(parseProfileSheet(definitions, ap, n, namedSheets, true, usage, issues, wg, fmm));
                }
            }
        }
        int i = 0;
        while (i < namedSheets.size()) {
            String fmm = ap.metadata("fmm-" + namedSheets.get(i));
            if (Utilities.noString(fmm))
                fmm = ap.metadata("fmm");
            if (Utilities.noString(fmm))
                // default fmm value
                fmm = "1";
            ap.getProfiles().add(parseProfileSheet(definitions, ap, namedSheets.get(i), namedSheets, false, usage, issues, wg, fmm));
            i++;
        }
        if (namedSheets.isEmpty() && xls.getSheets().containsKey("Search"))
            readSearchParams(ap, xls.getSheets().get("Search"), this.profileExtensionBase);
        if (xls.getSheets().containsKey("Operations"))
            readOperations(ap.getOperations(), loadSheet("Operations"));
    } catch (Exception e) {
        throw new Exception("exception parsing pack " + ap.getSource() + ": " + e.getMessage(), e);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ArrayList(java.util.ArrayList) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

Invariant (org.hl7.fhir.definitions.model.Invariant)21 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)10 ArrayList (java.util.ArrayList)8 TypeRef (org.hl7.fhir.definitions.model.TypeRef)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)5 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)5 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)4 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)4 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)3 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)3 StringType (org.hl7.fhir.r5.model.StringType)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 IParser (ca.uhn.fhir.parser.IParser)2 SingleValidationMessage (ca.uhn.fhir.validation.SingleValidationMessage)2 ValidationResult (ca.uhn.fhir.validation.ValidationResult)2 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)2 TypeDefn (org.hl7.fhir.definitions.model.TypeDefn)2 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)2