Search in sources :

Example 11 with XmlParser

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

the class DSTU3ValidationConvertor method convert.

public void convert(String bundleSource, String bundleTarget) throws Exception {
    System.out.println("Convert " + bundleSource);
    try {
        source = (Bundle) new XmlParser().parse(new FileInputStream(bundleSource));
        org.hl7.fhir.dstu3.model.Bundle target = Bundle30_50.convertBundle(source);
        new org.hl7.fhir.dstu3.formats.XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(bundleTarget), target);
    } catch (Exception e) {
        throw new Exception(e);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 12 with XmlParser

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

the class CDAGenerator method finish.

private void finish() throws FileNotFoundException, IOException {
    StringBuilder b = new StringBuilder();
    for (StructureDefinition sd : structures) {
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(target, sd.getId() + ".xml")), sd);
        b.append("   <resource>\r\n" + "     <purpose value=\"logical\"/>\r\n" + "     <name value=\"" + sd.getName() + "\"/>\r\n" + "     <sourceUri value=\"cda\\cda-logical-" + sd.getId() + ".xml\"/>\r\n" + "   </resource>\r\n");
    }
    TextFile.stringToFile(b.toString(), Utilities.path(target, "ig-template.xml"));
// dumpPaths();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) FileOutputStream(java.io.FileOutputStream)

Example 13 with XmlParser

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

the class BindingsParser method loadValueSet.

private ValueSet loadValueSet(String ref, String committee) throws Exception {
    String folder = new File(filename).getParent();
    String srcName;
    IParser p;
    if (new File(Utilities.path(folder, ref + ".xml")).exists()) {
        p = new XmlParser();
        srcName = Utilities.path(folder, ref + ".xml");
    } else if (new File(Utilities.path(folder, ref + ".json")).exists()) {
        p = new JsonParser();
        srcName = Utilities.path(folder, ref + ".json");
    } else
        throw new Exception("Unable to find source for " + ref + " in " + filename + " (" + Utilities.path(folder, ref + ".xml/json)"));
    FileInputStream input = new FileInputStream(srcName);
    try {
        ValueSet result = ValueSetUtilities.makeShareable((ValueSet) p.parse(input));
        result.setId(ref.substring(9));
        if (!result.hasExperimental())
            result.setExperimental(false);
        // if (!result.hasUrl())
        result.setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(9));
        if (!result.hasVersion() || result.getUrl().startsWith("http://hl7.org/fhir"))
            result.setVersion(version);
        if (!Utilities.noString(committee)) {
            if (!result.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
                result.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee));
            } else {
                String ec = ToolingExtensions.readStringExtension(result, ToolingExtensions.EXT_WORKGROUP);
                if (!ec.equals(committee))
                    System.out.println("ValueSet " + result.getUrl() + " WG mismatch 1: is " + ec + ", want to set to " + committee);
            }
        }
        result.setUserData("filename", "valueset-" + ref.substring(9));
        result.setUserData("path", "valueset-" + ref.substring(9) + ".html");
        new CodeSystemConvertor(codeSystems).convert(p, result, srcName, packageInfo);
        return result;
    } finally {
        IOUtils.closeQuietly(input);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) CodeSystemConvertor(org.hl7.fhir.definitions.parsers.CodeSystemConvertor) CodeType(org.hl7.fhir.r5.model.CodeType) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) URISyntaxException(java.net.URISyntaxException) FileInputStream(java.io.FileInputStream) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 14 with XmlParser

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

the class SourceParser method loadCommonSearchParameters.

private void loadCommonSearchParameters() throws FHIRFormatError, FileNotFoundException, IOException {
    Bundle bnd = (Bundle) new XmlParser().parse(new CSFileInputStream(Utilities.path(srcDir, "searchparameter", "common-search-parameters.xml")));
    for (BundleEntryComponent be : bnd.getEntry()) {
        SearchParameter sp = (SearchParameter) be.getResource();
        CommonSearchParameter csp = new CommonSearchParameter();
        csp.setId(sp.getId());
        csp.setCode(sp.getCode());
        for (CodeType ct : sp.getBase()) {
            csp.getResources().add(ct.asStringValue());
            definitions.getCommonSearchParameters().put(ct.asStringValue() + "::" + sp.getCode(), csp);
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r5.model.Bundle) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) CodeType(org.hl7.fhir.r5.model.CodeType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Example 15 with XmlParser

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

the class SourceParser method loadCodeSystem.

private void loadCodeSystem(String n) throws FileNotFoundException, Exception {
    XmlParser xml = new XmlParser();
    CodeSystem cs = (CodeSystem) xml.parse(new CSFileInputStream(srcDir + ini.getStringProperty("codesystems", n).replace('\\', File.separatorChar)));
    if (!cs.hasId())
        cs.setId(FormatUtilities.makeId(n));
    if (cs.getUrl().startsWith("http://hl7.org/fhir"))
        cs.setVersion(version.toCode());
    cs.setUserData("path", "codesystem-" + cs.getId() + ".html");
    cs.setUserData("filename", "codesystem-" + cs.getId());
    definitions.getCodeSystems().see(cs, page.packageInfo());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

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