001package org.hl7.fhir.r5.utils.validation; 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 033import org.hl7.fhir.exceptions.FHIRException; 034import org.hl7.fhir.r5.context.IWorkerContext; 035import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; 036import org.hl7.fhir.r5.model.Coding; 037import org.hl7.fhir.r5.model.StructureDefinition; 038import org.hl7.fhir.r5.model.UsageContext; 039import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; 040import org.hl7.fhir.r5.utils.validation.constants.CheckDisplayOption; 041import org.hl7.fhir.r5.utils.validation.constants.IdStatus; 042import org.hl7.fhir.utilities.json.model.JsonObject; 043import org.hl7.fhir.utilities.validation.ValidationMessage; 044 045import java.io.IOException; 046import java.io.InputStream; 047import java.util.List; 048 049/** 050 * Interface to the instance validator. This takes a resource, in one of many forms, and 051 * checks whether it is valid 052 * 053 * @author Grahame Grieve 054 * 055 */ 056public interface IResourceValidator { 057 058 IWorkerContext getContext(); 059 060 /** 061 * how much to check displays for coded elements 062 */ 063 CheckDisplayOption getCheckDisplay(); 064 void setCheckDisplay(CheckDisplayOption checkDisplay); 065 066 /** 067 * whether the resource must have an id or not (depends on context) 068 */ 069 IdStatus getResourceIdRule(); 070 void setResourceIdRule(IdStatus resourceIdRule); 071 072 /** 073 * whether the validator should enforce best practice guidelines 074 * as defined by various HL7 committees 075 */ 076 BestPracticeWarningLevel getBestPracticeWarningLevel(); 077 IResourceValidator setBestPracticeWarningLevel(BestPracticeWarningLevel value); 078 079 IValidatorResourceFetcher getFetcher(); 080 IResourceValidator setFetcher(IValidatorResourceFetcher value); 081 082 IValidationPolicyAdvisor getPolicyAdvisor(); 083 void setPolicyAdvisor(IValidationPolicyAdvisor advisor); 084 085 IValidationProfileUsageTracker getTracker(); 086 IResourceValidator setTracker(IValidationProfileUsageTracker value); 087 088 boolean isNoBindingMsgSuppressed(); 089 IResourceValidator setNoBindingMsgSuppressed(boolean noBindingMsgSuppressed); 090 091 boolean isNoInvariantChecks(); 092 IResourceValidator setNoInvariantChecks(boolean value) ; 093 094 boolean isWantInvariantInMessage(); 095 IResourceValidator setWantInvariantInMessage(boolean wantInvariantInMessage); 096 097 boolean isNoTerminologyChecks(); 098 IResourceValidator setNoTerminologyChecks(boolean noTerminologyChecks); 099 100 boolean isNoExtensibleWarnings(); 101 IResourceValidator setNoExtensibleWarnings(boolean noExtensibleWarnings); 102 103 boolean isNoUnicodeBiDiControlChars(); 104 void setNoUnicodeBiDiControlChars(boolean noUnicodeBiDiControlChars); 105 106 boolean isForPublication(); 107 IResourceValidator setForPublication(boolean forPublication); 108 109 boolean isExample(); 110 IResourceValidator setExample(boolean example); 111 112 // used to decide whether additional bindings, constraints etc apply 113 public List<UsageContext> getUsageContexts(); 114 115 public boolean isWarnOnDraftOrExperimental(); 116 117 public IResourceValidator setWarnOnDraftOrExperimental(boolean warnOnDraftOrExperimental); 118 119 /** 120 * 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 121 */ 122 boolean isErrorForUnknownProfiles(); 123 void setErrorForUnknownProfiles(boolean errorForUnknownProfiles); 124 125 boolean isShowMessagesFromReferences(); 126 void setShowMessagesFromReferences(boolean value); 127 128 /** 129 * this is used internally in the publishing stack to ensure that everything is water tight, but 130 * this check is not necessary or appropriate at run time when the validator is hosted in HAPI 131 * @return 132 */ 133 boolean isWantCheckSnapshotUnchanged(); 134 void setWantCheckSnapshotUnchanged(boolean wantCheckSnapshotUnchanged); 135 136 /** 137 * It's common to see references such as Patient/234234 - these usually mean a reference to a Patient resource. 138 * But there's no actual technical rule that it does, so the validator doesn't enforce that unless this setting is 139 * set to true 140 * 141 * @return 142 */ 143 boolean isAssumeValidRestReferences(); 144 void setAssumeValidRestReferences(boolean value); 145 146 /** 147 * if this is true, the validator will accept extensions and references to example.org and acme.com as 148 * valid, on the basis that they are understood to be references to content that could exist in priniple but can't in practice 149 */ 150 boolean isAllowExamples(); 151 void setAllowExamples(boolean value) ; 152 153 boolean isNoCheckAggregation(); 154 void setNoCheckAggregation(boolean value); 155 156 /** 157 * CrumbTrail - whether the validator creates hints to 158 * @return 159 */ 160 boolean isCrumbTrails(); 161 void setCrumbTrails(boolean crumbTrails); 162 163 boolean isValidateValueSetCodesOnTxServer(); 164 void setValidateValueSetCodesOnTxServer(boolean value); 165 166 public Coding getJurisdiction(); 167 public IResourceValidator setJurisdiction(Coding jurisdiction); 168 169 /** 170 * Bundle validation rules allow for requesting particular entries in a bundle get validated against particular profiles 171 * Typically this is used from the command line to avoid having to construct profile just to validate a particular resource 172 * in a bundle against a particular profile 173 * 174 * @return 175 */ 176 List<BundleValidationRule> getBundleValidationRules(); 177 178 /** 179 * Validate suite 180 * 181 * you can validate one of the following representations of resources: 182 * 183 * stream - provide a format - this is the preferred choice 184 * 185 * Use one of these two if the content is known to be valid XML/JSON, and already parsed 186 * - a DOM element or Document 187 * - a Json Object 188 * 189 * In order to use these, the content must already be parsed - e.g. it must syntactically valid 190 * - a native resource 191 * - a elementmodel resource 192 * 193 * in addition, you can pass one or more profiles ti validate beyond the base standard - as structure definitions or canonical URLs 194 * @throws IOException 195 */ 196 void validate(Object Context, List<ValidationMessage> errors, String initialPath, org.hl7.fhir.r5.elementmodel.Element element) throws FHIRException; 197 void validate(Object Context, List<ValidationMessage> errors, String initialPath, org.hl7.fhir.r5.elementmodel.Element element, String profile) throws FHIRException; 198 void validate(Object Context, List<ValidationMessage> errors, String initialPath, org.hl7.fhir.r5.elementmodel.Element element, List<StructureDefinition> profiles) throws FHIRException; 199 200 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format) throws FHIRException; 201 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, String profile) throws FHIRException; 202 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, InputStream stream, FhirFormat format, List<StructureDefinition> profiles) throws FHIRException; 203 204 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r5.model.Resource resource) throws FHIRException; 205 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r5.model.Resource resource, String profile) throws FHIRException; 206 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.hl7.fhir.r5.model.Resource resource, List<StructureDefinition> profiles) throws FHIRException; 207 208 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element) throws FHIRException; 209 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, String profile) throws FHIRException; 210 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Element element, List<StructureDefinition> profile) throws FHIRException; 211 212 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document) throws FHIRException; 213 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, String profile) throws FHIRException; 214 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, org.w3c.dom.Document document, List<StructureDefinition> profile) throws FHIRException; 215 216 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object) throws FHIRException; 217 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, String profile) throws FHIRException; 218 org.hl7.fhir.r5.elementmodel.Element validate(Object Context, List<ValidationMessage> errors, JsonObject object, List<StructureDefinition> profile) throws FHIRException; 219 220 221}