001package org.hl7.fhir.r5.utils.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
033import org.hl7.fhir.exceptions.FHIRException;
034import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
035import org.hl7.fhir.r5.model.Coding;
036import org.hl7.fhir.r5.model.StructureDefinition;
037import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel;
038import org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption;
039import org.hl7.fhir.r5.utils.validation.constants.IdStatus;
040import org.hl7.fhir.utilities.json.model.JsonObject;
041import org.hl7.fhir.utilities.validation.ValidationMessage;
042
043import java.io.IOException;
044import java.io.InputStream;
045import java.util.List;
046
047/**
048 * Interface to the instance validator. This takes a resource, in one of many forms, and 
049 * checks whether it is valid
050   *  
051   * @author Grahame Grieve
052   *
053   */
054public interface IResourceValidator {
055
056  /**
057   * how much to check displays for coded elements 
058   */
059  CheckDisplayOption getCheckDisplay();
060  void setCheckDisplay(CheckDisplayOption checkDisplay);
061
062  /**
063   * whether the resource must have an id or not (depends on context)
064   */
065        IdStatus getResourceIdRule();
066        void setResourceIdRule(IdStatus resourceIdRule);
067  
068  /**
069   * whether the validator should enforce best practice guidelines
070   * as defined by various HL7 committees 
071   */
072  BestPracticeWarningLevel getBestPracticeWarningLevel();
073  IResourceValidator setBestPracticeWarningLevel(BestPracticeWarningLevel value);
074
075  IValidatorResourceFetcher getFetcher();
076  IResourceValidator setFetcher(IValidatorResourceFetcher value);
077
078  IValidationPolicyAdvisor getPolicyAdvisor();
079  IResourceValidator setPolicyAdvisor(IValidationPolicyAdvisor advisor);
080
081  IValidationProfileUsageTracker getTracker();
082  IResourceValidator setTracker(IValidationProfileUsageTracker value);
083
084  boolean isNoBindingMsgSuppressed();
085  IResourceValidator setNoBindingMsgSuppressed(boolean noBindingMsgSuppressed);
086  
087  boolean isNoInvariantChecks();
088  IResourceValidator setNoInvariantChecks(boolean value) ;
089
090  boolean isWantInvariantInMessage();
091  IResourceValidator setWantInvariantInMessage(boolean wantInvariantInMessage);
092
093  boolean isNoTerminologyChecks();
094  IResourceValidator setNoTerminologyChecks(boolean noTerminologyChecks);
095
096  boolean isNoExtensibleWarnings();
097  IResourceValidator setNoExtensibleWarnings(boolean noExtensibleWarnings);
098  
099  boolean isNoUnicodeBiDiControlChars();
100  void setNoUnicodeBiDiControlChars(boolean noUnicodeBiDiControlChars);
101  
102  boolean isForPublication();
103  void setForPublication(boolean forPublication);
104  
105  /**
106   * Whether being unable to resolve a profile in found in Resource.meta.profile or ElementDefinition.type.profile or targetProfile is an error or just a warning
107   */
108  boolean isErrorForUnknownProfiles();
109  void setErrorForUnknownProfiles(boolean errorForUnknownProfiles);
110
111  boolean isShowMessagesFromReferences();
112  void setShowMessagesFromReferences(boolean value);
113
114  /** 
115   * this is used internally in the publishing stack to ensure that everything is water tight, but 
116   * this check is not necessary or appropriate at run time when the validator is hosted in HAPI
117   * @return
118   */
119  boolean isWantCheckSnapshotUnchanged();
120  void setWantCheckSnapshotUnchanged(boolean wantCheckSnapshotUnchanged);
121  
122  /**
123   * It's common to see references such as Patient/234234 - these usually mean a reference to a Patient resource. 
124   * But there's no actual technical rule that it does, so the validator doesn't enforce that unless this setting is 
125   * set to true
126   * 
127   * @return
128   */
129  boolean isAssumeValidRestReferences();
130  void setAssumeValidRestReferences(boolean value);
131  
132  /** 
133   * if this is true, the validator will accept extensions and references to example.org and acme.com as 
134   * valid, on the basis that they are understood to be references to content that could exist in priniple but can't in practice
135   */
136  boolean isAllowExamples();
137  void setAllowExamples(boolean value) ;
138 
139  boolean isNoCheckAggregation();
140  void setNoCheckAggregation(boolean value);
141
142  /**
143   * CrumbTrail - whether the validator creates hints to 
144   * @return
145   */
146  boolean isCrumbTrails();
147  void setCrumbTrails(boolean crumbTrails);
148
149  boolean isValidateValueSetCodesOnTxServer();
150  void setValidateValueSetCodesOnTxServer(boolean value);
151
152  public Coding getJurisdiction();
153  public IResourceValidator setJurisdiction(Coding jurisdiction);
154
155  /** 
156   * Bundle validation rules allow for requesting particular entries in a bundle get validated against particular profiles
157   * Typically this is used from the command line to avoid having to construct profile just to validate a particular resource 
158   * in a bundle against a particular profile 
159   *  
160   * @return
161   */
162  List<BundleValidationRule> getBundleValidationRules();
163  
164  /**
165   * Validate suite
166   *  
167   * you can validate one of the following representations of resources:
168   *  
169   * stream - provide a format - this is the preferred choice
170   * 
171   * Use one of these two if the content is known to be valid XML/JSON, and already parsed
172   * - a DOM element or Document
173   * - a Json Object
174   *  
175   * In order to use these, the content must already be parsed - e.g. it must syntactically valid    
176   * - a native resource
177   * - a elementmodel resource  
178   * 
179   * in addition, you can pass one or more profiles ti validate beyond the base standard - as structure definitions or canonical URLs 
180   * @throws IOException 
181   */
182  void validate(Object Context, List<ValidationMessage> errors, String initialPath, org.hl7.fhir.r5.elementmodel.Element element) throws FHIRException;
183  void validate(Object Context, List<ValidationMessage> errors, String initialPath, org.hl7.fhir.r5.elementmodel.Element element, String profile) throws FHIRException;
184  void validate(Object Context, List<ValidationMessage> errors, String initialPath, org.hl7.fhir.r5.elementmodel.Element element, List<StructureDefinition> profiles) throws FHIRException;
185  
186  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format) throws FHIRException;
187  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, String profile) throws FHIRException;
188  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, List<StructureDefinition> profiles) throws FHIRException;
189
190  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r5.model.Resource resource) throws FHIRException;
191  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r5.model.Resource resource, String profile) throws FHIRException;
192  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r5.model.Resource resource, List<StructureDefinition> profiles) throws FHIRException;
193
194  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element) throws FHIRException;
195  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, String profile) throws FHIRException;
196  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, List<StructureDefinition> profile) throws FHIRException;
197
198  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document) throws FHIRException;
199  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, String profile) throws FHIRException;
200  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, List<StructureDefinition> profile) throws FHIRException;
201
202  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object) throws FHIRException;
203  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, String profile) throws FHIRException;
204  org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, List<StructureDefinition> profile) throws FHIRException;
205
206
207}