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