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