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