001package org.hl7.fhir.dstu2.utils; 002 003/*- 004 * #%L 005 * org.hl7.fhir.dstu2 006 * %% 007 * Copyright (C) 2014 - 2019 Health Level 7 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023 024import java.util.List; 025 026import org.hl7.fhir.dstu2.model.StructureDefinition; 027import org.hl7.fhir.utilities.validation.ValidationMessage; 028import org.w3c.dom.Document; 029import org.w3c.dom.Element; 030 031import com.google.gson.JsonObject; 032 033public interface IResourceValidator { 034 035 /** 036 * whether the validator should enforce best practice guidelines 037 * as defined by various HL7 committees 038 * 039 * 040 * @author Grahame Grieve 041 * 042 */ 043 public enum BestPracticeWarningLevel { 044 Ignore, 045 Hint, 046 Warning, 047 Error 048 } 049 050 public enum CheckDisplayOption { 051 Ignore, 052 Check, 053 CheckCaseAndSpace, 054 CheckCase, 055 CheckSpace 056 } 057 058 /** 059 * how much to check displays for coded elements 060 * @return 061 */ 062 CheckDisplayOption getCheckDisplay(); 063 064 /** 065 * how much to check displays for coded elements 066 * @return 067 */ 068 void setCheckDisplay(CheckDisplayOption checkDisplay); 069 070 enum IdStatus { 071 OPTIONAL, REQUIRED, PROHIBITED 072 } 073 074 /** 075 * whether the resource must have an id or not (depends on context) 076 * 077 * @return 078 */ 079 080 IdStatus getResourceIdRule(); 081 void setResourceIdRule(IdStatus resourceIdRule); 082 083 BestPracticeWarningLevel getBasePracticeWarningLevel(); 084 void setBestPracticeWarningLevel(BestPracticeWarningLevel value); 085 086 087 /** 088 * Given a DOM element, return a list of errors in the resource 089 * 090 * @param errors 091 * @param elem 092 * @- if the underlying infrastructure fails (not if the resource is invalid) 093 */ 094 void validate(List<ValidationMessage> errors, Element element) throws Exception; 095 096 /** 097 * Given a JSON Object, return a list of errors in the resource 098 * 099 * @param errors 100 * @param elem 101 * @- if the underlying infrastructure fails (not if the resource is invalid) 102 */ 103 void validate(List<ValidationMessage> errors, JsonObject object) throws Exception; 104 105 /** 106 * Given a DOM element, return a list of errors in the resource 107 * 108 * @param errors 109 * @param elem 110 * @- if the underlying infrastructure fails (not if the resource is invalid) 111 */ 112 List<ValidationMessage> validate(Element element) throws Exception; 113 114 /** 115 * Given a DOM element, return a list of errors in the resource 116 * 117 * @param errors 118 * @param elem 119 * @- if the underlying infrastructure fails (not if the resource is invalid) 120 */ 121 List<ValidationMessage> validate(JsonObject object) throws Exception; 122 123 /** 124 * Given a DOM element, return a list of errors in the resource 125 * with regard to the specified profile (by logical identifier) 126 * 127 * @param errors 128 * @param element 129 * @param profile 130 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 131 */ 132 void validate(List<ValidationMessage> errors, Element element, String profile) throws Exception; 133 134 /** 135 * Given a DOM element, return a list of errors in the resource 136 * with regard to the specified profile (by logical identifier) 137 * 138 * @param errors 139 * @param element 140 * @param profile 141 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 142 */ 143 List<ValidationMessage> validate(Element element, String profile) throws Exception; 144 145 /** 146 * Given a DOM element, return a list of errors in the resource 147 * with regard to the specified profile (by logical identifier) 148 * 149 * @param errors 150 * @param element 151 * @param profile 152 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 153 */ 154 List<ValidationMessage> validate(JsonObject object, StructureDefinition profile) throws Exception; 155 156 /** 157 * Given a DOM element, return a list of errors in the resource 158 * with regard to the specified profile (by logical identifier) 159 * 160 * @param errors 161 * @param element 162 * @param profile 163 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 164 */ 165 List<ValidationMessage> validate(JsonObject object, String profile) throws Exception; 166 167 /** 168 * Given a DOM element, return a list of errors in the resource 169 * with regard to the specified profile 170 * 171 * @param errors 172 * @param element 173 * @param profile 174 * @- if the underlying infrastructure fails (not if the resource is invalid) 175 */ 176 void validate(List<ValidationMessage> errors, Element element, StructureDefinition profile) throws Exception; 177 178 /** 179 * Given a DOM element, return a list of errors in the resource 180 * with regard to the specified profile 181 * 182 * @param errors 183 * @param element 184 * @param profile 185 * @- if the underlying infrastructure fails (not if the resource is invalid) 186 */ 187 void validate(List<ValidationMessage> errors, JsonObject object, StructureDefinition profile) throws Exception; 188 189 /** 190 * Given a DOM element, return a list of errors in the resource 191 * with regard to the specified profile 192 * 193 * @param errors 194 * @param element 195 * @param profile 196 * @- if the underlying infrastructure fails (not if the resource is invalid) 197 */ 198 void validate(List<ValidationMessage> errors, JsonObject object, String profile) throws Exception; 199 200 /** 201 * Given a DOM element, return a list of errors in the resource 202 * with regard to the specified profile 203 * 204 * @param errors 205 * @param element 206 * @param profile 207 * @- if the underlying infrastructure fails (not if the resource is invalid) 208 */ 209 List<ValidationMessage> validate(Element element, StructureDefinition profile) throws Exception; 210 211 212 /** 213 * Given a DOM document, return a list of errors in the resource 214 * 215 * @param errors 216 * @param elem 217 * @- if the underlying infrastructure fails (not if the resource is invalid) 218 */ 219 void validate(List<ValidationMessage> errors, Document document) throws Exception; 220 221 /** 222 * Given a DOM document, return a list of errors in the resource 223 * 224 * @param errors 225 * @param elem 226 * @- if the underlying infrastructure fails (not if the resource is invalid) 227 */ 228 List<ValidationMessage> validate(Document document) throws Exception; 229 230 /** 231 * Given a DOM document, return a list of errors in the resource 232 * with regard to the specified profile (by logical identifier) 233 * 234 * @param errors 235 * @param element 236 * @param profile 237 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 238 */ 239 void validate(List<ValidationMessage> errors, Document document, String profile) throws Exception; 240 241 /** 242 * Given a DOM document, return a list of errors in the resource 243 * with regard to the specified profile (by logical identifier) 244 * 245 * @param errors 246 * @param element 247 * @param profile 248 * @- if the underlying infrastructure fails, or the profile can't be found (not if the resource is invalid) 249 */ 250 List<ValidationMessage> validate(Document document, String profile) throws Exception; 251 252 /** 253 * Given a DOM document, return a list of errors in the resource 254 * with regard to the specified profile 255 * 256 * @param errors 257 * @param element 258 * @param profile 259 * @- if the underlying infrastructure fails (not if the resource is invalid) 260 */ 261 void validate(List<ValidationMessage> errors, Document document, StructureDefinition profile) throws Exception; 262 263 /** 264 * Given a DOM document, return a list of errors in the resource 265 * with regard to the specified profile 266 * 267 * @param errors 268 * @param element 269 * @param profile 270 * @- if the underlying infrastructure fails (not if the resource is invalid) 271 */ 272 List<ValidationMessage> validate(Document document, StructureDefinition profile) throws Exception; 273 274}