Skip to content

Commit

Permalink
Merge pull request #752 from HL7/2023-09-gg-link-spec
Browse files Browse the repository at this point in the history
2023 09 gg link spec
  • Loading branch information
grahamegrieve authored Sep 6, 2023
2 parents 49163f8 + 23dc22e commit d4cfd91
Show file tree
Hide file tree
Showing 16 changed files with 623 additions and 107 deletions.
17 changes: 17 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* Loader: Update to cqframework 2.11 and remove unused common-beanutils declaration (#1419)
* Version Conversion: Fix for Requirements.reference between versions
* Terminology Subsystem: NPE proofing property handling for Code Systems
* Validator: Test concept map code validity
* Validator: Rework type checking on target profiles to support imposesProfile
* Validator: Fix imposesProfile extension being missed on primary profile
* Validator: Fix warning/error message about experimental property on CodeSystems and ValueSets
* Validator: Fix unknown code message to include code system version
* Validator: Add provisional SHLinks validation
* Renderer: Requirements.reference
* Renderer: Fix DF markdown engine to escape < properly
* Renderer: fix extensions missing from extensions view
* Renderer: Fix issue with improper HTML generation on collapsible reference lists
* Link checker: Add support for linking to package content without depending on the packages (http://hl7.org/fhir/tools/StructureDefinition/ig-link-dependency)
* Publication Process: fix handling of sub-packages for THO
* Publication Process: update to support cross-linking between versions in header (US Core)
* XIG: Rework XIG to slpit into two parts (WIP)
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public String getNextId() {
private String rootFolder;
private String altRootFolder;
private List<SpecMapManager> specs;
private List<SpecMapManager> linkSpecs;
private Map<String, LoadedFile> cache = new HashMap<String, LoadedFile>();
private int iteration = 0;
private List<StringPair> otherlinks = new ArrayList<StringPair>();
Expand All @@ -191,9 +192,6 @@ public String getNextId() {
private boolean requirePublishBox;
private List<String> igs;
private FilesystemPackageCacheManager pcm;
private Map<String, SpecMapManager> otherSpecs = new HashMap<String, SpecMapManager>();
private Map<String, String> specList = new HashMap<>();
private List<String> errorPackages = new ArrayList<>();
private String canonical;

private String statusText;
Expand All @@ -205,9 +203,10 @@ public String getNextId() {
private Map<String, List<String>> trackedFragments;
private Set<String> foundFragments = new HashSet<>();

public HTMLInspector(String rootFolder, List<SpecMapManager> specs, ILoggingService log, String canonical, String packageId, Map<String, List<String>> trackedFragments) {
public HTMLInspector(String rootFolder, List<SpecMapManager> specs, List<SpecMapManager> linkSpecs, ILoggingService log, String canonical, String packageId, Map<String, List<String>> trackedFragments) {
this.rootFolder = rootFolder.replace("/", File.separator);
this.specs = specs;
this.linkSpecs = linkSpecs;
this.log = log;
this.canonical = canonical;
this.forHL7 = canonical.contains("hl7.org/fhir");
Expand Down Expand Up @@ -639,6 +638,17 @@ private boolean checkResolveLink(String filename, Location loc, String path, Str
}
}
}
if (!resolved && linkSpecs != null){
for (SpecMapManager spec : linkSpecs) {
if (!resolved && spec.getBase() != null) {
resolved = resolved || spec.getBase().equals(rref) || (spec.getBase()).equals(rref+"/") || (spec.getBase()+"/").equals(rref)|| spec.hasTarget(rref) || Utilities.existsInList(rref, Utilities.pathURL(spec.getBase(), "history.html"));
}
if (!resolved && spec.getBase2() != null) {
resolved = spec.getBase2().equals(rref) || (spec.getBase2()).equals(rref+"/");
}
}
}


if (!resolved) {
if (Utilities.isAbsoluteFileName(ref)) {
Expand Down Expand Up @@ -825,7 +835,7 @@ public int links() {
}

public static void main(String[] args) throws Exception {
HTMLInspector inspector = new HTMLInspector(args[0], null, null, "http://hl7.org/fhir/us/core", "hl7.fhir.us.core", new HashMap<>());
HTMLInspector inspector = new HTMLInspector(args[0], null, null, null, "http://hl7.org/fhir/us/core", "hl7.fhir.us.core", new HashMap<>());
inspector.setStrict(false);
List<ValidationMessage> linkmsgs = inspector.check("test text");
int bl = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ public enum GenerationTool {
private XVerExtensionManager xverManager;
private IGKnowledgeProvider igpkp;
private List<SpecMapManager> specMaps = new ArrayList<SpecMapManager>();
private List<SpecMapManager> linkSpecMaps = new ArrayList<SpecMapManager>();
private List<String> suppressedIds = new ArrayList<>();

private Map<String, MappingSpace> mappingSpaces = new HashMap<String, MappingSpace>();
Expand Down Expand Up @@ -2986,7 +2987,7 @@ else if (vsCache == null) {
} else {
sourceIg.getDefinition().addExtension("http://hl7.org/fhir/tools/StructureDefinition/ig-internal-dependency", new CodeType("hl7.fhir.uv.tools#current"));
}
inspector = new HTMLInspector(outputDir, specMaps, this, igpkp.getCanonical(), sourceIg.getPackageId(), trackedFragments);
inspector = new HTMLInspector(outputDir, specMaps, linkSpecMaps, this, igpkp.getCanonical(), sourceIg.getPackageId(), trackedFragments);
inspector.getManual().add("full-ig.zip");
if (historyPage != null) {
inspector.getManual().add(historyPage);
Expand All @@ -3002,6 +3003,10 @@ else if (vsCache == null) {
loadIg(dep, i, !dep.hasUserData("no-load-deps"));
i++;
}
// we're also going to look for packages that can be referred to but aren't dependencies
for (Extension ext : sourceIg.getDefinition().getExtensionsByUrl("http://hl7.org/fhir/tools/StructureDefinition/ig-link-dependency")) {
loadLinkIg(ext.getValue().primitiveValue());
}

if (!"hl7.fhir.uv.tools".equals(sourceIg.getPackageId())) {
loadIg("igtools", "hl7.fhir.uv.tools", "current", "http://hl7.org/fhir/tools/ImplementationGuide/hl7.fhir.uv.tools", i, false);
Expand Down Expand Up @@ -3464,7 +3469,7 @@ else if (mode == IGBuildMode.AUTOBUILD)
businessVersion = configuration.asString("fixed-business-version");
}

inspector = new HTMLInspector(outputDir, specMaps, this, igpkp.getCanonical(), configuration.has("npm-name") ? configuration.asString("npm-name") : null, trackedFragments);
inspector = new HTMLInspector(outputDir, specMaps, linkSpecMaps, this, igpkp.getCanonical(), configuration.has("npm-name") ? configuration.asString("npm-name") : null, trackedFragments);
inspector.getManual().add("full-ig.zip");
historyPage = ostr(paths, "history");
if (historyPage != null) {
Expand Down Expand Up @@ -4006,6 +4011,26 @@ private Parameters makeExpProfile() {
return ep;
}

private void loadLinkIg(String packageId) throws Exception {
if (!Utilities.noString(packageId)) {
String[] p = packageId.split("\\#");
NpmPackage pi = p.length == 1 ? pcm.loadPackageFromCacheOnly(p[0]) : pcm.loadPackageFromCacheOnly(p[0], p[1]);
if (pi == null) {
throw new Exception("Package Id "+packageId+" is unknown");
}
logDebugMessage(LogCategory.PROGRESS, "Load Link package "+packageId);
String webref = pi.getWebLocation();
webref = PackageHacker.fixPackageUrl(webref);

SpecMapManager igm = pi.hasFile("other", "spec.internals") ? new SpecMapManager( TextFile.streamToBytes(pi.load("other", "spec.internals")), pi.fhirVersion()) : SpecMapManager.createSpecialPackage(pi);
igm.setName(pi.title());
igm.setBase(pi.canonical());
igm.setBase2(PackageHacker.fixPackageUrl(pi.url()));
linkSpecMaps.add(igm);
}
}


private void loadIg(ImplementationGuideDependsOnComponent dep, int index, boolean loadDeps) throws Exception {
String name = dep.getId();
if (!dep.hasId()) {
Expand Down Expand Up @@ -5578,7 +5603,7 @@ private void validate(String type) throws Exception {
} else {
throw new Error("Cannot use resources of type "+r.fhirType()+" in a IG with version "+version);
}
Element e = new org.hl7.fhir.r5.elementmodel.JsonParser(context).parseSingle(new ByteArrayInputStream(cnt));
Element e = new org.hl7.fhir.r5.elementmodel.JsonParser(context).parseSingle(new ByteArrayInputStream(cnt), null);
e.copyUserData(r.getElement());
r.setElement(e);
}
Expand Down Expand Up @@ -6073,8 +6098,8 @@ private Element loadFromMap(FetchedFile file) throws Exception {
throw new Error("Loading Map Files is not supported for version "+VersionUtilities.getNameForVersion(context.getVersion()));
}
FmlParser fp = new FmlParser(context);
fp.setupValidation(ValidationPolicy.EVERYTHING, file.getErrors());
Element res = fp.parse(TextFile.bytesToString(file.getSource()));
fp.setupValidation(ValidationPolicy.EVERYTHING);
Element res = fp.parse(file.getErrors(), TextFile.bytesToString(file.getSource()));
if (res == null) {
throw new Exception("Unable to parse Map Source for "+file.getName());
}
Expand All @@ -6084,8 +6109,8 @@ private Element loadFromMap(FetchedFile file) throws Exception {
private Element loadFromXml(FetchedFile file) throws Exception {
org.hl7.fhir.r5.elementmodel.XmlParser xp = new org.hl7.fhir.r5.elementmodel.XmlParser(context);
xp.setAllowXsiLocation(true);
xp.setupValidation(ValidationPolicy.EVERYTHING, file.getErrors());
Element res = xp.parseSingle(new ByteArrayInputStream(file.getSource()));
xp.setupValidation(ValidationPolicy.EVERYTHING);
Element res = xp.parseSingle(new ByteArrayInputStream(file.getSource()), file.getErrors());
if (res == null) {
throw new Exception("Unable to parse XML for "+file.getName());
}
Expand All @@ -6094,9 +6119,9 @@ private Element loadFromXml(FetchedFile file) throws Exception {

private Element loadFromJson(FetchedFile file) throws Exception {
org.hl7.fhir.r5.elementmodel.JsonParser jp = new org.hl7.fhir.r5.elementmodel.JsonParser(context);
jp.setupValidation(ValidationPolicy.EVERYTHING, file.getErrors());
jp.setupValidation(ValidationPolicy.EVERYTHING);
jp.setAllowComments(true);
return jp.parseSingle(new ByteArrayInputStream(file.getSource()));
return jp.parseSingle(new ByteArrayInputStream(file.getSource()), file.getErrors());
}

private void saveToXml(FetchedFile file, Element e) throws Exception {
Expand Down Expand Up @@ -6133,9 +6158,9 @@ private Element loadFromXmlWithVersionChange(FetchedFile file, String srcV, Stri
}
org.hl7.fhir.r5.elementmodel.XmlParser xp = new org.hl7.fhir.r5.elementmodel.XmlParser(context);
xp.setAllowXsiLocation(true);
xp.setupValidation(ValidationPolicy.EVERYTHING, file.getErrors());
xp.setupValidation(ValidationPolicy.EVERYTHING);
file.getErrors().clear();
Element res = xp.parseSingle(new ByteArrayInputStream(dst.toByteArray()));
Element res = xp.parseSingle(new ByteArrayInputStream(dst.toByteArray()), file.getErrors());
if (res == null) {
throw new Exception("Unable to parse XML for "+file.getName());
}
Expand Down Expand Up @@ -6856,7 +6881,7 @@ private void validate(FetchedFile f, FetchedResource r, Binary bin, List<Validat
long ts = System.currentTimeMillis();
validator.validate(r.getElement(), errs, new ByteArrayInputStream(bin.getContent()), fmt, profiles);
long tf = System.currentTimeMillis();
if (tf-ts > validationLogTime) {
if (tf-ts > validationLogTime && validationLogTime > 0) {
reportLongValidation(f, r, tf-ts);
}
}
Expand All @@ -6865,7 +6890,7 @@ private void validate(FetchedFile f, FetchedResource r, List<ValidationMessage>
long ts = System.currentTimeMillis();
validator.validate(r.getElement(), errs, null, r.getElement(), profiles);
long tf = System.currentTimeMillis();
if (tf-ts > validationLogTime) {
if (tf-ts > validationLogTime && validationLogTime > 0) {
reportLongValidation(f, r, tf-ts);
}
}
Expand All @@ -6874,7 +6899,7 @@ private void validate(FetchedFile f, FetchedResource r, List<ValidationMessage>
long ts = System.currentTimeMillis();
validator.validate(r.getElement(), errs, new ByteArrayInputStream(bin.getContent()), FhirFormat.readFromMimeType(bin.getContentType()));
long tf = System.currentTimeMillis();
if (tf-ts > validationLogTime) {
if (tf-ts > validationLogTime && validationLogTime > 0) {
reportLongValidation(f, r, tf-ts);
}
}
Expand All @@ -6883,7 +6908,7 @@ private void validate(FetchedFile f, FetchedResource r, List<ValidationMessage>
long ts = System.currentTimeMillis();
validator.validate(r.getElement(), errs, ber, ber.getUserString("profile"));
long tf = System.currentTimeMillis();
if (tf-ts > validationLogTime) {
if (tf-ts > validationLogTime && validationLogTime > 0) {
reportLongValidation(f, r, tf-ts);
}
}
Expand All @@ -6892,7 +6917,7 @@ private void validate(FetchedFile f, FetchedResource r, List<ValidationMessage>
long ts = System.currentTimeMillis();
validator.validate(r.getElement(), errs, null, r.getElement());
long tf = System.currentTimeMillis();
if (tf-ts > validationLogTime) {
if (tf-ts > validationLogTime && validationLogTime > 0) {
reportLongValidation(f, r, tf-ts);
}
}
Expand Down Expand Up @@ -7299,9 +7324,12 @@ private void generate() throws Exception {
} else if (mode == IGBuildMode.PUBLICATION) {
pcm.addPackageToCache(publishedIg.getPackageId(), publishedIg.getVersion(), new FileInputStream(npm.filename()), "[output]");
}
JsonArray json = new JsonArray();
for (String s : generateVersions) {
json.add(s);
generatePackageVersion(npm.filename(), s);
}
TextFile.bytesToFile(org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(json), Utilities.path(outputDir, "sub-package-list.json"));
generateZips(df);
}
}
Expand Down Expand Up @@ -7614,7 +7642,7 @@ private Element convertToElement(FetchedResource r, Resource res) throws Excepti
jp.compose(bs, res);
}
ByteArrayInputStream bi = new ByteArrayInputStream(bs.toByteArray());
Element e = new org.hl7.fhir.r5.elementmodel.JsonParser(context).parseSingle(bi);
Element e = new org.hl7.fhir.r5.elementmodel.JsonParser(context).parseSingle(bi, null);
if (xhtml != null) {
Element div = e.getNamedChild("text").getNamedChild("div");
div.setXhtml(xhtml);
Expand Down Expand Up @@ -11583,7 +11611,8 @@ public static void main(String[] args) throws Exception {
} else if (CliParams.hasNamedParam(args, "-generate-package-registry")) {
new PackageRegistryBuilder(CliParams.getNamedParam(args, "-generate-package-registry")).build();
} else if (CliParams.hasNamedParam(args, "-xig")) {
new XIGGenerator(CliParams.getNamedParam(args, "-xig")).execute();
new XIGGenerator(CliParams.getNamedParam(args, "-xig"), CliParams.getNamedParam(args, "-xig-cache")).execute("step1");
new XIGGenerator(CliParams.getNamedParam(args, "-xig"), CliParams.getNamedParam(args, "-xig-cache")).execute("step2");
} else if (CliParams.hasNamedParam(args, "-update-history")) {
new HistoryPageUpdater().updateHistoryPages(CliParams.getNamedParam(args, "-history"), CliParams.getNamedParam(args, "-website"), CliParams.getNamedParam(args, "-website"));
} else if (CliParams.hasNamedParam(args, "-publish-update")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public List<FetchedFile> scan(String sourceDir, IWorkerContext context, boolean
boolean ok = false;
if (!Utilities.existsInList(ext, fixedFileTypes()))
try {
org.hl7.fhir.r5.elementmodel.Element e = new org.hl7.fhir.r5.elementmodel.XmlParser(context).parseSingle(new FileInputStream(f));
org.hl7.fhir.r5.elementmodel.Element e = new org.hl7.fhir.r5.elementmodel.XmlParser(context).parseSingle(new FileInputStream(f), null);
addFile(res, f, e, "application/fhir+xml");
count++;
ok = true;
Expand Down Expand Up @@ -361,7 +361,7 @@ public List<FetchedFile> scan(String sourceDir, IWorkerContext context, boolean
}
if (!ok && !Utilities.existsInList(ext, "json", "xml", "html", "txt", "fml")) {
try {
org.hl7.fhir.r5.elementmodel.Element e = new org.hl7.fhir.r5.elementmodel.TurtleParser(context).parseSingle(new FileInputStream(fn));
org.hl7.fhir.r5.elementmodel.Element e = new org.hl7.fhir.r5.elementmodel.TurtleParser(context).parseSingle(new FileInputStream(fn), null);
addFile(res, f, e, "application/fhir+turtle");
count++;
ok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Element fetch(IResourceValidator validator, Object appContext, String url
s = npm.loadExampleResource(ul[0], ul[1]);
}
if (s != null)
return Manager.makeParser(context, FhirFormat.JSON).parseSingle(s);
return Manager.makeParser(context, FhirFormat.JSON).parseSingle(s, null);
}
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public Element fetch(IResourceValidator validator, Object appContext, String url
NpmPackage npm = packages.get(i);
InputStream s = npm.loadExampleResource(parts[parts.length - 2], parts[parts.length - 1]);
if (s != null) {
return Manager.makeParser(context, FhirFormat.JSON).parseSingle(s);
return Manager.makeParser(context, FhirFormat.JSON).parseSingle(s, null);
}
}
}
Expand Down
Loading

0 comments on commit d4cfd91

Please sign in to comment.