![](/hapi-fhir/images/logos/raccoon-forwards.png)
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 void removeChild(String name, Base value) throws FHIRException { 962 if (name.equals("use")) { 963 this.use = null; 964 } else if (name.equals("text")) { 965 this.text = null; 966 } else if (name.equals("family")) { 967 this.family = null; 968 } else if (name.equals("given")) { 969 this.getGiven().remove(castToString(value)); 970 } else if (name.equals("prefix")) { 971 this.getPrefix().remove(castToString(value)); 972 } else if (name.equals("suffix")) { 973 this.getSuffix().remove(castToString(value)); 974 } else if (name.equals("period")) { 975 this.period = null; 976 } else 977 super.removeChild(name, value); 978 979 } 980 981 @Override 982 public Base makeProperty(int hash, String name) throws FHIRException { 983 switch (hash) { 984 case 116103: 985 return getUseElement(); 986 case 3556653: 987 return getTextElement(); 988 case -1281860764: 989 return getFamilyElement(); 990 case 98367357: 991 return addGivenElement(); 992 case -980110702: 993 return addPrefixElement(); 994 case -891422895: 995 return addSuffixElement(); 996 case -991726143: 997 return getPeriod(); 998 default: 999 return super.makeProperty(hash, name); 1000 } 1001 1002 } 1003 1004 @Override 1005 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 1006 switch (hash) { 1007 case 116103: 1008 /* use */ return new String[] { "code" }; 1009 case 3556653: 1010 /* text */ return new String[] { "string" }; 1011 case -1281860764: 1012 /* family */ return new String[] { "string" }; 1013 case 98367357: 1014 /* given */ return new String[] { "string" }; 1015 case -980110702: 1016 /* prefix */ return new String[] { "string" }; 1017 case -891422895: 1018 /* suffix */ return new String[] { "string" }; 1019 case -991726143: 1020 /* period */ return new String[] { "Period" }; 1021 default: 1022 return super.getTypesForProperty(hash, name); 1023 } 1024 1025 } 1026 1027 @Override 1028 public Base addChild(String name) throws FHIRException { 1029 if (name.equals("use")) { 1030 throw new FHIRException("Cannot call addChild on a singleton property HumanName.use"); 1031 } else if (name.equals("text")) { 1032 throw new FHIRException("Cannot call addChild on a singleton property HumanName.text"); 1033 } else if (name.equals("family")) { 1034 throw new FHIRException("Cannot call addChild on a singleton property HumanName.family"); 1035 } else if (name.equals("given")) { 1036 throw new FHIRException("Cannot call addChild on a singleton property HumanName.given"); 1037 } else if (name.equals("prefix")) { 1038 throw new FHIRException("Cannot call addChild on a singleton property HumanName.prefix"); 1039 } else if (name.equals("suffix")) { 1040 throw new FHIRException("Cannot call addChild on a singleton property HumanName.suffix"); 1041 } else if (name.equals("period")) { 1042 this.period = new Period(); 1043 return this.period; 1044 } else 1045 return super.addChild(name); 1046 } 1047 1048 public String fhirType() { 1049 return "HumanName"; 1050 1051 } 1052 1053 public HumanName copy() { 1054 HumanName dst = new HumanName(); 1055 copyValues(dst); 1056 return dst; 1057 } 1058 1059 public void copyValues(HumanName dst) { 1060 super.copyValues(dst); 1061 dst.use = use == null ? null : use.copy(); 1062 dst.text = text == null ? null : text.copy(); 1063 dst.family = family == null ? null : family.copy(); 1064 if (given != null) { 1065 dst.given = new ArrayList<StringType>(); 1066 for (StringType i : given) 1067 dst.given.add(i.copy()); 1068 } 1069 ; 1070 if (prefix != null) { 1071 dst.prefix = new ArrayList<StringType>(); 1072 for (StringType i : prefix) 1073 dst.prefix.add(i.copy()); 1074 } 1075 ; 1076 if (suffix != null) { 1077 dst.suffix = new ArrayList<StringType>(); 1078 for (StringType i : suffix) 1079 dst.suffix.add(i.copy()); 1080 } 1081 ; 1082 dst.period = period == null ? null : period.copy(); 1083 } 1084 1085 protected HumanName typedCopy() { 1086 return copy(); 1087 } 1088 1089 @Override 1090 public boolean equalsDeep(Base other_) { 1091 if (!super.equalsDeep(other_)) 1092 return false; 1093 if (!(other_ instanceof HumanName)) 1094 return false; 1095 HumanName o = (HumanName) other_; 1096 return compareDeep(use, o.use, true) && compareDeep(text, o.text, true) && compareDeep(family, o.family, true) 1097 && compareDeep(given, o.given, true) && compareDeep(prefix, o.prefix, true) 1098 && compareDeep(suffix, o.suffix, true) && compareDeep(period, o.period, true); 1099 } 1100 1101 @Override 1102 public boolean equalsShallow(Base other_) { 1103 if (!super.equalsShallow(other_)) 1104 return false; 1105 if (!(other_ instanceof HumanName)) 1106 return false; 1107 HumanName o = (HumanName) other_; 1108 return compareValues(use, o.use, true) && compareValues(text, o.text, true) && compareValues(family, o.family, true) 1109 && compareValues(given, o.given, true) && compareValues(prefix, o.prefix, true) 1110 && compareValues(suffix, o.suffix, true); 1111 } 1112 1113 public boolean isEmpty() { 1114 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(use, text, family, given, prefix, suffix, period); 1115 } 1116 1117}