001package org.hl7.fhir.dstu2.utils; 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 033 034import java.util.List; 035 036import org.hl7.fhir.dstu2.model.StructureDefinition; 037import org.hl7.fhir.utilities.validation.ValidationMessage; 038import org.w3c.dom.Document; 039import org.w3c.dom.Element; 040 041import com.google.gson.JsonObject; 042 043public interface IResourceValidator { 044 045 /** 046 * whether the validator should enforce best practice guidelines 047 * as defined by various HL7 committees 048 * 049 * 050 * @author Grahame Grieve 051 * 052 */ 053 public enum BestPracticeWarningLevel { 054 Ignore, 055 Hint, 056 Warning, 057 Error 058 } 059 060 public enum CheckDisplayOption { 061 Ignore, 062 Check, 063 CheckCaseAndSpace, 064 CheckCase, 065 CheckSpace 066 } 067 068 /** 069 * how much to check displays for coded elements 070 * @return 071 */ 072 CheckDisplayOption getCheckDisplay(); 073 074 /** 075 * how much to check displays for coded elements 076 * @return 077 */ 078 void setCheckDisplay(CheckDisplayOption checkDisplay); 079 080 enum IdStatus { 081 OPTIONAL, REQUIRED, PROHIBITED 082 } 083 084 /** 085 * whether the resource must have an id or not (depends on context) 086 * 087 * @return 088 */ 089 090 IdStatus getResourceIdRule(); 091 void setResourceIdRule(IdStatus resourceIdRule); 092 093 BestPracticeWarningLevel getBasePracticeWarningLevel(); 094 void setBestPracticeWarningLevel(BestPracticeWarningLevel value); 095 096 097 /** 098 * Given a DOM element, return a list of errors in the resource 099 * 100 * @param errors 101 * @param elem 102 * @- if the underlying infrastructure fails (not if the resource is invalid) 103 */ 104 void validate(List<ValidationMessage> errors, Element element) throws Exception; 105 106 /** 107 * Given a JSON Object, return a list of errors in the resource 108 * 109 * @param errors 110 * @param elem 111 * @- if the underlying infrastructure fails (not if the resource is invalid) 112 */ 113 void validate(List<ValidationMessage> errors, JsonObject object) throws Exception; 114 115 /** 116 * Given a DOM element, return a list of errors in the resource 117 * 118 * @param errors 119 * @param elem 120 * @- if the underlying infrastructure fails (not if the resource is invalid) 121 */ 122 List<ValidationMessage> validate(Element element) throws Exception; 123 124 /** 125 * Given a DOM element, return a list of errors in the resource 126 * 127 * @param errors 128 * @param elem 129 * @- if the underlying infrastructure fails (not if the resource is invalid) 130 */ 131 List<ValidationMessage> validate(JsonObject object) throws Exception; 132 133 /** 134 * Given a DOM element, return a list of errors in the resource 135 * with regard to the specified profile (by logical identifier) 136 * 137 * @param errors 138 * @param element 139 * @param profile 140 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 141 */ 142 void validate(List<ValidationMessage> errors, Element element, String profile) throws Exception; 143 144 /** 145 * Given a DOM element, return a list of errors in the resource 146 * with regard to the specified profile (by logical identifier) 147 * 148 * @param errors 149 * @param element 150 * @param profile 151 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 152 */ 153 List<ValidationMessage> validate(Element element, String profile) throws Exception; 154 155 /** 156 * Given a DOM element, return a list of errors in the resource 157 * with regard to the specified profile (by logical identifier) 158 * 159 * @param errors 160 * @param element 161 * @param profile 162 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 163 */ 164 List<ValidationMessage> validate(JsonObject object, StructureDefinition profile) throws Exception; 165 166 /** 167 * Given a DOM element, return a list of errors in the resource 168 * with regard to the specified profile (by logical identifier) 169 * 170 * @param errors 171 * @param element 172 * @param profile 173 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 174 */ 175 List<ValidationMessage> validate(JsonObject object, String profile) throws Exception; 176 177 /** 178 * Given a DOM element, return a list of errors in the resource 179 * with regard to the specified profile 180 * 181 * @param errors 182 * @param element 183 * @param profile 184 * @- if the underlying infrastructure fails (not if the resource is invalid) 185 */ 186 void validate(List<ValidationMessage> errors, Element element, StructureDefinition profile) throws Exception; 187 188 /** 189 * Given a DOM element, return a list of errors in the resource 190 * with regard to the specified profile 191 * 192 * @param errors 193 * @param element 194 * @param profile 195 * @- if the underlying infrastructure fails (not if the resource is invalid) 196 */ 197 void validate(List<ValidationMessage> errors, JsonObject object, StructureDefinition profile) throws Exception; 198 199 /** 200 * Given a DOM element, return a list of errors in the resource 201 * with regard to the specified profile 202 * 203 * @param errors 204 * @param element 205 * @param profile 206 * @- if the underlying infrastructure fails (not if the resource is invalid) 207 */ 208 void validate(List<ValidationMessage> errors, JsonObject object, String profile) throws Exception; 209 210 /** 211 * Given a DOM element, return a list of errors in the resource 212 * with regard to the specified profile 213 * 214 * @param errors 215 * @param element 216 * @param profile 217 * @- if the underlying infrastructure fails (not if the resource is invalid) 218 */ 219 List<ValidationMessage> validate(Element element, StructureDefinition profile) throws Exception; 220 221 222 /** 223 * Given a DOM document, return a list of errors in the resource 224 * 225 * @param errors 226 * @param elem 227 * @- if the underlying infrastructure fails (not if the resource is invalid) 228 */ 229 void validate(List<ValidationMessage> errors, Document document) throws Exception; 230 231 /** 232 * Given a DOM document, return a list of errors in the resource 233 * 234 * @param errors 235 * @param elem 236 * @- if the underlying infrastructure fails (not if the resource is invalid) 237 */ 238 List<ValidationMessage> validate(Document document) throws Exception; 239 240 /** 241 * Given a DOM document, return a list of errors in the resource 242 * with regard to the specified profile (by logical identifier) 243 * 244 * @param errors 245 * @param element 246 * @param profile 247 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 248 */ 249 void validate(List<ValidationMessage> errors, Document document, String profile) throws Exception; 250 251 /** 252 * Given a DOM document, return a list of errors in the resource 253 * with regard to the specified profile (by logical identifier) 254 * 255 * @param errors 256 * @param element 257 * @param profile 258 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 259 */ 260 List<ValidationMessage> validate(Document document, String profile) throws Exception; 261 262 /** 263 * Given a DOM document, return a list of errors in the resource 264 * with regard to the specified profile 265 * 266 * @param errors 267 * @param element 268 * @param profile 269 * @- if the underlying infrastructure fails (not if the resource is invalid) 270 */ 271 void validate(List<ValidationMessage> errors, Document document, StructureDefinition profile) throws Exception; 272 273 /** 274 * Given a DOM document, return a list of errors in the resource 275 * with regard to the specified profile 276 * 277 * @param errors 278 * @param element 279 * @param profile 280 * @- if the underlying infrastructure fails (not if the resource is invalid) 281 */ 282 List<ValidationMessage> validate(Document document, StructureDefinition profile) throws Exception; 283 284}