Search in sources :

Example 21 with Element

use of org.hl7.fhir.dstu2.model.Element in project kindling by HL7.

the class CDAGenerator method processDataTypes.

private void processDataTypes(String filename) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException, FHIRFormatError, DefinitionException {
    System.out.println("Process Data Types");
    Document dtMif = XMLUtil.parseFileToDom(filename);
    List<Element> dts = new ArrayList<Element>();
    XMLUtil.getNamedChildren(dtMif.getDocumentElement(), "mif:datatype", dts);
    for (Element dt : dts) {
        String n = dt.getAttribute("name");
        types.put(n, dt);
        if (n.equals("IVL")) {
            processDataType(dt, n + "_TS", "TS");
            processDataType(dt, n + "_PQ", "PQ");
            processDataType(dt, n + "_INT", "INT");
        } else if (n.equals("PIVL")) {
            processDataType(dt, n + "_TS", null);
        } else if (n.equals("EIVL")) {
            processDataType(dt, n + "_TS", null);
        } else if (n.equals("RTO")) {
            processDataType(dt, n + "_PQ_PQ", "PQ");
        } else if (!"Binding".equals(dt.getAttribute("datatypeKind")))
            processDataType(dt, n, null);
    }
    buildSXPR();
    buildInfrastructureRoot();
    for (StructureDefinition sd : structures) {
        // if (!sd.getAbstract())
        generateSnapShot(sd);
    }
    System.out.println(" ... done");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document)

Example 22 with Element

use of org.hl7.fhir.dstu2.model.Element in project kindling by HL7.

the class CKMImporter method downloadArchetype.

private void downloadArchetype(String id) throws Exception {
    String destFn = Utilities.path(dest, id + ".xml");
    if (new File(destFn).exists())
        System.out.println(id + " already fetched");
    else {
        System.out.println("Fetch " + id);
        Document sxml = loadXml(ckm + "/services/ArchetypeFinderBean/getArchetypeInXML?archetypeId=" + id);
        Element e = XMLUtil.getFirstChild(sxml.getDocumentElement());
        String src = Utilities.path("c:\\temp", id + ".xml");
        TextFile.stringToFile(e.getTextContent(), src);
    }
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Example 23 with Element

use of org.hl7.fhir.dstu2.model.Element in project kindling by HL7.

the class BuildWorkerContext method queryForTerm.

private SnomedServerResponse queryForTerm(String code) throws Exception {
    if (!triedServer || serverOk) {
        triedServer = true;
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://tx.fhir.org/snomed/tool/" + SNOMED_EDITION + "/" + URLEncoder.encode(code, "UTF-8").replace("+", "%20"));
        // HttpGet httpget = new HttpGet("http://local.fhir.org:960/r4/snomed/tool/"+SNOMED_EDITION+"/"+URLEncoder.encode(code, "UTF-8").replace("+", "%20")); // don't like the url encoded this way
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        InputStream instream = entity.getContent();
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document xdoc = builder.parse(instream);
            // we always get back a version, and a type. What we do depends on the type
            String t = xdoc.getDocumentElement().getAttribute("type");
            serverOk = true;
            if (t.equals("error"))
                throw new Exception(xdoc.getDocumentElement().getAttribute("message"));
            if (t.equals("description"))
                throw new Exception("The Snomed code (\"" + code + "\") is a description id not a concept id which is not valid");
            if (t.equals("concept")) {
                Concept c = new Concept();
                c.display = xdoc.getDocumentElement().getAttribute("display");
                Element child = XMLUtil.getFirstChild(xdoc.getDocumentElement());
                while (child != null) {
                    c.displays.add(child.getAttribute("value"));
                    child = XMLUtil.getNextSibling(child);
                }
                snomedCodes.put(code, c);
                return null;
            }
            if (t.equals("expression")) {
                SnomedServerResponse resp = new SnomedServerResponse();
                resp.correctExpression = xdoc.getDocumentElement().getAttribute("expressionMinimal");
                resp.display = xdoc.getDocumentElement().getAttribute("display");
                if (!snomedCodes.containsKey(resp.correctExpression)) {
                    Concept c = new Concept();
                    c.display = resp.display;
                    snomedCodes.put(resp.correctExpression, c);
                }
                return resp;
            }
            throw new Exception("Unrecognised response from server");
        } finally {
            instream.close();
        }
    } else
        return null;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HttpEntity(org.apache.http.HttpEntity) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.w3c.dom.Element) HttpResponse(org.apache.http.HttpResponse) Document(org.w3c.dom.Document) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UcumException(org.fhir.ucum.UcumException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient)

Example 24 with Element

use of org.hl7.fhir.dstu2.model.Element 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 25 with Element

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

Aggregations

Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)659 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)488 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)486 ArrayList (java.util.ArrayList)240 FHIRException (org.hl7.fhir.exceptions.FHIRException)162 Element (org.hl7.fhir.r5.elementmodel.Element)98 IOException (java.io.IOException)97 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)91 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)84 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)84 Element (org.w3c.dom.Element)74 JsonElement (com.google.gson.JsonElement)62 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)61 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)60 HashSet (java.util.HashSet)53 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)49 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)48 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)47 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)46 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)43