Search in sources :

Example 1 with ManifestPageComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ManifestPageComponent 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");
}
Also used : SpecMapManager(org.hl7.fhir.tools.publisher.SpecMapManager) XmlParser(org.hl7.fhir.r5.formats.XmlParser) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) HashMap(java.util.HashMap) Reference(org.hl7.fhir.r5.model.Reference) BooleanType(org.hl7.fhir.r5.model.BooleanType) NPMPackageGenerator(org.hl7.fhir.r5.utils.NPMPackageGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) FHIRVersion(org.hl7.fhir.r5.model.Enumerations.FHIRVersion) ManifestResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ManifestResourceComponent) ManifestPageComponent(org.hl7.fhir.r5.model.ImplementationGuide.ManifestPageComponent) File(java.io.File) IniFile(org.hl7.fhir.utilities.IniFile) TextFile(org.hl7.fhir.utilities.TextFile) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 JsonParser (org.hl7.fhir.r5.formats.JsonParser)1 XmlParser (org.hl7.fhir.r5.formats.XmlParser)1 BooleanType (org.hl7.fhir.r5.model.BooleanType)1 FHIRVersion (org.hl7.fhir.r5.model.Enumerations.FHIRVersion)1 ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)1 ManifestPageComponent (org.hl7.fhir.r5.model.ImplementationGuide.ManifestPageComponent)1 ManifestResourceComponent (org.hl7.fhir.r5.model.ImplementationGuide.ManifestResourceComponent)1 Reference (org.hl7.fhir.r5.model.Reference)1 NPMPackageGenerator (org.hl7.fhir.r5.utils.NPMPackageGenerator)1 SpecMapManager (org.hl7.fhir.tools.publisher.SpecMapManager)1 IniFile (org.hl7.fhir.utilities.IniFile)1 TextFile (org.hl7.fhir.utilities.TextFile)1