001package org.hl7.fhir.utilities.validation;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009    
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030 */
031
032
033
034/*
035 Copyright (c) 2011+, HL7, Inc
036 All rights reserved.
037
038 Redistribution and use in source and binary forms, with or without modification, 
039 are permitted provided that the following conditions are met:
040
041 * Redistributions of source code must retain the above copyright notice, this 
042 list of conditions and the following disclaimer.
043 * Redistributions in binary form must reproduce the above copyright notice, 
044 this list of conditions and the following disclaimer in the documentation 
045 and/or other materials provided with the distribution.
046 * Neither the name of HL7 nor the names of its contributors may be used to 
047 endorse or promote products derived from this software without specific 
048 prior written permission.
049
050 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
051 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
052 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
053 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
054 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
055 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
056 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
057 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
058 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
059 POSSIBILITY OF SUCH DAMAGE.
060
061 */
062
063import java.util.Comparator;
064import java.util.EnumMap;
065
066import org.apache.commons.lang3.builder.ToStringBuilder;
067import org.apache.commons.lang3.builder.ToStringStyle;
068import org.hl7.fhir.exceptions.FHIRException;
069import org.hl7.fhir.utilities.Utilities;
070
071public class ValidationMessage implements Comparator<ValidationMessage>, Comparable<ValidationMessage>
072{
073  public enum Source {
074    ExampleValidator, 
075    ProfileValidator, 
076    ResourceValidator, 
077    InstanceValidator,
078    Template,
079    Schema, 
080    Schematron, 
081    Publisher, 
082    LinkChecker,
083    Ontology, 
084    ProfileComparer, 
085    TerminologyEngine,
086    QuestionnaireResponseValidator
087  }
088
089  public enum IssueSeverity {
090    /**
091     * The issue caused the action to fail, and no further checking could be performed.
092     */
093    FATAL, 
094    /**
095     * The issue is sufficiently important to cause the action to fail.
096     */
097    ERROR, 
098    /**
099     * The issue is not important enough to cause the action to fail, but may cause it to be performed suboptimally or in a way that is not as desired.
100     */
101    WARNING, 
102    /**
103     * The issue has no relation to the degree of success of the action.
104     */
105    INFORMATION, 
106    /**
107     * added to help the parsers with the generic types
108     */
109    NULL;
110    public static IssueSeverity fromCode(String codeString) throws FHIRException {
111      if (codeString == null || "".equals(codeString))
112        return null;
113      if ("fatal".equals(codeString))
114        return FATAL;
115      if ("error".equals(codeString))
116        return ERROR;
117      if ("warning".equals(codeString))
118        return WARNING;
119      if ("information".equals(codeString))
120        return INFORMATION;
121      else
122        throw new FHIRException("Unknown IssueSeverity code '"+codeString+"'");
123    }
124    public String toCode() {
125      switch (this) {
126      case FATAL: return "fatal";
127      case ERROR: return "error";
128      case WARNING: return "warning";
129      case INFORMATION: return "information";
130      default: return "?";
131      }
132    }
133    public String getSystem() {
134      switch (this) {
135      case FATAL: return "http://hl7.org/fhir/issue-severity";
136      case ERROR: return "http://hl7.org/fhir/issue-severity";
137      case WARNING: return "http://hl7.org/fhir/issue-severity";
138      case INFORMATION: return "http://hl7.org/fhir/issue-severity";
139      default: return "?";
140      }
141    }
142    public String getDefinition() {
143      switch (this) {
144      case FATAL: return "The issue caused the action to fail, and no further checking could be performed.";
145      case ERROR: return "The issue is sufficiently important to cause the action to fail.";
146      case WARNING: return "The issue is not important enough to cause the action to fail, but may cause it to be performed suboptimally or in a way that is not as desired.";
147      case INFORMATION: return "The issue has no relation to the degree of success of the action.";
148      default: return "?";
149      }
150    }
151    public String getDisplay() {
152      switch (this) {
153      case FATAL: return "Fatal";
154      case ERROR: return "Error";
155      case WARNING: return "Warning";
156      case INFORMATION: return "Information";
157      default: return "?";
158      }
159    }
160    public boolean isError() {
161      return this == FATAL || this == ERROR;
162    }
163  }
164
165  public enum IssueType {
166    /**
167     * Content invalid against the specification or a profile.
168     */
169    INVALID, 
170    DELETED,
171    /**
172     * A structural issue in the content such as wrong namespace, or unable to parse the content completely, or invalid json syntax.
173     */
174    STRUCTURE, 
175    /**
176     * A required element is missing.
177     */
178    REQUIRED, 
179    /**
180     * An element value is invalid.
181     */
182    VALUE, 
183    /**
184     * A content validation rule failed - e.g. a schematron rule.
185     */
186    INVARIANT, 
187    /**
188     * An authentication/authorization/permissions issue of some kind.
189     */
190    SECURITY, 
191    /**
192     * The client needs to initiate an authentication process.
193     */
194    LOGIN, 
195    /**
196     * The user or system was not able to be authenticated (either there is no process, or the proferred token is unacceptable).
197     */
198    MULTIPLEMATCHES,
199    UNKNOWN, 
200    /**
201     * User session expired; a login may be required.
202     */
203    EXPIRED, 
204    /**
205     * The user does not have the rights to perform this action.
206     */
207    FORBIDDEN, 
208    /**
209     * Some information was not or may not have been returned due to business rules, consent or privacy rules, or access permission constraints.  This information may be accessible through alternate processes.
210     */
211    SUPPRESSED, 
212    /**
213     * Processing issues. These are expected to be final e.g. there is no point resubmitting the same content unchanged.
214     */
215    PROCESSING, 
216    /**
217     * The resource or profile is not supported.
218     */
219    NOTSUPPORTED, 
220    /**
221     * An attempt was made to create a duplicate record.
222     */
223    DUPLICATE, 
224    /**
225     * The reference provided was not found. In a pure RESTful environment, this would be an HTTP 404 error, but this code may be used where the content is not found further into the application architecture.
226     */
227    NOTFOUND, 
228    /**
229     * Provided content is too long (typically, this is a denial of service protection type of error).
230     */
231    TOOLONG, 
232    /**
233     * The code or system could not be understood, or it was not valid in the context of a particular ValueSet.code.
234     */
235    CODEINVALID, 
236    /**
237     * An extension was found that was not acceptable, could not be resolved, or a modifierExtension was not recognized.
238     */
239    EXTENSION, 
240    /**
241     * The operation was stopped to protect server resources; e.g. a request for a value set expansion on all of SNOMED CT.
242     */
243    TOOCOSTLY, 
244    /**
245     * The content/operation failed to pass some business rule, and so could not proceed.
246     */
247    BUSINESSRULE, 
248    /**
249     * Content could not be accepted because of an edit conflict (i.e. version aware updates) (In a pure RESTful environment, this would be an HTTP 404 error, but this code may be used where the conflict is discovered further into the application architecture.)
250     */
251    CONFLICT, 
252    /**
253     * Not all data sources typically accessed could be reached, or responded in time, so the returned information may not be complete.
254     */
255    INCOMPLETE, 
256    /**
257     * Transient processing issues. The system receiving the error may be able to resubmit the same content once an underlying issue is resolved.
258     */
259    TRANSIENT, 
260    /**
261     * A resource/record locking failure (usually in an underlying database).
262     */
263    LOCKERROR, 
264    /**
265     * The persistent store is unavailable; e.g. the database is down for maintenance or similar action.
266     */
267    NOSTORE, 
268    /**
269     * An unexpected internal error has occurred.
270     */
271    EXCEPTION, 
272    /**
273     * An internal timeout has occurred.
274     */
275    TIMEOUT, 
276    /**
277     * The system is not prepared to handle this request due to load management.
278     */
279    THROTTLED, 
280    /**
281     * A message unrelated to the processing success of the completed operation (examples of the latter include things like reminders of password expiry, system maintenance times, etc.).
282     */
283    INFORMATIONAL, 
284    /**
285     * added to help the parsers with the generic types
286     */
287    NULL;
288    public static IssueType fromCode(String codeString) throws FHIRException {
289      if (codeString == null || "".equals(codeString))
290        return null;
291      if ("invalid".equals(codeString))
292        return INVALID;
293      if ("structure".equals(codeString))
294        return STRUCTURE;
295      if ("required".equals(codeString))
296        return REQUIRED;
297      if ("value".equals(codeString))
298        return VALUE;
299      if ("invariant".equals(codeString))
300        return INVARIANT;
301      if ("security".equals(codeString))
302        return SECURITY;
303      if ("login".equals(codeString))
304        return LOGIN;
305      if ("unknown".equals(codeString))
306        return UNKNOWN;
307      if ("expired".equals(codeString))
308        return EXPIRED;
309      if ("forbidden".equals(codeString))
310        return FORBIDDEN;
311      if ("suppressed".equals(codeString))
312        return SUPPRESSED;
313      if ("processing".equals(codeString))
314        return PROCESSING;
315      if ("not-supported".equals(codeString))
316        return NOTSUPPORTED;
317      if ("duplicate".equals(codeString))
318        return DUPLICATE;
319      if ("not-found".equals(codeString))
320        return NOTFOUND;
321      if ("too-long".equals(codeString))
322        return TOOLONG;
323      if ("code-invalid".equals(codeString))
324        return CODEINVALID;
325      if ("extension".equals(codeString))
326        return EXTENSION;
327      if ("too-costly".equals(codeString))
328        return TOOCOSTLY;
329      if ("business-rule".equals(codeString))
330        return BUSINESSRULE;
331      if ("conflict".equals(codeString))
332        return CONFLICT;
333      if ("incomplete".equals(codeString))
334        return INCOMPLETE;
335      if ("transient".equals(codeString))
336        return TRANSIENT;
337      if ("lock-error".equals(codeString))
338        return LOCKERROR;
339      if ("no-store".equals(codeString))
340        return NOSTORE;
341      if ("exception".equals(codeString))
342        return EXCEPTION;
343      if ("timeout".equals(codeString))
344        return TIMEOUT;
345      if ("throttled".equals(codeString))
346        return THROTTLED;
347      if ("informational".equals(codeString))
348        return INFORMATIONAL;
349      else
350        throw new FHIRException("Unknown IssueType code '"+codeString+"'");
351    }
352    public String toCode() {
353      switch (this) {
354      case INVALID: return "invalid";
355      case STRUCTURE: return "structure";
356      case REQUIRED: return "required";
357      case VALUE: return "value";
358      case INVARIANT: return "invariant";
359      case SECURITY: return "security";
360      case LOGIN: return "login";
361      case UNKNOWN: return "unknown";
362      case EXPIRED: return "expired";
363      case FORBIDDEN: return "forbidden";
364      case SUPPRESSED: return "suppressed";
365      case PROCESSING: return "processing";
366      case NOTSUPPORTED: return "not-supported";
367      case DUPLICATE: return "duplicate";
368      case NOTFOUND: return "not-found";
369      case TOOLONG: return "too-long";
370      case CODEINVALID: return "code-invalid";
371      case EXTENSION: return "extension";
372      case TOOCOSTLY: return "too-costly";
373      case BUSINESSRULE: return "business-rule";
374      case CONFLICT: return "conflict";
375      case INCOMPLETE: return "incomplete";
376      case TRANSIENT: return "transient";
377      case LOCKERROR: return "lock-error";
378      case NOSTORE: return "no-store";
379      case EXCEPTION: return "exception";
380      case TIMEOUT: return "timeout";
381      case THROTTLED: return "throttled";
382      case INFORMATIONAL: return "informational";
383      default: return "?";
384      }
385    }
386    public String getSystem() {
387      switch (this) {
388      case INVALID: return "http://hl7.org/fhir/issue-type";
389      case STRUCTURE: return "http://hl7.org/fhir/issue-type";
390      case REQUIRED: return "http://hl7.org/fhir/issue-type";
391      case VALUE: return "http://hl7.org/fhir/issue-type";
392      case INVARIANT: return "http://hl7.org/fhir/issue-type";
393      case SECURITY: return "http://hl7.org/fhir/issue-type";
394      case LOGIN: return "http://hl7.org/fhir/issue-type";
395      case UNKNOWN: return "http://hl7.org/fhir/issue-type";
396      case EXPIRED: return "http://hl7.org/fhir/issue-type";
397      case FORBIDDEN: return "http://hl7.org/fhir/issue-type";
398      case SUPPRESSED: return "http://hl7.org/fhir/issue-type";
399      case PROCESSING: return "http://hl7.org/fhir/issue-type";
400      case NOTSUPPORTED: return "http://hl7.org/fhir/issue-type";
401      case DUPLICATE: return "http://hl7.org/fhir/issue-type";
402      case NOTFOUND: return "http://hl7.org/fhir/issue-type";
403      case TOOLONG: return "http://hl7.org/fhir/issue-type";
404      case CODEINVALID: return "http://hl7.org/fhir/issue-type";
405      case EXTENSION: return "http://hl7.org/fhir/issue-type";
406      case TOOCOSTLY: return "http://hl7.org/fhir/issue-type";
407      case BUSINESSRULE: return "http://hl7.org/fhir/issue-type";
408      case CONFLICT: return "http://hl7.org/fhir/issue-type";
409      case INCOMPLETE: return "http://hl7.org/fhir/issue-type";
410      case TRANSIENT: return "http://hl7.org/fhir/issue-type";
411      case LOCKERROR: return "http://hl7.org/fhir/issue-type";
412      case NOSTORE: return "http://hl7.org/fhir/issue-type";
413      case EXCEPTION: return "http://hl7.org/fhir/issue-type";
414      case TIMEOUT: return "http://hl7.org/fhir/issue-type";
415      case THROTTLED: return "http://hl7.org/fhir/issue-type";
416      case INFORMATIONAL: return "http://hl7.org/fhir/issue-type";
417      default: return "?";
418      }
419    }
420    public String getDefinition() {
421      switch (this) {
422      case INVALID: return "Content invalid against the specification or a profile.";
423      case STRUCTURE: return "A structural issue in the content such as wrong namespace, or unable to parse the content completely, or invalid json syntax.";
424      case REQUIRED: return "A required element is missing.";
425      case VALUE: return "An element value is invalid.";
426      case INVARIANT: return "A content validation rule failed - e.g. a schematron rule.";
427      case SECURITY: return "An authentication/authorization/permissions issue of some kind.";
428      case LOGIN: return "The client needs to initiate an authentication process.";
429      case UNKNOWN: return "The user or system was not able to be authenticated (either there is no process, or the proferred token is unacceptable).";
430      case EXPIRED: return "User session expired; a login may be required.";
431      case FORBIDDEN: return "The user does not have the rights to perform this action.";
432      case SUPPRESSED: return "Some information was not or may not have been returned due to business rules, consent or privacy rules, or access permission constraints.  This information may be accessible through alternate processes.";
433      case PROCESSING: return "Processing issues. These are expected to be final e.g. there is no point resubmitting the same content unchanged.";
434      case NOTSUPPORTED: return "The resource or profile is not supported.";
435      case DUPLICATE: return "An attempt was made to create a duplicate record.";
436      case NOTFOUND: return "The reference provided was not found. In a pure RESTful environment, this would be an HTTP 404 error, but this code may be used where the content is not found further into the application architecture.";
437      case TOOLONG: return "Provided content is too long (typically, this is a denial of service protection type of error).";
438      case CODEINVALID: return "The code or system could not be understood, or it was not valid in the context of a particular ValueSet.code.";
439      case EXTENSION: return "An extension was found that was not acceptable, could not be resolved, or a modifierExtension was not recognized.";
440      case TOOCOSTLY: return "The operation was stopped to protect server resources; e.g. a request for a value set expansion on all of SNOMED CT.";
441      case BUSINESSRULE: return "The content/operation failed to pass some business rule, and so could not proceed.";
442      case CONFLICT: return "Content could not be accepted because of an edit conflict (i.e. version aware updates) (In a pure RESTful environment, this would be an HTTP 404 error, but this code may be used where the conflict is discovered further into the application architecture.)";
443      case INCOMPLETE: return "Not all data sources typically accessed could be reached, or responded in time, so the returned information may not be complete.";
444      case TRANSIENT: return "Transient processing issues. The system receiving the error may be able to resubmit the same content once an underlying issue is resolved.";
445      case LOCKERROR: return "A resource/record locking failure (usually in an underlying database).";
446      case NOSTORE: return "The persistent store is unavailable; e.g. the database is down for maintenance or similar action.";
447      case EXCEPTION: return "An unexpected internal error has occurred.";
448      case TIMEOUT: return "An internal timeout has occurred.";
449      case THROTTLED: return "The system is not prepared to handle this request due to load management.";
450      case INFORMATIONAL: return "A message unrelated to the processing success of the completed operation (examples of the latter include things like reminders of password expiry, system maintenance times, etc.).";
451      default: return "?";
452      }
453    }
454    public String getDisplay() {
455      switch (this) {
456      case INVALID: return "Invalid Content";
457      case STRUCTURE: return "Structural Issue";
458      case REQUIRED: return "Required element missing";
459      case VALUE: return "Element value invalid";
460      case INVARIANT: return "Validation rule failed";
461      case SECURITY: return "Security Problem";
462      case LOGIN: return "Login Required";
463      case UNKNOWN: return "Unknown User";
464      case EXPIRED: return "Session Expired";
465      case FORBIDDEN: return "Forbidden";
466      case SUPPRESSED: return "Information  Suppressed";
467      case PROCESSING: return "Processing Failure";
468      case NOTSUPPORTED: return "Content not supported";
469      case DUPLICATE: return "Duplicate";
470      case NOTFOUND: return "Not Found";
471      case TOOLONG: return "Content Too Long";
472      case CODEINVALID: return "Invalid Code";
473      case EXTENSION: return "Unacceptable Extension";
474      case TOOCOSTLY: return "Operation Too Costly";
475      case BUSINESSRULE: return "Business Rule Violation";
476      case CONFLICT: return "Edit Version Conflict";
477      case INCOMPLETE: return "Incomplete Results";
478      case TRANSIENT: return "Transient Issue";
479      case LOCKERROR: return "Lock Error";
480      case NOSTORE: return "No Store Available";
481      case EXCEPTION: return "Exception";
482      case TIMEOUT: return "Timeout";
483      case THROTTLED: return "Throttled";
484      case INFORMATIONAL: return "Informational Note";
485      default: return "?";
486      }
487    }
488  }
489
490
491  private Source source;
492  private int line;
493  private int col;
494  private String location; // fhirPath
495  private String message;
496  private String messageId; // source, for grouping
497  private IssueType type;
498  private IssueSeverity level;
499  private String html;
500  private String locationLink;
501  private String txLink;
502  public String sliceHtml;
503  private boolean slicingHint;
504  private boolean signpost;
505
506
507  /**
508   * Constructor
509   */
510  public ValidationMessage() {
511    // nothing
512  }
513
514  public ValidationMessage(Source source, IssueType type, String path, String message, IssueSeverity level) {
515    super();
516    this.line = -1;
517    this.col = -1;
518    this.location = path;
519    if (message == null)
520      throw new Error("message is null");
521    this.message = message;
522    this.html = Utilities.escapeXml(message);
523    this.level = level;
524    this.source = source;
525    this.type = type;
526    if (level == IssueSeverity.NULL)
527      determineLevel(path);
528    if (type == null)
529      throw new Error("A type must be provided");
530  }
531
532  public ValidationMessage(Source source, IssueType type, int line, int col, String path, String message, IssueSeverity level) {
533    super();
534    this.line = line;
535    this.col = col;
536    this.location = path;
537    this.message = message;
538    this.html = Utilities.escapeXml(message);
539    this.level = level;
540    this.source = source;
541    this.type = type;
542    if (level == IssueSeverity.NULL)
543      determineLevel(path);
544    if (type == null)
545      throw new Error("A type must be provided");
546  }
547
548  public ValidationMessage(Source source, IssueType type, String path, String message, String html, IssueSeverity level) {
549    super();
550    this.line = -1;
551    this.col = -1;
552    this.location = path;
553    if (message == null)
554      throw new Error("message is null");
555    this.message = message;
556    this.html = html;
557    this.level = level;
558    this.source = source;
559    this.type = type;
560    if (level == IssueSeverity.NULL)
561      determineLevel(path);
562    if (type == null)
563      throw new Error("A type must be provided");
564  }
565
566  public ValidationMessage(Source source, IssueType type, int line, int col, String path, String message, String html, IssueSeverity level) {
567    super();
568    this.line = line;
569    this.col = col;
570    this.location = path;
571    if (message == null)
572      throw new Error("message is null");
573    this.message = message;
574    this.html = html;
575    this.level = level;
576    this.source = source;
577    this.type = type;
578    if (level == IssueSeverity.NULL)
579      determineLevel(path);
580    if (type == null)
581      throw new Error("A type must be provided");
582  }
583
584//  public ValidationMessage(Source source, IssueType type, String message, IssueSeverity level) {
585//    super();
586//    this.line = -1;
587//    this.col = -1;
588//    if (message == null)
589//      throw new Error("message is null");
590//    this.message = message;
591//    this.level = level;
592//    this.source = source;
593//    this.type = type;
594//    if (type == null)
595//      throw new Error("A type must be provided");
596//  }
597
598  private IssueSeverity determineLevel(String path) {
599    if (isGrandfathered(path))
600      return IssueSeverity.WARNING;
601    else
602      return IssueSeverity.ERROR;
603  }
604
605  private boolean isGrandfathered(String path) {
606    if (path.startsWith("xds-documentmanifest."))
607      return true;
608    if (path.startsWith("observation-device-metric-devicemetricobservation."))
609      return true;
610    if (path.startsWith("medicationadministration-immunization-vaccine."))
611      return true;
612    if (path.startsWith("elementdefinition-de-dataelement."))
613      return true;
614    if (path.startsWith("dataelement-sdc-sdcelement."))
615      return true;
616    if (path.startsWith("questionnaireresponse-sdc-structureddatacaptureanswers."))
617      return true;
618    if (path.startsWith("valueset-sdc-structureddatacapturevalueset."))
619      return true;
620    if (path.startsWith("dataelement-sdc-de-sdcelement."))
621      return true;
622    if (path.startsWith("do-uslab-uslabdo."))
623      return true;
624    if (path.startsWith("."))
625      return true;
626    if (path.startsWith("."))
627      return true;
628    if (path.startsWith("."))
629      return true;
630    if (path.startsWith("."))
631      return true;
632
633    return false;
634  }
635
636  public String getMessage() {
637    return message;
638  }
639  public ValidationMessage setMessage(String message) {
640    this.message = message;
641    return this;
642  }
643
644  public IssueSeverity getLevel() {
645    return level;
646  }
647  public ValidationMessage setLevel(IssueSeverity level) {
648    this.level = level;
649    return this;
650  }
651
652  public Source getSource() {
653    return source;
654  }
655  public ValidationMessage setSource(Source source) {
656    this.source = source;
657    return this;
658  }
659
660  public int getLine() {
661    return line;
662  }
663
664  public void setLine(int theLine) {
665    line = theLine;
666  }
667
668  public int getCol() {
669    return col;
670  }
671
672  public void setCol(int theCol) {
673    col = theCol;
674  }
675
676  public String getLocation() {
677    return location;
678  }
679  public ValidationMessage setLocation(String location) {
680    this.location = location;
681    return this;
682  }
683
684  public IssueType getType() {
685    return type;
686  }
687
688  public ValidationMessage setType(IssueType type) {
689    this.type = type;
690    return this;
691  }
692
693  public String summary() {
694    return level.toString()+" @ "+location+(line>= 0 && col >= 0 ? " (line "+Integer.toString(line)+", col"+Integer.toString(col)+"): " : ": ") +message +(source != null ? " (src = "+source+")" : "");
695  }
696
697
698  public String toXML() {
699    return "<message source=\"" + source + "\" line=\"" + line + "\" col=\"" + col + "\" location=\"" + Utilities.escapeXml(location) + "\" type=\"" + type + "\" level=\"" + level + "\" display=\"" + Utilities.escapeXml(getDisplay()) + "\" ><plain>" + Utilities.escapeXml(message) + "</plain><html>" + html + "</html></message>";
700  }
701
702  public String getHtml() {
703    return html == null ? Utilities.escapeXml(message) : html;
704  }
705
706  public String getDisplay() {
707    return level + ": " + (location==null || location.isEmpty() ? "" : (location + ": ")) + message;
708  }
709  
710  /**
711   * Returns a representation of this ValidationMessage suitable for logging. The values of
712   * most of the internal fields are included, so this may not be suitable for display to 
713   * an end user.
714   */
715  @Override
716  public String toString() {
717    ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
718    b.append("level", level);
719    b.append("type", type);
720    b.append("location", location);
721    b.append("message", message);
722    return b.build();
723  }
724
725  @Override
726  public boolean equals(Object o) {
727    return (this.getMessage() != null && this.getMessage().equals(((ValidationMessage)o).getMessage())) && (this.getLocation() != null && this.getLocation().equals(((ValidationMessage)o).getLocation()));
728  }
729
730  @Override
731  public int compare(ValidationMessage x, ValidationMessage y) {
732    String sx = x.getLevel().getDisplay() + x.getType().getDisplay() + String.format("%06d", x.getLine()) + x.getMessage();
733    String sy = y.getLevel().getDisplay() + y.getType().getDisplay() + String.format("%06d", y.getLine()) + y.getMessage();
734    return sx.compareTo(sy);
735  }  
736
737  @Override
738  public int compareTo(ValidationMessage y) {
739    return compare(this, y);
740  }
741
742  public String getLocationLink() {
743    return locationLink;
744  }
745
746  public ValidationMessage setLocationLink(String locationLink) {
747    this.locationLink = locationLink;
748    return this;
749  }
750
751  public String getTxLink() {
752    return txLink;
753  }
754
755  public ValidationMessage setTxLink(String txLink) {
756    this.txLink = txLink;
757    return this;
758  }
759
760  public void setHtml(String html) {
761    this.html = html;
762  }
763
764  public boolean isSlicingHint() {
765    return slicingHint;
766  }
767
768  public ValidationMessage setSlicingHint(boolean slicingHint) {
769    this.slicingHint = slicingHint;
770    return this;
771  }
772
773  public String getSliceHtml() {
774    return sliceHtml;
775  }
776
777  public void setSliceHtml(String sliceHtml) {
778    this.sliceHtml = sliceHtml;
779  }
780
781  public String getMessageId() {
782    return messageId;
783  }
784
785  public ValidationMessage setMessageId(String messageId) {
786    this.messageId = messageId;
787    return this;
788  }
789
790  public boolean isSignpost() {
791    return signpost;
792  }
793
794  public void setSignpost(boolean signpost) {
795    this.signpost = signpost;
796  }
797
798  
799}