use of org.hl7.fhir.r4b.model.ConceptMap 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.r4b.model.ConceptMap in project kindling by HL7.
the class Publisher method generateConceptMaps.
private void generateConceptMaps() throws Exception {
List<ConceptMap> list = new ArrayList<>();
page.getConceptMaps().listAll(list);
for (ConceptMap cm : list) {
if (cm.hasUserData("generate")) {
generateConceptMap(cm);
}
}
}
use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.
the class Publisher method generateConceptMap.
private void generateConceptMap(ConceptMap cm) throws Exception {
String filename = cm.getUserString("path");
RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
RendererFactory.factory(cm, lrc).render(cm);
IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".json"));
json.compose(s, cm);
s.close();
json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.json"));
json.compose(s, cm);
s.close();
String n = Utilities.changeFileExt(filename, "");
jsonToXhtml(n, cm.getName(), resource2Json(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
ttlToXhtml(n, cm.getName(), resource2Ttl(cm), "conceptmap-instance", "Concept Map", null, wg("vocab"));
IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".xml"));
xml.compose(s, cm);
s.close();
xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(filename, ".canonical.xml"));
xml.compose(s, cm);
s.close();
cloneToXhtml(n, cm.getName(), false, "conceptmap-instance", "Concept Map", null, wg("vocab"));
// now, we create an html page from the narrative
String narrative = new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv());
String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", narrative);
html = page.processPageIncludes(Utilities.changeFileExt(filename, ".html"), html, "conceptmap-instance", null, null, null, "Concept Map", null, null, wg("vocab"));
TextFile.stringToFile(html, page.getFolders().dstDir + Utilities.changeFileExt(filename, ".html"));
conceptMapsFeed.getEntry().add(new BundleEntryComponent().setResource(cm).setFullUrl("http://hl7.org/fhir/" + cm.fhirType() + "/" + cm.getId()));
page.getConceptMaps().see(cm, page.packageInfo());
page.getHTMLChecker().registerFile(n + ".html", cm.getName(), HTMLLinkChecker.XHTML_TYPE, false);
}
use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.
the class Publisher method produceConceptMap.
private void produceConceptMap(ConceptMap cm, ResourceDefn rd, SectionTracker st) throws Exception {
RenderingContext lrc = page.getRc().copy().setLocalPrefix("");
RendererFactory.factory(cm, lrc).render(cm);
String n = cm.getUserString("path");
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cm);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".canonical.xml"));
new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cm);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".json"));
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cm);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + Utilities.changeFileExt(n, ".canonical.json"));
new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cm);
s.close();
Utilities.copyFile(new CSFile(page.getFolders().dstDir + Utilities.changeFileExt(n, ".xml")), new CSFile(page.getFolders().dstDir + "examples" + File.separator + Utilities.changeFileExt(n, ".xml")));
// saveAsPureHtml(cm, new FileOutputStream(Utilities.path(page.getFolders().dstDir, "html", n)), true);
String src = TextFile.fileToString(page.getFolders().templateDir + "template-status-map.html");
Map<String, String> others = new HashMap<String, String>();
others.put("status-map", new XhtmlComposer(XhtmlComposer.HTML).compose(cm.getText().getDiv()));
TextFile.stringToFile(insertSectionNumbers(page.processPageIncludes(n, src, "conceptmap-instance", others, null, null, "Profile", null, rd, rd.getWg()), st, n, 0, null), page.getFolders().dstDir + n);
page.getHTMLChecker().registerFile(n, cm.getTitle(), HTMLLinkChecker.XHTML_TYPE, true);
cloneToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), true, "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
jsonToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), resource2Json(cm), "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
ttlToXhtml(Utilities.changeFileExt(n, ""), cm.getTitle(), resource2Ttl(cm), "conceptmap-instance", "Profile", null, ((ResourceDefn) cm.getUserData("resource-definition")).getWg());
}
use of org.hl7.fhir.r4b.model.ConceptMap in project kindling by HL7.
the class PageProcessor method parseConceptMapMapping.
private ConceptMap parseConceptMapMapping(ElementDefn logical, ElementDefinition resource, String src) throws FHIRException {
if (!src.startsWith("{map:"))
return null;
ConceptMap map = new ConceptMap();
map.setId(logical.getPath() + "2" + resource.getPath());
map.setUrl("http://hl7.org/fhir/ConceptMap/" + map.getId());
map.setVersion(version.toCode());
ConceptMapGroupComponent grp = map.addGroup();
String[] statements = src.substring(0, src.length() - 1).substring(5).split("\\;");
if (statements.length == 0)
throw new FHIRException("Unable to parse map details '" + src + "'");
for (String s : statements) {
String[] p = s.split("\\=");
if (p.length < 2)
throw new FHIRException("Unable to parse map details '" + src + "'");
if (":default".equals(p[0].trim())) {
grp.getUnmapped().setMode(ConceptMapGroupUnmappedMode.FIXED);
grp.getUnmapped().setCode(p[1].trim());
} else {
grp.addElement().setCode(p[0].trim()).addTarget().setRelationship(ConceptMapRelationship.EQUIVALENT).setCode(p[1].trim());
}
}
return map;
}
Aggregations