use of org.hl7.fhir.r5.model.ImplementationGuide.ManifestResourceComponent in project kindling by HL7.
the class SpecNPMPackageGenerator method generate.
//
// public static void main(String[] args) throws Exception {
// // generateForVersion("F:\\fhir\\web\\DSTU2", "http://hl7.org/fhir/DSTU2");
// generateForVersion("E:\\fhir\\web\\2016May", "http://hl7.org/fhir/2016May", new Date());
// // generateForVersion("F:\\fhir\\web\\STU3", "http://hl7.org/fhir/2016STU3");
// System.out.println("Done");
// }
// private static void generateForVersion(String folder, String url, Date genDate) throws Exception {
// SpecNPMPackageGenerator self = new SpecNPMPackageGenerator();
// self.generate(folder, url, false, genDate);
// }
//
public void generate(String folder, String url, boolean forWeb, Date genDate, String pidRoot) throws Exception {
System.out.println("Generate Package for " + folder);
Map<String, byte[]> files = loadZip(new FileInputStream(Utilities.path(folder, "igpack.zip")));
FHIRVersion version = determineVersion(files);
System.out.println(" .. Loading v" + version);
SpecMapManager spm = new SpecMapManager(files.get("spec.internals"), version.toCode());
System.out.println(" .. Conformance Resources");
List<ResourceEntry> reslist = makeResourceList(files, version.toCode());
System.out.println(" .. Other Resources");
addToResList(folder, reslist, version.toCode());
System.out.println(" .. building IG");
ImplementationGuide ig = new ImplementationGuide();
ig.setId("fhir");
ig.setUrl("http://hl7.org/fhir/ImplementationGuide/fhir");
ig.setVersion(version.toCode());
ig.addFhirVersion(version);
ig.setLicense(SPDXLicense.CC01_0);
ig.setTitle("FHIR Core package");
ig.setDescription("FHIR Core package - the NPM package that contains all the definitions for the base FHIR specification");
ig.setPublisher("HL7 Inc");
ig.getContactFirstRep().getTelecomFirstRep().setSystem(ContactPointSystem.URL).setValue("http://hl7.org/fhir");
ig.setPackageId(pidRoot + ".core");
ig.getManifest().setRendering(url);
for (ResourceEntry e : reslist) {
ManifestResourceComponent r = ig.getManifest().addResource();
r.setReference(new Reference(e.type + "/" + e.id));
if (e.conf)
r.setExample(new BooleanType(true));
r.setRelativePath(spm.getPath(e.canonical, null));
}
for (String k : files.keySet()) {
if (k.endsWith(".png") || k.endsWith(".gif"))
ig.getManifest().addImage(k);
else if (k.endsWith(".css"))
ig.getManifest().addOther(k);
}
Map<String, ManifestPageComponent> map = new HashMap<String, ManifestPageComponent>();
for (String k : spm.getPages()) {
ManifestPageComponent pp = ig.getManifest().addPage();
pp.setName(k).setTitle(spm.getPage(k));
map.put(pp.getName(), pp);
}
for (String k : spm.getTargets()) {
String n = null;
String f = null;
if (k.contains("#")) {
n = k.substring(0, k.indexOf("#"));
f = k.substring(k.indexOf("#") + 1);
} else
n = k;
ManifestPageComponent p = map.get(n);
if (p == null) {
p = ig.getManifest().addPage();
p.setName(n);
map.put(p.getName(), p);
}
if (f != null)
p.addAnchor(f);
}
// ok ig is full loaded...
System.out.println(" .. Building NPM Package");
NPMPackageGenerator npm = new NPMPackageGenerator(Utilities.path(folder, pidRoot + ".core.tgz"), "http://hl7.org/fhir", url, PackageType.CORE, ig, genDate, true);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(bs, ig);
// npm.addFile(Category.RESOURCE, "ig-r4.json", bs.toByteArray());
addConvertedIg(npm, ig, version.toCode());
for (ResourceEntry e : reslist) {
npm.addFile(Category.RESOURCE, e.type + "-" + e.id + ".json", e.json);
}
for (String k : files.keySet()) {
if (k.endsWith(".png") || k.endsWith(".css") || k.endsWith(".template") || k.endsWith(".zip") || k.endsWith(".gif") || k.equals("spec.internals") || k.equals("mappingSpaces.details"))
npm.addFile(Category.OTHER, k, files.get(k));
}
for (String fn : new File(folder).list()) {
if (fn.endsWith(".schema.json") || fn.endsWith(".openapi.json")) {
byte[] b = TextFile.fileToBytes(Utilities.path(folder, fn));
npm.addFile(Category.OPENAPI, fn, b);
}
if (fn.endsWith(".xsd") || fn.endsWith(".sch")) {
byte[] b = TextFile.fileToBytes(Utilities.path(folder, fn));
npm.addFile(Category.SCHEMATRON, fn, b);
}
}
npm.finish();
System.out.println(" .. Built");
System.out.println(" .. Building NPM Package (xml)");
ig.setId("fhir-xml");
ig.setUrl("http://hl7.org/fhir/ImplementationGuide/fhir-xml");
ig.setTitle("FHIR Core package (XML Conformance files)");
ig.setDescription("FHIR Core package - the NPM package that contains all the definitions for the base FHIR specification (XML)");
ig.setPackageId(pidRoot + ".corexml");
npm = new NPMPackageGenerator(Utilities.path(folder, pidRoot + ".corexml.tgz"), "http://hl7.org/fhir", url, PackageType.CORE, ig, genDate, true);
bs = new ByteArrayOutputStream();
new org.hl7.fhir.r5.formats.XmlParser().setOutputStyle(OutputStyle.NORMAL).compose(bs, ig);
npm.addFile(Category.RESOURCE, "ig-r4.json", bs.toByteArray());
addConvertedIgX(npm, ig, version.toCode());
for (ResourceEntry e : reslist) {
if (e.xml != null)
npm.addFile(Category.RESOURCE, e.type + "-" + e.id + ".xml", e.xml);
}
npm.finish();
System.out.println(" .. Built");
}
Aggregations