001package org.hl7.fhir.utilities.validation; 002 003import java.util.HashSet; 004import java.util.Set; 005 006import org.hl7.fhir.utilities.FhirPublication; 007import org.hl7.fhir.utilities.Utilities; 008import org.hl7.fhir.utilities.i18n.AcceptLanguageHeader; 009 010import com.google.gson.JsonElement; 011 012public class ValidationOptions { 013 014 private AcceptLanguageHeader langs = null; 015 private boolean useServer = true; 016 private boolean useClient = true; 017 private boolean guessSystem = false; 018 private boolean membershipOnly = false; 019 private boolean displayWarningMode = false; 020 private boolean vsAsUrl; 021 private boolean versionFlexible = true; 022 private boolean useValueSetDisplays; 023 private boolean englishOk = true; 024 private boolean activeOnly = false; 025 private boolean exampleOK = false; 026 private FhirPublication fhirVersion; 027 028 public ValidationOptions() { this(FhirPublication.R5); } 029 030 public ValidationOptions(FhirPublication fhirVersion) { 031 super(); 032 this.fhirVersion = fhirVersion; 033 } 034 035 public ValidationOptions(FhirPublication fhirVersion, String language) { 036 super(); 037 if (!Utilities.noString(language)) { 038 langs = new AcceptLanguageHeader(language, false); 039 } 040 } 041 042 public static ValidationOptions defaults() { 043 return new ValidationOptions(FhirPublication.R5, "en, en-US"); 044 } 045 046 /** 047 * The language that the validation is in (for display name checking etc 048 * 049 * See also englishOK 050 * 051 * @return 052 */ 053 public AcceptLanguageHeader getLanguages() { 054 return langs; 055 } 056 057 public boolean hasLanguages() { 058 return langs != null && !Utilities.noString(langs.getSource()); 059 } 060 061 062 /** 063 * true (which is default) means that the validator will use the server if it needs to for this request 064 * 065 * (there's a few corner cases where you want to turn this off?) 066 * @return 067 */ 068 public boolean isUseServer() { 069 return useServer; 070 } 071 072 /** 073 * True means that the validator will try to resolve the terminology request locally with the resources at hand 074 * 075 * There have been a few corner case code systems where the local code system from THO is wrong 076 * 077 * @return 078 */ 079 public boolean isUseClient() { 080 return useClient; 081 } 082 083 /** 084 * True if this is called from a code context where there's no known code system (inferred from the value set) 085 * 086 * @return 087 */ 088 public boolean isGuessSystem() { 089 return guessSystem; 090 } 091 092 public boolean isActiveOnly() { 093 return activeOnly; 094 } 095 096 /** 097 * Don't know what this does 098 * 099 * @return 100 */ 101 public boolean getVsAsUrl() { 102 return vsAsUrl; 103 } 104 105 /** 106 * Don't know exactly what this does 107 * 108 * @return 109 */ 110 public boolean isVersionFlexible() { 111 return versionFlexible; 112 } 113 114 /** 115 * see {link} 116 * 117 * @return 118 */ 119 public boolean isUseValueSetDisplays() { 120 return useValueSetDisplays; 121 } 122 123 public boolean isMembershipOnly() { 124 return membershipOnly; 125 } 126 127 /** 128 * if the language is other than english, should the validator accept english as well? 129 * 130 * @return 131 */ 132 public boolean isEnglishOk() { 133 return englishOk; 134 } 135 136 137 public ValidationOptions withLanguage(String language) { 138 if (language == null) { 139 return this; 140 } 141 ValidationOptions n = this.copy(); 142 n.addLanguage(language); 143 return n; 144 } 145 146 public ValidationOptions withNoServer() { 147 ValidationOptions n = this.copy(); 148 n.useServer = false; 149 return n; 150 } 151 152 public ValidationOptions withNoClient() { 153 ValidationOptions n = this.copy(); 154 n.useClient = false; 155 return n; 156 } 157 158 public ValidationOptions withGuessSystem() { 159 ValidationOptions n = this.copy(); 160 n.guessSystem = true; 161 return n; 162 } 163 164 165 public ValidationOptions withGuessSystem(boolean value) { 166 ValidationOptions n = this.copy(); 167 n.guessSystem = value; 168 return n; 169 } 170 171 public ValidationOptions withActiveOnly() { 172 ValidationOptions n = this.copy(); 173 n.activeOnly = true; 174 return n; 175 } 176 177 /** Only for additional bindings **/ 178 public ValidationOptions withCheckValueSetOnly() { 179 ValidationOptions n = this.copy(); 180 n.membershipOnly = true; 181 return n; 182 } 183 184 public ValidationOptions withVsAsUrl() { 185 ValidationOptions n = this.copy(); 186 n.vsAsUrl = true; 187 return n; 188 } 189 190 public ValidationOptions withVersionFlexible(boolean value) { 191 ValidationOptions n = this.copy(); 192 n.versionFlexible = value; 193 return n; 194 } 195 196 public ValidationOptions withUseValueSetDisplays(boolean useValueSetDisplays) { 197 ValidationOptions n = this.copy(); 198 n.useValueSetDisplays = useValueSetDisplays; 199 return n; 200 } 201 202 public ValidationOptions withEnglishOk(boolean englishOk) { 203 ValidationOptions n = this.copy(); 204 n.englishOk = englishOk; 205 return n; 206 } 207 208 public ValidationOptions addLanguage(String language) { 209 if (this.langs == null) { 210 langs = new AcceptLanguageHeader(language, false); 211 } else { 212 langs.add(language); 213 } 214 return this; 215 } 216 217 public ValidationOptions setLanguages(String language) { 218 langs = new AcceptLanguageHeader(language, false); 219 return this; 220 } 221 222 public ValidationOptions setNoServer(boolean useServer) { 223 this.useServer = useServer; 224 return this; 225 } 226 227 public ValidationOptions setNoClient(boolean useClient) { 228 this.useClient = useClient; 229 return this; 230 } 231 232 public ValidationOptions setGuessSystem(boolean guessSystem) { 233 this.guessSystem = guessSystem; 234 return this; 235 } 236 237 public ValidationOptions setActiveOnly(boolean activeOnly) { 238 this.activeOnly = activeOnly; 239 return this; 240 } 241 242 public ValidationOptions setCheckValueSetOnly() { 243 this.membershipOnly = true; 244 return this; 245 } 246 247 public ValidationOptions setVsAsUrl(boolean value) { 248 this.vsAsUrl = value; 249 return this; 250 } 251 252 public ValidationOptions setVersionFlexible(boolean value) { 253 this.versionFlexible = value; 254 return this; 255 } 256 257 public ValidationOptions setUseValueSetDisplays(boolean useValueSetDisplays) { 258 this.useValueSetDisplays = useValueSetDisplays; 259 return this; 260 } 261 262 public ValidationOptions setEnglishOk(boolean englishOk) { 263 this.englishOk = englishOk; 264 return this; 265 } 266 267 public boolean isDisplayWarningMode() { 268 return displayWarningMode; 269 } 270 271 public ValidationOptions setDisplayWarningMode(boolean displayWarningMode) { 272 this.displayWarningMode = displayWarningMode; 273 return this; 274 } 275 276 public boolean isExampleOK() { 277 return exampleOK; 278 } 279 280 public ValidationOptions setExampleOK(boolean exampleOK) { 281 this.exampleOK = exampleOK; 282 return this; 283 } 284 285 public ValidationOptions withExampleOK() { 286 return setExampleOK(true); 287 } 288 289 public ValidationOptions copy() { 290 ValidationOptions n = new ValidationOptions(fhirVersion); 291 n.langs = langs == null ? null : langs.copy(); 292 n.useServer = useServer; 293 n.useClient = useClient; 294 n.guessSystem = guessSystem; 295 n.activeOnly = activeOnly; 296 n.vsAsUrl = vsAsUrl; 297 n.versionFlexible = versionFlexible; 298 n.membershipOnly = membershipOnly; 299 n.useValueSetDisplays = useValueSetDisplays; 300 n.displayWarningMode = displayWarningMode; 301 n.exampleOK = exampleOK; 302 return n; 303 } 304 305 306 public String toJson() { 307 return "\"langs\":\""+( langs == null ? "" : langs.toString())+"\", \"useServer\":\""+Boolean.toString(useServer)+"\", \"useClient\":\""+Boolean.toString(useClient)+"\", "+ 308 "\"guessSystem\":\""+Boolean.toString(guessSystem)+"\", \"activeOnly\":\""+Boolean.toString(activeOnly)+(exampleOK ? "\", \"exampleOK\":\""+Boolean.toString(exampleOK) : "")+"\", \"membershipOnly\":\""+Boolean.toString(membershipOnly)+"\", \"displayWarningMode\":\""+Boolean.toString(displayWarningMode)+"\", \"versionFlexible\":\""+Boolean.toString(versionFlexible)+"\""; 309 } 310 311 public String langSummary() { 312 if (langs == null) { 313 return "--"; 314 } else { 315 String s = langs.toString(); 316 if (Utilities.noString(s)) { 317 s = "--"; 318 } 319 return s; 320 } 321 } 322 323 public FhirPublication getFhirVersion() { 324 return fhirVersion; 325 } 326 327 328}