001package org.hl7.fhir.r4.utils; 002 003import java.io.IOException; 004import java.io.InputStream; 005import java.util.List; 006 007import org.hl7.fhir.r4.elementmodel.Element; 008import org.hl7.fhir.r4.elementmodel.Manager.FhirFormat; 009import org.hl7.fhir.r4.model.StructureDefinition; 010import org.hl7.fhir.r4.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 public boolean isNoExtensibleWarnings(); 107 public IResourceValidator setNoExtensibleWarnings(boolean noExtensibleWarnings); 108 109 /** 110 * 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 111 * @return 112 */ 113 public boolean isErrorForUnknownProfiles(); 114 public void setErrorForUnknownProfiles(boolean errorForUnknownProfiles); 115 116 /** 117 * Validate suite 118 * 119 * you can validate one of the following representations of resources: 120 * 121 * stream - provide a format - this is the preferred choice 122 * 123 * Use one of these two if the content is known to be valid XML/JSON, and already parsed 124 * - a DOM element or Document 125 * - a Json Object 126 * 127 * In order to use these, the content must already be parsed - e.g. it must syntactically valid 128 * - a native resource 129 * - a elementmodel resource 130 * 131 * in addition, you can pass one or more profiles ti validate beyond the base standard - as structure definitions or canonical URLs 132 * @throws IOException 133 */ 134 void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element) throws FHIRException, IOException; 135 void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, ValidationProfileSet profiles) throws FHIRException, IOException; 136 @Deprecated 137 void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, String profile) throws FHIRException, IOException; 138 @Deprecated 139 void validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.elementmodel.Element element, StructureDefinition profile) throws FHIRException, IOException; 140 141 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format) throws FHIRException, IOException; 142 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, ValidationProfileSet profiles) throws FHIRException, IOException; 143 @Deprecated 144 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, String profile) throws FHIRException, IOException; 145 @Deprecated 146 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, StructureDefinition profile) throws FHIRException, IOException; 147 148 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource) throws FHIRException, IOException; 149 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, ValidationProfileSet profiles) throws FHIRException, IOException; 150 @Deprecated 151 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, String profile) throws FHIRException, IOException; 152 @Deprecated 153 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r4.model.Resource resource, StructureDefinition profile) throws FHIRException, IOException; 154 155 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element) throws FHIRException, IOException; 156 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, ValidationProfileSet profiles) throws FHIRException, IOException; 157 @Deprecated 158 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, String profile) throws FHIRException, IOException; 159 @Deprecated 160 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, StructureDefinition profile) throws FHIRException, IOException; 161 162 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document) throws FHIRException, IOException; 163 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, ValidationProfileSet profiles) throws FHIRException, IOException; 164 @Deprecated 165 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, String profile) throws FHIRException, IOException; 166 @Deprecated 167 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, StructureDefinition profile) throws FHIRException, IOException; 168 169 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object) throws FHIRException, IOException; 170 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, ValidationProfileSet profiles) throws FHIRException, IOException; 171 @Deprecated 172 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, String profile) throws FHIRException, IOException; 173 @Deprecated 174 org.hl7.fhir.r4.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, StructureDefinition profile) throws FHIRException, IOException; 175 176 177}