diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java index fe28e6cb4..862961b3e 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/validation/ValidationMessage.java @@ -482,6 +482,7 @@ public class ValidationMessage implements Comparator, Compara private int col; private String location; // fhirPath private String message; + private String messageId; // source, for grouping private IssueType type; private IssueSeverity level; private String html; @@ -765,5 +766,14 @@ public class ValidationMessage implements Comparator, Compara this.sliceHtml = sliceHtml; } + public String getMessageId() { + return messageId; + } + + public ValidationMessage setMessageId(String messageId) { + this.messageId = messageId; + return this; + } + } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java index 28bcc9074..50f516560 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java @@ -50,7 +50,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ import java.util.List; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.r5.context.IWorkerContext; @@ -85,15 +85,15 @@ public class BaseValidator { @Deprecated protected boolean fail(List errors, IssueType type, int line, int col, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.FATAL); - } + addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.FATAL, null); + } return thePass; } protected boolean fail(List errors, IssueType type, int line, int col, String path, boolean thePass, String theMessage, Object... theMessageArguments) { if (!thePass) { String msg = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.FATAL); + addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.FATAL, theMessage); } return thePass; } @@ -109,11 +109,11 @@ public class BaseValidator { protected boolean fail(List errors, IssueType type, List pathParts, boolean thePass, String msg) { if (!thePass) { String path = toPath(pathParts); - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.FATAL); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.FATAL, null); + } return thePass; } - + /** * Test a rule and add a {@link IssueSeverity#FATAL} validation message if the validation fails * @@ -125,8 +125,8 @@ public class BaseValidator { protected boolean fail(List errors, IssueType type, List pathParts, boolean thePass, String theMessage, Object... theMessageArguments) { if (!thePass) { String path = toPath(pathParts); - addValidationMessage(errors, type, -1, -1, path, context.formatMessage(theMessage, theMessageArguments), IssueSeverity.FATAL); - } + addValidationMessage(errors, type, -1, -1, path, context.formatMessage(theMessage, theMessageArguments), IssueSeverity.FATAL, theMessage); + } return thePass; } @@ -140,8 +140,8 @@ public class BaseValidator { @Deprecated protected boolean fail(List errors, IssueType type, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.FATAL); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.FATAL, null); + } return thePass; } //TODO: i18n @@ -159,8 +159,8 @@ public class BaseValidator { protected boolean hint(List errors, IssueType type, int line, int col, String path, boolean thePass, String msg) { if (!thePass) { String message = context.formatMessage(msg); - addValidationMessage(errors, type, line, col, path, message, IssueSeverity.INFORMATION); - } + addValidationMessage(errors, type, line, col, path, message, IssueSeverity.INFORMATION, msg); + } return thePass; } @@ -174,11 +174,11 @@ public class BaseValidator { //FIXME: formatMessage should be done here protected boolean slicingHint(List errors, IssueType type, int line, int col, String path, boolean thePass, String msg, String html) { if (!thePass) { - addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.INFORMATION).setSlicingHint(true).setSliceHtml(html); - } + addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.INFORMATION, null).setSlicingHint(true).setSliceHtml(html); + } return thePass; } - + /** * Test a rule and add a {@link IssueSeverity#INFORMATION} validation message if the validation fails * @@ -189,15 +189,15 @@ public class BaseValidator { protected boolean hint(List errors, IssueType type, int line, int col, String path, boolean thePass, String theMessage, Object... theMessageArguments) { if (!thePass) { String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, line, col, path, message, IssueSeverity.INFORMATION); - } + addValidationMessage(errors, type, line, col, path, message, IssueSeverity.INFORMATION, theMessage); + } return thePass; } protected boolean txHint(List errors, String txLink, IssueType type, int line, int col, String path, boolean thePass, String theMessage, Object... theMessageArguments) { if (!thePass) { String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, line, col, path, message, IssueSeverity.INFORMATION, Source.TerminologyEngine).setTxLink(txLink); + addValidationMessage(errors, type, line, col, path, message, IssueSeverity.INFORMATION, Source.TerminologyEngine, theMessage).setTxLink(txLink); } return thePass; } @@ -213,8 +213,8 @@ public class BaseValidator { if (!thePass) { String path = toPath(pathParts); String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.INFORMATION); - } + addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.INFORMATION, theMessage); + } return thePass; } @@ -227,8 +227,8 @@ public class BaseValidator { */ protected boolean hint(List errors, IssueType type, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.INFORMATION); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.INFORMATION, null); + } return thePass; } @@ -242,8 +242,8 @@ public class BaseValidator { protected boolean rule(List errors, IssueType type, int line, int col, String path, boolean thePass, String theMessage, Object... theMessageArguments) { if (!thePass) { String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, line, col, path, message, IssueSeverity.ERROR); - } + addValidationMessage(errors, type, line, col, path, message, IssueSeverity.ERROR, theMessage); + } return thePass; } @@ -265,8 +265,8 @@ public class BaseValidator { protected boolean rule(List errors, IssueType type, List pathParts, boolean thePass, String msg) { if (!thePass) { String path = toPath(pathParts); - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.ERROR); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.ERROR, null); + } return thePass; } @@ -281,11 +281,11 @@ public class BaseValidator { if (!thePass) { String path = toPath(pathParts); String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.ERROR); - } + addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.ERROR, theMessage); + } return thePass; } - + /** * Test a rule and add a {@link IssueSeverity#ERROR} validation message if the validation fails * @@ -297,23 +297,23 @@ public class BaseValidator { //todo: delete this when finished i18n protected boolean rule(List errors, IssueType type, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.ERROR); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.ERROR, null); + } return thePass; } protected boolean rule(List errors, IssueType type, String path, boolean thePass, String theMessage, Object... theMessageArguments) { if (!thePass) { String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.ERROR); + addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.ERROR, theMessage); } return thePass; } public boolean rule(List errors, Source source, IssueType type, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.ERROR, source); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.ERROR, source, null); + } return thePass; } @@ -328,8 +328,8 @@ public class BaseValidator { if (!thePass) { msg = context.formatMessage(msg, null); html = context.formatMessage(html, null); - addValidationMessage(errors, type, path, msg, html, IssueSeverity.ERROR); - } + addValidationMessage(errors, type, path, msg, html, IssueSeverity.ERROR, null); + } return thePass; } @@ -370,26 +370,26 @@ public class BaseValidator { */ protected boolean warning(List errors, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) { if (!thePass) { - msg = context.formatMessage(msg, theMessageArguments); - IssueSeverity severity = IssueSeverity.WARNING; - addValidationMessage(errors, type, line, col, path, msg, severity); - } + String nmsg = context.formatMessage(msg, theMessageArguments); + IssueSeverity severity = IssueSeverity.WARNING; + addValidationMessage(errors, type, line, col, path, nmsg, severity, msg); + } return thePass; } - protected ValidationMessage addValidationMessage(List errors, IssueType type, int line, int col, String path, String msg, IssueSeverity theSeverity) { - Source source = this.source; - return addValidationMessage(errors, type, line, col, path, msg, theSeverity, source); - } + protected ValidationMessage addValidationMessage(List errors, IssueType type, int line, int col, String path, String msg, IssueSeverity theSeverity, String id) { + Source source = this.source; + return addValidationMessage(errors, type, line, col, path, msg, theSeverity, source, id); + } - protected ValidationMessage addValidationMessage(List errors, IssueType type, int line, int col, String path, String msg, IssueSeverity theSeverity, Source theSource) { - ValidationMessage validationMessage = new ValidationMessage(theSource, type, line, col, path, msg, theSeverity); - errors.add(validationMessage); - return validationMessage; - } + protected ValidationMessage addValidationMessage(List errors, IssueType type, int line, int col, String path, String msg, IssueSeverity theSeverity, Source theSource, String id) { + ValidationMessage validationMessage = new ValidationMessage(theSource, type, line, col, path, msg, theSeverity).setMessageId(id); + errors.add(validationMessage); + return validationMessage; + } - /** + /** * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails * * @param thePass @@ -398,8 +398,8 @@ public class BaseValidator { */ protected boolean txWarning(List errors, String txLink, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) { if (!thePass) { - msg = context.formatMessage(msg, theMessageArguments); - errors.add(new ValidationMessage(Source.TerminologyEngine, type, line, col, path, msg, IssueSeverity.WARNING).setTxLink(txLink)); + String nmsg = context.formatMessage(msg, theMessageArguments); + errors.add(new ValidationMessage(Source.TerminologyEngine, type, line, col, path, nmsg, IssueSeverity.WARNING).setTxLink(txLink).setMessageId(msg)); } return thePass; @@ -407,9 +407,9 @@ public class BaseValidator { protected boolean warningOrError(boolean isError, List errors, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) { if (!thePass) { - msg = context.formatMessage(msg, theMessageArguments); - addValidationMessage(errors, type, line, col, path, msg, isError ? IssueSeverity.ERROR : IssueSeverity.WARNING); - } + String nmsg = context.formatMessage(msg, theMessageArguments); + addValidationMessage(errors, type, line, col, path, nmsg, isError ? IssueSeverity.ERROR : IssueSeverity.WARNING, msg); + } return thePass; } @@ -425,8 +425,8 @@ public class BaseValidator { if (!thePass) { String path = toPath(pathParts); String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.WARNING); - } + addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.WARNING, theMessage); + } return thePass; } @@ -439,8 +439,8 @@ public class BaseValidator { */ protected boolean warning(List errors, IssueType type, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.WARNING); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.WARNING, null); + } return thePass; } @@ -453,8 +453,8 @@ public class BaseValidator { */ protected boolean warning(List errors, IssueType type, String path, boolean thePass, String msg, String html) { if (!thePass) { - addValidationMessage(errors, type, path, msg, html, IssueSeverity.WARNING); - } + addValidationMessage(errors, type, path, msg, html, IssueSeverity.WARNING, null); + } return thePass; } @@ -467,9 +467,9 @@ public class BaseValidator { */ protected boolean warning(List errors, IssueType type, String path, boolean thePass, String msg, String html, Object... theMessageArguments) { if (!thePass) { - msg = context.formatMessage(msg, theMessageArguments); - addValidationMessage(errors, type, path, msg, html, IssueSeverity.WARNING); - } + String nmsg = context.formatMessage(msg, theMessageArguments); + addValidationMessage(errors, type, path, nmsg, html, IssueSeverity.WARNING, msg); + } return thePass; } @@ -483,9 +483,9 @@ public class BaseValidator { */ protected boolean suppressedwarning(List errors, IssueType type, int line, int col, String path, boolean thePass, String msg, Object... theMessageArguments) { if (!thePass) { - msg = context.formatMessage(msg, theMessageArguments); - addValidationMessage(errors, type, line, col, path, msg, IssueSeverity.INFORMATION); - } + String nmsg = context.formatMessage(msg, theMessageArguments); + addValidationMessage(errors, type, line, col, path, nmsg, IssueSeverity.INFORMATION, msg); + } return thePass; } @@ -501,8 +501,8 @@ public class BaseValidator { if (!thePass) { String path = toPath(pathParts); String message = context.formatMessage(theMessage, theMessageArguments); - addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.INFORMATION); - } + addValidationMessage(errors, type, -1, -1, path, message, IssueSeverity.INFORMATION, theMessage); + } return thePass; } @@ -515,8 +515,8 @@ public class BaseValidator { */ protected boolean suppressedwarning(List errors, IssueType type, String path, boolean thePass, String msg) { if (!thePass) { - addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.INFORMATION); - } + addValidationMessage(errors, type, -1, -1, path, msg, IssueSeverity.INFORMATION, null); + } return thePass; } @@ -529,17 +529,17 @@ public class BaseValidator { */ protected boolean suppressedwarning(List errors, IssueType type, String path, boolean thePass, String msg, String html) { if (!thePass) { - IssueSeverity severity = IssueSeverity.INFORMATION; - addValidationMessage(errors, type, path, msg, html, severity); - } + IssueSeverity severity = IssueSeverity.INFORMATION; + addValidationMessage(errors, type, path, msg, html, severity, null); + } return thePass; } - protected void addValidationMessage(List errors, IssueType type, String path, String msg, String html, IssueSeverity theSeverity) { - errors.add(new ValidationMessage(source, type, -1, -1, path, msg, html, theSeverity)); - } + protected void addValidationMessage(List errors, IssueType type, String path, String msg, String html, IssueSeverity theSeverity, String id) { + errors.add(new ValidationMessage(source, type, -1, -1, path, msg, html, theSeverity).setMessageId(id)); + } - /** + /** * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails * * @param thePass @@ -548,13 +548,13 @@ public class BaseValidator { */ protected boolean suppressedwarning(List errors, IssueType type, String path, boolean thePass, String msg, String html, Object... theMessageArguments) { if (!thePass) { - msg = context.formatMessage(msg, theMessageArguments); - addValidationMessage(errors, type, path, msg, html, IssueSeverity.INFORMATION); - } + String nmsg = context.formatMessage(msg, theMessageArguments); + addValidationMessage(errors, type, path, nmsg, html, IssueSeverity.INFORMATION, msg); + } return thePass; } - - + + protected ValueSet resolveBindingReference(DomainResource ctxt, String reference, String uri) { if (reference != null) { if (reference.startsWith("#")) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java index 2dfeb9b51..dc8949724 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java @@ -515,7 +515,7 @@ public class QuestionnaireValidator extends BaseValidator { if (!res.isOk()) { txRule(errors, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION, c.getSystem(), c.getCode()); } else if (res.getSeverity() != null) { - super.addValidationMessage(errors, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), res.getMessage(), res.getSeverity(), Source.TerminologyEngine); + super.addValidationMessage(errors, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), res.getMessage(), res.getSeverity(), Source.TerminologyEngine, null); } } catch (Exception e) { warning(errors, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_CODING, e.getMessage());