001package org.hl7.fhir.validation.cli.model; 002 003import java.util.ArrayList; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Locale; 007import java.util.Map; 008import java.util.Objects; 009 010import org.hl7.fhir.r5.utils.validation.BundleValidationRule; 011import org.hl7.fhir.validation.cli.utils.QuestionnaireMode; 012import org.hl7.fhir.validation.cli.utils.ValidationLevel; 013import org.hl7.fhir.validation.cli.utils.EngineMode; 014 015import com.fasterxml.jackson.annotation.JsonProperty; 016 017/** 018 * A POJO for storing the flags/values for the CLI validator. 019 */ 020public class CliContext { 021 022 @JsonProperty("doNative") 023 private boolean doNative = false; 024 @JsonProperty("anyExtensionsAllowed") 025 private boolean anyExtensionsAllowed = true; 026 @JsonProperty("hintAboutNonMustSupport") 027 private boolean hintAboutNonMustSupport = false; 028 @JsonProperty("recursive") 029 private boolean recursive = false; 030 @JsonProperty("showMessagesFromReferences") 031 private boolean showMessagesFromReferences = false; 032 @JsonProperty("doDebug") 033 private boolean doDebug = false; 034 @JsonProperty("assumeValidRestReferences") 035 private boolean assumeValidRestReferences = false; 036 @JsonProperty("canDoNative") 037 private boolean canDoNative = false; 038 @JsonProperty("noInternalCaching") 039 private boolean noInternalCaching = false; // internal, for when debugging terminology validation 040 @JsonProperty("noExtensibleBindingMessages") 041 private boolean noExtensibleBindingMessages = false; 042 @JsonProperty("noUnicodeBiDiControlChars") 043 private boolean noUnicodeBiDiControlChars = false; 044 @JsonProperty("noInvariants") 045 private boolean noInvariants = false; 046 @JsonProperty("wantInvariantsInMessages") 047 private boolean wantInvariantsInMessages = false; 048 049 @JsonProperty("map") 050 private String map = null; 051 @JsonProperty("output") 052 private String output = null; 053 @JsonProperty("htmlOutput") 054 private String htmlOutput = null; 055 @JsonProperty("txServer") 056 private String txServer = "http://tx.fhir.org"; 057 @JsonProperty("sv") 058 private String sv = null; 059 @JsonProperty("txLog") 060 private String txLog = null; 061 @JsonProperty("mapLog") 062 private String mapLog = null; 063 @JsonProperty("lang") 064 private String lang = null; 065 @JsonProperty("fhirpath") 066 private String fhirpath = null; 067 @JsonProperty("snomedCT") 068 private String snomedCT = "900000000000207008"; 069 @JsonProperty("targetVer") 070 private String targetVer = null; 071 072 @JsonProperty("igs") 073 private List<String> igs = new ArrayList<String>(); 074 @JsonProperty("questionnaire") 075 private QuestionnaireMode questionnaireMode = QuestionnaireMode.CHECK; 076 @JsonProperty("level") 077 private ValidationLevel level = ValidationLevel.HINTS; 078 079 @JsonProperty("profiles") 080 private List<String> profiles = new ArrayList<String>(); 081 @JsonProperty("sources") 082 private List<String> sources = new ArrayList<String>(); 083 084 @JsonProperty("mode") 085 private EngineMode mode = EngineMode.VALIDATION; 086 087 @JsonProperty("securityChecks") 088 private boolean securityChecks = false; 089 090 @JsonProperty("crumbTrails") 091 private boolean crumbTrails = false; 092 093 @JsonProperty("allowExampleUrls") 094 private boolean allowExampleUrls = false; 095 096 @JsonProperty("showTimes") 097 private boolean showTimes = false; 098 099 @JsonProperty("locale") 100 private String locale = Locale.ENGLISH.getDisplayLanguage(); 101 102 @JsonProperty("locations") 103 private Map<String, String> locations = new HashMap<String, String>(); 104 105 @JsonProperty("outputStyle") 106 private String outputStyle = null; 107 108 // TODO: Mark what goes here? 109 private List<BundleValidationRule> bundleValidationRules = new ArrayList<>(); 110 111 112 @JsonProperty("map") 113 public String getMap() { 114 return map; 115 } 116 117 @JsonProperty("map") 118 public CliContext setMap(String map) { 119 this.map = map; 120 return this; 121 } 122 123 @JsonProperty("igs") 124 public List<String> getIgs() { 125 return igs; 126 } 127 128 @JsonProperty("igs") 129 public CliContext setIgs(List<String> igs) { 130 this.igs = igs; 131 return this; 132 } 133 134 // TODO: Mark what goes here? 135 public List<BundleValidationRule> getBundleValidationRules() { 136 return bundleValidationRules; 137 } 138 139 public CliContext addIg(String ig) { 140 if (this.igs == null) { 141 this.igs = new ArrayList<>(); 142 } 143 this.igs.add(ig); 144 return this; 145 } 146 147 @JsonProperty("questionnaire") 148 public QuestionnaireMode getQuestionnaireMode() { 149 return questionnaireMode; 150 } 151 152 @JsonProperty("questionnaire") 153 public CliContext setQuestionnaireMode(QuestionnaireMode questionnaireMode) { 154 this.questionnaireMode = questionnaireMode; 155 return this; 156 } 157 158 @JsonProperty("level") 159 public ValidationLevel getLevel() { 160 return level; 161 } 162 163 @JsonProperty("level") 164 public CliContext setLevel(ValidationLevel level) { 165 this.level = level; 166 return this; 167 } 168 169 @JsonProperty("txServer") 170 public String getTxServer() { 171 return txServer; 172 } 173 174 @JsonProperty("txServer") 175 public CliContext setTxServer(String txServer) { 176 this.txServer = txServer; 177 return this; 178 } 179 180 @JsonProperty("doNative") 181 public boolean isDoNative() { 182 return doNative; 183 } 184 185 @JsonProperty("doNative") 186 public CliContext setDoNative(boolean doNative) { 187 this.doNative = doNative; 188 return this; 189 } 190 191 @JsonProperty("anyExtensionsAllowed") 192 public boolean isAnyExtensionsAllowed() { 193 return anyExtensionsAllowed; 194 } 195 196 @JsonProperty("anyExtensionsAllowed") 197 public CliContext setAnyExtensionsAllowed(boolean anyExtensionsAllowed) { 198 this.anyExtensionsAllowed = anyExtensionsAllowed; 199 return this; 200 } 201 202 @JsonProperty("hintAboutNonMustSupport") 203 public boolean isHintAboutNonMustSupport() { 204 return hintAboutNonMustSupport; 205 } 206 207 @JsonProperty("hintAboutNonMustSupport") 208 public CliContext setHintAboutNonMustSupport(boolean hintAboutNonMustSupport) { 209 this.hintAboutNonMustSupport = hintAboutNonMustSupport; 210 return this; 211 } 212 213 @JsonProperty("recursive") 214 public boolean isRecursive() { 215 return recursive; 216 } 217 218 @JsonProperty("recursive") 219 public CliContext setRecursive(boolean recursive) { 220 this.recursive = recursive; 221 return this; 222 } 223 224 @JsonProperty("showMessagesFromReferences") 225 public boolean isShowMessagesFromReferences() { 226 return showMessagesFromReferences; 227 } 228 229 @JsonProperty("showMessagesFromReferences") 230 public CliContext setShowMessagesFromReferences(boolean showMessagesFromReferences) { 231 this.showMessagesFromReferences = showMessagesFromReferences; 232 return this; 233 } 234 235 @JsonProperty("locale") 236 public String getLanguageCode() { 237 return locale; 238 } 239 240 public Locale getLocale() { 241 return Locale.forLanguageTag(this.locale); 242 } 243 244 @JsonProperty("locale") 245 public CliContext setLocale(String languageString) { 246 this.locale = languageString; 247 return this; 248 } 249 250 public CliContext setLocale(Locale locale) { 251 this.locale = locale.getDisplayLanguage(); 252 return this; 253 } 254 255 @JsonProperty("profiles") 256 public List<String> getProfiles() { 257 return profiles; 258 } 259 260 @JsonProperty("profiles") 261 public CliContext setProfiles(List<String> profiles) { 262 this.profiles = profiles; 263 return this; 264 } 265 266 public CliContext addProfile(String profile) { 267 if (this.profiles == null) { 268 this.profiles = new ArrayList<>(); 269 } 270 this.profiles.add(profile); 271 return this; 272 } 273 274 @JsonProperty("mode") 275 public EngineMode getMode() { 276 return mode; 277 } 278 279 @JsonProperty("mode") 280 public CliContext setMode(EngineMode mode) { 281 this.mode = mode; 282 return this; 283 } 284 285 @JsonProperty("output") 286 public String getOutput() { 287 return output; 288 } 289 290 @JsonProperty("output") 291 public CliContext setOutput(String output) { 292 this.output = output; 293 return this; 294 } 295 296 @JsonProperty("htmlOutput") 297 public String getHtmlOutput() { 298 return htmlOutput; 299 } 300 301 @JsonProperty("htmlOutput") 302 public CliContext setHtmlOutput(String htmlOutput) { 303 this.htmlOutput = htmlOutput; 304 return this; 305 } 306 307 @JsonProperty("canDoNative") 308 public boolean getCanDoNative() { 309 return canDoNative; 310 } 311 312 @JsonProperty("canDoNative") 313 public CliContext setCanDoNative(boolean canDoNative) { 314 this.canDoNative = canDoNative; 315 return this; 316 } 317 318 @JsonProperty("sources") 319 public List<String> getSources() { 320 return sources; 321 } 322 323 @JsonProperty("sources") 324 public CliContext setSources(List<String> sources) { 325 this.sources = sources; 326 return this; 327 } 328 329 public CliContext addSource(String source) { 330 if (this.sources == null) { 331 this.sources = new ArrayList<>(); 332 } 333 this.sources.add(source); 334 return this; 335 } 336 337 @JsonProperty("locations") 338 public Map<String, String> getLocations() { 339 return locations; 340 } 341 342 @JsonProperty("locations") 343 public CliContext setLocations(Map<String, String> locations) { 344 this.locations = locations; 345 return this; 346 } 347 348 public CliContext addLocation(String profile, String location) { 349 this.locations.put(profile, location); 350 return this; 351 } 352 353 @JsonProperty("sv") 354 public String getSv() { 355 return sv; 356 } 357 358 @JsonProperty("sv") 359 public CliContext setSv(String sv) { 360 this.sv = sv; 361 return this; 362 } 363 364 @JsonProperty("txLog") 365 public String getTxLog() { 366 return txLog; 367 } 368 369 @JsonProperty("txLog") 370 public CliContext setTxLog(String txLog) { 371 this.txLog = txLog; 372 return this; 373 } 374 375 @JsonProperty("mapLog") 376 public String getMapLog() { 377 return mapLog; 378 } 379 380 @JsonProperty("mapLog") 381 public CliContext setMapLog(String mapLog) { 382 this.mapLog = mapLog; 383 return this; 384 } 385 386 @JsonProperty("lang") 387 public String getLang() { 388 return lang; 389 } 390 391 @JsonProperty("lang") 392 public CliContext setLang(String lang) { 393 this.lang = lang; 394 return this; 395 } 396 397 @JsonProperty("fhirpath") 398 public String getFhirpath() { 399 return fhirpath; 400 } 401 402 @JsonProperty("fhirpath") 403 public CliContext setFhirpath(String fhirpath) { 404 this.fhirpath = fhirpath; 405 return this; 406 } 407 408 409 @JsonProperty("snomedCT") 410 public String getSnomedCTCode() { 411 if ("intl".equals(snomedCT)) return "900000000000207008"; 412 if ("us".equals(snomedCT)) return "731000124108"; 413 if ("uk".equals(snomedCT)) return "999000041000000102"; 414 if ("au".equals(snomedCT)) return "32506021000036107"; 415 if ("ca".equals(snomedCT)) return "20611000087101"; 416 if ("nl".equals(snomedCT)) return "11000146104"; 417 if ("se".equals(snomedCT)) return "45991000052106"; 418 if ("es".equals(snomedCT)) return "449081005"; 419 if ("dk".equals(snomedCT)) return "554471000005108"; 420 return snomedCT; 421 } 422 423 @JsonProperty("snomedCT") 424 public CliContext setSnomedCT(String snomedCT) { 425 this.snomedCT = snomedCT; 426 return this; 427 } 428 429 @JsonProperty("targetVer") 430 public String getTargetVer() { 431 return targetVer; 432 } 433 434 @JsonProperty("targetVer") 435 public CliContext setTargetVer(String targetVer) { 436 this.targetVer = targetVer; 437 return this; 438 } 439 440 @JsonProperty("doDebug") 441 public boolean isDoDebug() { 442 return doDebug; 443 } 444 445 @JsonProperty("doDebug") 446 public CliContext setDoDebug(boolean doDebug) { 447 this.doDebug = doDebug; 448 return this; 449 } 450 451 @JsonProperty("assumeValidRestReferences") 452 public boolean isAssumeValidRestReferences() { 453 return assumeValidRestReferences; 454 } 455 456 @JsonProperty("assumeValidRestReferences") 457 public CliContext setAssumeValidRestReferences(boolean assumeValidRestReferences) { 458 this.assumeValidRestReferences = assumeValidRestReferences; 459 return this; 460 } 461 462 @JsonProperty("noInternalCaching") 463 public boolean isNoInternalCaching() { 464 return noInternalCaching; 465 } 466 467 @JsonProperty("noInternalCaching") 468 public CliContext setNoInternalCaching(boolean noInternalCaching) { 469 this.noInternalCaching = noInternalCaching; 470 return this; 471 } 472 473 @JsonProperty("noExtensibleBindingMessages") 474 public boolean isNoExtensibleBindingMessages() { 475 return noExtensibleBindingMessages; 476 } 477 478 @JsonProperty("noExtensibleBindingMessages") 479 public CliContext setNoExtensibleBindingMessages(boolean noExtensibleBindingMessages) { 480 this.noExtensibleBindingMessages = noExtensibleBindingMessages; 481 return this; 482 } 483 484 @JsonProperty("noInvariants") 485 public boolean isNoInvariants() { 486 return noInvariants; 487 } 488 489 @JsonProperty("noInvariants") 490 public void setNoInvariants(boolean noInvariants) { 491 this.noInvariants = noInvariants; 492 } 493 494 @JsonProperty("wantInvariantsInMessages") 495 public boolean isWantInvariantsInMessages() { 496 return wantInvariantsInMessages; 497 } 498 499 @JsonProperty("wantInvariantsInMessages") 500 public void setWantInvariantsInMessages(boolean wantInvariantsInMessages) { 501 this.wantInvariantsInMessages = wantInvariantsInMessages; 502 } 503 504 @JsonProperty("securityChecks") 505 public boolean isSecurityChecks() { 506 return securityChecks; 507 } 508 509 @JsonProperty("securityChecks") 510 public CliContext setSecurityChecks(boolean securityChecks) { 511 this.securityChecks = securityChecks; 512 return this; 513 } 514 515 public boolean isCrumbTrails() { 516 return crumbTrails; 517 } 518 519 public void setCrumbTrails(boolean crumbTrails) { 520 this.crumbTrails = crumbTrails; 521 } 522 523 public boolean isAllowExampleUrls() { 524 return allowExampleUrls; 525 } 526 527 public void setAllowExampleUrls(boolean allowExampleUrls) { 528 this.allowExampleUrls = allowExampleUrls; 529 } 530 531 public boolean isShowTimes() { 532 return showTimes; 533 } 534 535 public void setShowTimes(boolean showTimes) { 536 this.showTimes = showTimes; 537 } 538 539 public String getOutputStyle() { 540 return outputStyle; 541 } 542 543 public void setOutputStyle(String outputStyle) { 544 this.outputStyle = outputStyle; 545 } 546 547 public boolean isNoUnicodeBiDiControlChars() { 548 return noUnicodeBiDiControlChars; 549 } 550 551 public void setNoUnicodeBiDiControlChars(boolean noUnicodeBiDiControlChars) { 552 this.noUnicodeBiDiControlChars = noUnicodeBiDiControlChars; 553 } 554 555 @Override 556 public boolean equals(Object o) { 557 if (this == o) return true; 558 if (o == null || getClass() != o.getClass()) return false; 559 CliContext that = (CliContext) o; 560 return doNative == that.doNative && 561 anyExtensionsAllowed == that.anyExtensionsAllowed && 562 hintAboutNonMustSupport == that.hintAboutNonMustSupport && 563 recursive == that.recursive && 564 doDebug == that.doDebug && 565 assumeValidRestReferences == that.assumeValidRestReferences && 566 canDoNative == that.canDoNative && 567 noInternalCaching == that.noInternalCaching && 568 noExtensibleBindingMessages == that.noExtensibleBindingMessages && 569 noUnicodeBiDiControlChars == that.noUnicodeBiDiControlChars && 570 noInvariants == that.noInvariants && 571 wantInvariantsInMessages == that.wantInvariantsInMessages && 572 Objects.equals(map, that.map) && 573 Objects.equals(output, that.output) && 574 Objects.equals(htmlOutput, that.htmlOutput) && 575 Objects.equals(txServer, that.txServer) && 576 Objects.equals(sv, that.sv) && 577 Objects.equals(txLog, that.txLog) && 578 Objects.equals(mapLog, that.mapLog) && 579 Objects.equals(lang, that.lang) && 580 Objects.equals(fhirpath, that.fhirpath) && 581 Objects.equals(snomedCT, that.snomedCT) && 582 Objects.equals(targetVer, that.targetVer) && 583 Objects.equals(igs, that.igs) && 584 Objects.equals(questionnaireMode, that.questionnaireMode) && 585 Objects.equals(level, that.level) && 586 Objects.equals(profiles, that.profiles) && 587 Objects.equals(sources, that.sources) && 588 Objects.equals(crumbTrails, that.crumbTrails) && 589 Objects.equals(allowExampleUrls, that.allowExampleUrls) && 590 Objects.equals(showTimes, that.showTimes) && 591 mode == that.mode && 592 Objects.equals(locale, that.locale) && 593 Objects.equals(outputStyle, that.outputStyle) && 594 Objects.equals(locations, that.locations); 595 } 596 597 @Override 598 public int hashCode() { 599 return Objects.hash(doNative, anyExtensionsAllowed, hintAboutNonMustSupport, recursive, doDebug, assumeValidRestReferences, canDoNative, noInternalCaching, 600 noExtensibleBindingMessages, noInvariants, wantInvariantsInMessages, map, output, htmlOutput, txServer, sv, txLog, mapLog, lang, fhirpath, snomedCT, 601 targetVer, igs, questionnaireMode, level, profiles, sources, mode, locale, locations, crumbTrails, showTimes, allowExampleUrls, outputStyle, noUnicodeBiDiControlChars); 602 } 603 604 @Override 605 public String toString() { 606 return "CliContext{" + 607 "doNative=" + doNative + 608 ", anyExtensionsAllowed=" + anyExtensionsAllowed + 609 ", hintAboutNonMustSupport=" + hintAboutNonMustSupport + 610 ", recursive=" + recursive + 611 ", doDebug=" + doDebug + 612 ", assumeValidRestReferences=" + assumeValidRestReferences + 613 ", canDoNative=" + canDoNative + 614 ", noInternalCaching=" + noInternalCaching + 615 ", noExtensibleBindingMessages=" + noExtensibleBindingMessages + 616 ", noUnicodeBiDiControlChars=" + noUnicodeBiDiControlChars + 617 ", noInvariants=" + noInvariants + 618 ", wantInvariantsInMessages=" + wantInvariantsInMessages + 619 ", map='" + map + '\'' + 620 ", output='" + output + '\'' + 621 ", htmlOutput='" + htmlOutput + '\'' + 622 ", txServer='" + txServer + '\'' + 623 ", sv='" + sv + '\'' + 624 ", txLog='" + txLog + '\'' + 625 ", mapLog='" + mapLog + '\'' + 626 ", lang='" + lang + '\'' + 627 ", fhirpath='" + fhirpath + '\'' + 628 ", snomedCT='" + snomedCT + '\'' + 629 ", targetVer='" + targetVer + '\'' + 630 ", igs=" + igs + 631 ", questionnaireMode=" + questionnaireMode + 632 ", level=" + level + 633 ", profiles=" + profiles + 634 ", sources=" + sources + 635 ", mode=" + mode + 636 ", securityChecks=" + securityChecks + 637 ", crumbTrails=" + crumbTrails + 638 ", outputStyle=" + outputStyle + 639 ", allowExampleUrls=" + allowExampleUrls + 640 ", showTimes=" + showTimes + 641 ", locale='" + locale + '\'' + 642 ", locations=" + locations + 643 ", bundleValidationRules=" + bundleValidationRules + 644 '}'; 645 } 646}