001package org.hl7.fhir.r4.utils;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r4
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.exceptions.DefinitionException;
029import org.hl7.fhir.exceptions.FHIRException;
030import org.hl7.fhir.exceptions.FHIRFormatError;
031import org.hl7.fhir.r4.elementmodel.Element;
032import org.hl7.fhir.r4.elementmodel.Manager.FhirFormat;
033import org.hl7.fhir.r4.model.StructureDefinition;
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, FHIRException, IOException;
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 getBestPracticeWarningLevel();
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  public boolean isNoExtensibleWarnings();
127  public IResourceValidator setNoExtensibleWarnings(boolean noExtensibleWarnings);
128  
129  /**
130   * 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
131   * @return
132   */
133  public boolean isErrorForUnknownProfiles();
134  public void setErrorForUnknownProfiles(boolean errorForUnknownProfiles);
135
136  public String getValidationLanguage();
137  public void setValidationLanguage(String value);
138  
139  /**
140   * Validate suite
141   *  
142   * you can validate one of the following representations of resources:
143   *  
144   * stream - provide a format - this is the preferred choice
145   * 
146   * Use one of these two if the content is known to be valid XML/JSON, and already parsed
147   * - a DOM element or Document
148   * - a Json Object
149   *  
150   * In order to use these, the content must already be parsed - e.g. it must syntactically valid    
151   * - a native resource
152   * - a elementmodel resource  
153   * 
154   * in addition, you can pass one or more profiles ti validate beyond the base standard - as structure definitions or canonical URLs 
155   * @throws IOException 
156   */
157  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element) throws FHIRException;
158  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, ValidationProfileSet profiles) throws FHIRException;
159  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, String profile) throws FHIRException;
160  void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, StructureDefinition profile) throws FHIRException;
161  
162  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format) throws FHIRException;
163  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, ValidationProfileSet profiles) throws FHIRException;
164  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, String profile) throws FHIRException;
165  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, StructureDefinition profile) throws FHIRException;
166
167  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource) throws FHIRException;
168  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, ValidationProfileSet profiles) throws FHIRException;
169  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, String profile) throws FHIRException;
170  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, StructureDefinition profile) throws FHIRException;
171
172  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element) throws FHIRException;
173  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, ValidationProfileSet profiles) throws FHIRException;
174  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, String profile) throws FHIRException;
175  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, StructureDefinition profile) throws FHIRException;
176
177  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document) throws FHIRException;
178  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, ValidationProfileSet profiles) throws FHIRException;
179  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, String profile) throws FHIRException;
180  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, StructureDefinition profile) throws FHIRException;
181
182  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object) throws FHIRException;
183  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, ValidationProfileSet profiles) throws FHIRException;
184  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, String profile) throws FHIRException;
185  org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, StructureDefinition profile) throws FHIRException; 
186
187
188}