Improve validator error message if a fixed coding can't be matched
This commit is contained in:
parent
ce392c47bb
commit
d1c3e522ab
|
@ -34,7 +34,9 @@ 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;
|
||||||
|
@ -968,20 +970,32 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
for (int i = 0; i < fixed.getCoding().size(); i++) {
|
for (int i = 0; i < fixed.getCoding().size(); i++) {
|
||||||
Coding fixedCoding = fixed.getCoding().get(i);
|
Coding fixedCoding = fixed.getCoding().get(i);
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
List<ValidationMessage> errorsFixed = null;
|
List<ValidationMessage> allErrorsFixed = new ArrayList<>();
|
||||||
|
List<ValidationMessage> errorsFixed;
|
||||||
for (int j = 0; j < codings.size() && !found; ++j) {
|
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);
|
checkFixedValue(errorsFixed, path + ".coding", codings.get(j), fixedCoding, "coding", focus);
|
||||||
if (!hasErrors(errorsFixed)) {
|
if (!hasErrors(errorsFixed)) {
|
||||||
found = true;
|
found = true;
|
||||||
|
} else {
|
||||||
|
errorsFixed
|
||||||
|
.stream()
|
||||||
|
.filter(t->t.getLevel().ordinal() >= IssueSeverity.ERROR.ordinal())
|
||||||
|
.forEach(t->allErrorsFixed.add(t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, false,
|
// The argonaut DSTU2 labs profile requires userSelected=false on the category.coding and this
|
||||||
"Expected patternCodeableConcept not found for"+
|
// needs to produce an understandable error message
|
||||||
|
String message = "Expected fixed CodeableConcept not found for" +
|
||||||
" system: " + fixedCoding.getSystemElement().asStringValue() +
|
" system: " + fixedCoding.getSystemElement().asStringValue() +
|
||||||
" code: " + fixedCoding.getCodeElement().asStringValue() +
|
" code: " + fixedCoding.getCodeElement().asStringValue() +
|
||||||
" display: " + fixedCoding.getDisplayElement().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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue