Corrections to binding rendering; don't cache SD elements in HAPI

This commit is contained in:
Lloyd McKenzie 2022-10-06 11:36:06 -06:00
parent bdea5b70b8
commit 1bb4c27651
2 changed files with 35 additions and 29 deletions

View File

@ -32,14 +32,15 @@ public class AdditionalBindingsRenderer {
private String valueSet; private String valueSet;
private String doco; private String doco;
private UsageContext usage; private UsageContext usage;
private boolean any; private boolean any = false;
private boolean unchanged; private boolean isUnchanged = false;
private boolean matched; private boolean matched = false;
private boolean removed = false;
private AdditionalBindingDetail compare; private AdditionalBindingDetail compare;
private int count = 1; private int count = 1;
private String getKey() { private String getKey() {
// Todo: Consider extending this with content from usageContext if purpose isn't sufficiently differentiating // Todo: Consider extending this with content from usageContext if purpose isn't sufficiently differentiating
return purpose; return purpose + Integer.toString(count);
} }
private void incrementCount() { private void incrementCount() {
count++; count++;
@ -51,9 +52,21 @@ public class AdditionalBindingsRenderer {
private boolean alreadyMatched() { private boolean alreadyMatched() {
return matched; return matched;
} }
public boolean unchanged() {
if (!isUnchanged)
return false;
if (compare==null)
return true;
isUnchanged = true;
isUnchanged = isUnchanged && ((purpose==null && compare.purpose==null) || purpose.equals(compare.purpose));
isUnchanged = isUnchanged && ((valueSet==null && compare.valueSet==null) || valueSet.equals(compare.valueSet));
isUnchanged = isUnchanged && ((doco==null && compare.doco==null) || doco.equals(compare.doco));
isUnchanged = isUnchanged && ((usage==null && compare.usage==null) || usage.equals(compare.usage));
return isUnchanged;
}
} }
private static String STYLE_UNCHANGED = "font-color: darkgray;"; private static String STYLE_UNCHANGED = "opacity: 0.5;";
private static String STYLE_REMOVED = STYLE_UNCHANGED + "text-decoration: line-through;"; private static String STYLE_REMOVED = STYLE_UNCHANGED + "text-decoration: line-through;";
private List<AdditionalBindingDetail> bindings = new ArrayList<>(); private List<AdditionalBindingDetail> bindings = new ArrayList<>();
@ -86,12 +99,12 @@ public class AdditionalBindingsRenderer {
abr.purpose = label; abr.purpose = label;
abr.valueSet = ext.getValue().primitiveValue(); abr.valueSet = ext.getValue().primitiveValue();
if (compare) { if (compare) {
abr.unchanged = compExt!=null && ext.getValue().primitiveValue().equals(compExt.getValue().primitiveValue()); abr.isUnchanged = compExt!=null && ext.getValue().primitiveValue().equals(compExt.getValue().primitiveValue());
abr.compare = new AdditionalBindingDetail(); abr.compare = new AdditionalBindingDetail();
abr.compare.valueSet = compExt==null ? null : compExt.getValue().primitiveValue(); abr.compare.valueSet = compExt==null ? null : compExt.getValue().primitiveValue();
} else { } else {
abr.unchanged = ext.hasUserData(ProfileUtilities.DERIVATION_EQUALS); abr.isUnchanged = ext.hasUserData(ProfileUtilities.DERIVATION_EQUALS);
} }
bindings.add(abr); bindings.add(abr);
} }
@ -113,8 +126,9 @@ public class AdditionalBindingsRenderer {
if (compare && compList!=null) { if (compare && compList!=null) {
for (Extension ext : compList) { for (Extension ext : compList) {
AdditionalBindingDetail abr = additionalBinding(ext); AdditionalBindingDetail abr = additionalBinding(ext);
while (compBindings.containsKey(abr.getKey())) if (compBindings.containsKey(abr.getKey())) {
abr.incrementCount(); abr.incrementCount();
}
compBindings.put(abr.getKey(), abr); compBindings.put(abr.getKey(), abr);
} }
} }
@ -127,12 +141,19 @@ public class AdditionalBindingsRenderer {
match = compBindings.get(abr.getKey()); match = compBindings.get(abr.getKey());
if (abr.alreadyMatched()) if (abr.alreadyMatched())
abr.incrementCount(); abr.incrementCount();
} while (match!=null && !match.alreadyMatched()); } while (match!=null && abr.alreadyMatched());
if (match!=null) if (match!=null)
abr.setCompare(match); abr.setCompare(match);
bindings.add(abr);
if (abr.compare!=null)
compBindings.remove(abr.compare.getKey());
} else } else
bindings.add(abr); bindings.add(abr);
} }
for (AdditionalBindingDetail b: compBindings.values()) {
b.removed = true;
bindings.add(b);
}
} }
protected AdditionalBindingDetail additionalBinding(Extension ext) { protected AdditionalBindingDetail additionalBinding(Extension ext) {
@ -142,7 +163,7 @@ public class AdditionalBindingsRenderer {
abr.doco = ext.getExtensionString("documentation"); abr.doco = ext.getExtensionString("documentation");
abr.usage = (ext.hasExtension("usage")) && ext.getExtensionByUrl("usage").hasValueUsageContext() ? ext.getExtensionByUrl("usage").getValueUsageContext() : null; abr.usage = (ext.hasExtension("usage")) && ext.getExtensionByUrl("usage").hasValueUsageContext() ? ext.getExtensionByUrl("usage").getValueUsageContext() : null;
abr.any = "any".equals(ext.getExtensionString("scope")); abr.any = "any".equals(ext.getExtensionString("scope"));
abr.unchanged = ext.hasUserData(ProfileUtilities.DERIVATION_EQUALS); abr.isUnchanged = ext.hasUserData(ProfileUtilities.DERIVATION_EQUALS);
return abr; return abr;
} }
@ -192,8 +213,10 @@ public class AdditionalBindingsRenderer {
} }
for (AdditionalBindingDetail binding : bindings) { for (AdditionalBindingDetail binding : bindings) {
tr = new XhtmlNode(NodeType.Element, "tr"); tr = new XhtmlNode(NodeType.Element, "tr");
if (binding.unchanged) { if (binding.unchanged()) {
tr.style("opacity: 0.5"); tr.style(STYLE_REMOVED);
} else if (binding.removed) {
tr.style(STYLE_REMOVED);
} }
children.add(tr); children.add(tr);
BindingResolution br = pkp == null ? makeNullBr(binding) : pkp.resolveBinding(profile, binding.valueSet, path); BindingResolution br = pkp == null ? makeNullBr(binding) : pkp.resolveBinding(profile, binding.valueSet, path);

View File

@ -355,7 +355,6 @@ public class ProfileUtilities extends TranslatingUtilities {
private boolean wantFixDifferentialFirstElementType; private boolean wantFixDifferentialFirstElementType;
private Set<String> masterSourceFileNames; private Set<String> masterSourceFileNames;
private Map<ElementDefinition, List<ElementDefinition>> childMapCache = new HashMap<>(); private Map<ElementDefinition, List<ElementDefinition>> childMapCache = new HashMap<>();
private Map<String, Map<String, ElementDefinition>> sdMapCache = new HashMap<>();
public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) { public ProfileUtilities(IWorkerContext context, List<ValidationMessage> messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) {
super(); super();
@ -432,22 +431,6 @@ public class ProfileUtilities extends TranslatingUtilities {
String getLinkForUrl(String corePath, String s); String getLinkForUrl(String corePath, String s);
} }
public ElementDefinition getElementById(String structureCanonical, String id) {
Map<String, ElementDefinition> sdCache = sdMapCache.get(structureCanonical);
if (sdCache == null) {
StructureDefinition sd = (StructureDefinition) context.fetchResource(StructureDefinition.class, structureCanonical);
if (sd==null)
throw new FHIRException("Unable to retrieve StructureDefinition with URL " + structureCanonical);
sdCache = new HashMap<String, ElementDefinition>();
sdMapCache.put(structureCanonical, sdCache);
for (ElementDefinition e : sd.getSnapshot().getElement()) {
sdCache.put(e.getId(), e);
}
}
return sdCache.get(id);
}
public List<ElementDefinition> getChildMap(StructureDefinition profile, ElementDefinition element) throws DefinitionException { public List<ElementDefinition> getChildMap(StructureDefinition profile, ElementDefinition element) throws DefinitionException {
if (childMapCache .containsKey(element)) { if (childMapCache .containsKey(element)) {
return childMapCache.get(element); return childMapCache.get(element);