Indexed Element refactored.

This commit is contained in:
markiantorno 2020-02-21 15:06:36 -05:00
parent 6af30d5f7f
commit abd46acae3
2 changed files with 60 additions and 29 deletions

View File

@ -130,6 +130,7 @@ import org.hl7.fhir.r5.validation.BaseValidator;
import org.hl7.fhir.r5.validation.EnableWhenEvaluator; import org.hl7.fhir.r5.validation.EnableWhenEvaluator;
import org.hl7.fhir.r5.validation.EnableWhenEvaluator.QStack; import org.hl7.fhir.r5.validation.EnableWhenEvaluator.QStack;
import org.hl7.fhir.r5.validation.XVerExtensionManager; import org.hl7.fhir.r5.validation.XVerExtensionManager;
import org.hl7.fhir.r5.validation.instancevalidator.utils.IndexedElement;
import org.hl7.fhir.r5.validation.instancevalidator.utils.ResolvedReference; import org.hl7.fhir.r5.validation.instancevalidator.utils.ResolvedReference;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
@ -2602,21 +2603,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return null; return null;
} }
private class IndexedElement { private IndexedElement getContainedById(Element container, String id) {
private int index;
private Element match;
private Element entry;
public IndexedElement(int index, Element match, Element entry) {
super();
this.index = index;
this.match = match;
this.entry = entry;
}
}
private IndexedElement getContainedById(Element container, String id) {
List<Element> contained = new ArrayList<Element>(); List<Element> contained = new ArrayList<Element>();
container.getNamedChildren("contained", contained); container.getNamedChildren("contained", contained);
for (int i = 0; i < contained.size(); i++) { for (int i = 0; i < contained.size(); i++) {
@ -2962,9 +2949,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (res != null) { if (res != null) {
ResolvedReference rr = new ResolvedReference(); ResolvedReference rr = new ResolvedReference();
rr.setResource(stack.getElement()); rr.setResource(stack.getElement());
rr.setFocus(res.match); rr.setFocus(res.getMatch());
rr.setExternal(false); rr.setExternal(false);
rr.setStack(stack.push(res.match, res.index, res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition())); rr.setStack(stack.push(res.getMatch(), res.getIndex(), res.getMatch().getProperty().getDefinition(), res.getMatch().getProperty().getDefinition()));
return rr; return rr;
} }
} }
@ -2993,12 +2980,12 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return null; return null;
} else { } else {
ResolvedReference rr = new ResolvedReference(); ResolvedReference rr = new ResolvedReference();
rr.setResource(res.match); rr.setResource(res.getMatch());
rr.setFocus(res.match); rr.setFocus(res.getMatch());
rr.setExternal(false); rr.setExternal(false);
rr.setStack(stack.push(res.entry, res.index, res.entry.getProperty().getDefinition(), rr.setStack(stack.push(res.getEntry(), res.getIndex(), res.getEntry().getProperty().getDefinition(),
res.entry.getProperty().getDefinition()).push(res.match, -1, res.getEntry().getProperty().getDefinition()).push(res.getMatch(), -1,
res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition())); res.getMatch().getProperty().getDefinition(), res.getMatch().getProperty().getDefinition()));
return rr; return rr;
} }
} }
@ -3014,12 +3001,12 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return null; return null;
} else { } else {
ResolvedReference rr = new ResolvedReference(); ResolvedReference rr = new ResolvedReference();
rr.setResource(res.match); rr.setResource(res.getMatch());
rr.setFocus(res.match); rr.setFocus(res.getMatch());
rr.setExternal(false); rr.setExternal(false);
rr.setStack(new NodeStack(hostContext).push(res.entry, res.index, res.entry.getProperty().getDefinition(), rr.setStack(new NodeStack(hostContext).push(res.getEntry(), res.getIndex(), res.getEntry().getProperty().getDefinition(),
res.entry.getProperty().getDefinition()).push(res.match, -1, res.getEntry().getProperty().getDefinition()).push(res.getMatch(), -1,
res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition())); res.getMatch().getProperty().getDefinition(), res.getMatch().getProperty().getDefinition()));
return rr; return rr;
} }
} }
@ -4564,8 +4551,8 @@ private boolean isAnswerRequirementFulfilled(QuestionnaireItemComponent qItem, L
for (String reference: references) { for (String reference: references) {
// We don't want errors when just retrieving the element as they will be caught (with better path info) in subsequent processing // We don't want errors when just retrieving the element as they will be caught (with better path info) in subsequent processing
IndexedElement r = getFromBundle(stack.getElement(), reference, entry.getChildValue("fullUrl"), new ArrayList<ValidationMessage>(), stack.addToLiteralPath("entry[" + candidateResources.indexOf(resource) + "]"), type, "transaction".equals(stack.getElement().getChildValue("type"))); IndexedElement r = getFromBundle(stack.getElement(), reference, entry.getChildValue("fullUrl"), new ArrayList<ValidationMessage>(), stack.addToLiteralPath("entry[" + candidateResources.indexOf(resource) + "]"), type, "transaction".equals(stack.getElement().getChildValue("type")));
if (r!=null && !visitedResources.containsValue(r.match)) { if (r!=null && !visitedResources.containsValue(r.getMatch())) {
followResourceLinks(candidateEntries.get(r.match), visitedResources, candidateEntries, candidateResources, errors, stack, depth+1); followResourceLinks(candidateEntries.get(r.getMatch()), visitedResources, candidateEntries, candidateResources, errors, stack, depth+1);
} }
} }
} }

View File

@ -0,0 +1,44 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils;
import org.hl7.fhir.r5.elementmodel.Element;
public class IndexedElement {
private int index;
private Element match;
private Element entry;
public int getIndex() {
return index;
}
public IndexedElement setIndex(int index) {
this.index = index;
return this;
}
public Element getMatch() {
return match;
}
public IndexedElement setMatch(Element match) {
this.match = match;
return this;
}
public Element getEntry() {
return entry;
}
public IndexedElement setEntry(Element entry) {
this.entry = entry;
return this;
}
public IndexedElement(int index, Element match, Element entry) {
super();
this.index = index;
this.match = match;
this.entry = entry;
}
}