001package org.hl7.fhir.r4.model; 002 003/* 004 Copyright (c) 2011+, HL7, Inc. 005 All rights reserved. 006 007 Redistribution and use in source and binary forms, with or without modification, 008 are permitted provided that the following conditions are met: 009 010 * Redistributions of source code must retain the above copyright notice, this 011 list of conditions and the following disclaimer. 012 * Redistributions in binary form must reproduce the above copyright notice, 013 this list of conditions and the following disclaimer in the documentation 014 and/or other materials provided with the distribution. 015 * Neither the name of HL7 nor the names of its contributors may be used to 016 endorse or promote products derived from this software without specific 017 prior written permission. 018 019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 022 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 025 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 026 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 POSSIBILITY OF SUCH DAMAGE. 029 030*/ 031 032// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1 033import java.util.ArrayList; 034import java.util.List; 035 036import org.hl7.fhir.exceptions.FHIRException; 037import org.hl7.fhir.instance.model.api.ICompositeType; 038import org.hl7.fhir.instance.model.api.IPrimitiveType; 039import org.hl7.fhir.utilities.Utilities; 040 041import ca.uhn.fhir.model.api.annotation.Child; 042import ca.uhn.fhir.model.api.annotation.DatatypeDef; 043import ca.uhn.fhir.model.api.annotation.Description; 044import ca.uhn.fhir.util.DatatypeUtil; 045 046/** 047 * A human's name with the ability to identify parts and usage. 048 */ 049@DatatypeDef(name = "HumanName") 050public class HumanName extends Type implements ICompositeType { 051 052 public enum NameUse { 053 /** 054 * Known as/conventional/the one you normally use. 055 */ 056 USUAL, 057 /** 058 * The formal name as registered in an official (government) registry, but which 059 * name might not be commonly used. May be called "legal name". 060 */ 061 OFFICIAL, 062 /** 063 * A temporary name. Name.period can provide more detailed information. This may 064 * also be used for temporary names assigned at birth or in emergency 065 * situations. 066 */ 067 TEMP, 068 /** 069 * A name that is used to address the person in an informal manner, but is not 070 * part of their formal or usual name. 071 */ 072 NICKNAME, 073 /** 074 * Anonymous assigned name, alias, or pseudonym (used to protect a person's 075 * identity for privacy reasons). 076 */ 077 ANONYMOUS, 078 /** 079 * This name is no longer in use (or was never correct, but retained for 080 * records). 081 */ 082 OLD, 083 /** 084 * A name used prior to changing name because of marriage. This name use is for 085 * use by applications that collect and store names that were used prior to a 086 * marriage. Marriage naming customs vary greatly around the world, and are 087 * constantly changing. This term is not gender specific. The use of this term 088 * does not imply any particular history for a person's name. 089 */ 090 MAIDEN, 091 /** 092 * added to help the parsers with the generic types 093 */ 094 NULL; 095 096 public static NameUse fromCode(String codeString) throws FHIRException { 097 if (codeString == null || "".equals(codeString)) 098 return null; 099 if ("usual".equals(codeString)) 100 return USUAL; 101 if ("official".equals(codeString)) 102 return OFFICIAL; 103 if ("temp".equals(codeString)) 104 return TEMP; 105 if ("nickname".equals(codeString)) 106 return NICKNAME; 107 if ("anonymous".equals(codeString)) 108 return ANONYMOUS; 109 if ("old".equals(codeString)) 110 return OLD; 111 if ("maiden".equals(codeString)) 112 return MAIDEN; 113 if (Configuration.isAcceptInvalidEnums()) 114 return null; 115 else 116 throw new FHIRException("Unknown NameUse code '" + codeString + "'"); 117 } 118 119 public String toCode() { 120 switch (this) { 121 case USUAL: 122 return "usual"; 123 case OFFICIAL: 124 return "official"; 125 case TEMP: 126 return "temp"; 127 case NICKNAME: 128 return "nickname"; 129 case ANONYMOUS: 130 return "anonymous"; 131 case OLD: 132 return "old"; 133 case MAIDEN: 134 return "maiden"; 135 case NULL: 136 return null; 137 default: 138 return "?"; 139 } 140 } 141 142 public String getSystem() { 143 switch (this) { 144 case USUAL: 145 return "http://hl7.org/fhir/name-use"; 146 case OFFICIAL: 147 return "http://hl7.org/fhir/name-use"; 148 case TEMP: 149 return "http://hl7.org/fhir/name-use"; 150 case NICKNAME: 151 return "http://hl7.org/fhir/name-use"; 152 case ANONYMOUS: 153 return "http://hl7.org/fhir/name-use"; 154 case OLD: 155 return "http://hl7.org/fhir/name-use"; 156 case MAIDEN: 157 return "http://hl7.org/fhir/name-use"; 158 case NULL: 159 return null; 160 default: 161 return "?"; 162 } 163 } 164 165 public String getDefinition() { 166 switch (this) { 167 case USUAL: 168 return "Known as/conventional/the one you normally use."; 169 case OFFICIAL: 170 return "The formal name as registered in an official (government) registry, but which name might not be commonly used. May be called \"legal name\"."; 171 case TEMP: 172 return "A temporary name. Name.period can provide more detailed information. This may also be used for temporary names assigned at birth or in emergency situations."; 173 case NICKNAME: 174 return "A name that is used to address the person in an informal manner, but is not part of their formal or usual name."; 175 case ANONYMOUS: 176 return "Anonymous assigned name, alias, or pseudonym (used to protect a person's identity for privacy reasons)."; 177 case OLD: 178 return "This name is no longer in use (or was never correct, but retained for records)."; 179 case MAIDEN: 180 return "A name used prior to changing name because of marriage. This name use is for use by applications that collect and store names that were used prior to a marriage. Marriage naming customs vary greatly around the world, and are constantly changing. This term is not gender specific. The use of this term does not imply any particular history for a person's name."; 181 case NULL: 182 return null; 183 default: 184 return "?"; 185 } 186 } 187 188 public String getDisplay() { 189 switch (this) { 190 case USUAL: 191 return "Usual"; 192 case OFFICIAL: 193 return "Official"; 194 case TEMP: 195 return "Temp"; 196 case NICKNAME: 197 return "Nickname"; 198 case ANONYMOUS: 199 return "Anonymous"; 200 case OLD: 201 return "Old"; 202 case MAIDEN: 203 return "Name changed for Marriage"; 204 case NULL: 205 return null; 206 default: 207 return "?"; 208 } 209 } 210 } 211 212 public static class NameUseEnumFactory implements EnumFactory<NameUse> { 213 public NameUse fromCode(String codeString) throws IllegalArgumentException { 214 if (codeString == null || "".equals(codeString)) 215 if (codeString == null || "".equals(codeString)) 216 return null; 217 if ("usual".equals(codeString)) 218 return NameUse.USUAL; 219 if ("official".equals(codeString)) 220 return NameUse.OFFICIAL; 221 if ("temp".equals(codeString)) 222 return NameUse.TEMP; 223 if ("nickname".equals(codeString)) 224 return NameUse.NICKNAME; 225 if ("anonymous".equals(codeString)) 226 return NameUse.ANONYMOUS; 227 if ("old".equals(codeString)) 228 return NameUse.OLD; 229 if ("maiden".equals(codeString)) 230 return NameUse.MAIDEN; 231 throw new IllegalArgumentException("Unknown NameUse code '" + codeString + "'"); 232 } 233 234 public Enumeration<NameUse> fromType(PrimitiveType<?> code) throws FHIRException { 235 if (code == null) 236 return null; 237 if (code.isEmpty()) 238 return new Enumeration<NameUse>(this, NameUse.NULL, code); 239 String codeString = code.asStringValue(); 240 if (codeString == null || "".equals(codeString)) 241 return new Enumeration<NameUse>(this, NameUse.NULL, code); 242 if ("usual".equals(codeString)) 243 return new Enumeration<NameUse>(this, NameUse.USUAL, code); 244 if ("official".equals(codeString)) 245 return new Enumeration<NameUse>(this, NameUse.OFFICIAL, code); 246 if ("temp".equals(codeString)) 247 return new Enumeration<NameUse>(this, NameUse.TEMP, code); 248 if ("nickname".equals(codeString)) 249 return new Enumeration<NameUse>(this, NameUse.NICKNAME, code); 250 if ("anonymous".equals(codeString)) 251 return new Enumeration<NameUse>(this, NameUse.ANONYMOUS, code); 252 if ("old".equals(codeString)) 253 return new Enumeration<NameUse>(this, NameUse.OLD, code); 254 if ("maiden".equals(codeString)) 255 return new Enumeration<NameUse>(this, NameUse.MAIDEN, code); 256 throw new FHIRException("Unknown NameUse code '" + codeString + "'"); 257 } 258 259 public String toCode(NameUse code) { 260 if (code == NameUse.USUAL) 261 return "usual"; 262 if (code == NameUse.OFFICIAL) 263 return "official"; 264 if (code == NameUse.TEMP) 265 return "temp"; 266 if (code == NameUse.NICKNAME) 267 return "nickname"; 268 if (code == NameUse.ANONYMOUS) 269 return "anonymous"; 270 if (code == NameUse.OLD) 271 return "old"; 272 if (code == NameUse.MAIDEN) 273 return "maiden"; 274 return "?"; 275 } 276 277 public String toSystem(NameUse code) { 278 return code.getSystem(); 279 } 280 } 281 282 /** 283 * Identifies the purpose for this name. 284 */ 285 @Child(name = "use", type = { CodeType.class }, order = 0, min = 0, max = 1, modifier = true, summary = true) 286 @Description(shortDefinition = "usual | official | temp | nickname | anonymous | old | maiden", formalDefinition = "Identifies the purpose for this name.") 287 @ca.uhn.fhir.model.api.annotation.Binding(valueSet = "http://hl7.org/fhir/ValueSet/name-use") 288 protected Enumeration<NameUse> use; 289 290 /** 291 * Specifies the entire name as it should be displayed e.g. on an application 292 * UI. This may be provided instead of or as well as the specific parts. 293 */ 294 @Child(name = "text", type = { StringType.class }, order = 1, min = 0, max = 1, modifier = false, summary = true) 295 @Description(shortDefinition = "Text representation of the full name", formalDefinition = "Specifies the entire name as it should be displayed e.g. on an application UI. This may be provided instead of or as well as the specific parts.") 296 protected StringType text; 297 298 /** 299 * The part of a name that links to the genealogy. In some cultures (e.g. 300 * Eritrea) the family name of a son is the first name of his father. 301 */ 302 @Child(name = "family", type = { StringType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true) 303 @Description(shortDefinition = "Family name (often called 'Surname')", formalDefinition = "The part of a name that links to the genealogy. In some cultures (e.g. Eritrea) the family name of a son is the first name of his father.") 304 protected StringType family; 305 306 /** 307 * Given name. 308 */ 309 @Child(name = "given", type = { 310 StringType.class }, order = 3, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 311 @Description(shortDefinition = "Given names (not always 'first'). Includes middle names", formalDefinition = "Given name.") 312 protected List<StringType> given; 313 314 /** 315 * Part of the name that is acquired as a title due to academic, legal, 316 * employment or nobility status, etc. and that appears at the start of the 317 * name. 318 */ 319 @Child(name = "prefix", type = { 320 StringType.class }, order = 4, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 321 @Description(shortDefinition = "Parts that come before the name", formalDefinition = "Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the start of the name.") 322 protected List<StringType> prefix; 323 324 /** 325 * Part of the name that is acquired as a title due to academic, legal, 326 * employment or nobility status, etc. and that appears at the end of the name. 327 */ 328 @Child(name = "suffix", type = { 329 StringType.class }, order = 5, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 330 @Description(shortDefinition = "Parts that come after the name", formalDefinition = "Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the end of the name.") 331 protected List<StringType> suffix; 332 333 /** 334 * Indicates the period of time when this name was valid for the named person. 335 */ 336 @Child(name = "period", type = { Period.class }, order = 6, min = 0, max = 1, modifier = false, summary = true) 337 @Description(shortDefinition = "Time period when name was/is in use", formalDefinition = "Indicates the period of time when this name was valid for the named person.") 338 protected Period period; 339 340 private static final long serialVersionUID = -507469160L; 341 342 /** 343 * Constructor 344 */ 345 public HumanName() { 346 super(); 347 } 348 349 /** 350 * @return {@link #use} (Identifies the purpose for this name.). This is the 351 * underlying object with id, value and extensions. The accessor 352 * "getUse" gives direct access to the value 353 */ 354 public Enumeration<NameUse> getUseElement() { 355 if (this.use == null) 356 if (Configuration.errorOnAutoCreate()) 357 throw new Error("Attempt to auto-create HumanName.use"); 358 else if (Configuration.doAutoCreate()) 359 this.use = new Enumeration<NameUse>(new NameUseEnumFactory()); // bb 360 return this.use; 361 } 362 363 public boolean hasUseElement() { 364 return this.use != null && !this.use.isEmpty(); 365 } 366 367 public boolean hasUse() { 368 return this.use != null && !this.use.isEmpty(); 369 } 370 371 /** 372 * @param value {@link #use} (Identifies the purpose for this name.). This is 373 * the underlying object with id, value and extensions. The 374 * accessor "getUse" gives direct access to the value 375 */ 376 public HumanName setUseElement(Enumeration<NameUse> value) { 377 this.use = value; 378 return this; 379 } 380 381 /** 382 * @return Identifies the purpose for this name. 383 */ 384 public NameUse getUse() { 385 return this.use == null ? null : this.use.getValue(); 386 } 387 388 /** 389 * @param value Identifies the purpose for this name. 390 */ 391 public HumanName setUse(NameUse value) { 392 if (value == null) 393 this.use = null; 394 else { 395 if (this.use == null) 396 this.use = new Enumeration<NameUse>(new NameUseEnumFactory()); 397 this.use.setValue(value); 398 } 399 return this; 400 } 401 402 /** 403 * @return {@link #text} (Specifies the entire name as it should be displayed 404 * e.g. on an application UI. This may be provided instead of or as well 405 * as the specific parts.). This is the underlying object with id, value 406 * and extensions. The accessor "getText" gives direct access to the 407 * value 408 */ 409 public StringType getTextElement() { 410 if (this.text == null) 411 if (Configuration.errorOnAutoCreate()) 412 throw new Error("Attempt to auto-create HumanName.text"); 413 else if (Configuration.doAutoCreate()) 414 this.text = new StringType(); // bb 415 return this.text; 416 } 417 418 public boolean hasTextElement() { 419 return this.text != null && !this.text.isEmpty(); 420 } 421 422 public boolean hasText() { 423 return this.text != null && !this.text.isEmpty(); 424 } 425 426 /** 427 * @param value {@link #text} (Specifies the entire name as it should be 428 * displayed e.g. on an application UI. This may be provided 429 * instead of or as well as the specific parts.). This is the 430 * underlying object with id, value and extensions. The accessor 431 * "getText" gives direct access to the value 432 */ 433 public HumanName setTextElement(StringType value) { 434 this.text = value; 435 return this; 436 } 437 438 /** 439 * @return Specifies the entire name as it should be displayed e.g. on an 440 * application UI. This may be provided instead of or as well as the 441 * specific parts. 442 */ 443 public String getText() { 444 return this.text == null ? null : this.text.getValue(); 445 } 446 447 /** 448 * @param value Specifies the entire name as it should be displayed e.g. on an 449 * application UI. This may be provided instead of or as well as 450 * the specific parts. 451 */ 452 public HumanName setText(String value) { 453 if (Utilities.noString(value)) 454 this.text = null; 455 else { 456 if (this.text == null) 457 this.text = new StringType(); 458 this.text.setValue(value); 459 } 460 return this; 461 } 462 463 /** 464 * @return {@link #family} (The part of a name that links to the genealogy. In 465 * some cultures (e.g. Eritrea) the family name of a son is the first 466 * name of his father.). This is the underlying object with id, value 467 * and extensions. The accessor "getFamily" gives direct access to the 468 * value 469 */ 470 public StringType getFamilyElement() { 471 if (this.family == null) 472 if (Configuration.errorOnAutoCreate()) 473 throw new Error("Attempt to auto-create HumanName.family"); 474 else if (Configuration.doAutoCreate()) 475 this.family = new StringType(); // bb 476 return this.family; 477 } 478 479 public boolean hasFamilyElement() { 480 return this.family != null && !this.family.isEmpty(); 481 } 482 483 public boolean hasFamily() { 484 return this.family != null && !this.family.isEmpty(); 485 } 486 487 /** 488 * @param value {@link #family} (The part of a name that links to the genealogy. 489 * In some cultures (e.g. Eritrea) the family name of a son is the 490 * first name of his father.). This is the underlying object with 491 * id, value and extensions. The accessor "getFamily" gives direct 492 * access to the value 493 */ 494 public HumanName setFamilyElement(StringType value) { 495 this.family = value; 496 return this; 497 } 498 499 /** 500 * @return The part of a name that links to the genealogy. In some cultures 501 * (e.g. Eritrea) the family name of a son is the first name of his 502 * father. 503 */ 504 public String getFamily() { 505 return this.family == null ? null : this.family.getValue(); 506 } 507 508 /** 509 * @param value The part of a name that links to the genealogy. In some cultures 510 * (e.g. Eritrea) the family name of a son is the first name of his 511 * father. 512 */ 513 public HumanName setFamily(String value) { 514 if (Utilities.noString(value)) 515 this.family = null; 516 else { 517 if (this.family == null) 518 this.family = new StringType(); 519 this.family.setValue(value); 520 } 521 return this; 522 } 523 524 /** 525 * @return {@link #given} (Given name.) 526 */ 527 public List<StringType> getGiven() { 528 if (this.given == null) 529 this.given = new ArrayList<StringType>(); 530 return this.given; 531 } 532 533 /** 534 * @return Returns a reference to <code>this</code> for easy method chaining 535 */ 536 public HumanName setGiven(List<StringType> theGiven) { 537 this.given = theGiven; 538 return this; 539 } 540 541 public boolean hasGiven() { 542 if (this.given == null) 543 return false; 544 for (StringType item : this.given) 545 if (!item.isEmpty()) 546 return true; 547 return false; 548 } 549 550 /** 551 * @return {@link #given} (Given name.) 552 */ 553 public StringType addGivenElement() {// 2 554 StringType t = new StringType(); 555 if (this.given == null) 556 this.given = new ArrayList<StringType>(); 557 this.given.add(t); 558 return t; 559 } 560 561 /** 562 * @param value {@link #given} (Given name.) 563 */ 564 public HumanName addGiven(String value) { // 1 565 StringType t = new StringType(); 566 t.setValue(value); 567 if (this.given == null) 568 this.given = new ArrayList<StringType>(); 569 this.given.add(t); 570 return this; 571 } 572 573 /** 574 * @param value {@link #given} (Given name.) 575 */ 576 public boolean hasGiven(String value) { 577 if (this.given == null) 578 return false; 579 for (StringType v : this.given) 580 if (v.getValue().equals(value)) // string 581 return true; 582 return false; 583 } 584 585 /** 586 * @return {@link #prefix} (Part of the name that is acquired as a title due to 587 * academic, legal, employment or nobility status, etc. and that appears 588 * at the start of the name.) 589 */ 590 public List<StringType> getPrefix() { 591 if (this.prefix == null) 592 this.prefix = new ArrayList<StringType>(); 593 return this.prefix; 594 } 595 596 /** 597 * @return Returns a reference to <code>this</code> for easy method chaining 598 */ 599 public HumanName setPrefix(List<StringType> thePrefix) { 600 this.prefix = thePrefix; 601 return this; 602 } 603 604 public boolean hasPrefix() { 605 if (this.prefix == null) 606 return false; 607 for (StringType item : this.prefix) 608 if (!item.isEmpty()) 609 return true; 610 return false; 611 } 612 613 /** 614 * @return {@link #prefix} (Part of the name that is acquired as a title due to 615 * academic, legal, employment or nobility status, etc. and that appears 616 * at the start of the name.) 617 */ 618 public StringType addPrefixElement() {// 2 619 StringType t = new StringType(); 620 if (this.prefix == null) 621 this.prefix = new ArrayList<StringType>(); 622 this.prefix.add(t); 623 return t; 624 } 625 626 /** 627 * @param value {@link #prefix} (Part of the name that is acquired as a title 628 * due to academic, legal, employment or nobility status, etc. and 629 * that appears at the start of the name.) 630 */ 631 public HumanName addPrefix(String value) { // 1 632 StringType t = new StringType(); 633 t.setValue(value); 634 if (this.prefix == null) 635 this.prefix = new ArrayList<StringType>(); 636 this.prefix.add(t); 637 return this; 638 } 639 640 /** 641 * @param value {@link #prefix} (Part of the name that is acquired as a title 642 * due to academic, legal, employment or nobility status, etc. and 643 * that appears at the start of the name.) 644 */ 645 public boolean hasPrefix(String value) { 646 if (this.prefix == null) 647 return false; 648 for (StringType v : this.prefix) 649 if (v.getValue().equals(value)) // string 650 return true; 651 return false; 652 } 653 654 /** 655 * @return {@link #suffix} (Part of the name that is acquired as a title due to 656 * academic, legal, employment or nobility status, etc. and that appears 657 * at the end of the name.) 658 */ 659 public List<StringType> getSuffix() { 660 if (this.suffix == null) 661 this.suffix = new ArrayList<StringType>(); 662 return this.suffix; 663 } 664 665 /** 666 * @return Returns a reference to <code>this</code> for easy method chaining 667 */ 668 public HumanName setSuffix(List<StringType> theSuffix) { 669 this.suffix = theSuffix; 670 return this; 671 } 672 673 public boolean hasSuffix() { 674 if (this.suffix == null) 675 return false; 676 for (StringType item : this.suffix) 677 if (!item.isEmpty()) 678 return true; 679 return false; 680 } 681 682 /** 683 * @return {@link #suffix} (Part of the name that is acquired as a title due to 684 * academic, legal, employment or nobility status, etc. and that appears 685 * at the end of the name.) 686 */ 687 public StringType addSuffixElement() {// 2 688 StringType t = new StringType(); 689 if (this.suffix == null) 690 this.suffix = new ArrayList<StringType>(); 691 this.suffix.add(t); 692 return t; 693 } 694 695 /** 696 * @param value {@link #suffix} (Part of the name that is acquired as a title 697 * due to academic, legal, employment or nobility status, etc. and 698 * that appears at the end of the name.) 699 */ 700 public HumanName addSuffix(String value) { // 1 701 StringType t = new StringType(); 702 t.setValue(value); 703 if (this.suffix == null) 704 this.suffix = new ArrayList<StringType>(); 705 this.suffix.add(t); 706 return this; 707 } 708 709 /** 710 * @param value {@link #suffix} (Part of the name that is acquired as a title 711 * due to academic, legal, employment or nobility status, etc. and 712 * that appears at the end of the name.) 713 */ 714 public boolean hasSuffix(String value) { 715 if (this.suffix == null) 716 return false; 717 for (StringType v : this.suffix) 718 if (v.getValue().equals(value)) // string 719 return true; 720 return false; 721 } 722 723 /** 724 * @return {@link #period} (Indicates the period of time when this name was 725 * valid for the named person.) 726 */ 727 public Period getPeriod() { 728 if (this.period == null) 729 if (Configuration.errorOnAutoCreate()) 730 throw new Error("Attempt to auto-create HumanName.period"); 731 else if (Configuration.doAutoCreate()) 732 this.period = new Period(); // cc 733 return this.period; 734 } 735 736 public boolean hasPeriod() { 737 return this.period != null && !this.period.isEmpty(); 738 } 739 740 /** 741 * @param value {@link #period} (Indicates the period of time when this name was 742 * valid for the named person.) 743 */ 744 public HumanName setPeriod(Period value) { 745 this.period = value; 746 return this; 747 } 748 749 /** 750 * /** Returns all repetitions of {@link #getGiven() given name} as a space 751 * separated string 752 * 753 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 754 */ 755 public String getGivenAsSingleString() { 756 return joinStringsSpaceSeparated(getGiven()); 757 } 758 759 /** 760 * Returns all repetitions of {@link #getPrefix() prefix name} as a space 761 * separated string 762 * 763 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 764 */ 765 public String getPrefixAsSingleString() { 766 return joinStringsSpaceSeparated(getPrefix()); 767 } 768 769 /** 770 * Returns all repetitions of {@link #getSuffix() suffix} as a space separated 771 * string 772 * 773 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 774 */ 775 public String getSuffixAsSingleString() { 776 return joinStringsSpaceSeparated(getSuffix()); 777 } 778 779 /** 780 * <p> 781 * Returns the {@link #getTextElement() text} element value if it is not null. 782 * </p> 783 * 784 * <p> 785 * If the {@link #getTextElement() text} element value is null, returns all the 786 * components of the name (prefix, given, family, suffix) as a single string 787 * with a single spaced string separating each part. 788 * </p> 789 * 790 * @return the human name as a single string 791 */ 792 public String getNameAsSingleString() { 793 if (hasText()) { 794 return getText().toString(); 795 } 796 797 List<StringType> nameParts = new ArrayList<StringType>(); 798 nameParts.addAll(getPrefix()); 799 nameParts.addAll(getGiven()); 800 if (hasFamilyElement()) { 801 nameParts.add(getFamilyElement()); 802 } 803 nameParts.addAll(getSuffix()); 804 if (nameParts.size() > 0) { 805 return joinStringsSpaceSeparated(nameParts); 806 } else { 807 return getTextElement().getValue(); 808 } 809 } 810 811 /** 812 * Joins a list of strings with a single space (' ') between each string 813 * 814 * TODO: replace with call to 815 * ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 816 * 1.4 817 */ 818 private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) { 819 StringBuilder stringBuilder = new StringBuilder(); 820 for (IPrimitiveType<String> string : theStrings) { 821 if (string.isEmpty()) { 822 continue; 823 } 824 if (stringBuilder.length() > 0) { 825 stringBuilder.append(' '); 826 } 827 stringBuilder.append(string.getValue()); 828 } 829 return stringBuilder.toString(); 830 } 831 832 protected void listChildren(List<Property> children) { 833 super.listChildren(children); 834 children.add(new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use)); 835 children.add(new Property("text", "string", 836 "Specifies the entire name as it should be displayed e.g. on an application UI. This may be provided instead of or as well as the specific parts.", 837 0, 1, text)); 838 children.add(new Property("family", "string", 839 "The part of a name that links to the genealogy. In some cultures (e.g. Eritrea) the family name of a son is the first name of his father.", 840 0, 1, family)); 841 children.add(new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given)); 842 children.add(new Property("prefix", "string", 843 "Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the start of the name.", 844 0, java.lang.Integer.MAX_VALUE, prefix)); 845 children.add(new Property("suffix", "string", 846 "Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the end of the name.", 847 0, java.lang.Integer.MAX_VALUE, suffix)); 848 children.add(new Property("period", "Period", 849 "Indicates the period of time when this name was valid for the named person.", 0, 1, period)); 850 } 851 852 @Override 853 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 854 switch (_hash) { 855 case 116103: 856 /* use */ return new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use); 857 case 3556653: 858 /* text */ return new Property("text", "string", 859 "Specifies the entire name as it should be displayed e.g. on an application UI. This may be provided instead of or as well as the specific parts.", 860 0, 1, text); 861 case -1281860764: 862 /* family */ return new Property("family", "string", 863 "The part of a name that links to the genealogy. In some cultures (e.g. Eritrea) the family name of a son is the first name of his father.", 864 0, 1, family); 865 case 98367357: 866 /* given */ return new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given); 867 case -980110702: 868 /* prefix */ return new Property("prefix", "string", 869 "Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the start of the name.", 870 0, java.lang.Integer.MAX_VALUE, prefix); 871 case -891422895: 872 /* suffix */ return new Property("suffix", "string", 873 "Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the end of the name.", 874 0, java.lang.Integer.MAX_VALUE, suffix); 875 case -991726143: 876 /* period */ return new Property("period", "Period", 877 "Indicates the period of time when this name was valid for the named person.", 0, 1, period); 878 default: 879 return super.getNamedProperty(_hash, _name, _checkValid); 880 } 881 882 } 883 884 @Override 885 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 886 switch (hash) { 887 case 116103: 888 /* use */ return this.use == null ? new Base[0] : new Base[] { this.use }; // Enumeration<NameUse> 889 case 3556653: 890 /* text */ return this.text == null ? new Base[0] : new Base[] { this.text }; // StringType 891 case -1281860764: 892 /* family */ return this.family == null ? new Base[0] : new Base[] { this.family }; // StringType 893 case 98367357: 894 /* given */ return this.given == null ? new Base[0] : this.given.toArray(new Base[this.given.size()]); // StringType 895 case -980110702: 896 /* prefix */ return this.prefix == null ? new Base[0] : this.prefix.toArray(new Base[this.prefix.size()]); // StringType 897 case -891422895: 898 /* suffix */ return this.suffix == null ? new Base[0] : this.suffix.toArray(new Base[this.suffix.size()]); // StringType 899 case -991726143: 900 /* period */ return this.period == null ? new Base[0] : new Base[] { this.period }; // Period 901 default: 902 return super.getProperty(hash, name, checkValid); 903 } 904 905 } 906 907 @Override 908 public Base setProperty(int hash, String name, Base value) throws FHIRException { 909 switch (hash) { 910 case 116103: // use 911 value = new NameUseEnumFactory().fromType(castToCode(value)); 912 this.use = (Enumeration) value; // Enumeration<NameUse> 913 return value; 914 case 3556653: // text 915 this.text = castToString(value); // StringType 916 return value; 917 case -1281860764: // family 918 this.family = castToString(value); // StringType 919 return value; 920 case 98367357: // given 921 this.getGiven().add(castToString(value)); // StringType 922 return value; 923 case -980110702: // prefix 924 this.getPrefix().add(castToString(value)); // StringType 925 return value; 926 case -891422895: // suffix 927 this.getSuffix().add(castToString(value)); // StringType 928 return value; 929 case -991726143: // period 930 this.period = castToPeriod(value); // Period 931 return value; 932 default: 933 return super.setProperty(hash, name, value); 934 } 935 936 } 937 938 @Override 939 public Base setProperty(String name, Base value) throws FHIRException { 940 if (name.equals("use")) { 941 value = new NameUseEnumFactory().fromType(castToCode(value)); 942 this.use = (Enumeration) value; // Enumeration<NameUse> 943 } else if (name.equals("text")) { 944 this.text = castToString(value); // StringType 945 } else if (name.equals("family")) { 946 this.family = castToString(value); // StringType 947 } else if (name.equals("given")) { 948 this.getGiven().add(castToString(value)); 949 } else if (name.equals("prefix")) { 950 this.getPrefix().add(castToString(value)); 951 } else if (name.equals("suffix")) { 952 this.getSuffix().add(castToString(value)); 953 } else if (name.equals("period")) { 954 this.period = castToPeriod(value); // Period 955 } else 956 return super.setProperty(name, value); 957 return value; 958 } 959 960 @Override 961 public Base makeProperty(int hash, String name) throws FHIRException { 962 switch (hash) { 963 case 116103: 964 return getUseElement(); 965 case 3556653: 966 return getTextElement(); 967 case -1281860764: 968 return getFamilyElement(); 969 case 98367357: 970 return addGivenElement(); 971 case -980110702: 972 return addPrefixElement(); 973 case -891422895: 974 return addSuffixElement(); 975 case -991726143: 976 return getPeriod(); 977 default: 978 return super.makeProperty(hash, name); 979 } 980 981 } 982 983 @Override 984 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 985 switch (hash) { 986 case 116103: 987 /* use */ return new String[] { "code" }; 988 case 3556653: 989 /* text */ return new String[] { "string" }; 990 case -1281860764: 991 /* family */ return new String[] { "string" }; 992 case 98367357: 993 /* given */ return new String[] { "string" }; 994 case -980110702: 995 /* prefix */ return new String[] { "string" }; 996 case -891422895: 997 /* suffix */ return new String[] { "string" }; 998 case -991726143: 999 /* period */ return new String[] { "Period" }; 1000 default: 1001 return super.getTypesForProperty(hash, name); 1002 } 1003 1004 } 1005 1006 @Override 1007 public Base addChild(String name) throws FHIRException { 1008 if (name.equals("use")) { 1009 throw new FHIRException("Cannot call addChild on a singleton property HumanName.use"); 1010 } else if (name.equals("text")) { 1011 throw new FHIRException("Cannot call addChild on a singleton property HumanName.text"); 1012 } else if (name.equals("family")) { 1013 throw new FHIRException("Cannot call addChild on a singleton property HumanName.family"); 1014 } else if (name.equals("given")) { 1015 throw new FHIRException("Cannot call addChild on a singleton property HumanName.given"); 1016 } else if (name.equals("prefix")) { 1017 throw new FHIRException("Cannot call addChild on a singleton property HumanName.prefix"); 1018 } else if (name.equals("suffix")) { 1019 throw new FHIRException("Cannot call addChild on a singleton property HumanName.suffix"); 1020 } else if (name.equals("period")) { 1021 this.period = new Period(); 1022 return this.period; 1023 } else 1024 return super.addChild(name); 1025 } 1026 1027 public String fhirType() { 1028 return "HumanName"; 1029 1030 } 1031 1032 public HumanName copy() { 1033 HumanName dst = new HumanName(); 1034 copyValues(dst); 1035 return dst; 1036 } 1037 1038 public void copyValues(HumanName dst) { 1039 super.copyValues(dst); 1040 dst.use = use == null ? null : use.copy(); 1041 dst.text = text == null ? null : text.copy(); 1042 dst.family = family == null ? null : family.copy(); 1043 if (given != null) { 1044 dst.given = new ArrayList<StringType>(); 1045 for (StringType i : given) 1046 dst.given.add(i.copy()); 1047 } 1048 ; 1049 if (prefix != null) { 1050 dst.prefix = new ArrayList<StringType>(); 1051 for (StringType i : prefix) 1052 dst.prefix.add(i.copy()); 1053 } 1054 ; 1055 if (suffix != null) { 1056 dst.suffix = new ArrayList<StringType>(); 1057 for (StringType i : suffix) 1058 dst.suffix.add(i.copy()); 1059 } 1060 ; 1061 dst.period = period == null ? null : period.copy(); 1062 } 1063 1064 protected HumanName typedCopy() { 1065 return copy(); 1066 } 1067 1068 @Override 1069 public boolean equalsDeep(Base other_) { 1070 if (!super.equalsDeep(other_)) 1071 return false; 1072 if (!(other_ instanceof HumanName)) 1073 return false; 1074 HumanName o = (HumanName) other_; 1075 return compareDeep(use, o.use, true) && compareDeep(text, o.text, true) && compareDeep(family, o.family, true) 1076 && compareDeep(given, o.given, true) && compareDeep(prefix, o.prefix, true) 1077 && compareDeep(suffix, o.suffix, true) && compareDeep(period, o.period, true); 1078 } 1079 1080 @Override 1081 public boolean equalsShallow(Base other_) { 1082 if (!super.equalsShallow(other_)) 1083 return false; 1084 if (!(other_ instanceof HumanName)) 1085 return false; 1086 HumanName o = (HumanName) other_; 1087 return compareValues(use, o.use, true) && compareValues(text, o.text, true) && compareValues(family, o.family, true) 1088 && compareValues(given, o.given, true) && compareValues(prefix, o.prefix, true) 1089 && compareValues(suffix, o.suffix, true); 1090 } 1091 1092 public boolean isEmpty() { 1093 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(use, text, family, given, prefix, suffix, period); 1094 } 1095 1096}