Search in sources :

Example 6 with ZipGenerator

use of org.hl7.fhir.utilities.ZipGenerator in project kindling by HL7.

the class Publisher method produceSchemaZip.

private void produceSchemaZip() throws Exception {
    char sc = File.separatorChar;
    File f = new CSFile(page.getFolders().dstDir + "fhir-all-xsd.zip");
    if (f.exists())
        f.delete();
    ZipGenerator zip = new ZipGenerator(page.getFolders().tmpResDir + "fhir-all-xsd.zip");
    zip.addFiles(page.getFolders().dstDir, "", ".xsd", null);
    zip.addFiles(page.getFolders().dstDir, "", ".sch", null);
    zip.addFiles(page.getFolders().rootDir + "tools" + sc + "schematron" + sc, "", ".xsl", "");
    zip.close();
    Utilities.copyFile(new CSFile(page.getFolders().tmpResDir + "fhir-all-xsd.zip"), f);
    f = new CSFile(page.getFolders().dstDir + "fhir-codegen-xsd.zip");
    if (f.exists())
        f.delete();
    zip = new ZipGenerator(page.getFolders().tmpResDir + "fhir-codegen-xsd.zip");
    zip.addFiles(page.getFolders().xsdDir + "codegen" + File.separator, "", ".xsd", null);
    zip.close();
    Utilities.copyFile(new CSFile(page.getFolders().tmpResDir + "fhir-codegen-xsd.zip"), f);
    f = new CSFile(page.getFolders().dstDir + "fhir.schema.json.zip");
    if (f.exists())
        f.delete();
    zip = new ZipGenerator(page.getFolders().tmpResDir + "fhir.schema.json.zip");
    zip.addFiles(page.getFolders().dstDir, "", ".schema.json", null);
    zip.close();
    Utilities.copyFile(new CSFile(page.getFolders().tmpResDir + "fhir.schema.json.zip"), f);
    f = new CSFile(page.getFolders().dstDir + "fhir.schema.graphql.zip");
    if (f.exists())
        f.delete();
    zip = new ZipGenerator(page.getFolders().tmpResDir + "fhir.schema.graphql.zip");
    zip.addFiles(page.getFolders().dstDir, "", ".graphql", null);
    zip.close();
    Utilities.copyFile(new CSFile(page.getFolders().tmpResDir + "fhir.schema.graphql.zip"), f);
    zip = new ZipGenerator(page.getFolders().dstDir + "fhir.schema.shex.zip");
    zip.addFileName("fhir.shex", Utilities.path(page.getFolders().dstDir, "fhir.shex"), false);
    zip.close();
}
Also used : 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) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator)

Example 7 with ZipGenerator

use of org.hl7.fhir.utilities.ZipGenerator in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method convert.

private void convert(String sourceFolder, String filename, Coding clss) throws IOException {
    if (new File(Utilities.path(sourceFolder, filename)).length() == 0)
        return;
    CDAUtilities cda;
    try {
        System.out.println("Process " + Utilities.path(sourceFolder, filename));
        cda = new CDAUtilities(new FileInputStream(Utilities.path(sourceFolder, filename)));
        zipJ = new ZipGenerator(Utilities.path(destFolder, "json/doc", Utilities.changeFileExt(filename, ".json.zip")));
        zipX = new ZipGenerator(Utilities.path(destFolder, "xml/doc", Utilities.changeFileExt(filename, ".xml.zip")));
        Element doc = cda.getElement();
        Convert convert = new Convert(cda, ucumSvc, "-0400");
        convert.setGenerateMissingExtensions(true);
        Context context = new Context();
        context.setBaseId(Utilities.changeFileExt(filename, ""));
        context.setEncClass(clss);
        makeSubject(cda, convert, doc, context, context.getBaseId() + "-patient");
        makeAuthor(cda, convert, doc, context, context.getBaseId() + "-author");
        makeEncounter(cda, convert, doc, context, context.getBaseId() + "-encounter");
        Element body = cda.getDescendent(doc, "component/structuredBody");
        for (Element c : cda.getChildren(body, "component")) {
            processSection(cda, convert, context, cda.getChild(c, "section"));
        }
        oids.addAll(convert.getOids());
        saveResource(context.getEncounter());
        makeBinary(sourceFolder, filename, context);
        makeDocumentReference(cda, convert, doc, context);
        zipJ.close();
        zipX.close();
    } catch (Exception e) {
        throw new Error("Unable to process " + Utilities.path(sourceFolder, filename) + ": " + e.getMessage(), e);
    }
}
Also used : SimpleWorkerContext(org.hl7.fhir.dstu3.context.SimpleWorkerContext) Convert(org.hl7.fhir.convertors.misc.Convert) CDAUtilities(org.hl7.fhir.convertors.misc.CDAUtilities) Element(org.w3c.dom.Element) File(java.io.File) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 8 with ZipGenerator

use of org.hl7.fhir.utilities.ZipGenerator in project org.hl7.fhir.core by hapifhir.

the class SpecDifferenceEvaluator method saveResource.

private void saveResource(ZipGenerator zip, Resource t, FhirFormat fmt) throws IOException {
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    if (fmt == FhirFormat.JSON)
        new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(bs, t);
    else
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(bs, t);
    zip.addBytes(t.fhirType() + "-" + t.getId() + "." + fmt.getExtension(), bs.toByteArray(), true);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

ZipGenerator (org.hl7.fhir.utilities.ZipGenerator)7 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 CSFile (org.hl7.fhir.utilities.CSFile)3 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)3 IniFile (org.hl7.fhir.utilities.IniFile)3 TextFile (org.hl7.fhir.utilities.TextFile)3 Element (org.w3c.dom.Element)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 JsonParser (org.hl7.fhir.r5.formats.JsonParser)2 XmlParser (org.hl7.fhir.r5.formats.XmlParser)2 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1