Add warning about resources not linked to in bundles

This commit is contained in:
Grahame Grieve 2021-11-10 17:04:51 +11:00
parent f508f7279a
commit 1e69909466
4 changed files with 38 additions and 7 deletions

View File

@ -32,6 +32,7 @@ public class I18nConstants {
public static final String BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES = "BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES";
public static final String BUNDLE_BUNDLE_ENTRY_NOTFOUND = "Bundle_BUNDLE_Entry_NotFound";
public static final String BUNDLE_BUNDLE_ENTRY_ORPHAN = "Bundle_BUNDLE_Entry_Orphan";
public static final String BUNDLE_BUNDLE_ENTRY_REVERSE = "BUNDLE_BUNDLE_ENTRY_REVERSE";
public static final String BUNDLE_BUNDLE_ENTRY_TYPE = "Bundle_BUNDLE_Entry_Type";
public static final String BUNDLE_BUNDLE_ENTRY_TYPE2 = "Bundle_BUNDLE_Entry_Type2";
public static final String BUNDLE_BUNDLE_ENTRY_TYPE3 = "Bundle_BUNDLE_Entry_Type3";

View File

@ -11,6 +11,7 @@ BUNDLE_BUNDLE_ENTRY_FULLURL_REQUIRED = Except for transactions and batches, each
Bundle_BUNDLE_Entry_NoProfile = No profile found for contained resource of type ''{0}''
Bundle_BUNDLE_Entry_NotFound = Can''t find ''{0}'' in the bundle ({1})
Bundle_BUNDLE_Entry_Orphan = Entry {0} isn''t reachable by traversing from first Bundle entry
BUNDLE_BUNDLE_ENTRY_REVERSE = Entry {0} isn''t reachable by traversing forwards from first Bundle entry, and isn''t a resource type that is typically used that way - check this is not missed somewhere
Bundle_BUNDLE_Entry_Type = The type ''{0}'' is not valid - no resources allowed here (allowed = {1})
Bundle_BUNDLE_Entry_Type2 = The type ''{0}'' is not valid - must be {1} (allowed = {2})
Bundle_BUNDLE_Entry_Type3 = The type ''{0}'' is not valid - must be one of {1}

View File

@ -396,20 +396,30 @@ public class BundleValidator extends BaseValidator{
private void checkAllInterlinked(List<ValidationMessage> errors, List<Element> entries, NodeStack stack, Element bundle, boolean isError) {
List<EntrySummary> entryList = new ArrayList<>();
int i = 0;
for (Element entry : entries) {
Element r = entry.getNamedChild(RESOURCE);
if (r != null) {
entryList.add(new EntrySummary(entry, r));
EntrySummary e = new EntrySummary(i, entry, r);
entryList.add(e);
System.out.println("Found entry "+e.dbg());
}
i++;
}
for (EntrySummary e : entryList) {
Set<String> references = findReferences(e.getEntry());
for (String ref : references) {
Element tgt = resolveInBundle(entries, ref, e.getEntry().getChildValue(FULL_URL), e.getResource().fhirType(), e.getResource().getIdBase());
if (tgt != null) {
EntrySummary t = entryForTarget(entryList, tgt);
if (t != null) {
e.getTargets().add(t);
if (t != null ) {
if (t != e) {
System.out.println("Entry "+e.getIndex()+" refers to "+t.getIndex()+" by ref '"+ref+"'");
e.getTargets().add(t);
} else {
System.out.println("Entry "+e.getIndex()+" refers to itself by '"+ref+"'");
}
}
}
}
@ -422,6 +432,7 @@ public class BundleValidator extends BaseValidator{
foundRevLinks = false;
for (EntrySummary e : entryList) {
if (!visited.contains(e)) {
System.out.println("Not visited "+e.getIndex()+" - check for reverse links");
boolean add = false;
for (EntrySummary t : e.getTargets()) {
if (visited.contains(t)) {
@ -429,6 +440,10 @@ public class BundleValidator extends BaseValidator{
}
}
if (add) {
warning(errors, IssueType.INFORMATIONAL, e.getEntry().line(), e.getEntry().col(),
stack.addToLiteralPath(ENTRY + '[' + (i + 1) + ']'), isExpectedToBeReverse(e.getResource().fhirType()),
I18nConstants.BUNDLE_BUNDLE_ENTRY_REVERSE, (e.getEntry().getChildValue(FULL_URL) != null ? "'" + e.getEntry().getChildValue(FULL_URL) + "'" : ""));
System.out.println("Found reverse links for "+e.getIndex());
foundRevLinks = true;
visitLinked(visited, e);
}
@ -436,7 +451,7 @@ public class BundleValidator extends BaseValidator{
}
} while (foundRevLinks);
int i = 0;
i = 0;
for (EntrySummary e : entryList) {
Element entry = e.getEntry();
if (isError) {
@ -450,6 +465,10 @@ public class BundleValidator extends BaseValidator{
private boolean isExpectedToBeReverse(String fhirType) {
return Utilities.existsInList(fhirType, "Provenance");
}
private String uriRegexForVersion() {
if (VersionUtilities.isR3Ver(context.getVersion()))
return URI_REGEX3;

View File

@ -10,6 +10,7 @@ public class EntrySummary {
Element entry;
Element resource;
List<EntrySummary> targets = new ArrayList<>();
private int index;
public Element getEntry() {
return entry;
@ -38,8 +39,17 @@ public class EntrySummary {
return this;
}
public EntrySummary(Element entry, Element resource) {
this.entry = entry;
this.resource = resource;
public EntrySummary(int i, Element entry, Element resource) {
this.index = i;
this.entry = entry;
this.resource = resource;
}
public String dbg() {
return ""+index+"="+ entry.getChildValue("fullUrl")+" | "+resource.getIdBase() + "("+resource.fhirType()+")";
}
public String getIndex() {
return Integer.toString(index);
}
}