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