Added more information to the error message about misplaced QuestionnaireResponseItem

This commit is contained in:
Matti Uusitalo 2018-11-28 15:20:00 +02:00
parent 076d18977d
commit 311d92f276
2 changed files with 15 additions and 7 deletions

View File

@ -2745,7 +2745,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
return -1;
}
private void validateQuestionannaireResponseItems(Questionnaire qsrc, List<QuestionnaireItemComponent> qItems, List<ValidationMessage> errors, Element element, NodeStack stack, boolean inProgress, Element questionnaireResponseRoot) {
List<Element> items = new ArrayList<Element>();
element.getNamedChildren("item", items);
@ -2759,7 +2759,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (index == -1) {
QuestionnaireItemComponent qItem = findQuestionnaireItem(qsrc, linkId);
if (qItem != null) {
rule(errors, IssueType.STRUCTURE, item.line(), item.col(), stack.getLiteralPath(), index > -1, "Structural Error: item is in the wrong place");
rule(errors, IssueType.STRUCTURE, item.line(), item.col(), stack.getLiteralPath(), index > -1, misplacedItemError(qItem));
NodeStack ns = stack.push(item, -1, null, null);
validateQuestionannaireResponseItem(qsrc, qItem, errors, item, ns, inProgress, questionnaireResponseRoot);
}
@ -2770,11 +2770,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
{
rule(errors, IssueType.STRUCTURE, item.line(), item.col(), stack.getLiteralPath(), index >= lastIndex, "Structural Error: items are out of order");
lastIndex = index;
List<Element> mapItem = map.get(linkId);
if (mapItem == null) {
mapItem = new ArrayList<Element>();
map.put(linkId, mapItem);
}
List<Element> mapItem = map.computeIfAbsent(linkId, key -> new ArrayList<>());
mapItem.add(item);
}
}
@ -2795,6 +2793,13 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
}
private String misplacedItemError(QuestionnaireItemComponent qItem) {
return qItem.hasLinkId() ?
String.format("Structural Error: item with linkid %s is in the wrong place", qItem.getLinkId())
:
"Structural Error: item is in the wrong place";
}
private void validateQuestionnaireResponseItemQuantity( List<ValidationMessage> errors, Element answer, NodeStack stack) {
}

View File

@ -507,6 +507,9 @@ public class QuestionnaireResponseValidatorDstu3Test {
ValidationResult errors = myVal.validateWithResult(qr);
assertThat(errors.toString(), Matchers.not(containsString("No issues")));
assertTrue("Must contain structural error about misplaced link1 item",
errors.getMessages().stream().filter(vm -> vm.getMessage().contains("Structural Error"))
.anyMatch(vm -> vm.getMessage().contains("link1")));
}
@Test