Search in sources :

Example 11 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class BuildWorkerContext method loadLoinc.

public void loadLoinc(String filename) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(filename));
    Element code = XMLUtil.getFirstChild(xdoc.getDocumentElement());
    while (code != null) {
        Concept c = new Concept();
        c.display = code.getAttribute("long");
        c.shortN = code.getAttribute("short");
        if (!code.getAttribute("long").equalsIgnoreCase(code.getAttribute("short")))
            c.displays.add(code.getAttribute("short"));
        loincCodes.put(code.getAttribute("id"), c);
        code = XMLUtil.getNextSibling(code);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 12 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class Navigation method parse.

public void parse(String file) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(file));
    Element root = xdoc.getDocumentElement();
    if (root.getNodeName().equals("Navigation"))
        parseNavigation(root);
    else
        throw new Exception("Unexpected node " + root.getNodeName());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 13 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class SourceParser method divideContainedResources.

private Map<String, Document> divideContainedResources(String rootId, Document doc) throws Exception {
    Map<String, Document> res = new HashMap<String, Document>();
    List<Element> list = new ArrayList<Element>();
    XMLUtil.getNamedChildren(doc.getDocumentElement(), "contained", list);
    for (Element e : list) {
        Element r = XMLUtil.getFirstChild(e);
        String id = XMLUtil.getNamedChildValue(r, "id");
        if (Utilities.noString(id))
            throw new Exception("Contained Resource has no id");
        String nid = rootId + "-" + id;
        if (!nid.matches(FormatUtilities.ID_REGEX))
            throw new Exception("Contained Resource combination is illegal");
        replaceReferences(doc.getDocumentElement(), id, r.getNodeName() + "/" + nid);
        XMLUtil.setNamedChildValue(r, "id", nid);
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document ndoc = docBuilder.newDocument();
        Node newNode = ndoc.importNode(r, true);
        ndoc.appendChild(newNode);
        res.put(id, ndoc);
        doc.getDocumentElement().removeChild(e);
    }
    return res;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class SourceParser method loadIgs.

private void loadIgs() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(srcDir + "igs.xml"));
    Element root = xdoc.getDocumentElement();
    if (root.getNodeName().equals("igs")) {
        Element ig = XMLUtil.getFirstChild(root);
        while (ig != null) {
            if (ig.getNodeName().equals("ig") && (!ig.hasAttribute("local") || isOkLocally(ig.getAttribute("code"))) && !isRuledOutLocally(ig.getAttribute("code"))) {
                ImplementationGuideDefn igg = new ImplementationGuideDefn(ig.getAttribute("committee"), ig.getAttribute("code"), ig.getAttribute("name"), ig.getAttribute("brief"), ig.getAttribute("source").replace('\\', File.separatorChar), "1".equals(ig.getAttribute("review")), ig.getAttribute("ballot"), ig.getAttribute("fmm"), ig.getAttribute("section"), "yes".equals(ig.getAttribute("core")), page.getValidationErrors());
                definitions.getIgs().put(igg.getCode(), igg);
                definitions.getSortedIgs().add(igg);
            }
            ig = XMLUtil.getNextSibling(ig);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 15 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class SourceParser method parseXml.

private Document parseXml(InputStream in, String name) throws FHIRException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(in);
    } catch (Exception e) {
        throw new FHIRException("Error processing " + name + ": " + e.getMessage(), e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FHIRException(org.hl7.fhir.exceptions.FHIRException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

Document (org.w3c.dom.Document)48 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 DocumentBuilder (javax.xml.parsers.DocumentBuilder)36 IOException (java.io.IOException)33 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 ArrayList (java.util.ArrayList)28 Element (org.w3c.dom.Element)20 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)15 HashMap (java.util.HashMap)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 FileNotFoundException (java.io.FileNotFoundException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 List (java.util.List)11 CSFile (org.hl7.fhir.utilities.CSFile)11 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 XmlGenerator (org.hl7.fhir.utilities.xml.XmlGenerator)9 Identifier (org.hl7.fhir.r4.model.Identifier)8 TextFile (org.hl7.fhir.utilities.TextFile)8