refactoring InstanceValidator code for readability.
This commit is contained in:
parent
26d595a21c
commit
6af30d5f7f
|
@ -21,7 +21,6 @@ package org.hl7.fhir.r5.validation;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.stream.*;
|
import java.util.stream.*;
|
||||||
|
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
@ -29,7 +28,7 @@ import org.hl7.fhir.r5.elementmodel.Element;
|
||||||
import org.hl7.fhir.r5.model.*;
|
import org.hl7.fhir.r5.model.*;
|
||||||
import org.hl7.fhir.r5.model.Questionnaire.*;
|
import org.hl7.fhir.r5.model.Questionnaire.*;
|
||||||
import org.hl7.fhir.r5.utils.FHIRPathEngine;
|
import org.hl7.fhir.r5.utils.FHIRPathEngine;
|
||||||
import org.hl7.fhir.r5.validation.InstanceValidator.ValidatorHostContext;
|
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator.ValidatorHostContext;
|
||||||
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.hl7.fhir.r5.terminologies.ConceptMapEngine;
|
||||||
import org.hl7.fhir.r5.utils.*;
|
import org.hl7.fhir.r5.utils.*;
|
||||||
import org.hl7.fhir.r5.utils.IResourceValidator.*;
|
import org.hl7.fhir.r5.utils.IResourceValidator.*;
|
||||||
import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices;
|
import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices;
|
||||||
|
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator;
|
||||||
import org.hl7.fhir.utilities.IniFile;
|
import org.hl7.fhir.utilities.IniFile;
|
||||||
import org.hl7.fhir.utilities.TextFile;
|
import org.hl7.fhir.utilities.TextFile;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hl7.fhir.r5.validation;
|
package org.hl7.fhir.r5.validation.instancevalidator;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -35,9 +35,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hl7.fhir.r5.model.Reference;
|
import org.hl7.fhir.r5.model.Reference;
|
||||||
|
@ -94,8 +92,6 @@ import org.hl7.fhir.r5.model.Extension;
|
||||||
import org.hl7.fhir.r5.model.FhirPublication;
|
import org.hl7.fhir.r5.model.FhirPublication;
|
||||||
import org.hl7.fhir.r5.model.HumanName;
|
import org.hl7.fhir.r5.model.HumanName;
|
||||||
import org.hl7.fhir.r5.model.Identifier;
|
import org.hl7.fhir.r5.model.Identifier;
|
||||||
import org.hl7.fhir.r5.model.ImplementationGuide;
|
|
||||||
import org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent;
|
|
||||||
import org.hl7.fhir.r5.model.InstantType;
|
import org.hl7.fhir.r5.model.InstantType;
|
||||||
import org.hl7.fhir.r5.model.IntegerType;
|
import org.hl7.fhir.r5.model.IntegerType;
|
||||||
import org.hl7.fhir.r5.model.Period;
|
import org.hl7.fhir.r5.model.Period;
|
||||||
|
@ -130,11 +126,12 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine;
|
||||||
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
||||||
import org.hl7.fhir.r5.utils.IResourceValidator;
|
import org.hl7.fhir.r5.utils.IResourceValidator;
|
||||||
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
||||||
|
import org.hl7.fhir.r5.validation.BaseValidator;
|
||||||
|
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.InstanceValidator.EntrySummary;
|
import org.hl7.fhir.r5.validation.XVerExtensionManager;
|
||||||
import org.hl7.fhir.r5.validation.InstanceValidator.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.TerminologyServiceOptions;
|
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
import org.hl7.fhir.utilities.Utilities.DecimalStatus;
|
import org.hl7.fhir.utilities.Utilities.DecimalStatus;
|
||||||
import org.hl7.fhir.utilities.VersionUtilities;
|
import org.hl7.fhir.utilities.VersionUtilities;
|
||||||
|
@ -172,38 +169,6 @@ import ca.uhn.fhir.util.ObjectUtil;
|
||||||
public class InstanceValidator extends BaseValidator implements IResourceValidator {
|
public class InstanceValidator extends BaseValidator implements IResourceValidator {
|
||||||
|
|
||||||
|
|
||||||
public class ResolvedReference {
|
|
||||||
|
|
||||||
private Element resource;
|
|
||||||
private Element focus;
|
|
||||||
private boolean external;
|
|
||||||
private NodeStack stack;
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return focus.fhirType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValidatorHostContext hostContext(ValidatorHostContext hostContext, StructureDefinition profile) {
|
|
||||||
if (external) {
|
|
||||||
return hostContext.forRemoteReference(profile, resource);
|
|
||||||
} else {
|
|
||||||
return hostContext.forLocalReference(profile, resource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element getResource() {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element getFocus() {
|
|
||||||
return focus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NodeStack getStack() {
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ValidatorHostContext {
|
public class ValidatorHostContext {
|
||||||
private Object appContext;
|
private Object appContext;
|
||||||
private Element container; // bundle, or parameters
|
private Element container; // bundle, or parameters
|
||||||
|
@ -2996,10 +2961,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
IndexedElement res = getContainedById(stack.getElement(), ref.substring(1));
|
IndexedElement res = getContainedById(stack.getElement(), ref.substring(1));
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
ResolvedReference rr = new ResolvedReference();
|
ResolvedReference rr = new ResolvedReference();
|
||||||
rr.resource = stack.getElement();
|
rr.setResource(stack.getElement());
|
||||||
rr.focus = res.match;
|
rr.setFocus(res.match);
|
||||||
rr.external = false;
|
rr.setExternal(false);
|
||||||
rr.stack = stack.push(res.match, res.index, res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition());
|
rr.setStack(stack.push(res.match, res.index, res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition()));
|
||||||
return rr;
|
return rr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3028,10 +2993,12 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
ResolvedReference rr = new ResolvedReference();
|
ResolvedReference rr = new ResolvedReference();
|
||||||
rr.resource = res.match;
|
rr.setResource(res.match);
|
||||||
rr.focus = res.match;
|
rr.setFocus(res.match);
|
||||||
rr.external = false;
|
rr.setExternal(false);
|
||||||
rr.stack = stack.push(res.entry, res.index, res.entry.getProperty().getDefinition(), res.entry.getProperty().getDefinition()).push(res.match, -1, res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition());
|
rr.setStack(stack.push(res.entry, res.index, res.entry.getProperty().getDefinition(),
|
||||||
|
res.entry.getProperty().getDefinition()).push(res.match, -1,
|
||||||
|
res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition()));
|
||||||
return rr;
|
return rr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3047,10 +3014,12 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
ResolvedReference rr = new ResolvedReference();
|
ResolvedReference rr = new ResolvedReference();
|
||||||
rr.resource = res.match;
|
rr.setResource(res.match);
|
||||||
rr.focus = res.match;
|
rr.setFocus(res.match);
|
||||||
rr.external = false;
|
rr.setExternal(false);
|
||||||
rr.stack = new NodeStack(hostContext).push(res.entry, res.index, res.entry.getProperty().getDefinition(), res.entry.getProperty().getDefinition()).push(res.match, -1, res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition());
|
rr.setStack(new NodeStack(hostContext).push(res.entry, res.index, res.entry.getProperty().getDefinition(),
|
||||||
|
res.entry.getProperty().getDefinition()).push(res.match, -1,
|
||||||
|
res.match.getProperty().getDefinition(), res.match.getProperty().getDefinition()));
|
||||||
return rr;
|
return rr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3071,16 +3040,16 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
|
|
||||||
private ResolvedReference makeExternalRef(Element external, String path) {
|
private ResolvedReference makeExternalRef(Element external, String path) {
|
||||||
ResolvedReference res = new ResolvedReference();
|
ResolvedReference res = new ResolvedReference();
|
||||||
res.resource = external;
|
res.setResource(external);
|
||||||
res.focus = external;
|
res.setFocus(external);
|
||||||
res.external = true;
|
res.setExternal(true);
|
||||||
res.stack = new NodeStack(external, path);
|
res.setStack(new NodeStack(external, path));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Element resolve(Object appContext, String ref, NodeStack stack, List<ValidationMessage> errors, String path) throws IOException, FHIRException {
|
private Element resolve(Object appContext, String ref, NodeStack stack, List<ValidationMessage> errors, String path) throws IOException, FHIRException {
|
||||||
Element local = localResolve(ref, stack, errors, path, null, null).focus;
|
Element local = localResolve(ref, stack, errors, path, null, null).getFocus();
|
||||||
if (local!=null)
|
if (local!=null)
|
||||||
return local;
|
return local;
|
||||||
if (fetcher == null)
|
if (fetcher == null)
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hl7.fhir.r5.validation;
|
package org.hl7.fhir.r5.validation.instancevalidator;
|
||||||
|
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package org.hl7.fhir.r5.validation.instancevalidator.utils;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r5.elementmodel.Element;
|
||||||
|
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||||
|
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator;
|
||||||
|
|
||||||
|
public class ResolvedReference {
|
||||||
|
|
||||||
|
private Element resource;
|
||||||
|
private Element focus;
|
||||||
|
private boolean external;
|
||||||
|
private InstanceValidator.NodeStack stack;
|
||||||
|
|
||||||
|
public ResolvedReference setResource(Element resource) {
|
||||||
|
this.resource = resource;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getResource() {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolvedReference setFocus(Element focus) {
|
||||||
|
this.focus = focus;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExternal() {
|
||||||
|
return external;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolvedReference setExternal(boolean external) {
|
||||||
|
this.external = external;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolvedReference setStack(InstanceValidator.NodeStack stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstanceValidator.NodeStack getStack() {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return focus.fhirType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getFocus() {
|
||||||
|
return focus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstanceValidator.ValidatorHostContext hostContext(InstanceValidator.ValidatorHostContext hostContext, StructureDefinition profile) {
|
||||||
|
if (external) {
|
||||||
|
return hostContext.forRemoteReference(profile, resource);
|
||||||
|
} else {
|
||||||
|
return hostContext.forLocalReference(profile, resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
||||||
import org.hl7.fhir.r5.utils.IResourceValidator;
|
import org.hl7.fhir.r5.utils.IResourceValidator;
|
||||||
import org.hl7.fhir.r5.utils.IResourceValidator.IValidatorResourceFetcher;
|
import org.hl7.fhir.r5.utils.IResourceValidator.IValidatorResourceFetcher;
|
||||||
import org.hl7.fhir.r5.utils.IResourceValidator.ReferenceValidationPolicy;
|
import org.hl7.fhir.r5.utils.IResourceValidator.ReferenceValidationPolicy;
|
||||||
import org.hl7.fhir.r5.validation.InstanceValidator;
|
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator;
|
||||||
import org.hl7.fhir.r5.validation.ValidationEngine;
|
import org.hl7.fhir.r5.validation.ValidationEngine;
|
||||||
import org.hl7.fhir.utilities.TextFile;
|
import org.hl7.fhir.utilities.TextFile;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
|
Loading…
Reference in New Issue