001package org.hl7.fhir.r4.utils;
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
034import java.io.IOException;
035import java.io.InputStream;
036import java.util.List;
037
038import org.hl7.fhir.exceptions.DefinitionException;
039import org.hl7.fhir.exceptions.FHIRException;
040import org.hl7.fhir.exceptions.FHIRFormatError;
041import org.hl7.fhir.r4.elementmodel.Element;
042import org.hl7.fhir.r4.elementmodel.Manager.FhirFormat;
043import org.hl7.fhir.r4.model.StructureDefinition;
044import org.hl7.fhir.utilities.validation.ValidationMessage;
045
046import com.google.gson.JsonObject;
047
048/**
049 * Interface to the instance validator. This takes a resource, in one of many forms, and 
050 * checks whether it is valid
051   *  
052   * @author Grahame Grieve
053   *
054   */
055public interface IResourceValidator {
056
057  public enum ReferenceValidationPolicy {
058    IGNORE, CHECK_TYPE_IF_EXISTS, CHECK_EXISTS, CHECK_EXISTS_AND_TYPE, CHECK_VALID;
059    
060    public boolean checkExists() {
061      return this == CHECK_EXISTS_AND_TYPE || this == CHECK_EXISTS || this == CHECK_VALID;
062    }
063    
064    public boolean checkType() {
065      return this == CHECK_TYPE_IF_EXISTS || this == CHECK_EXISTS_AND_TYPE || this == CHECK_VALID;
066    }
067    
068    public boolean checkValid() {
069      return this == CHECK_VALID;
070    }
071  }
072  
073  public interface IValidatorResourceFetcher {
074    Element fetch(Object appContext, String url) throws FHIRFormatError, DefinitionException, FHIRException, IOException;
075    ReferenceValidationPolicy validationPolicy(Object appContext, String path, String url);
076    boolean resolveURL(Object appContext, String path, String url) throws IOException, FHIRException; 
077  }
078  
079  public enum BestPracticeWarningLevel {
080    Ignore,
081    Hint,
082    Warning,
083    Error
084  }
085
086  public enum CheckDisplayOption {
087    Ignore,
088    Check,
089    CheckCaseAndSpace,
090    CheckCase,
091    CheckSpace
092  }
093
094  enum IdStatus {
095    OPTIONAL, REQUIRED, PROHIBITED
096  }
097  
098  
099
100  /**
101   * how much to check displays for coded elements 
102   * @return
103   */
104  CheckDisplayOption getCheckDisplay();
105  void setCheckDisplay(CheckDisplayOption checkDisplay);
106
107  /**
108   * whether the resource must have an id or not (depends on context)
109   * 
110   * @return
111   */
112
113        IdStatus getResourceIdRule();
114        void setResourceIdRule(IdStatus resourceIdRule);
115  
116  /**
117   * whether the validator should enforce best practice guidelines
118   * as defined by various HL7 committees 
119   *  
120   */
121  BestPracticeWarningLevel getBestPracticeWarningLevel();
122  IResourceValidator setBestPracticeWarningLevel(BestPracticeWarningLevel value);
123
124  IValidatorResourceFetcher getFetcher();
125  IResourceValidator setFetcher(IValidatorResourceFetcher value);
126  
127  boolean isNoBindingMsgSuppressed();
128  IResourceValidator setNoBindingMsgSuppressed(boolean noBindingMsgSuppressed);
129  
130  public boolean isNoInvariantChecks();
131  public IResourceValidator setNoInvariantChecks(boolean value) ;
132  
133  public boolean isNoTerminologyChecks();
134  public IResourceValidator setNoTerminologyChecks(boolean noTerminologyChecks);
135
136  public boolean isNoExtensibleWarnings();
137  public IResourceValidator setNoExtensibleWarnings(boolean noExtensibleWarnings);
138  
139  /**
140   * 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
141   * @return
142   */
143  public boolean isErrorForUnknownProfiles();
144  public void setErrorForUnknownProfiles(boolean errorForUnknownProfiles);
145
146  public String getValidationLanguage();
147  public void setValidationLanguage(String value);
148  
149  /**
150   * Validate suite
151   *  
152   * you can validate one of the following representations of resources:
153   *  
154   * stream - provide a format - this is the preferred choice
155   * 
156   * Use one of these two if the content is known to be valid XML/JSON, and already parsed
157   * - a DOM element or Document
158   * - a Json Object
159   *  
160   * In order to use these, the content must already be parsed - e.g. it must syntactically valid    
161   * - a native resource
162   * - a elementmodel resource  
163   * 
164   * in addition, you can pass one or more profiles ti validate beyond the base standard - as structure definitions or canonical URLs 
165   * @throws IOException 
166   */
167  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element) throws FHIRException;
168  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, ValidationProfileSet profiles) throws FHIRException;
169  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, String profile) throws FHIRException;
170  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, StructureDefinition profile) throws FHIRException;
171  
172  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format) throws FHIRException;
173  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, ValidationProfileSet profiles) throws FHIRException;
174  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, String profile) throws FHIRException;
175  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, StructureDefinition profile) throws FHIRException;
176
177  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource) throws FHIRException;
178  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, ValidationProfileSet profiles) throws FHIRException;
179  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, String profile) throws FHIRException;
180  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, StructureDefinition profile) throws FHIRException;
181
182  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element) throws FHIRException;
183  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, ValidationProfileSet profiles) throws FHIRException;
184  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, String profile) throws FHIRException;
185  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, StructureDefinition profile) throws FHIRException;
186
187  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document) throws FHIRException;
188  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, ValidationProfileSet profiles) throws FHIRException;
189  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, String profile) throws FHIRException;
190  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, StructureDefinition profile) throws FHIRException;
191
192  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object) throws FHIRException;
193  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, ValidationProfileSet profiles) throws FHIRException;
194  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, String profile) throws FHIRException;
195  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, StructureDefinition profile) throws FHIRException; 
196
197
198}