use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class ValueSetValidator method validateValueSetCompose.
private void validateValueSetCompose(List<ValidationMessage> errors, Element compose, NodeStack stack, String vsid, boolean retired) {
List<Element> includes = compose.getChildrenByName("include");
int ci = 0;
for (Element include : includes) {
validateValueSetInclude(errors, include, stack.push(include, ci, null, null), vsid, retired);
ci++;
}
List<Element> excludes = compose.getChildrenByName("exclude");
int ce = 0;
for (Element exclude : excludes) {
validateValueSetInclude(errors, exclude, stack.push(exclude, ce, null, null), vsid, retired);
ce++;
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class ValueSetValidator method validateValueSet.
public void validateValueSet(List<ValidationMessage> errors, Element vs, NodeStack stack) {
if (!VersionUtilities.isR2Ver(context.getVersion())) {
List<Element> composes = vs.getChildrenByName("compose");
int cc = 0;
for (Element compose : composes) {
validateValueSetCompose(errors, compose, stack.push(compose, cc, null, null), vs.getNamedChildValue("url"), "retired".equals(vs.getNamedChildValue("url")));
cc++;
}
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class ValueSetValidator method validateValueSetIncludeConcept.
private boolean validateValueSetIncludeConcept(List<ValidationMessage> errors, Element concept, NodeStack stack, String system, String version) {
String code = concept.getChildValue("code");
if (version == null) {
ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null), null);
if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
return false;
} else {
boolean ok = vv.isOk();
warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), ok, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, code);
}
} else {
ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null).setVersion(version), null);
if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
return false;
} else {
boolean ok = vv.isOk();
warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), ok, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, code);
}
}
return true;
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class ValueSetValidator method validateValueSetInclude.
private void validateValueSetInclude(List<ValidationMessage> errors, Element include, NodeStack stack, String vsid, boolean retired) {
String system = include.getChildValue("system");
String version = include.getChildValue("version");
List<Element> valuesets = include.getChildrenByName("valueSet");
int i = 0;
for (Element ve : valuesets) {
String v = ve.getValue();
ValueSet vs = context.fetchResource(ValueSet.class, v);
if (vs == null) {
NodeStack ns = stack.push(ve, i, ve.getProperty().getDefinition(), ve.getProperty().getDefinition());
Resource rs = context.fetchResource(Resource.class, v);
if (rs != null) {
warning(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), false, I18nConstants.VALUESET_REFERENCE_INVALID_TYPE, v, rs.fhirType());
} else {
// todo: it's possible, at this point, that the txx server knows the value set, but it's not in scope
// should we handle this case?
warning(errors, IssueType.BUSINESSRULE, ns.getLiteralPath(), false, I18nConstants.VALUESET_REFERENCE_UNKNOWN, v);
}
}
i++;
}
if (valuesets.size() > 1) {
warning(errors, IssueType.INFORMATIONAL, stack.getLiteralPath(), false, I18nConstants.VALUESET_IMPORT_UNION_INTERSECTION);
}
List<Element> concepts = include.getChildrenByName("concept");
List<Element> filters = include.getChildrenByName("filter");
if (!Utilities.noString(system)) {
boolean systemOk = true;
int cc = 0;
List<VSCodingValidationRequest> batch = new ArrayList<>();
boolean first = true;
for (Element concept : concepts) {
// we treat the first differently because we want to know if tbe system is worth validating. if it is, then we batch the rest
if (first) {
systemOk = validateValueSetIncludeConcept(errors, concept, stack.push(concept, cc, null, null), system, version);
first = false;
} else if (systemOk) {
batch.add(prepareValidateValueSetIncludeConcept(errors, concept, stack.push(concept, cc, null, null), system, version));
}
cc++;
}
if (parent.isValidateValueSetCodesOnTxServer() && batch.size() > 0) {
long t = System.currentTimeMillis();
if (parent.isDebug()) {
System.out.println(" : Validate " + batch.size() + " codes from " + system + " for " + vsid);
}
context.validateCodeBatch(ValidationOptions.defaults(), batch, null);
if (parent.isDebug()) {
System.out.println(" : .. " + (System.currentTimeMillis() - t) + "ms");
}
for (VSCodingValidationRequest cv : batch) {
if (version == null) {
warningOrHint(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, cv.getCoding().getCode());
} else {
warningOrHint(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, cv.getCoding().getCode());
}
}
}
int cf = 0;
for (Element filter : filters) {
if (systemOk && !validateValueSetIncludeFilter(errors, include, stack.push(filter, cf, null, null), system, version)) {
systemOk = false;
}
cf++;
}
warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), systemOk, version == null ? I18nConstants.VALUESET_UNC_SYSTEM_WARNING : I18nConstants.VALUESET_UNC_SYSTEM_WARNING_VER);
} else {
warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), filters.size() == 0 && concepts.size() == 0, I18nConstants.VALUESET_NO_SYSTEM_WARNING);
}
}
use of org.hl7.fhir.validation.instance.utils.NodeStack in project org.hl7.fhir.core by hapifhir.
the class MeasureValidator method validateMeasure.
public void validateMeasure(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element element, NodeStack stack) throws FHIRException {
MeasureContext mctxt = new MeasureContext();
List<Element> libs = element.getChildrenByName("library");
for (Element lib : libs) {
String ref = lib.isPrimitive() ? lib.primitiveValue() : lib.getChildValue("reference");
if (!Utilities.noString(ref)) {
Library l = context.fetchResource(Library.class, ref);
if (hint(errors, IssueType.NOTFOUND, lib.line(), lib.col(), stack.getLiteralPath(), l != null, I18nConstants.MEASURE_M_LIB_UNKNOWN, ref)) {
mctxt.seeLibrary(l);
}
}
}
List<Element> groups = element.getChildrenByName("group");
if (warning(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), groups.size() > 0, I18nConstants.MEASURE_M_NO_GROUPS)) {
int c = 0;
for (Element group : groups) {
NodeStack ns = stack.push(group, c, null, null);
warning(errors, IssueType.REQUIRED, group.line(), group.col(), ns.getLiteralPath(), groups.size() == 1 || group.hasChild("code"), I18nConstants.MEASURE_M_GROUP_CODE);
warning(errors, IssueType.REQUIRED, group.line(), group.col(), ns.getLiteralPath(), group.hasChildren("population"), I18nConstants.MEASURE_M_GROUP_POP);
int c1 = 0;
List<Element> pl = group.getChildrenByName("population");
for (Element p : pl) {
NodeStack ns2 = ns.push(p, c1, null, null);
warning(errors, IssueType.REQUIRED, p.line(), p.col(), ns2.getLiteralPath(), pl.size() == 1 || p.hasChild("code"), I18nConstants.MEASURE_M_GROUP_POP_NO_CODE);
c1++;
}
c1 = 0;
List<Element> stl = group.getChildrenByName("stratifier");
for (Element st : stl) {
NodeStack ns2 = ns.push(st, c1, null, null);
warning(errors, IssueType.REQUIRED, st.line(), st.col(), ns2.getLiteralPath(), stl.size() == 1 || st.hasChild("code"), I18nConstants.MEASURE_M_GROUP_STRATA_NO_CODE);
if (st.hasChild("criteria")) {
Element crit = st.getNamedChild("criteria");
NodeStack nsc = ns2.push(crit, -1, null, null);
validateMeasureCriteria(hostContext, errors, mctxt, crit, nsc);
}
int c2 = 0;
List<Element> cpl = group.getChildrenByName("component");
for (Element cp : cpl) {
NodeStack ns3 = ns2.push(cp, c2, null, null);
warning(errors, IssueType.REQUIRED, cp.line(), cp.col(), ns3.getLiteralPath(), cpl.size() == 1 || cp.hasChild("code"), I18nConstants.MEASURE_M_GROUP_STRATA_COMP_NO_CODE);
if (cp.hasChild("criteria")) {
Element crit = cp.getNamedChild("criteria");
NodeStack nsc = ns3.push(crit, -1, null, null);
validateMeasureCriteria(hostContext, errors, mctxt, crit, nsc);
}
c2++;
}
c1++;
}
c++;
}
}
}
Aggregations