Search in sources :

Example 36 with ResourceDefn

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

the class ExampleInspector method testSearchParameters.

private void testSearchParameters(org.w3c.dom.Element xe, String rn, boolean inBundle) throws FHIRException {
    ResourceDefn r = definitions.getResources().get(rn);
    for (SearchParameterDefn sp : r.getSearchParams().values()) {
        if (!sp.isXPathDone() && !Utilities.noString(sp.getXPath())) {
            try {
                sp.setXPathDone(true);
                NamespaceContext context = new NamespaceContextMap("f", "http://hl7.org/fhir", "h", "http://www.w3.org/1999/xhtml");
                XPathFactory factory = XPathFactory.newInstance();
                XPath xpath = factory.newXPath();
                xpath.setNamespaceContext(context);
                XPathExpression expression;
                expression = inBundle ? xpath.compile("/f:Bundle/f:entry/f:resource/" + sp.getXPath()) : xpath.compile("/" + sp.getXPath());
                NodeList resultNodes = (NodeList) expression.evaluate(xe, XPathConstants.NODESET);
                if (resultNodes.getLength() > 0)
                    sp.setWorks(true);
            } catch (Exception e1) {
                throw new FHIRException("Xpath \"" + sp.getXPath() + "\" execution failed: " + e1.getMessage(), e1);
            }
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) NamespaceContext(javax.xml.namespace.NamespaceContext) NamespaceContextMap(org.hl7.fhir.utilities.xml.NamespaceContextMap) NodeList(org.w3c.dom.NodeList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ValidationException(org.everit.json.schema.ValidationException) MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 37 with ResourceDefn

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

the class BookMaker method addContent.

private void addContent(XhtmlNode body) throws Exception {
    List<String> list = new ArrayList<String>();
    loadResources(list, page.getDefinitions().getResources().keySet());
    XhtmlNode e = body.getElement("contents");
    XhtmlNode div = body.addTag(body.getChildNodes().indexOf(e), "div");
    body.getChildNodes().remove(e);
    List<String> links = new ArrayList<String>();
    LevelCounter lvl = new LevelCounter();
    lvl.l1 = 0;
    for (Navigation.Category s : page.getNavigation().getCategories()) {
        lvl.l1++;
        // div.addTag("div").setAttribute("class", "page-break");
        XhtmlNode divS = div.addTag("div");
        divS.attribute("class", "section");
        XhtmlNode h1 = divS.addTag("h1");
        h1.addText(Integer.toString(lvl.l1) + ": " + s.getName());
        addPageContent(lvl, divS, s.getLink(), s.getName());
        links.add(s.getLink());
        lvl.l2 = 0;
        for (Navigation.Entry n : s.getEntries()) {
            lvl.l2++;
            lvl.l3 = 0;
            if (n.getLink() != null) {
                if (n.getLink().equals("[codes]")) {
                    lvl.l2--;
                    List<String> names = new ArrayList<String>();
                    throw new Error("fix this");
                // for (BindingSpecification bs : page.getDefinitions().getBindings().values()) {
                // if (bs.getBinding() == Binding.CodeList)
                // names.add(bs.getReference());
                // }
                // Collections.sort(names);
                // for (String l : names) {
                // addPageContent(lvl, divS, l.substring(1), page.getDefinitions().getBindingByReference(l).getName());
                // //              links.add(l.substring(1));
                // }
                } else {
                    addPageContent(lvl, divS, n.getLink(), n.getName());
                    links.add(n.getLink());
                }
            }
            for (Navigation.Entry g : n.getEntries()) {
                if (g.getLink() != null) {
                    addPageContent(lvl, divS, g.getLink(), g.getName());
                    links.add(g.getLink());
                }
            }
        }
        if (s.getEntries().size() == 0 && s.getLink().equals("resourcelist")) {
            for (String rn : list) {
                if (!links.contains(rn.toLowerCase())) {
                    lvl.l2++;
                    lvl.l3 = 0;
                    ResourceDefn r = page.getDefinitions().getResourceByName(rn);
                    addPageContent(lvl, divS, rn.toLowerCase(), r.getName());
                }
            }
        }
        if (s.getLink().equals("page") && s.getName().equals("Examples")) {
            for (String rn : list) {
                lvl.l2++;
                lvl.l3 = 0;
                ResourceDefn r = page.getDefinitions().getResourceByName(rn);
                addPageContent(lvl, divS, rn.toLowerCase() + "Ex", r.getName());
            }
        }
        if (s.getLink().equals("page") && s.getName().equals("Detailed Descriptions")) {
            for (String rn : list) {
                lvl.l2++;
                lvl.l3 = 0;
                ResourceDefn r = page.getDefinitions().getResourceByName(rn);
                addPageContent(lvl, divS, rn.toLowerCase() + "Defn", r.getName());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 38 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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 39 with ResourceDefn

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

the class OldSpreadsheetParser method readExamples.

private void readExamples(ResourceDefn defn, Sheet sheet) throws Exception {
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                String id = sheet.getColumn(row, "Identity");
                if (id == null || id.equals(""))
                    throw new Exception("Example " + name + " has no identity parsing " + this.name);
                String desc = sheet.getColumn(row, "Description");
                if (desc == null || desc.equals(""))
                    throw new Exception("Example " + name + " has no description parsing " + this.name);
                String filename = sheet.getColumn(row, "Filename");
                if (filename.startsWith(defn.getName().toLowerCase() + "-examples."))
                    throw new Exception("Cannot name an example file " + filename);
                File file = new CSFile(folder + filename);
                String type = sheet.getColumn(row, "Type");
                if (!file.exists() && !("tool".equals(type) || isSpecialType(type)))
                    throw new Exception("Example " + name + " file '" + file.getAbsolutePath() + "' not found parsing " + this.name);
                List<Example> list = defn.getExamples();
                String pn = sheet.getColumn(row, "Profile");
                if (!Utilities.noString(pn) && !pn.startsWith("!")) {
                    Profile ap = null;
                    for (Profile r : defn.getConformancePackages()) {
                        if (r.getTitle().equals(pn))
                            ap = r;
                    }
                    if (ap == null)
                        throw new Exception("Example " + name + " profile '" + pn + "' not found parsing " + this.name);
                    else
                        list = ap.getExamples();
                }
                ExampleType etype = parseExampleType(type, row);
                list.add(new Example(name, id, desc, file, parseBoolean(sheet.getColumn(row, "Registered"), row, true), etype, isAbstract));
            }
        }
    }
    if (defn.getExamples().size() == 0) {
        File file = new CSFile(folder + title + "-example.xml");
        if (!file.exists() && !isAbstract)
            throw new Exception("Example (file '" + file.getAbsolutePath() + "') not found parsing " + this.name);
        if (file.exists())
            defn.getExamples().add(new Example("General", "example", "Example of " + title, file, true, ExampleType.XmlFile, isAbstract));
    }
}
Also used : Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) Profile(org.hl7.fhir.definitions.model.Profile) ExampleType(org.hl7.fhir.definitions.model.Example.ExampleType)

Example 40 with ResourceDefn

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

the class OldSpreadsheetParser method resolveElementReferences.

private void resolveElementReferences(ResourceDefn parent, ElementDefn root) throws Exception {
    for (TypeRef ref : root.getTypes()) {
        if (ref.isElementReference()) {
            ElementDefn referredElement = parent.getRoot().getElementByName(definitions, ref.getName().substring(1), true, false, null);
            if (referredElement == null)
                throw new Exception("Element reference " + ref.getName() + " cannot be found in type " + parent.getName());
            if (referredElement.getDeclaredTypeName() == null)
                throw new Exception("Element reference " + ref.getName() + " in " + parent.getName() + " refers to an anonymous group of elements. Please specify names with the '=<name>' construct in the typename column.");
            ref.setResolvedTypeName(referredElement.getDeclaredTypeName());
        }
    }
    for (ElementDefn element : root.getElements()) {
        resolveElementReferences(parent, element);
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14