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