Improve validator error message if a fixed coding can't be matched

This commit is contained in:
James Agnew 2019-08-08 14:39:45 -04:00
parent ce392c47bb
commit d1c3e522ab
1 changed files with 21 additions and 7 deletions

View File

@ -34,7 +34,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
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.StringUtils;
import org.hl7.fhir.r5.model.Reference;
@ -968,20 +970,32 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
for (int i = 0; i < fixed.getCoding().size(); i++) {
Coding fixedCoding = fixed.getCoding().get(i);
boolean found = false;
List<ValidationMessage> errorsFixed = null;
List<ValidationMessage> allErrorsFixed = new ArrayList<>();
List<ValidationMessage> errorsFixed;
for (int j = 0; j < codings.size() && !found; ++j) {
errorsFixed = new ArrayList<ValidationMessage>();
errorsFixed = new ArrayList<>();
checkFixedValue(errorsFixed, path + ".coding", codings.get(j), fixedCoding, "coding", focus);
if (!hasErrors(errorsFixed)) {
found = true;
} else {
errorsFixed
.stream()
.filter(t->t.getLevel().ordinal() >= IssueSeverity.ERROR.ordinal())
.forEach(t->allErrorsFixed.add(t));
}
}
if (!found) {
rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, false,
"Expected patternCodeableConcept not found for"+
" system: " + fixedCoding.getSystemElement().asStringValue() +
" code: " + fixedCoding.getCodeElement().asStringValue() +
" display: " + fixedCoding.getDisplayElement().asStringValue());
// The argonaut DSTU2 labs profile requires userSelected=false on the category.coding and this
// needs to produce an understandable error message
String message = "Expected fixed CodeableConcept not found for" +
" system: " + fixedCoding.getSystemElement().asStringValue() +
" code: " + fixedCoding.getCodeElement().asStringValue() +
" display: " + fixedCoding.getDisplayElement().asStringValue();
if (fixedCoding.hasUserSelected()) {
message += " userSelected: " + fixedCoding.getUserSelected();
}
message += " - Issues: " + allErrorsFixed;
rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, false, message);
}
}
}