Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binding table order #986

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8865,6 +8865,8 @@ private void generateSummaryOutputs(DBBuilder db) throws Exception {
start = System.currentTimeMillis();
trackedFragment("3", "dependency-table-short", depr.render(publishedIg, false, false, false), otherFilesRun, start, "dependency-table-short", "Cross");
start = System.currentTimeMillis();
trackedFragment("3", "dependency-table-nontech", depr.renderNonTech(publishedIg), otherFilesRun, start, "dependency-table-nontech", "Cross");
start = System.currentTimeMillis();
trackedFragment("4", "globals-table", depr.renderGlobals(), otherFilesRun, start, "globals-table", "Cross");

// now, list the profiles - all the profiles
Expand Down Expand Up @@ -11251,7 +11253,7 @@ private String processFragment(String arguments, FetchedFile f) throws FHIRExcep
String format = (secondSpace == -1) ? arguments.substring(firstSpace) : arguments.substring(firstSpace, secondSpace);
format = format.trim().toLowerCase();
String filters = (secondSpace == -1) ? "" : arguments.substring(secondSpace).trim();
Pattern refPattern = Pattern.compile("^([A-Z][a-z]+)+\\/([A-Za-z0-9\\-\\.]{1,64})$");
Pattern refPattern = Pattern.compile("^([A-Za-z]+)\\/([A-Za-z0-9\\-\\.]{1,64})$");
Matcher refMatcher = refPattern.matcher(reference);
if (!refMatcher.find())
throw new FHIRException("Fragment syntax error: Referenced instance must be expressed as [ResourceType]/[id]. Found " + reference + " in file " + f.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Map;
import java.util.Set;

import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
Expand Down Expand Up @@ -113,6 +115,7 @@ public enum VersionState {
private MarkDownProcessor mdEngine;
private RenderingContext rc;
private List<SpecMapManager> specMaps;
private Map<String, PackageInfo> packagesByName;

public DependencyRenderer(BasePackageCacheManager pcm, String dstFolder, String npmName, TemplateManager templateManager,
List<DependencyAnalyser.ArtifactDependency> dependencies, IWorkerContext context, MarkDownProcessor mdEngine, RenderingContext rc, List<SpecMapManager> specMaps) {
Expand All @@ -128,10 +131,153 @@ public DependencyRenderer(BasePackageCacheManager pcm, String dstFolder, String
this.specMaps = specMaps;
}

private class PackageVersionInfo {
private NpmPackage p;
@Getter
@Setter
private boolean direct;
@Getter
@Setter
private String reason;
private String parent;
public PackageVersionInfo(NpmPackage p, boolean direct, String reason, String parent) {
this.p = p;
this.direct = direct;
this.reason = reason;
this.parent = parent;
}

public String getReason() {
if (reason!=null)
return reason;
else
return "Imported by " + parent + " (and potentially others)";
}
}

private class PackageInfo {
private NpmPackage p;
private boolean direct;
private Map<String, PackageVersionInfo> versions = new HashMap<String, PackageVersionInfo>();
public PackageInfo(NpmPackage p, String reason, boolean direct, String parent) {
this.p = p;
this.direct = direct;
versions = new HashMap<String, PackageVersionInfo>();
PackageVersionInfo v = new PackageVersionInfo(p, direct, reason, parent);
versions.put(p.version(), v);
}

// Returns true if the version wasn't already present
protected boolean addVersion (NpmPackage p, String reason, boolean direct, String parent) {
if (versions.containsKey(p.version())) {
if (direct) {
this.direct = direct;
PackageVersionInfo v = versions.get(p.version());
v.setDirect(direct);
v.setReason(reason);
}
return false;
}
this.direct = this.direct || direct;
PackageVersionInfo v = new PackageVersionInfo(p, direct, reason, parent);
versions.put(p.version(), v);
return true;
}
}

public String renderNonTech(ImplementationGuide ig) throws FHIRException, IOException {
packagesByName = new HashMap<String, PackageInfo>();
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
NpmPackage p = resolve(d);
boolean dloaded = isLoaded(p);
if (dloaded) {
addPackage(p, d.hasReason() ? d.getReason() : ToolingExtensions.readStringExtension(d, ToolingExtensions.EXT_IGDEP_COMMENT), true);
}
}

if (packagesByName.isEmpty())
return "";
else {
StringBuilder b = new StringBuilder();
b.append("<table style=\"border: 0px #F0F0F0 solid;\"><thead><tr style=\"border: 1px #F0F0F0 solid; font-size: 11px; font-family: verdana; vertical-align: top;\"><th><b>Implementation Guide</b></th><th><b>Version(s)</b></th><th><b>Reason</b></th></tr></thead><tbody>");
List<String> names = new ArrayList<String>(packagesByName.keySet());
Collections.sort(names);
int lineCount = 1;
for (String name: names) {
PackageInfo info = packagesByName.get(name);
String newRow = "<tr style=\"font-size: 11px; font-family: verdana; vertical-align: top; background-color: " + ((lineCount % 2 == 0) ? "#F7F7F7" : "white") + "\"><td";
b.append(newRow);
if (info.versions.size()!=1)
b.append(" rowspan=\"" + info.versions.size() + "\"");
b.append("><span class=\"copy-text\" title=\"canonical: " + info.p.canonical() + "\"><a style=\"font-size: 11px; font-family: verdana; font-weight:" + (info.direct ? "bold" : "normal") + "\"");
b.append(" href=\"" + info.p.url() + "\">" + Utilities.escapeXml(name) + "</a><button class=\"btn-copy\" title=\"Click to copy URL\" data-clipboard-text=\"" + info.p.canonical() + "\"/></span></td><td>");
boolean first = true;
List<String> versions = new ArrayList<String>(info.versions.keySet());
Collections.sort(versions, Collections.reverseOrder());
for (String version: versions) {
PackageVersionInfo verInfo = info.versions.get(version);
if (!first)
b.append(newRow + ">");
b.append("<span class=\"copy-text\" title=\"package: " + verInfo.p.id() + "#" + version + "\"><a style=\"font-size: 11px; font-family: verdana; font-weight: " + (verInfo.direct ? "bold" : "normal") + "\"");
b.append(" href=\"https://simplifier.net/packages/" + info.p.name() + "/" + version + "\">" + version + "</a><button class=\"btn-copy\" title=\"Click to copy package\" data-clipboard-text=\"" + verInfo.p.id() + "#" + version + "\"/></span>");
b.append("</td><td" + (verInfo.direct ? "" : " style=\"font-style: italic;\"") + ">" + Utilities.escapeXml(verInfo.getReason()) + "</td></tr>");

first = false;
}
lineCount++;
first = true;
}
b.append("</tbody></table>");

return b.toString();
}
}

private void addPackage(NpmPackage p, String reason, boolean direct) {
addPackage(p, reason, direct, null);
}
private void addPackage(NpmPackage p, String reason, boolean direct, String parent) {
PackageInfo packageInfo;
String title;
if (p.getNpm().has("title"))
title = p.title();
else if (p.name().endsWith(".vsac"))
title = "Value Set Authority Center (VSAC)";
else if (p.name().endsWith(".phinvads"))
title = "Public Health Information Network Vocabulary Access and Distribution System (PHIN VADS)";
else
title = p.name();
if (title.contains("Wrapper)"))
title = title.substring(0, title.indexOf("(")).trim();
if (title.endsWith("Implementation Guide"))
title = title.substring(0, title.length()-20).trim();
if (packagesByName.containsKey(title)) {
packageInfo = packagesByName.get(title);
if (!packageInfo.addVersion(p, reason, direct, parent))
return;
} else {
packageInfo = new PackageInfo(p, reason, direct, parent);
packagesByName.put(title, packageInfo);
}

for (String d: p.dependencies()) {
if (isLoaded(d)) {
String id = d.substring(0, d.indexOf("#"));
String version = d.substring(d.indexOf("#") + 1);
try {
NpmPackage dp = resolve(id, version);
addPackage(dp, null, false, title);
} catch (Exception e) {
// Do nothing - this'll be dealt with elsewhere
}
}
}
}

public String render(ImplementationGuide ig, boolean QA, boolean details, boolean first) throws FHIRException, IOException {
boolean hasDesc = false;
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
hasDesc = hasDesc || d.hasExtension(ToolingExtensions.EXT_IGDEP_COMMENT);
hasDesc = hasDesc || d.hasExtension(ToolingExtensions.EXT_IGDEP_COMMENT) || d.hasReason();
}

HierarchicalTableGenerator gen = new HierarchicalTableGenerator(rc, dstFolder, true, true, "dep");
Expand All @@ -149,7 +295,7 @@ public String render(ImplementationGuide ig, boolean QA, boolean details, boolea
NpmPackage p = resolve(d);
boolean dloaded = isLoaded(p);
if (QA || dloaded) {
addPackageRow(gen, row.getSubRows(), p, d.getVersion(), realm, QA, b, ToolingExtensions.readStringExtension(d, ToolingExtensions.EXT_IGDEP_COMMENT), hasDesc, processed, listed, dloaded);
addPackageRow(gen, row.getSubRows(), p, d.getVersion(), realm, QA, b, d.hasReason() ? d.getReason() : ToolingExtensions.readStringExtension(d, ToolingExtensions.EXT_IGDEP_COMMENT), hasDesc, processed, listed, dloaded);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,17 @@ else if (!tx.hasDescription())
if (brd.suffix != null) {
b.append(brd.suffix);
}
if (tx.hasValueSet()) {
b.append("<div><code>"+Utilities.escapeXml(tx.getValueSet())+"</code><button title=\"Click to copy URL\" class=\"btn-copy\" data-clipboard-text=\""+Utilities.escapeXml(tx.getValueSet())+"\"></button></div>");
if (link != null) {
if (Utilities.isAbsoluteUrlLinkable(link)) {
b.append("<div>from <a href=\""+Utilities.escapeXml(link)+"\">"+Utilities.escapeXml(link)+"</a></div>");
} else {
b.append("<div>from "+Utilities.escapeXml(link)+"</div>");
}
}
} else {
}
AdditionalBindingsRenderer abr = new AdditionalBindingsRenderer(igp, corePath, sd, path, gen, this, sdr);
if (tx.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
abr.seeMaxBinding(ToolingExtensions.getExtension(tx, ToolingExtensions.EXT_MAX_VALUESET));
Expand All @@ -825,17 +836,6 @@ else if (!tx.hasDescription())
abr.render(x.getChildNodes(), true);
b.append(new XhtmlComposer(true, true).compose(x));
}
if (tx.hasValueSet()) {
b.append("<div><code>"+Utilities.escapeXml(tx.getValueSet())+"</code><button title=\"Click to copy URL\" class=\"btn-copy\" data-clipboard-text=\""+Utilities.escapeXml(tx.getValueSet())+"\"></button></div>");
if (link != null) {
if (Utilities.isAbsoluteUrlLinkable(link)) {
b.append("<div>from <a href=\""+Utilities.escapeXml(link)+"\">"+Utilities.escapeXml(link)+"</a></div>");
} else {
b.append("<div>from "+Utilities.escapeXml(link)+"</div>");
}
}
} else {
}
b.append("</td>");
b.append("</tr>\r\n");
}
Expand Down
Loading