use of org.hl7.fhir.tools.publisher.SpecMapManager in project kindling by HL7.
the class Publisher method produceSpecMap.
private void produceSpecMap() throws IOException {
SpecMapManager spm = new SpecMapManager("hl7.fhir.core", page.getVersion().toCode(), page.getVersion().toCode(), page.getBuildId(), page.getGenDate(), CANONICAL_BASE);
for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
if (sd.hasUserData("path")) {
spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
spm.target(sd.getUserString("path").replace("\\", "/"));
}
}
for (StructureDefinition sd : page.getWorkerContext().getExtensionDefinitions()) {
if (sd.hasUserData("path")) {
spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
spm.target(sd.getUserString("path").replace("\\", "/"));
}
}
for (String s : page.getCodeSystems().keys()) {
CodeSystem cs = page.getCodeSystems().get(s);
if (cs == null && !Utilities.existsInList(s, "http://unitsofmeasure.org", "http://loinc.org", "http://fdasis.nlm.nih.gov", "http://www.nlm.nih.gov/research/umls/rxnorm", "urn:oid:1.2.36.1.2001.1005.17") && !SIDUtilities.isknownCodeSystem(s))
System.out.println("No code system resource found for " + s);
}
for (CodeSystem cs : page.getCodeSystems().getList()) {
if (cs != null && cs.hasUserData("path")) {
spm.path(cs.getUrl(), cs.getUserString("path").replace("\\", "/"));
spm.target(cs.getUserString("path").replace("\\", "/"));
}
}
for (ValueSet vs : page.getValueSets().getList()) {
if (vs.hasUserData("path")) {
spm.path(vs.getUrl(), vs.getUserString("path").replace("\\", "/"));
spm.target(vs.getUserString("path").replace("\\", "/"));
}
}
for (ConceptMap cm : page.getConceptMaps().getList()) {
if (cm.hasUserData("path")) {
spm.path(cm.getUrl(), cm.getUserString("path").replace("\\", "/"));
spm.target(cm.getUserString("path").replace("\\", "/"));
}
}
for (String s : page.getDefinitions().getPageTitles().keySet()) {
spm.page(s, page.getDefinitions().getPageTitles().get(s));
}
for (String n : page.getIni().getPropertyNames("pages")) {
spm.target(n);
}
for (ResourceDefn rd : page.getDefinitions().getResources().values()) {
spm.target(rd.getName().toLowerCase() + ".html");
spm.target(rd.getName().toLowerCase() + "-definitions.html");
spm.target(rd.getName().toLowerCase() + "-mappings.html");
spm.target(rd.getName().toLowerCase() + "-examples.html");
spm.target(rd.getName().toLowerCase() + "-profiles.html");
if (!rd.getOperations().isEmpty())
spm.target(rd.getName().toLowerCase() + "-operations.html");
for (Example ex : rd.getExamples()) {
ImplementationGuideDefn ig = ex.getIg() == null ? null : page.getDefinitions().getIgs().get(ex.getIg());
String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + "/";
spm.target(prefix + ex.getTitle() + ".html");
}
}
for (Profile p : page.getDefinitions().getPackList()) {
spm.target(p.getId() + ".html");
}
// for (String url : page.getDefinitions().getMapTypes().keySet()) {
// spm.map(url, page.getDefinitions().getMapTypes().get(url).getPreamble());
// }
scanForImages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
scanForPages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
for (String url : page.getDefinitions().getRedirectList().keySet()) {
// http://hl7.org/fhir/ = 20 chars
spm.target(url.substring(20));
}
spm.save(page.getFolders().dstDir + "spec.internals");
}
use of org.hl7.fhir.tools.publisher.SpecMapManager 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