
001package org.hl7.fhir.convertors.misc; 002 003import java.io.File; 004import java.io.FileInputStream; 005import java.io.FileOutputStream; 006import java.io.IOException; 007 008import org.hl7.fhir.exceptions.FHIRFormatError; 009import org.hl7.fhir.utilities.Utilities; 010import org.hl7.fhir.utilities.json.model.JsonObject; 011import org.hl7.fhir.utilities.json.parser.JsonParser; 012import org.hl7.fhir.utilities.npm.NpmPackage; 013 014 015public class CorePackageTools { 016 017 public static void main(String[] args) throws FHIRFormatError, IOException { 018 if ("-xml".equals(args[0])) { 019 new CorePackageTools().buildXml(args[1], args[2], args[3]); 020 } 021 if ("-pack".equals(args[0])) { 022 new CorePackageTools().buildPackage(args[1], args[2]); 023 } 024 } 025 026 private void buildPackage(String path, String output) throws IOException { 027 NpmPackage npm = NpmPackage.fromFolder(path); 028 npm.loadAllFiles(); 029 npm.save(new FileOutputStream(output)); 030 031 } 032 033 private void buildXml(String json, String xml, String version) throws FHIRFormatError, IOException { 034 for (File f : new File(Utilities.path(json, "package")).listFiles()) { 035 if (f.getName().endsWith(".json")) { 036 JsonObject j = JsonParser.parseObject(f); 037 if (j.has("resourceType")) { 038 if ("1.4".equals(version)) { 039 String n = f.getName(); 040 System.out.println(n); 041 String xn = Utilities.changeFileExt(n, ".xml"); 042 org.hl7.fhir.dstu2016may.model.Resource r = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(new FileInputStream(f)); 043 new org.hl7.fhir.dstu2016may.formats.XmlParser().setOutputStyle(org.hl7.fhir.dstu2016may.formats.IParser.OutputStyle.NORMAL).compose(new FileOutputStream(Utilities.path(xml, "package", xn)), r); 044 } 045 } 046 } 047 } 048 } 049}