use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method resolve.
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, null).getFocus();
if (local != null)
return local;
if (fetcher == null)
return null;
if (fetchCache.containsKey(ref)) {
return fetchCache.get(ref);
} else {
Element res = fetcher.fetch(this, appContext, ref);
setParents(res);
fetchCache.put(ref, res);
return res;
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method checkMaxValueSet.
private void checkMaxValueSet(List<ValidationMessage> errors, String path, Element element, StructureDefinition profile, String maxVSUrl, Coding c, NodeStack stack) {
ValueSet valueset = resolveBindingReference(profile, maxVSUrl, profile.getUrl());
if (valueset == null) {
CodeSystem cs = context.fetchCodeSystem(maxVSUrl);
if (rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, cs == null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND_CS, describeReference(maxVSUrl))) {
warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, valueset != null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND, describeReference(maxVSUrl));
}
} else {
try {
long t = System.nanoTime();
ValidationResult vr = checkCodeOnServer(stack, valueset, c, true);
timeTracker.tx(t, "vc " + c.getSystem() + "#" + c.getCode() + " '" + c.getDisplay() + "'");
if (!vr.isOk()) {
if (vr.getErrorClass() != null && vr.getErrorClass().isInfrastructure())
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_9, describeValueSet(maxVSUrl), vr.getMessage());
else
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_10, describeValueSet(maxVSUrl), c.getSystem(), c.getCode());
}
} catch (Exception e) {
if (STACK_TRACE)
e.printStackTrace();
warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_ERROR_CODEABLECONCEPT_MAX, e.getMessage());
}
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method checkElementUsage.
private void checkElementUsage(List<ValidationMessage> errors, Element element, NodeStack stack) {
String elementUsage = element.getUserString("elementSupported");
hint(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), elementUsage == null || elementUsage.equals("Y"), I18nConstants.MUSTSUPPORT_VAL_MUSTSUPPORT, element.getName(), element.getProperty().getStructure().getUrl());
if (element.hasChildren()) {
String prevName = "";
int elementCount = 0;
for (Element ce : element.getChildren()) {
if (ce.getName().equals(prevName))
elementCount++;
else {
elementCount = 1;
prevName = ce.getName();
}
checkElementUsage(errors, ce, stack.push(ce, elementCount, null, null));
}
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method validateResource.
/*
* The actual base entry point for internal use (re-entrant)
*/
private void validateResource(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element resource, Element element, StructureDefinition defn, IdStatus idstatus, NodeStack stack) throws FHIRException {
// check here if we call validation policy here, and then change it to the new interface
assert stack != null;
assert resource != null;
boolean ok = true;
// todo: consider namespace...?
String resourceName = element.getType();
if (defn == null) {
long t = System.nanoTime();
defn = element.getProperty().getStructure();
if (defn == null)
defn = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + resourceName);
timeTracker.sd(t);
// check exists
ok = rule(errors, IssueType.INVALID, element.line(), element.col(), stack.addToLiteralPath(resourceName), defn != null, I18nConstants.VALIDATION_VAL_PROFILE_NODEFINITION, resourceName);
}
// special case: we have a bundle, and the profile is not for a bundle. We'll try the first entry instead
if (!typeMatchesDefn(resourceName, defn) && resourceName.equals(BUNDLE)) {
NodeStack first = getFirstEntry(stack);
if (first != null && typeMatchesDefn(first.getElement().getType(), defn)) {
element = first.getElement();
stack = first;
// todo: consider namespace...?
resourceName = element.getType();
// why?
idstatus = IdStatus.OPTIONAL;
}
// todo: validate everything in this bundle.
}
if (ok) {
if (idstatus == IdStatus.REQUIRED && (element.getNamedChild(ID) == null)) {
rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.RESOURCE_RES_ID_MISSING);
} else if (idstatus == IdStatus.PROHIBITED && (element.getNamedChild(ID) != null)) {
rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.RESOURCE_RES_ID_PROHIBITED);
}
if (element.getNamedChild(ID) != null) {
Element eid = element.getNamedChild(ID);
if (eid.getProperty() != null && eid.getProperty().getDefinition() != null && eid.getProperty().getDefinition().getBase().getPath().equals("Resource.id")) {
NodeStack ns = stack.push(eid, -1, eid.getProperty().getDefinition(), null);
rule(errors, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), FormatUtilities.isValidId(eid.primitiveValue()), I18nConstants.RESOURCE_RES_ID_MALFORMED);
}
}
// validate
if (rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), resourceName.equals(defn.getType()), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE, defn.getType(), resourceName, defn.getUrl())) {
// root is both definition and type
start(hostContext, errors, element, element, defn, stack);
}
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class MeasureValidator method banned.
private void banned(List<ValidationMessage> errors, NodeStack stack, Element e, String msgId, Object... params) {
if (e != null) {
NodeStack ns = stack.push(e, -1, e.getProperty().getDefinition(), e.getProperty().getDefinition());
rule(errors, IssueType.BUSINESSRULE, e.line(), e.col(), ns.getLiteralPath(), false, msgId, params);
}
}
Aggregations