Search in sources :

Example 16 with XmlParser

use of org.hl7.fhir.r4b.formats.XmlParser in project kindling by HL7.

the class SourceParser method loadValueSet.

private void loadValueSet(String n) throws FileNotFoundException, Exception {
    XmlParser xml = new XmlParser();
    ValueSet vs = (ValueSet) xml.parse(new CSFileInputStream(srcDir + ini.getStringProperty("valuesets", n).replace('\\', File.separatorChar)));
    new CodeSystemConvertor(definitions.getCodeSystems()).convert(xml, vs, srcDir + ini.getStringProperty("valuesets", n).replace('\\', File.separatorChar), page.packageInfo());
    vs.setId(FormatUtilities.makeId(n));
    vs.setUrl("http://hl7.org/fhir/ValueSet/" + vs.getId());
    if (!vs.hasVersion() || vs.getUrl().startsWith("http://hl7.org/fhir"))
        vs.setVersion(version.toCode());
    vs.setUserData("path", "valueset-" + vs.getId() + ".html");
    vs.setUserData("filename", "valueset-" + vs.getId());
    definitions.getExtraValuesets().put(n, vs);
    definitions.getExtraValuesets().put(vs.getUrl(), vs);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) ValueSet(org.hl7.fhir.r5.model.ValueSet) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 17 with XmlParser

use of org.hl7.fhir.r4b.formats.XmlParser in project kindling by HL7.

the class SourceParser method loadConformancePackage.

private void loadConformancePackage(Profile ap, List<ValidationMessage> issues, WorkGroup wg) throws FileNotFoundException, IOException, Exception {
    if (ap.getSourceType() == ConformancePackageSourceType.Spreadsheet) {
        OldSpreadsheetParser sparser = new OldSpreadsheetParser(ap.getCategory(), new CSFileInputStream(ap.getSource()), Utilities.noString(ap.getId()) ? ap.getSource() : ap.getId(), ap.getSource(), definitions, srcDir, logger, registry, version, context, genDate, false, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        sparser.setFolder(Utilities.getDirectoryForFile(ap.getSource()));
        sparser.parseConformancePackage(ap, definitions, Utilities.getDirectoryForFile(ap.getSource()), ap.getCategory(), issues, wg);
        errors.addAll(sparser.getErrors());
    } else if (ap.getSourceType() == ConformancePackageSourceType.StructureDefinition) {
        Resource rf;
        try {
            rf = new XmlParser().parse(new CSFileInputStream(ap.getSource()));
        } catch (Exception e) {
            throw new Exception("Error parsing " + ap.getSource() + ": " + e.getMessage(), e);
        }
        if (!(rf instanceof StructureDefinition))
            throw new Exception("Error parsing Profile: not a structure definition");
        StructureDefinition sd = (StructureDefinition) rf;
        sd.setVersion(version.toCode());
        ap.putMetadata("id", sd.getId() + "-pack");
        ap.putMetadata("date", sd.getDateElement().asStringValue());
        ap.putMetadata("title", sd.getTitle());
        ap.putMetadata("status", sd.getStatus().toCode());
        ap.putMetadata("description", new XhtmlComposer(XhtmlComposer.HTML).compose(sd.getText().getDiv()));
        if (ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg")) {
            wg = definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"));
            ap.putMetadata("workgroup", wg.getCode());
        }
        ap.setTitle(sd.getTitle());
        new ProfileUtilities(page.getWorkerContext(), null, null).setIds(sd, false);
        ap.getProfiles().add(new ConstraintStructure(sd, definitions.getUsageIG(ap.getCategory(), "Parsing " + ap.getSource()), wg == null ? wg(sd) : wg, fmm(sd), sd.getExperimental()));
    } else if (ap.getSource() != null) {
        parseConformanceDocument(ap, ap.getId(), new CSFile(ap.getSource()), ap.getCategory(), wg);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) CSFile(org.hl7.fhir.utilities.CSFile) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) 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 18 with XmlParser

use of org.hl7.fhir.r4b.formats.XmlParser in project kindling by HL7.

the class SpreadSheetBase method saveXml.

protected void saveXml(String fn, Resource res) throws IOException {
    File f = new CSFile(fn);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(f), res);
    f.setLastModified(date);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File)

Example 19 with XmlParser

use of org.hl7.fhir.r4b.formats.XmlParser in project kindling by HL7.

the class ADLImporter method execute.

private void execute() throws Exception {
    // load config
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
    // load ADL
    builder = factory.newDocumentBuilder();
    adl = builder.parse(new FileInputStream(source)).getDocumentElement();
    check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
    check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
    check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
    String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
    String baseType = XMLUtil.getNamedChild(XMLUtil.getNamedChild(adl, "definition"), "rm_type_name").getTextContent();
    if (!baseType.equals("OBSERVATION"))
        return;
    // load texts from ontology
    List<Element> set = new ArrayList<Element>();
    Element ontology = XMLUtil.getNamedChild(adl, "ontology");
    Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
    set.clear();
    XMLUtil.getNamedChildren(term_definitions, "items", set);
    for (Element item : set) {
        processTextItem(item);
    }
    // create structure definition
    StructureDefinition sd = new StructureDefinition();
    sd.setId("netha-" + id);
    sd.setUrl("http://hl7.org/fhir/StructureDefinition/" + sd.getId());
    sd.setKind(StructureDefinitionKind.LOGICAL);
    populateMetadata(set, sd);
    // load data and protocol
    Element definition = XMLUtil.getNamedChild(adl, "definition");
    NodeTreeEntry root = new NodeTreeEntry();
    root.typeName = XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent();
    root.atCode = XMLUtil.getNamedChild(definition, "node_id").getTextContent();
    root.name = generateToken(root.atCode, true);
    sd.setName(root.name);
    root.cardinality = readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences"));
    set.clear();
    XMLUtil.getNamedChildren(definition, "attributes", set);
    for (Element item : set) {
        // we're actually skipping this level - we don't care about data protocol etc.
        // XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
        Element attributes = item;
        loadChildren(root.atCode, root, attributes);
    }
    dumpChildren("", root);
    genElements(sd, root.name, root);
    // save
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
    System.out.println("done. saved as " + dest);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream)

Example 20 with XmlParser

use of org.hl7.fhir.r4b.formats.XmlParser in project kindling by HL7.

the class ResourceOrderUpdater method process.

private static void process(String filename) throws Exception {
    System.out.println("  process " + filename);
    XmlParser xml = new XmlParser();
    xml.setOutputStyle(OutputStyle.PRETTY);
    InputStream si = new FileInputStream(filename);
    Resource r = xml.parse(si);
    si.close();
    OutputStream so = new FileOutputStream(filename);
    xml.compose(so, r);
    so.close();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.r5.model.Resource) FileInputStream(java.io.FileInputStream)

Aggregations

FileOutputStream (java.io.FileOutputStream)130 XmlParser (org.hl7.fhir.r5.formats.XmlParser)97 FHIRException (org.hl7.fhir.exceptions.FHIRException)84 FileInputStream (java.io.FileInputStream)77 File (java.io.File)64 IOException (java.io.IOException)59 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)51 CSFile (org.hl7.fhir.utilities.CSFile)48 JsonParser (org.hl7.fhir.r5.formats.JsonParser)45 ArrayList (java.util.ArrayList)35 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)35 TextFile (org.hl7.fhir.utilities.TextFile)33 XmlParser (org.hl7.fhir.r4.formats.XmlParser)31 FileNotFoundException (java.io.FileNotFoundException)27 ByteArrayOutputStream (java.io.ByteArrayOutputStream)24 Resource (org.hl7.fhir.r5.model.Resource)24 XmlParser (org.hl7.fhir.r4b.formats.XmlParser)23 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19