001package org.hl7.fhir.dstu3.utils;
002
003/*-
004 * #%L
005 * org.hl7.fhir.dstu3
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import java.io.IOException;
025import java.io.InputStream;
026import java.util.List;
027
028import org.hl7.fhir.dstu3.elementmodel.Element;
029import org.hl7.fhir.dstu3.elementmodel.Manager.FhirFormat;
030import org.hl7.fhir.dstu3.model.StructureDefinition;
031import org.hl7.fhir.exceptions.DefinitionException;
032import org.hl7.fhir.exceptions.FHIRException;
033import org.hl7.fhir.exceptions.FHIRFormatError;
034import org.hl7.fhir.utilities.validation.ValidationMessage;
035
036import com.google.gson.JsonObject;
037
038/**
039 * Interface to the instance validator. This takes a resource, in one of many forms, and 
040 * checks whether it is valid
041   *  
042   * @author Grahame Grieve
043   *
044   */
045public interface IResourceValidator {
046
047  public enum ReferenceValidationPolicy {
048    IGNORE, CHECK_TYPE_IF_EXISTS, CHECK_EXISTS, CHECK_EXISTS_AND_TYPE, CHECK_VALID;
049    
050    public boolean checkExists() {
051      return this == CHECK_EXISTS_AND_TYPE || this == CHECK_EXISTS || this == CHECK_VALID;
052    }
053    
054    public boolean checkType() {
055      return this == CHECK_TYPE_IF_EXISTS || this == CHECK_EXISTS_AND_TYPE || this == CHECK_VALID;
056    }
057    
058    public boolean checkValid() {
059      return this == CHECK_VALID;
060    }
061  }
062  
063  public interface IValidatorResourceFetcher {
064    Element fetch(Object appContext, String url) throws FHIRFormatError, DefinitionException, IOException, FHIRException;
065    ReferenceValidationPolicy validationPolicy(Object appContext, String path, String url);
066    boolean resolveURL(Object appContext, String path, String url) throws IOException, FHIRException; 
067  }
068  
069  public enum BestPracticeWarningLevel {
070    Ignore,
071    Hint,
072    Warning,
073    Error
074  }
075
076  public enum CheckDisplayOption {
077    Ignore,
078    Check,
079    CheckCaseAndSpace,
080    CheckCase,
081    CheckSpace
082  }
083
084  enum IdStatus {
085    OPTIONAL, REQUIRED, PROHIBITED
086  }
087  
088  
089
090  /**
091   * how much to check displays for coded elements 
092   * @return
093   */
094  CheckDisplayOption getCheckDisplay();
095  void setCheckDisplay(CheckDisplayOption checkDisplay);
096
097  /**
098   * whether the resource must have an id or not (depends on context)
099   * 
100   * @return
101   */
102
103        IdStatus getResourceIdRule();
104        void setResourceIdRule(IdStatus resourceIdRule);
105  
106  /**
107   * whether the validator should enforce best practice guidelines
108   * as defined by various HL7 committees 
109   *  
110   */
111  BestPracticeWarningLevel getBasePracticeWarningLevel();
112  IResourceValidator setBestPracticeWarningLevel(BestPracticeWarningLevel value);
113
114  IValidatorResourceFetcher getFetcher();
115  IResourceValidator setFetcher(IValidatorResourceFetcher value);
116  
117  boolean isNoBindingMsgSuppressed();
118  IResourceValidator setNoBindingMsgSuppressed(boolean noBindingMsgSuppressed);
119  
120  public boolean isNoInvariantChecks();
121  public IResourceValidator setNoInvariantChecks(boolean value) ;
122  
123  public boolean isNoTerminologyChecks();
124  public IResourceValidator setNoTerminologyChecks(boolean noTerminologyChecks);
125
126  /**
127   * 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
128   * @return
129   */
130  public boolean isErrorForUnknownProfiles();
131  public void setErrorForUnknownProfiles(boolean errorForUnknownProfiles);
132
133  /**
134   * Validate suite
135   *  
136   * you can validate one of the following representations of resources:
137   *  
138   * stream - provide a format - this is the preferred choice
139   * 
140   * Use one of these two if the content is known to be valid XML/JSON, and already parsed
141   * - a DOM element or Document
142   * - a Json Object
143   *  
144   * In order to use these, the content must already be parsed - e.g. it must syntactically valid    
145   * - a native resource
146   * - a elementmodel resource  
147   * 
148   * in addition, you can pass one or more profiles ti validate beyond the base standard - as structure definitions or canonical URLs 
149   * @throws IOException 
150   */
151  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.elementmodel.Element element) throws FHIRException, IOException;
152  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.elementmodel.Element element, ValidationProfileSet profiles) throws FHIRException, IOException;
153  @Deprecated
154  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.elementmodel.Element element, String profile) throws FHIRException, IOException;
155  @Deprecated
156  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.elementmodel.Element element, StructureDefinition profile) throws FHIRException, IOException;
157  
158  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format) throws FHIRException, IOException;
159  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, ValidationProfileSet profiles) throws FHIRException, IOException;
160  @Deprecated
161  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, String profile) throws FHIRException, IOException;
162  @Deprecated
163  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, StructureDefinition profile) throws FHIRException, IOException;
164
165  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException, IOException;
166  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.model.Resource resource, ValidationProfileSet profiles) throws FHIRException, IOException;
167  @Deprecated
168  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.model.Resource resource, String profile) throws FHIRException, IOException;
169  @Deprecated
170  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.dstu3.model.Resource resource, StructureDefinition profile) throws FHIRException, IOException;
171
172  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element) throws FHIRException, IOException;
173  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, ValidationProfileSet profiles) throws FHIRException, IOException;
174  @Deprecated
175  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, String profile) throws FHIRException, IOException;
176  @Deprecated
177  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, StructureDefinition profile) throws FHIRException, IOException;
178
179  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document) throws FHIRException, IOException;
180  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, ValidationProfileSet profiles) throws FHIRException, IOException;
181  @Deprecated
182  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, String profile) throws FHIRException, IOException;
183  @Deprecated
184  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, StructureDefinition profile) throws FHIRException, IOException;
185
186  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object) throws FHIRException, IOException;
187  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, ValidationProfileSet profiles) throws FHIRException, IOException;
188  @Deprecated
189  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, String profile) throws FHIRException, IOException;
190  @Deprecated
191  org.hl7.fhir.dstu3.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, StructureDefinition profile) throws FHIRException, IOException; 
192
193
194}