use of org.hl7.fhir.utilities.graphql.Package in project kindling by HL7.
the class PageProcessor method processConformancePackageIncludes.
public String processConformancePackageIncludes(Profile pack, String src, String intro, String notes, String resourceName, ImplementationGuideDefn ig) throws Exception {
String workingTitle = null;
int level = (ig == null || ig.isCore()) ? 0 : 1;
while (src.contains("<%") || src.contains("[%")) {
int i1 = src.indexOf("<%");
int i2 = src.indexOf("%>");
if (i1 == -1) {
i1 = src.indexOf("[%");
i2 = src.indexOf("%]");
}
String s1 = src.substring(0, i1);
String s2 = src.substring(i1 + 2, i2).trim();
String s3 = src.substring(i2 + 2);
String[] com = s2.split(" ");
if (com[0].equals("file")) {
if (new File(folders.templateDir + com[1] + ".html").exists()) {
src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
} else {
src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
}
} else if (com[0].equals("settitle")) {
workingTitle = s2.substring(9).replace("{", "<%").replace("}", "%>");
src = s1 + s3;
} else if (com[0].equals("setlevel")) {
level = Integer.parseInt(com[1]);
src = s1 + s3;
} else if (com.length != 1)
throw new Exception("Instruction <%" + s2 + "%> not understood parsing profile " + pack.getId());
else if (com[0].equals("pageheader"))
src = s1 + pageHeader(pack.getId().toUpperCase().substring(0, 1) + pack.getId().substring(1)) + s3;
else if (com[0].equals("newheader"))
src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
else if (com[0].equals("newheader1"))
src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
else if (com[0].equals("footer"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
else if (com[0].equals("newfooter"))
src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
else if (com[0].equals("footer1"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
else if (com[0].equals("footer2"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
else if (com[0].equals("footer3"))
src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
else if (com[0].equals("title"))
src = s1 + (workingTitle == null ? Utilities.escapeXml(pack.getTitle()) : workingTitle) + s3;
else if (com[0].equals("xtitle"))
src = s1 + Utilities.escapeXml(pack.getId().toUpperCase().substring(0, 1) + pack.getId().substring(1)) + s3;
else if (com[0].equals("name"))
src = s1 + pack.getId() + s3;
else if (com[0].equals("package.intro"))
src = s1 + (intro == null ? pack.metadata("description") : intro) + s3;
else if (com[0].equals("package.notes"))
src = s1 + (notes == null ? "" : notes) + s3;
else if (com[0].equals("canonicalname"))
src = s1 + makeCanonical(pack.getId()) + s3;
else if (com[0].equals("prettyname"))
src = s1 + makePretty(pack.getId()) + s3;
else if (com[0].equals("version"))
src = s1 + version + s3;
else if (com[0].equals("gendate"))
src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
else if (com[0].equals("maindiv"))
src = s1 + "<div class=\"content\">" + s3;
else if (com[0].equals("/maindiv"))
src = s1 + "</div>" + s3;
else if (com[0].equals("mappings-table"))
src = s1 + genMappingsTable() + s3;
else if (com[0].equals("id"))
src = s1 + pack.getId() + s3;
else if (com[0].equals("events"))
src = s1 + getEventsTable(pack.getId()) + s3;
else if (com[0].equals("resourcecodes"))
src = s1 + genResCodes() + s3;
else if (com[0].equals("datatypecodes"))
src = s1 + genDTCodes() + s3;
else if (com[0].equals("allparams"))
src = s1 + allParamlist() + s3;
else // src = s1 + genBindingsTable() + s3;
if (com[0].equals("codeslist"))
src = s1 + genCodeSystemsTable() + s3;
else // src = s1 + genValueSetsTable() + s3;
if (com[0].equals("igvaluesetslist"))
src = s1 + genIGValueSetsTable() + s3;
else if (com[0].equals("namespacelist"))
src = s1 + genNSList() + s3;
else if (com[0].equals("conceptmapslist"))
src = s1 + genConceptMapsTable() + s3;
else // src = s1 + genBindingTable(false) + s3;
if (com[0].equals("resimplall"))
src = s1 + genResImplList() + s3;
else if (com[0].equals("breadcrumb"))
src = s1 + breadCrumbManager.make(pack.getId()) + s3;
else if (com[0].equals("navlist"))
src = s1 + breadCrumbManager.navlist(pack.getId(), genlevel(level)) + s3;
else if (com[0].equals("breadcrumblist"))
src = s1 + ((ig == null || ig.isCore()) ? breadCrumbManager.makelist(pack.getId(), "profile:" + resourceName + "/" + pack.getId(), genlevel(level), pack.getTitle()) : ig.makeList(pack.getId(), "profile:" + resourceName + "/" + pack.getId(), genlevel(level), pack.getTitle())) + s3;
else if (com[0].equals("year"))
src = s1 + new SimpleDateFormat("yyyy").format(new Date()) + s3;
else if (com[0].equals("buildId"))
src = s1 + buildId + s3;
else if (com[0].equals("pub-type"))
src = s1 + publicationType + s3;
else if (com[0].equals("pub-notice"))
src = s1 + publicationNotice + s3;
else if (com[0].equals("level"))
src = s1 + genlevel(level) + s3;
else if (com[0].equals("pagepath"))
src = s1 + pack.getId() + s3;
else if (com[0].equals("rellink")) {
if (pack.getId().contains(".html"))
throw new Error("Invalid link: " + pack.getId() + " at " + workingTitle);
src = s1 + Utilities.URLEncode(pack.getId() + ".html") + s3;
} else if (com[0].equals("baseURL"))
src = s1 + Utilities.URLEncode(baseURL) + s3;
else if (com[0].equals("description"))
src = s1 + Utilities.escapeXml(pack.getDescription()) + s3;
else if (com[0].equals("package-content"))
src = s1 + getPackageContent(pack, genlevel(level)) + s3;
else if (com[0].equals("search-footer"))
src = s1 + searchFooter(level) + s3;
else if (com[0].equals("search-header"))
src = s1 + searchHeader(level) + s3;
else if (com[0].equals("package.search"))
src = s1 + getSearch(pack) + s3;
else if (com[0].startsWith("!"))
src = s1 + s3;
else if (com[0].equals("wg")) {
String wg = pack.getWg();
if (Utilities.noString(wg) && definitions.hasResource(resourceName))
wg = definitions.getResourceByName(resourceName).getWg().getCode();
if (wg == null || !definitions.getWorkgroups().containsKey(wg))
src = s1 + "(No assigned work group) (" + wg + ") (4)" + s3;
else
src = s1 + "<a _target=\"blank\" href=\"" + definitions.getWorkgroups().get(wg).getUrl() + "\">" + definitions.getWorkgroups().get(wg).getName() + "</a> Work Group" + s3;
} else if (com[0].equals("res-type-count")) {
src = s1 + definitions.getResources().size() + s3;
} else if (macros.containsKey(com[0])) {
src = s1 + macros.get(com[0]) + s3;
} else
throw new Exception("Instruction <%" + s2 + "%> not understood parsing profile " + pack.getId());
}
return src;
}
use of org.hl7.fhir.utilities.graphql.Package in project kindling by HL7.
the class PageProcessor method getPackageContent.
private String getPackageContent(Profile pack, String prefix) throws Exception {
StringBuilder s = new StringBuilder();
s.append("<table class=\"lines\">");
if (pack.getProfiles().size() > 0) {
s.append("<tr><td colspan=\"2\"><b>Profiles</b>: </td></tr>");
for (ConstraintStructure p : pack.getProfiles()) s.append("<tr><td><a href=\"").append(p.getId()).append(".html\">").append(Utilities.escapeXml(p.getTitle())).append("</a></td><td>").append(Utilities.escapeXml(p.getResource().getDescription())).append("</td></tr>");
}
if (pack.getExtensions().size() > 0) {
s.append("<tr><td colspan=\"2\"><b>Extensions</b>: </td></tr>");
for (StructureDefinition ed : pack.getExtensions()) s.append("<tr><td><a name=\"extension-").append(prefix + ed.getId()).append("\"> </a><a href=\"extension-").append(ed.getId().toLowerCase()).append(".html\">").append(Utilities.escapeXml(ed.getId())).append("</a></td><td><b>").append(Utilities.escapeXml(ed.getName())).append("</b> : ").append(processMarkdown(pack.getId(), ed.getDescription(), prefix)).append("</td></tr>");
}
if (pack.getExamples().size() > 0) {
s.append("<tr><td colspan=\"2\"><b>Examples</b>: </td></tr>");
for (Example ex : pack.getExamples()) s.append("<tr><td><a href=\"").append(ex.getTitle()).append(".html\">").append(Utilities.escapeXml(Utilities.changeFileExt(ex.getName(), ""))).append("</a></td><td>").append(processMarkdown(pack.getId(), ex.getDescription(), prefix)).append("</td></tr>");
}
s.append("</table>");
if (pack.getSearchParameters().size() > 0) {
// search parameters
StringBuilder b = new StringBuilder();
b.append("<a name=\"search\"> </a>\r\n");
b.append("<h3>Search Parameters</h3>\r\n");
b.append("<p>Search parameters defined by this package. See <a href=\"" + prefix + "search.html\">Searching</a> for more information about searching in REST, messaging, and services.</p>\r\n");
b.append("<table class=\"list\">\r\n");
b.append("<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Description</b></td><td><b>Paths</b></td><td><b>Source</b></td></tr>\r\n");
List<String> names = new ArrayList<String>();
for (SearchParameter sp : pack.getSearchParameters()) names.add(sp.getName());
Collections.sort(names);
for (String name : names) {
SearchParameter p = null;
for (SearchParameter sp : pack.getSearchParameters()) if (name.equals(sp.getName()))
p = sp;
b.append("<tr><td>" + p.getName() + "</td><td><a href=\"" + prefix + "search.html#" + p.getType().toCode() + "\">" + p.getType().toCode() + "</a></td>" + "<td>" + Utilities.escapeXml(p.getDescription()) + "</td><td>" + (p.hasXpath() ? p.getXpath() : "") + (p.getType() == SearchParamType.REFERENCE && p.hasTarget() ? asText(p.getTarget()) : "") + "</td>" + "<td><a href=\"" + p.getId() + ".xml.html\">XML</a> / <a href=\"" + p.getId() + ".json.html\">JSON</a></td></tr>\r\n");
}
b.append("</table>\r\n");
s.append(b.toString());
}
return s.toString();
}
use of org.hl7.fhir.utilities.graphql.Package in project kindling by HL7.
the class IgParser method load.
public void load(String rootDir, ImplementationGuideDefn igd, List<ValidationMessage> issues, Set<String> loadedIgs) throws Exception {
logger.log(" ..." + igd.getName(), LogMessageType.Process);
// first: parse the IG, then use it
String myRoot = Utilities.path(rootDir, "guides", igd.getCode());
CSFile file = new CSFile(Utilities.path(rootDir, igd.getSource()));
ImplementationGuide ig = (ImplementationGuide) new XmlParser().parse(new FileInputStream(file));
if (// for things published in the hl7.org/fhir namespace...
!ig.getUrl().startsWith("http://hl7.org/fhir/"))
throw new Exception("Illegal namespace");
if (!ig.getUrl().equals("http://hl7.org/fhir/" + ig.getId()))
throw new Exception("Illegal URL");
if (!ig.hasName())
throw new Exception("no name on IG");
ig.setDateElement(new DateTimeType(genDate));
igd.setName(ig.getName());
igd.setIg(ig);
Map<String, Resource> resources = new HashMap<String, Resource>();
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
if (!loadedIgs.contains(d.getUri()))
throw new Exception("Dependency on " + ig.getName() + " not satisfied: " + d.getUri());
}
loadedIgs.add(ig.getUrl());
// for (UriType bin : ig.getBinary()) {
// if (!new File(Utilities.path(myRoot, bin.getValue())).exists())
// throw new Exception("Binary dependency in "+ig.getName()+" not found: "+bin.getValue());
// igd.getImageList().add(bin.getValue());
// }
processPage(ig.getDefinition().getPage(), igd);
List<Example> exr = new ArrayList<Example>();
// first pass - verify the resources can be loaded
for (ImplementationGuideDefinitionResourceComponent r : ig.getDefinition().getResource()) {
if (!r.hasReference())
throw new Exception("no source on resource in IG " + ig.getName());
CSFile fn = new CSFile(Utilities.path(myRoot, r.getReference().getReference()));
if (!fn.exists())
throw new Exception("Source " + r.getReference().getReference() + " resource in IG " + ig.getName() + " could not be located @ " + fn.getAbsolutePath());
String id = Utilities.changeFileExt(fn.getName(), "");
// we're going to try and load the resource directly.
// if that fails, then we'll treat it as an example.
boolean isExample = r.hasExample();
ResourceType rt = null;
try {
rt = new XmlParser().parse(new FileInputStream(fn)).getResourceType();
} catch (Exception e) {
rt = null;
isExample = true;
}
if (isExample) {
if (// which means that non conformance resources must be named
!r.hasName())
throw new Exception("no name on resource in IG " + ig.getName());
Example example = new Example(r.getName(), id, r.getDescription(), fn, false, ExampleType.XmlFile, false);
example.setIg(igd.getCode());
if (r.hasExampleCanonicalType()) {
example.setExampleFor(r.getExampleCanonicalType().asStringValue());
example.setRegistered(true);
exr.add(example);
}
igd.getExamples().add(example);
r.setUserData(ToolResourceUtilities.NAME_RES_EXAMPLE, example);
r.setReference(new Reference(example.getId() + ".html"));
} else if (rt == ResourceType.ValueSet) {
ValueSet vs = (ValueSet) new XmlParser().parse(new FileInputStream(fn));
if (id.startsWith("valueset-"))
id = id.substring(9);
vs.setId(id);
if (vs.getUrl() == null) {
// Asserting this all the time causes issues for non-HL7 URL value sets
vs.setUrl("http://hl7.org/fhir/ValueSet/" + id);
}
vs.setUserData(ToolResourceUtilities.NAME_RES_IG, igd);
vs.setUserData("path", igd.getPath() + "valueset-" + id + ".html");
vs.setUserData("filename", "valueset-" + id);
if (committee != null) {
if (!vs.hasExtension(ToolingExtensions.EXT_WORKGROUP)) {
vs.addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(committee.getCode()));
} else {
String ec = ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP);
if (!ec.equals(committee.getCode()))
System.out.println("ValueSet " + vs.getUrl() + " WG mismatch 2: is " + ec + ", want to set to " + committee);
}
}
new CodeSystemConvertor(codeSystems).convert(new XmlParser(), vs, fn.getAbsolutePath(), packageInfo);
// if (id.contains(File.separator))
igd.getValueSets().add(vs);
if (!r.hasName())
r.setName(vs.getName());
if (!r.hasDescription())
r.setDescription(vs.getDescription());
r.setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
r.setReference(new Reference(fn.getName()));
} else if (rt == ResourceType.StructureDefinition) {
StructureDefinition sd;
sd = (StructureDefinition) new XmlParser().parse(new CSFileInputStream(fn));
new ProfileUtilities(context, null, pkp).setIds(sd, false);
if (sd.getKind() == StructureDefinitionKind.LOGICAL) {
fn = new CSFile(Utilities.path(myRoot, r.getReference().getReference()));
LogicalModel lm = new LogicalModel(sd);
lm.setSource(fn.getAbsolutePath());
lm.setId(sd.getId());
igd.getLogicalModels().add(lm);
} else if ("Extension".equals(sd.getType())) {
sd.setId(tail(sd.getUrl()));
sd.setUserData(ToolResourceUtilities.NAME_RES_IG, igd.getCode());
ToolResourceUtilities.updateUsage(sd, igd.getCode());
this.context.cacheResource(sd);
} else {
Profile pr = new Profile(igd.getCode());
pr.setSource(fn.getAbsolutePath());
pr.setTitle(sd.getName());
if (!sd.hasId())
sd.setId(tail(sd.getUrl()));
// Lloyd: This causes issues for profiles & extensions defined outside of HL7
// sd.setUrl("http://hl7.org/fhir/StructureDefinition/"+sd.getId());
pr.forceMetadata("id", sd.getId() + "-profile");
pr.setSourceType(ConformancePackageSourceType.StructureDefinition);
ConstraintStructure cs = new ConstraintStructure(sd, igd, wg(sd), fmm(sd), sd.getExperimental());
pr.getProfiles().add(cs);
igd.getProfiles().add(pr);
}
} else if (rt == ResourceType.Bundle) {
Dictionary d = new Dictionary(id, r.getName(), igd.getCode(), fn.getAbsolutePath(), igd);
igd.getDictionaries().add(d);
} else
logger.log("Implementation Guides do not yet support " + rt.toString(), LogMessageType.Process);
// throw new Error("Not implemented yet - type = "+rt.toString());
// if (r.hasExampleFor()) {
// if (!resources.containsKey(r.getExampleFor().getReference()))
// throw new Exception("Unable to resolve example-for reference to "+r.getExampleFor().getReference());
// }
}
// second pass: load the spreadsheets
for (ImplementationGuideDefinitionGroupingComponent p : ig.getDefinition().getGrouping()) {
if (!p.hasName())
throw new Exception("no name on package in IG " + ig.getName());
for (Extension ex : p.getExtension()) {
if (ex.getUrl().equals(ToolResourceUtilities.EXT_PROFILE_SPREADSHEET)) {
String s = ((UriType) ex.getValue()).getValue();
File fn = new File(Utilities.path(myRoot, s));
if (!fn.exists())
throw new Exception("Spreadsheet " + s + " in package " + p.getName() + " in IG " + ig.getName() + " could not be located");
Profile pr = new Profile(igd.getCode());
ex.setUserData(ToolResourceUtilities.NAME_RES_PROFILE, pr);
pr.setSource(fn.getAbsolutePath());
pr.setSourceType(ConformancePackageSourceType.Spreadsheet);
OldSpreadsheetParser sparser = new OldSpreadsheetParser(pr.getCategory(), new CSFileInputStream(pr.getSource()), Utilities.noString(pr.getId()) ? pr.getSource() : pr.getId(), pr.getSource(), igd, rootDir, logger, registry, FHIRVersion.fromCode(context.getVersion()), context, genDate, false, pkp, false, committee, mappings, profileIds, codeSystems, maps, workgroups, exceptionIfExcelNotNormalised);
sparser.getBindings().putAll(commonBindings);
sparser.setFolder(Utilities.getDirectoryForFile(pr.getSource()));
sparser.parseConformancePackage(pr, null, Utilities.getDirectoryForFile(pr.getSource()), pr.getCategory(), issues, null);
// System.out.println("load "+pr.getId()+" from "+s);
igd.getProfiles().add(pr);
// what remains to be done now is to update the package with the loaded resources, but we need to wait for all the profiles to generated, so we'll do that later
for (BindingSpecification bs : sparser.getBindings().values()) {
if (!commonBindings.containsValue(bs) && bs.getValueSet() != null) {
ValueSet vs = bs.getValueSet();
String path = vs.getUserString("path");
path = path.substring(path.lastIndexOf("/") + 1);
ig.getDefinition().addResource().setName(vs.getName()).setDescription(vs.getDescription()).setReference(new Reference(path)).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
}
}
// now, register resources for all the things in the spreadsheet
for (ValueSet vs : sparser.getValuesets()) ig.getDefinition().addResource().setExample(new BooleanType(false)).setName(vs.getName()).setDescription(vs.getDescription()).setReference(new Reference("valueset-" + vs.getId() + ".html")).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
for (StructureDefinition exd : pr.getExtensions()) ig.getDefinition().addResource().setExample(new BooleanType(false)).setName(exd.getName()).setDescription(exd.getDescription()).setReference(new Reference("extension-" + exd.getId().toLowerCase() + ".html")).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, exd);
for (ConstraintStructure cs : pr.getProfiles()) {
cs.setResourceInfo(ig.getDefinition().addResource());
cs.getResourceInfo().setExample(new BooleanType(false)).setName(cs.getDefn().getName()).setDescription(cs.getDefn().getDefinition()).setReference(new Reference(cs.getId().toLowerCase() + ".html"));
}
}
if (ex.getUrl().equals(ToolResourceUtilities.EXT_LOGICAL_SPREADSHEET)) {
File fn = new CSFile(Utilities.path(myRoot, ((UriType) ex.getValue()).getValue()));
// String source = Utilities.path(file.getParent(), e.getAttribute("source"));
String s = fn.getName();
if (s.endsWith("-spreadsheet.xml"))
s = s.substring(0, s.length() - 16);
String id = igd.getCode() + "-" + s;
OldSpreadsheetParser sparser = new OldSpreadsheetParser(igd.getCode(), new CSFileInputStream(fn), id, fn.getAbsolutePath(), igd, rootDir, logger, registry, FHIRVersion.fromCode(context.getVersion()), context, genDate, false, pkp, false, committee, mappings, profileIds, codeSystems, maps, workgroups, exceptionIfExcelNotNormalised);
sparser.getBindings().putAll(commonBindings);
sparser.setFolder(Utilities.getDirectoryForFile(fn.getAbsolutePath()));
LogicalModel lm = sparser.parseLogicalModel();
lm.setId(id);
lm.setSource(fn.getAbsolutePath());
lm.getResource().setName(lm.getId());
igd.getLogicalModels().add(lm);
}
}
ToolingExtensions.removeExtension(p, ToolResourceUtilities.EXT_PROFILE_SPREADSHEET);
ToolingExtensions.removeExtension(p, ToolResourceUtilities.EXT_LOGICAL_SPREADSHEET);
}
for (Example ex : exr) {
Profile tp = null;
for (Profile pr : igd.getProfiles()) {
if (("StructureDefinition/" + pr.getId()).equals(ex.getExampleFor())) {
tp = pr;
break;
} else
for (ConstraintStructure cc : pr.getProfiles()) {
if (("StructureDefinition/" + cc.getId()).equals(ex.getExampleFor())) {
tp = pr;
break;
}
}
}
if (tp != null)
tp.getExamples().add(ex);
else
throw new Exception("no profile found matching exampleFor = " + ex.getExampleFor());
}
igd.numberPages();
// // second, parse the old ig, and use that. This is being phased out
// CSFile file = new CSFile(Utilities.path(rootDir, igd.getSource()));
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware(true);
// DocumentBuilder builder = factory.newDocumentBuilder();
// Document xdoc = builder.parse(new CSFileInputStream(file));
// Element root = xdoc.getDocumentElement();
// if (!root.getNodeName().equals("ig"))
// throw new Exception("wrong base node");
// Element e = XMLUtil.getFirstChild(root);
// while (e != null) {
// if (e.getNodeName().equals("dependsOn")) {
// // we ignore this for now
// } else if (e.getNodeName().equals("publishing")) {
// // if (e.hasAttribute("homepage"))
// // igd.setPage(e.getAttribute("homepage"));
// } else if (e.getNodeName().equals("page")) {
// // igd.getPageList().add(e.getAttribute("source"));
// } else if (e.getNodeName().equals("image")) {
// // moved above igd.getImageList().add(e.getAttribute("source"));
// } else if (e.getNodeName().equals("valueset")) {
// // XmlParser xml = new XmlParser();
// // ValueSet vs = (ValueSet) xml.parse(new CSFileInputStream(Utilities.path(file.getParent(), e.getAttribute("source"))));
// // String id = Utilities.changeFileExt(new File(Utilities.path(file.getParent(), e.getAttribute("source"))).getName(), "");
// // if (id.startsWith("valueset-"))
// // id = id.substring(9);
// // if (!vs.hasId() || !vs.hasUrl()) {
// // vs.setId(id);
// // vs.setUrl("http://hl7.org/fhir/ValueSet/"+vs.getId());
// // }
// // vs.setUserData(ToolResourceUtilities.NAME_RES_IG, igd);
// // vs.setUserData("path", igd.getCode()+File.separator+"valueset-"+vs.getId()+".html");
// // vs.setUserData("filename", "valueset-"+vs.getId());
// // vs.setUserData("committee", committee);
// // igd.getValueSets().add(vs);
// } else if (e.getNodeName().equals("acronym")) {
// igd.getTlas().put(e.getAttribute("target"), e.getAttribute("id"));
// } else if (e.getNodeName().equals("example")) {
// // String filename = e.getAttribute("source");
// // File efile = new File(Utilities.path(file.getParent(), filename));
// // Example example = new Example(e.getAttribute("name"), Utilities.changeFileExt(efile.getName(), ""), e.getAttribute("name"), efile, false, ExampleType.XmlFile, false);
// // example.setIg(igd.getCode());
// // igd.getExamples().add(example);
// } else if (e.getNodeName().equals("profile")) {
// // moved above
// // Profile p = new Profile(igd.getCode());
// // p.setSource(Utilities.path(file.getParent(), e.getAttribute("source")));
// // if ("spreadsheet".equals(e.getAttribute("type"))) {
// // p.setSourceType(ConformancePackageSourceType.Spreadsheet);
// // SpreadsheetParser sparser = new SpreadsheetParser(p.getCategory(), new CSFileInputStream(p.getSource()), Utilities.noString(p.getId()) ? p.getSource() : p.getId(), igd,
// // rootDir, logger, null, context.getVersion(), context, genDate, false, igd.getExtensions(), pkp, false, committee, mappings);
// // sparser.getBindings().putAll(commonBindings);
// // sparser.setFolder(Utilities.getDirectoryForFile(p.getSource()));
// // sparser.parseConformancePackage(p, null, Utilities.getDirectoryForFile(p.getSource()), p.getCategory(), issues);
// // for (BindingSpecification bs : sparser.getBindings().values()) {
// // if (!commonBindings.containsValue(bs) && bs.getValueSet() != null) {
// // ValueSet vs = bs.getValueSet();
// // String path = vs.getUserString("filename")+".xml";
// // ig.getPackage().get(0).addResource().setName(vs.getName()).setDescription(vs.getDescription()).setSource(new UriType(path)).setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, vs);
// // }
// // }
// // } else {
// // throw new Exception("Unknown profile type in IG : "+e.getNodeName());
// // // parseConformanceDocument(p, p.getId(), new File(p.getSource()), p.getCategory());
// // }
// //
// // String id = e.getAttribute("id");
// // if (Utilities.noString(id))
// // id = Utilities.changeFileExt(e.getAttribute("source"), "");
// // igd.getProfiles().add(p);
// // Element ex = XMLUtil.getFirstChild(e);
// // while (ex != null) {
// // if (ex.getNodeName().equals("example")) {
// // String filename = ex.getAttribute("source");
// // Example example = new Example(ex.getAttribute("name"), Utilities.changeFileExt(Utilities.getFileNameForName(filename), ""), ex.getAttribute("name"), new File(Utilities.path(file.getParent(), filename)), false, ExampleType.XmlFile, false);
// // p.getExamples().add(example);
// // } else
// // throw new Exception("Unknown element name in IG: "+ex.getNodeName());
// // ex = XMLUtil.getNextSibling(ex);
// // }
// } else if (e.getNodeName().equals("dictionary")) {
// // Dictionary d = new Dictionary(e.getAttribute("id"), e.getAttribute("name"), igd.getCode(), Utilities.path(Utilities.path(file.getParent(), e.getAttribute("source"))), igd);
// // igd.getDictionaries().add(d);
// } else if (e.getNodeName().equals("logicalModel")) {
// // String source = Utilities.path(file.getParent(), e.getAttribute("source"));
// // String id = igd.getCode()+"-"+e.getAttribute("id");
// // SpreadsheetParser sparser = new SpreadsheetParser(igd.getCode(), new CSFileInputStream(source), id, igd, rootDir, logger, null, context.getVersion(), context, genDate, false, igd.getExtensions(), pkp, false, committee, mappings);
// // sparser.getBindings().putAll(commonBindings);
// // sparser.setFolder(Utilities.getDirectoryForFile(source));
// // LogicalModel lm = sparser.parseLogicalModel(source);
// // lm.setId(id);
// // lm.setSource(source);
// // lm.getResource().setName(lm.getId());
// // igd.getLogicalModels().add(lm);
// } else
// throw new Exception("Unknown element name in IG: "+e.getNodeName());
// e = XMLUtil.getNextSibling(e);
// }
}
use of org.hl7.fhir.utilities.graphql.Package in project kindling by HL7.
the class Publisher method produceSpec.
private void produceSpec() throws Exception {
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
for (LogicalModel lm : ig.getLogicalModels()) {
page.log(" ...logical model " + lm.getId(), LogMessageType.Process);
produceLogicalModel(lm, ig);
}
}
for (StructureDefinition ed : page.getWorkerContext().getExtensionDefinitions()) {
String filename = "extension-" + (ed.getUrl().startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/") ? ed.getUrl().substring(59).toLowerCase() : ed.getUrl().substring(40).toLowerCase());
ed.setUserData("filename", filename);
ImplementationGuideDefn ig = page.getDefinitions().getIgs().get(ed.getUserString(ToolResourceUtilities.NAME_RES_IG));
if (ig == null) {
ig = page.getDefinitions().getIgs().get("core");
}
ed.setUserData("path", (ig.isCore() ? "" : ig.getCode() + File.separator) + filename + ".html");
}
page.updateDiffEngineDefinitions();
loadValueSets2();
page.log(" ...extensions", LogMessageType.Process);
for (StructureDefinition ae : page.getWorkerContext().getExtensionDefinitions()) produceExtensionDefinition(ae);
checkAllOk();
page.log(" ...resource identities", LogMessageType.Process);
for (String rname : page.getDefinitions().getBaseResources().keySet()) {
ResourceDefn r = page.getDefinitions().getBaseResources().get(rname);
produceResource1(r, r.isAbstract());
}
for (String rname : page.getDefinitions().sortedResourceNames()) {
if (!rname.equals("ValueSet") && !rname.equals("CodeSystem") && wantBuild(rname)) {
ResourceDefn r = page.getDefinitions().getResources().get(rname);
produceResource1(r, false);
}
}
if (buildFlags.get("all")) {
page.log(" ...base profiles", LogMessageType.Process);
produceBaseProfile();
}
for (String rname : page.getDefinitions().getBaseResources().keySet()) {
ResourceDefn r = page.getDefinitions().getBaseResources().get(rname);
page.log(" ...resource " + r.getName(), LogMessageType.Process);
produceResource2(r, !rname.equals("Parameters"), rname.equals("Resource") ? "Meta" : null, false);
}
for (String rname : page.getDefinitions().sortedResourceNames()) {
if (!rname.equals("ValueSet") && !rname.equals("CodeSystem") && wantBuild(rname)) {
ResourceDefn r = page.getDefinitions().getResources().get(rname);
page.log(" ...resource " + r.getName(), LogMessageType.Process);
produceResource2(r, false, null, false);
}
}
for (Compartment c : page.getDefinitions().getCompartments()) {
if (buildFlags.get("all")) {
page.log(" ...compartment " + c.getName(), LogMessageType.Process);
produceCompartment(c);
}
}
Regenerator regen = new Regenerator(page.getFolders().srcDir, page.getDefinitions(), page.getWorkerContext());
regen.generate();
Bundle searchParamsFeed = new Bundle();
searchParamsFeed.setId("searchParams");
searchParamsFeed.setType(BundleType.COLLECTION);
searchParamsFeed.setMeta(new Meta().setLastUpdated(page.getResourceBundle().getMeta().getLastUpdated()));
Set<String> uris = new HashSet<String>();
for (ResourceDefn rd : page.getDefinitions().getBaseResources().values()) addSearchParams(uris, searchParamsFeed, rd);
for (String n : page.getDefinitions().sortedResourceNames()) {
ResourceDefn rd = page.getDefinitions().getResources().get(n);
addSearchParams(uris, searchParamsFeed, rd);
}
for (Profile cp : page.getDefinitions().getPackList()) {
addSearchParams(uris, searchParamsFeed, cp);
}
checkBundleURLs(searchParamsFeed);
for (String n : page.getIni().getPropertyNames("pages")) {
if (buildFlags.get("all") || buildFlags.get("page-" + n.toLowerCase())) {
page.log(" ...page " + n, LogMessageType.Process);
producePage(n, page.getIni().getStringProperty("pages", n));
}
}
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
for (String n : ig.getPageList()) {
page.log(" ...ig page " + n, LogMessageType.Process);
produceIgPage(n, ig);
}
for (ImplementationGuideDefinitionPageComponent page : ig.getSpecialPages()) {
produceIgPage(ig, page);
}
for (Profile p : ig.getProfiles()) {
if (!p.getOperations().isEmpty()) {
produceIgOperations(ig, p);
}
}
}
if (page.getIni().getPropertyNames("ig-pages") != null) {
for (String n : page.getIni().getPropertyNames("ig-pages")) {
page.log(" ...page " + n, LogMessageType.Process);
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
if (!ig.isCore())
produceIgPage(n, ig, page.getIni().getStringProperty("ig-pages", n));
}
}
}
for (String n : page.getDefinitions().getDictionaries().keySet()) {
if (buildFlags.get("all")) {
// || buildFlags.get("dict-" + n.toLowerCase())) {
page.log(" ...dictionary " + n, LogMessageType.Process);
produceDictionary(page.getDefinitions().getDictionaries().get(n));
}
}
int i = 0;
for (String n : page.getIni().getPropertyNames("sid")) {
page.log(" ...sid " + n, LogMessageType.Process);
produceSid(i, n, page.getIni().getStringProperty("sid", n));
i++;
}
if (buildFlags.get("all")) {
page.log(" ...check Fragments", LogMessageType.Process);
checkFragments();
for (Profile p : page.getDefinitions().getPackList()) {
// if (!n.startsWith("http://")) {
page.log(" ...Profile " + p.getId(), LogMessageType.Process);
produceConformancePackage(null, p, null);
// }
}
produceUml();
page.getVsValidator().checkDuplicates(page.getValidationErrors());
if (buildFlags.get("all")) {
// if (page.getToc().containsKey("1.1"))
// throw new Exception("Duplicate DOC Entry "+"1.1");
page.getToc().put("1.1", new TocEntry("1.1", "Table Of Contents", "toc.html", false));
page.log(" ...page toc.html", LogMessageType.Process);
producePage("toc.html", null);
}
checkAllOk();
page.log(" ...collections ", LogMessageType.Process);
com.google.gson.JsonObject diff = new com.google.gson.JsonObject();
page.getDiffEngine().getDiffAsJson(diff);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(diff);
TextFile.stringToFile(json, Utilities.path(page.getFolders().dstDir, "fhir.diff.json"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.newDocument();
Element element = doc.createElement("difference");
doc.appendChild(element);
page.getDiffEngine().getDiffAsXml(doc, element);
prettyPrint(doc, Utilities.path(page.getFolders().dstDir, "fhir.diff.xml"));
checkBundleURLs(page.getResourceBundle());
checkStructureDefinitions(page.getResourceBundle());
page.getResourceBundle().getEntry().sort(new ProfileBundleSorter());
FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + "profiles-resources.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, page.getResourceBundle());
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "profiles-resources.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, page.getResourceBundle());
s.close();
checkBundleURLs(page.getTypeBundle());
checkStructureDefinitions(page.getTypeBundle());
page.getTypeBundle().getEntry().sort(new ProfileBundleSorter());
s = new FileOutputStream(page.getFolders().dstDir + "profiles-types.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, page.getTypeBundle());
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "profiles-types.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, page.getTypeBundle());
s.close();
Bundle extensionsFeed = new Bundle();
extensionsFeed.setId("extensions");
extensionsFeed.setType(BundleType.COLLECTION);
extensionsFeed.setMeta(new Meta().setLastUpdated(page.getResourceBundle().getMeta().getLastUpdated()));
Set<String> urls = new HashSet<String>();
for (StructureDefinition ed : page.getWorkerContext().getExtensionDefinitions()) {
if (!urls.contains(ed.getUrl())) {
urls.add(ed.getUrl());
extensionsFeed.getEntry().add(new BundleEntryComponent().setResource(ed).setFullUrl("http://hl7.org/fhir/" + ed.fhirType() + "/" + ed.getId()));
}
}
checkBundleURLs(extensionsFeed);
checkStructureDefinitions(extensionsFeed);
s = new FileOutputStream(page.getFolders().dstDir + "extension-definitions.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, extensionsFeed);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "extension-definitions.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, extensionsFeed);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "extension-definitions.xml", page.getFolders().dstDir + "examples" + File.separator + "extension-definitions.xml");
s = new FileOutputStream(page.getFolders().dstDir + "search-parameters.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, searchParamsFeed);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "search-parameters.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, searchParamsFeed);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "search-parameters.xml", page.getFolders().dstDir + "examples" + File.separator + "search-parameters.xml");
for (ResourceDefn rd : page.getDefinitions().getResources().values()) addOtherProfiles(profileBundle, rd);
for (Profile cp : page.getDefinitions().getPackList()) {
addOtherProfiles(profileBundle, cp);
}
checkBundleURLs(profileBundle);
checkStructureDefinitions(profileBundle);
s = new FileOutputStream(page.getFolders().dstDir + "profiles-others.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, profileBundle);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "profiles-others.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, profileBundle);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "profiles-others.xml", page.getFolders().dstDir + "examples" + File.separator + "profiles-others.xml");
// todo-bundle - should this be checked?
// int ec = 0;
// for (Resource e : valueSetsFeed.getItem()) {
// ValueSet vs = (ValueSet) e;
// if (!vs.getUrl().equals(e.getId())) {
// ec++;
// page.log("Valueset id mismatch: atom entry has '"+e.getId()+"', but value set is '"+vs.getUrl()+"'", LogMessageType.Error);
// }
// }
// if (ec > 0)
// throw new Exception("Cannot continue due to value set mis-identification");
checkBundleURLs(dataElements);
s = new FileOutputStream(page.getFolders().dstDir + "dataelements.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, dataElements);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "dataelements.xml", page.getFolders().dstDir + "examples" + File.separator + "dataelements.xml");
s = new FileOutputStream(page.getFolders().dstDir + "dataelements.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, dataElements);
s.close();
checkBundleURLs(valueSetsFeed);
s = new FileOutputStream(page.getFolders().dstDir + "valuesets.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, valueSetsFeed);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "valuesets.xml", page.getFolders().dstDir + "examples" + File.separator + "valuesets.xml");
s = new FileOutputStream(page.getFolders().dstDir + "valuesets.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, valueSetsFeed);
s.close();
checkBundleURLs(conceptMapsFeed);
s = new FileOutputStream(page.getFolders().dstDir + "conceptmaps.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, conceptMapsFeed);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "conceptmaps.xml", page.getFolders().dstDir + "examples" + File.separator + "conceptmaps.xml");
s = new FileOutputStream(page.getFolders().dstDir + "conceptmaps.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, conceptMapsFeed);
s.close();
checkBundleURLs(externals);
s = new FileOutputStream(page.getFolders().dstDir + "external-resources.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, externals);
s.close();
Utilities.copyFile(page.getFolders().dstDir + "external-resources.xml", page.getFolders().dstDir + "examples" + File.separator + "external-resources.xml");
s = new FileOutputStream(page.getFolders().dstDir + "external-resources.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, externals);
s.close();
ImplementationGuide expIg = new ImplementationGuide();
expIg.addFhirVersion(page.getVersion());
expIg.setPackageId(pidRoot() + ".expansions");
expIg.setVersion(page.getVersion().toCode());
expIg.setLicense(ImplementationGuide.SPDXLicense.CC01_0);
expIg.setTitle("FHIR " + page.getVersion().getDisplay() + " package : Expansions");
expIg.setDescription("Expansions for the " + page.getVersion().getDisplay() + " version of the FHIR standard");
NPMPackageGenerator npm = new NPMPackageGenerator(Utilities.path(page.getFolders().dstDir, pidRoot() + ".expansions.tgz"), "http://hl7.org/fhir", "http://hl7.org/fhir", PackageType.CORE, expIg, page.getGenDate().getTime(), true);
Bundle expansionFeed = new Bundle();
Set<String> urlset = new HashSet<>();
expansionFeed.setId("valueset-expansions");
expansionFeed.setType(BundleType.COLLECTION);
expansionFeed.setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
expansionFeed.getFormatCommentsPre().add("This collection contains expansions for all the value sets that are used on an element of type \r\n" + "'code', to help with code generation (saves the code generator having to figure out how to \r\n" + "do the expansions or find a terminology server that supports the same version of the value sets");
for (ValueSet vs : page.getValueSets().getList()) {
if (!urlset.contains(vs.getUrl())) {
urlset.add(vs.getUrl());
if (vs.getUserData(ToolResourceUtilities.NAME_VS_USE_MARKER) != null) {
ValueSet evs = null;
if (vs.hasUserData("expansion"))
evs = (ValueSet) vs.getUserData("expansion");
else {
ValueSetExpansionOutcome vse = page.getWorkerContext().expandVS(vs, true, false);
if (vse.getValueset() != null) {
evs = vse.getValueset();
vs.setUserData("expansion", evs);
}
}
if (evs != null) {
ValueSet vsc = vs.copy();
vsc.setText(null);
vsc.setExpansion(evs.getExpansion());
expansionFeed.addEntry().setFullUrl("http://hl7.org/fhir/" + vsc.fhirType() + "/" + vsc.getId()).setResource(vsc);
npm.addFile(Category.RESOURCE, "ValueSet-" + vsc.getId() + ".json", new JsonParser().composeBytes(vsc));
}
}
}
}
npm.finish();
if (!isCIBuild) {
String id = pidRoot() + ".expansions";
new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).addPackageToCache(id, "current", new FileInputStream(Utilities.path(page.getFolders().dstDir, id + ".tgz")), Utilities.path(page.getFolders().dstDir, id + ".tgz"));
}
s = new FileOutputStream(page.getFolders().dstDir + "expansions.xml");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, expansionFeed);
s.close();
s = new FileOutputStream(page.getFolders().dstDir + "expansions.json");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, expansionFeed);
s.close();
produceComparisons();
produceSpecMap();
processRDF();
page.log("....version maps", LogMessageType.Process);
ZipGenerator zip = new ZipGenerator(page.getFolders().dstDir + "r3r4maps.zip");
zip.addFiles(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R3toR4", ""), "r3/", null, null);
zip.addFiles(Utilities.path(page.getFolders().rootDir, "implementations", "r3maps", "R4toR3", ""), "r4/", null, null);
zip.close();
page.log("....definitions", LogMessageType.Process);
zip = new ZipGenerator(page.getFolders().dstDir + "definitions.xml.zip");
zip.addFileName("version.info", page.getFolders().dstDir + "version.info", false);
zip.addFileName("profiles-types.xml", page.getFolders().dstDir + "profiles-types.xml", false);
zip.addFileName("profiles-resources.xml", page.getFolders().dstDir + "profiles-resources.xml", false);
zip.addFileName("profiles-others.xml", page.getFolders().dstDir + "profiles-others.xml", false);
zip.addFileName("extension-definitions.xml", page.getFolders().dstDir + "extension-definitions.xml", false);
zip.addFileName("search-parameters.xml", page.getFolders().dstDir + "search-parameters.xml", false);
zip.addFileName("valuesets.xml", page.getFolders().dstDir + "valuesets.xml", false);
zip.addFileName("conceptmaps.xml", page.getFolders().dstDir + "conceptmaps.xml", false);
zip.addFileName("dataelements.xml", page.getFolders().dstDir + "dataelements.xml", false);
zip.addFileName("fhir-all-xsd.zip", page.getFolders().dstDir + "fhir-all-xsd.zip", false);
zip.close();
zip = new ZipGenerator(page.getFolders().dstDir + "definitions.json.zip");
zip.addFileName("version.info", page.getFolders().dstDir + "version.info", false);
zip.addFileName("profiles-types.json", page.getFolders().dstDir + "profiles-types.json", false);
zip.addFileName("profiles-resources.json", page.getFolders().dstDir + "profiles-resources.json", false);
zip.addFileName("profiles-others.json", page.getFolders().dstDir + "profiles-others.json", false);
zip.addFileName("extension-definitions.json", page.getFolders().dstDir + "extension-definitions.json", false);
zip.addFileName("search-parameters.json", page.getFolders().dstDir + "search-parameters.json", false);
zip.addFileName("valuesets.json", page.getFolders().dstDir + "valuesets.json", false);
zip.addFileName("conceptmaps.json", page.getFolders().dstDir + "conceptmaps.json", false);
zip.addFileName("dataelements.json", page.getFolders().dstDir + "dataelements.json", false);
zip.addFileName("fhir.schema.json.zip", page.getFolders().dstDir + "fhir.schema.json.zip", false);
zip.close();
zip = new ZipGenerator(page.getFolders().dstDir + "definitions.xlsx.zip");
for (String rn : page.getDefinitions().sortedResourceNames()) {
zip.addFileName(rn.toLowerCase() + ".xlsx", page.getFolders().dstDir + rn.toLowerCase() + ".xlsx", false);
}
zip.close();
// this is the actual package used by the validator.
zip = new ZipGenerator(page.getFolders().dstDir + "validator.pack");
// conformance resources
zip.addFileName("profiles-types.json", page.getFolders().dstDir + "profiles-types.json", false);
zip.addFileName("profiles-resources.json", page.getFolders().dstDir + "profiles-resources.json", false);
zip.addFileName("profiles-others.json", page.getFolders().dstDir + "profiles-others.json", false);
zip.addFileName("extension-definitions.json", page.getFolders().dstDir + "extension-definitions.json", false);
zip.addFileName("valuesets.json", page.getFolders().dstDir + "valuesets.json", false);
zip.addFileName("conceptmaps.json", page.getFolders().dstDir + "conceptmaps.json", false);
// native schema
zip.addFileName("fhir-all-xsd.zip", page.getFolders().dstDir + "fhir-all-xsd.zip", false);
zip.addFileName("fhir.schema.json.zip", page.getFolders().dstDir + "fhir.schema.json.zip", false);
zip.addFileName("fhir.shex", page.getFolders().dstDir + "fhir.shex", false);
zip.close();
page.log("....dstu3 format (xml)", LogMessageType.Process);
DSTU3ValidationConvertor dstu3 = new DSTU3ValidationConvertor();
dstu3.convert(page.getFolders().dstDir + "profiles-types.xml", page.getFolders().tmpDir + "profiles-types-r3.xml");
dstu3.convert(page.getFolders().dstDir + "profiles-resources.xml", page.getFolders().tmpDir + "profiles-resources-r3.xml");
dstu3.convert(page.getFolders().dstDir + "profiles-others.xml", page.getFolders().tmpDir + "profiles-others-r3.xml");
dstu3.convert(page.getFolders().dstDir + "extension-definitions.xml", page.getFolders().tmpDir + "extension-definitions-r3.xml");
dstu3.convert(page.getFolders().dstDir + "search-parameters.xml", page.getFolders().tmpDir + "search-parameters-r3.xml");
dstu3.convert(page.getFolders().dstDir + "valuesets.xml", page.getFolders().tmpDir + "valuesets-r3.xml");
dstu3.convert(page.getFolders().dstDir + "conceptmaps.xml", page.getFolders().tmpDir + "conceptmaps-r3.xml");
dstu3.convert(page.getFolders().dstDir + "dataelements.xml", page.getFolders().tmpDir + "dataelements-r3.xml");
zip = new ZipGenerator(page.getFolders().dstDir + "definitions-r3.xml.zip");
zip.addFileName("profiles-types.xml", page.getFolders().tmpDir + "profiles-types-r3.xml", false);
zip.addFileName("profiles-resources.xml", page.getFolders().tmpDir + "profiles-resources-r3.xml", false);
zip.addFileName("profiles-others.xml", page.getFolders().tmpDir + "profiles-others-r3.xml", false);
zip.addFileName("extension-definitions.xml", page.getFolders().tmpDir + "extension-definitions-r3.xml", false);
zip.addFileName("search-parameters.xml", page.getFolders().tmpDir + "search-parameters-r3.xml", false);
zip.addFileName("valuesets.xml", page.getFolders().tmpDir + "valuesets-r3.xml", false);
zip.addFileName("conceptmaps.xml", page.getFolders().tmpDir + "conceptmaps-r3.xml", false);
zip.addFileName("dataelements.xml", page.getFolders().tmpDir + "dataelements-r3.xml", false);
zip.close();
page.log("....dstu3 format (json)", LogMessageType.Process);
dstu3.convertJ(page.getFolders().dstDir + "profiles-types.xml", page.getFolders().tmpDir + "profiles-types-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "profiles-resources.xml", page.getFolders().tmpDir + "profiles-resources-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "profiles-others.xml", page.getFolders().tmpDir + "profiles-others-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "extension-definitions.xml", page.getFolders().tmpDir + "extension-definitions-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "search-parameters.xml", page.getFolders().tmpDir + "search-parameters-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "valuesets.xml", page.getFolders().tmpDir + "valuesets-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "conceptmaps.xml", page.getFolders().tmpDir + "conceptmaps-r3.json");
dstu3.convertJ(page.getFolders().dstDir + "dataelements.xml", page.getFolders().tmpDir + "dataelements-r3.json");
zip = new ZipGenerator(page.getFolders().dstDir + "definitions-r3.json.zip");
zip.addFileName("profiles-types.json", page.getFolders().tmpDir + "profiles-types-r3.json", false);
zip.addFileName("profiles-resources.json", page.getFolders().tmpDir + "profiles-resources-r3.json", false);
zip.addFileName("profiles-others.json", page.getFolders().tmpDir + "profiles-others-r3.json", false);
zip.addFileName("extension-definitions.json", page.getFolders().tmpDir + "extension-definitions-r3.json", false);
zip.addFileName("search-parameters.json", page.getFolders().tmpDir + "search-parameters-r3.json", false);
zip.addFileName("valuesets.json", page.getFolders().tmpDir + "valuesets-r3.json", false);
zip.addFileName("conceptmaps.json", page.getFolders().tmpDir + "conceptmaps-r3.json", false);
zip.addFileName("dataelements.json", page.getFolders().tmpDir + "dataelements-r3.json", false);
zip.close();
System.gc();
page.log("....r4 in r5 format", LogMessageType.Process);
zip = new ZipGenerator(page.getFolders().dstDir + "definitions-r2asr3.xml.zip");
page.getDiffEngine().saveR4AsR5(zip, FhirFormat.XML);
zip.close();
zip = new ZipGenerator(page.getFolders().dstDir + "definitions-r2asr3.json.zip");
page.getDiffEngine().saveR4AsR5(zip, FhirFormat.JSON);
zip.close();
zip = new ZipGenerator(page.getFolders().dstDir + "all-valuesets.zip");
zip.addFileName("valuesets.xml", page.getFolders().dstDir + "valuesets.xml", false);
zip.addFileName("valuesets.json", page.getFolders().dstDir + "valuesets.json", false);
zip.addFileName("conceptmaps.xml", page.getFolders().dstDir + "conceptmaps.xml", false);
zip.addFileName("conceptmaps.json", page.getFolders().dstDir + "conceptmaps.json", false);
zip.close();
page.log("....IG Builder Resources", LogMessageType.Process);
zip = new ZipGenerator(page.getFolders().tmpDir + "ig-template.zip");
zip.addFolder(Utilities.path(page.getFolders().rootDir, "tools", "ig"), "", false, null);
zip.close();
zip = new ZipGenerator(page.getFolders().dstDir + "igpack.zip");
zip.addFileName("fhir.css", page.getFolders().dstDir + "fhir.css", false);
zip.addFileName("spec.internals", page.getFolders().dstDir + "spec.internals", false);
zip.addFileName("profiles-types.xml", page.getFolders().dstDir + "profiles-types.xml", false);
zip.addFileName("profiles-resources.xml", page.getFolders().dstDir + "profiles-resources.xml", false);
zip.addFileName("profiles-others.xml", page.getFolders().dstDir + "profiles-others.xml", false);
zip.addFileName("extension-definitions.xml", page.getFolders().dstDir + "extension-definitions.xml", false);
zip.addFileName("search-parameters.xml", page.getFolders().dstDir + "search-parameters.xml", false);
zip.addFileName("valuesets.xml", page.getFolders().dstDir + "valuesets.xml", false);
zip.addFileName("conceptmaps.xml", page.getFolders().dstDir + "conceptmaps.xml", false);
zip.addFileName("dataelements.xml", page.getFolders().dstDir + "dataelements.xml", false);
zip.addFileName("version.info", page.getFolders().dstDir + "version.info", false);
zip.addFileName("mappingSpaces.details", page.getFolders().srcDir + "mappingSpaces.xml", false);
zip.addFileName("redirect.asp.template", page.getFolders().srcDir + "redirect.asp", false);
zip.addFileName("redirect.cgi.template", page.getFolders().srcDir + "redirect.cgi", false);
zip.addFileName("redirect.php.template", page.getFolders().srcDir + "redirect.php", false);
zip.addFileName("ig-template.zip", Utilities.path(page.getFolders().tmpDir, "ig-template.zip"), false);
zip.addFiles(Utilities.path(page.getFolders().rootDir, "publish", ""), "", ".png", null);
zip.addFiles(Utilities.path(page.getFolders().rootDir, "publish", ""), "", ".gif", null);
zip.close();
page.log("....IG Builder (2)", LogMessageType.Process);
SpecNPMPackageGenerator self = new SpecNPMPackageGenerator();
self.generate(page.getFolders().dstDir, page.getBaseURL(), false, page.getGenDate().getTime(), pidRoot());
if (!isCIBuild) {
new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).addPackageToCache(pidRoot() + ".core", "current", new FileInputStream(Utilities.path(page.getFolders().dstDir, pidRoot() + ".core.tgz")), Utilities.path(page.getFolders().dstDir, pidRoot() + ".core.tgz"));
}
page.log(" ...zips", LogMessageType.Process);
zip = new ZipGenerator(page.getFolders().dstDir + "examples.zip");
zip.addFiles(page.getFolders().dstDir + "examples" + File.separator, "", null, "expansions.xml");
zip.close();
zip = new ZipGenerator(page.getFolders().dstDir + "examples-json.zip");
gson = new GsonBuilder().setPrettyPrinting().create();
File f = new CSFile(page.getFolders().dstDir);
File[] files = f.listFiles();
String[] noExt = new String[] { ".schema.json", ".canonical.json", ".diff.json", "expansions.json", "package.json", "choice-elements.json", "backbone-elements.json" };
for (int fi = 0; fi < files.length; fi++) {
if (files[fi].isFile() && (files[fi].getName().endsWith(".json"))) {
boolean ok = true;
for (String n : noExt) {
ok = ok && !files[fi].getName().endsWith(n);
}
if (ok) {
JsonObject jr = JSONUtil.parse(TextFile.fileToString(files[fi]));
if (!jr.has("url")) {
JsonObject meta = JSONUtil.forceObject(jr, "meta");
JsonArray labels = JSONUtil.forceArray(meta, "tag");
JsonObject label = JSONUtil.addObj(labels);
label.addProperty("system", "http://terminology.hl7.org/CodeSystem/v3-ActReason");
label.addProperty("code", "HTEST");
label.addProperty("display", "test health data");
}
String jrs = gson.toJson(jr);
zip.addBytes(files[fi].getName(), jrs.getBytes(Charsets.UTF_8), true);
}
}
}
zip.close();
NDJsonWriter ndjson = new NDJsonWriter(page.getFolders().dstDir + "examples-ndjson.zip", page.getFolders().tmpDir);
ndjson.addFilesFiltered(page.getFolders().dstDir, ".json", new String[] { ".schema.json", ".canonical.json", ".diff.json", "expansions.json", "package.json" });
ndjson.close();
zip = new ZipGenerator(page.getFolders().dstDir + "examples-ttl.zip");
zip.addFilesFiltered(page.getFolders().dstDir, "", ".ttl", new String[0]);
zip.close();
page.log("Check HTML Links", LogMessageType.Process);
page.getHTMLChecker().produce();
checkAllOk();
} else
page.log("Partial Build - terminating now", LogMessageType.Error);
}
use of org.hl7.fhir.utilities.graphql.Package in project redmatch by aehrc.
the class CompletionProcessor method handleAttribute.
/**
* Handles searching for a FHIR resource attribute name.
*
* @param url The document url. Used to get the FHIR package for that document.
* @param tokens The list of tokens.
* @return A list of potential completions.
*/
private List<CompletionItem> handleAttribute(String url, List<? extends Token> tokens) {
List<CompletionItem> completionItems = new ArrayList<>();
// Look for ATTRIBUTE_START and return if we find a token that is not one of the following: NOT, PATH, OPEN_SQ,
// INDEX, CLOSE_SQ or ATTRIBUTE_START
List<Token> attributes = new ArrayList<>();
int i = tokens.size() - 1;
outer: for (; i >= 0; i--) {
switch(tokens.get(i).getType()) {
case RedmatchLexer.ATTRIBUTE_START:
break outer;
case RedmatchLexer.NOT:
case RedmatchLexer.PATH:
case RedmatchLexer.OPEN_SQ:
case RedmatchLexer.INDEX:
case RedmatchLexer.CLOSE_SQ:
case RedmatchLexer.DOT:
attributes.add(tokens.get(i));
break;
default:
return completionItems;
}
}
// We need to look for the resource token, because it is needed in the call to Ontoserver. This will be the second
// ID token after the colon, going from right to left
Token resourceToken = null;
boolean hasSeenColon = false;
boolean hasSeenResourceId = false;
outer: for (; i >= 0; i--) {
switch(tokens.get(i).getType()) {
case RedmatchLexer.COLON:
hasSeenColon = true;
break;
case RedmatchLexer.ID:
if (hasSeenColon) {
if (hasSeenResourceId) {
resourceToken = tokens.get(i);
break outer;
} else {
hasSeenResourceId = true;
}
}
break;
default:
break;
}
}
if (resourceToken == null) {
return completionItems;
}
// The attributes array contains the tokens that make up the prefix
StringBuilder sb = new StringBuilder();
for (i = attributes.size() - 1; i >= 0; i--) {
sb.append(attributes.get(i).getText());
}
String prefix = sb.toString();
VersionedFhirPackage fhirPackage = documentService.getFhirPackage(url);
if (fhirPackage == null) {
return Collections.emptyList();
}
try {
String parentResource = resourceToken.getText();
ValueSet expansion = terminologyService.expand(fhirPackage, prefix, false, parentResource);
for (ValueSet.ValueSetExpansionContainsComponent component : expansion.getExpansion().getContains()) {
// +1 to account for the dot
String code = component.getCode().substring(parentResource.length() + 1);
completionItems.add(new CompletionItem(code));
}
return completionItems;
} catch (IOException e) {
log.error("There was a problem creating auto-completion results for document " + url + " and prefix " + prefix);
return Collections.emptyList();
}
}
Aggregations