001package org.hl7.fhir.dstu2016may.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 Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0 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 name might not be commonly used. May be called "legal name". 059 */ 060 OFFICIAL, 061 /** 062 * 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. 063 */ 064 TEMP, 065 /** 066 * A name that is used to address the person in an informal manner, but is not part of their formal or usual name 067 */ 068 NICKNAME, 069 /** 070 * Anonymous assigned name, alias, or pseudonym (used to protect a person's identity for privacy reasons) 071 */ 072 ANONYMOUS, 073 /** 074 * This name is no longer in use (or was never correct, but retained for records) 075 */ 076 OLD, 077 /** 078 * A name used prior to marriage. Marriage naming customs vary greatly around the world. This name use is for use by applications that collect and store "maiden" names. Though the concept of 079 * maiden name is often gender specific, the use of this term is not gender specific. The use of this term does not imply any particular history for a person's name, nor should the maiden name 080 * be determined algorithmically. 081 */ 082 MAIDEN, 083 /** 084 * added to help the parsers 085 */ 086 NULL; 087 public static NameUse fromCode(String codeString) throws FHIRException { 088 if (codeString == null || "".equals(codeString)) 089 return null; 090 if ("usual".equals(codeString)) 091 return USUAL; 092 if ("official".equals(codeString)) 093 return OFFICIAL; 094 if ("temp".equals(codeString)) 095 return TEMP; 096 if ("nickname".equals(codeString)) 097 return NICKNAME; 098 if ("anonymous".equals(codeString)) 099 return ANONYMOUS; 100 if ("old".equals(codeString)) 101 return OLD; 102 if ("maiden".equals(codeString)) 103 return MAIDEN; 104 throw new FHIRException("Unknown NameUse code '" + codeString + "'"); 105 } 106 107 public String toCode() { 108 switch (this) { 109 case USUAL: 110 return "usual"; 111 case OFFICIAL: 112 return "official"; 113 case TEMP: 114 return "temp"; 115 case NICKNAME: 116 return "nickname"; 117 case ANONYMOUS: 118 return "anonymous"; 119 case OLD: 120 return "old"; 121 case MAIDEN: 122 return "maiden"; 123 default: 124 return "?"; 125 } 126 } 127 128 public String getSystem() { 129 switch (this) { 130 case USUAL: 131 return "http://hl7.org/fhir/name-use"; 132 case OFFICIAL: 133 return "http://hl7.org/fhir/name-use"; 134 case TEMP: 135 return "http://hl7.org/fhir/name-use"; 136 case NICKNAME: 137 return "http://hl7.org/fhir/name-use"; 138 case ANONYMOUS: 139 return "http://hl7.org/fhir/name-use"; 140 case OLD: 141 return "http://hl7.org/fhir/name-use"; 142 case MAIDEN: 143 return "http://hl7.org/fhir/name-use"; 144 default: 145 return "?"; 146 } 147 } 148 149 public String getDefinition() { 150 switch (this) { 151 case USUAL: 152 return "Known as/conventional/the one you normally use"; 153 case OFFICIAL: 154 return "The formal name as registered in an official (government) registry, but which name might not be commonly used. May be called \"legal name\"."; 155 case TEMP: 156 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."; 157 case NICKNAME: 158 return "A name that is used to address the person in an informal manner, but is not part of their formal or usual name"; 159 case ANONYMOUS: 160 return "Anonymous assigned name, alias, or pseudonym (used to protect a person's identity for privacy reasons)"; 161 case OLD: 162 return "This name is no longer in use (or was never correct, but retained for records)"; 163 case MAIDEN: 164 return "A name used prior to marriage. Marriage naming customs vary greatly around the world. This name use is for use by applications that collect and store \"maiden\" names. Though the concept of maiden name is often gender specific, the use of this term is not gender specific. The use of this term does not imply any particular history for a person's name, nor should the maiden name be determined algorithmically."; 165 default: 166 return "?"; 167 } 168 } 169 170 public String getDisplay() { 171 switch (this) { 172 case USUAL: 173 return "Usual"; 174 case OFFICIAL: 175 return "Official"; 176 case TEMP: 177 return "Temp"; 178 case NICKNAME: 179 return "Nickname"; 180 case ANONYMOUS: 181 return "Anonymous"; 182 case OLD: 183 return "Old"; 184 case MAIDEN: 185 return "Maiden"; 186 default: 187 return "?"; 188 } 189 } 190 } 191 192 public static class NameUseEnumFactory implements EnumFactory<NameUse> { 193 public NameUse fromCode(String codeString) throws IllegalArgumentException { 194 if (codeString == null || "".equals(codeString)) 195 if (codeString == null || "".equals(codeString)) 196 return null; 197 if ("usual".equals(codeString)) 198 return NameUse.USUAL; 199 if ("official".equals(codeString)) 200 return NameUse.OFFICIAL; 201 if ("temp".equals(codeString)) 202 return NameUse.TEMP; 203 if ("nickname".equals(codeString)) 204 return NameUse.NICKNAME; 205 if ("anonymous".equals(codeString)) 206 return NameUse.ANONYMOUS; 207 if ("old".equals(codeString)) 208 return NameUse.OLD; 209 if ("maiden".equals(codeString)) 210 return NameUse.MAIDEN; 211 throw new IllegalArgumentException("Unknown NameUse code '" + codeString + "'"); 212 } 213 214 public Enumeration<NameUse> fromType(Base code) throws FHIRException { 215 if (code == null || code.isEmpty()) 216 return null; 217 String codeString = ((PrimitiveType) code).asStringValue(); 218 if (codeString == null || "".equals(codeString)) 219 return null; 220 if ("usual".equals(codeString)) 221 return new Enumeration<NameUse>(this, NameUse.USUAL); 222 if ("official".equals(codeString)) 223 return new Enumeration<NameUse>(this, NameUse.OFFICIAL); 224 if ("temp".equals(codeString)) 225 return new Enumeration<NameUse>(this, NameUse.TEMP); 226 if ("nickname".equals(codeString)) 227 return new Enumeration<NameUse>(this, NameUse.NICKNAME); 228 if ("anonymous".equals(codeString)) 229 return new Enumeration<NameUse>(this, NameUse.ANONYMOUS); 230 if ("old".equals(codeString)) 231 return new Enumeration<NameUse>(this, NameUse.OLD); 232 if ("maiden".equals(codeString)) 233 return new Enumeration<NameUse>(this, NameUse.MAIDEN); 234 throw new FHIRException("Unknown NameUse code '" + codeString + "'"); 235 } 236 237 public String toCode(NameUse code) { 238 if (code == NameUse.USUAL) 239 return "usual"; 240 if (code == NameUse.OFFICIAL) 241 return "official"; 242 if (code == NameUse.TEMP) 243 return "temp"; 244 if (code == NameUse.NICKNAME) 245 return "nickname"; 246 if (code == NameUse.ANONYMOUS) 247 return "anonymous"; 248 if (code == NameUse.OLD) 249 return "old"; 250 if (code == NameUse.MAIDEN) 251 return "maiden"; 252 return "?"; 253 } 254 255 public String toSystem(NameUse code) { 256 return code.getSystem(); 257 } 258 } 259 260 /** 261 * Identifies the purpose for this name. 262 */ 263 @Child(name = "use", type = { CodeType.class }, order = 0, min = 0, max = 1, modifier = true, summary = true) 264 @Description(shortDefinition = "usual | official | temp | nickname | anonymous | old | maiden", formalDefinition = "Identifies the purpose for this name.") 265 protected Enumeration<NameUse> use; 266 267 /** 268 * A full text representation of the name. 269 */ 270 @Child(name = "text", type = { StringType.class }, order = 1, min = 0, max = 1, modifier = false, summary = true) 271 @Description(shortDefinition = "Text representation of the full name", formalDefinition = "A full text representation of the name.") 272 protected StringType text; 273 274 /** 275 * 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. 276 */ 277 @Child(name = "family", type = { StringType.class }, order = 2, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 278 @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.") 279 protected List<StringType> family; 280 281 /** 282 * Given name. 283 */ 284 @Child(name = "given", type = { StringType.class }, order = 3, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 285 @Description(shortDefinition = "Given names (not always 'first'). Includes middle names", formalDefinition = "Given name.") 286 protected List<StringType> given; 287 288 /** 289 * 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. 290 */ 291 @Child(name = "prefix", type = { StringType.class }, order = 4, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 292 @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.") 293 protected List<StringType> prefix; 294 295 /** 296 * 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. 297 */ 298 @Child(name = "suffix", type = { StringType.class }, order = 5, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true) 299 @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.") 300 protected List<StringType> suffix; 301 302 /** 303 * Indicates the period of time when this name was valid for the named person. 304 */ 305 @Child(name = "period", type = { Period.class }, order = 6, min = 0, max = 1, modifier = false, summary = true) 306 @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.") 307 protected Period period; 308 309 private static final long serialVersionUID = -210174642L; 310 311 /** 312 * Constructor 313 */ 314 public HumanName() { 315 super(); 316 } 317 318 /** 319 * @return {@link #use} (Identifies the purpose for this name.). This is the underlying object with id, value and extensions. The accessor "getUse" gives direct access to the value 320 */ 321 public Enumeration<NameUse> getUseElement() { 322 if (this.use == null) 323 if (Configuration.errorOnAutoCreate()) 324 throw new Error("Attempt to auto-create HumanName.use"); 325 else if (Configuration.doAutoCreate()) 326 this.use = new Enumeration<NameUse>(new NameUseEnumFactory()); // bb 327 return this.use; 328 } 329 330 public boolean hasUseElement() { 331 return this.use != null && !this.use.isEmpty(); 332 } 333 334 public boolean hasUse() { 335 return this.use != null && !this.use.isEmpty(); 336 } 337 338 /** 339 * @param value 340 * {@link #use} (Identifies the purpose for this name.). This is the underlying object with id, value and extensions. The accessor "getUse" gives direct access to the value 341 */ 342 public HumanName setUseElement(Enumeration<NameUse> value) { 343 this.use = value; 344 return this; 345 } 346 347 /** 348 * @return Identifies the purpose for this name. 349 */ 350 public NameUse getUse() { 351 return this.use == null ? null : this.use.getValue(); 352 } 353 354 /** 355 * @param value 356 * Identifies the purpose for this name. 357 */ 358 public HumanName setUse(NameUse value) { 359 if (value == null) 360 this.use = null; 361 else { 362 if (this.use == null) 363 this.use = new Enumeration<NameUse>(new NameUseEnumFactory()); 364 this.use.setValue(value); 365 } 366 return this; 367 } 368 369 /** 370 * @return {@link #text} (A full text representation of the name.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value 371 */ 372 public StringType getTextElement() { 373 if (this.text == null) 374 if (Configuration.errorOnAutoCreate()) 375 throw new Error("Attempt to auto-create HumanName.text"); 376 else if (Configuration.doAutoCreate()) 377 this.text = new StringType(); // bb 378 return this.text; 379 } 380 381 public boolean hasTextElement() { 382 return this.text != null && !this.text.isEmpty(); 383 } 384 385 public boolean hasText() { 386 return this.text != null && !this.text.isEmpty(); 387 } 388 389 /** 390 * @param value 391 * {@link #text} (A full text representation of the name.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value 392 */ 393 public HumanName setTextElement(StringType value) { 394 this.text = value; 395 return this; 396 } 397 398 /** 399 * @return A full text representation of the name. 400 */ 401 public String getText() { 402 return this.text == null ? null : this.text.getValue(); 403 } 404 405 /** 406 * @param value 407 * A full text representation of the name. 408 */ 409 public HumanName setText(String value) { 410 if (Utilities.noString(value)) 411 this.text = null; 412 else { 413 if (this.text == null) 414 this.text = new StringType(); 415 this.text.setValue(value); 416 } 417 return this; 418 } 419 420 /** 421 * @return {@link #family} (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.) 422 */ 423 public List<StringType> getFamily() { 424 if (this.family == null) 425 this.family = new ArrayList<StringType>(); 426 return this.family; 427 } 428 429 public boolean hasFamily() { 430 if (this.family == null) 431 return false; 432 for (StringType item : this.family) 433 if (!item.isEmpty()) 434 return true; 435 return false; 436 } 437 438 /** 439 * @return {@link #family} (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.) 440 */ 441 // syntactic sugar 442 public StringType addFamilyElement() {// 2 443 StringType t = new StringType(); 444 if (this.family == null) 445 this.family = new ArrayList<StringType>(); 446 this.family.add(t); 447 return t; 448 } 449 450 /** 451 * @param value 452 * {@link #family} (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.) 453 */ 454 public HumanName addFamily(String value) { // 1 455 StringType t = new StringType(); 456 t.setValue(value); 457 if (this.family == null) 458 this.family = new ArrayList<StringType>(); 459 this.family.add(t); 460 return this; 461 } 462 463 /** 464 * @param value 465 * {@link #family} (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.) 466 */ 467 public boolean hasFamily(String value) { 468 if (this.family == null) 469 return false; 470 for (StringType v : this.family) 471 if (v.equals(value)) // string 472 return true; 473 return false; 474 } 475 476 /** 477 * @return {@link #given} (Given name.) 478 */ 479 public List<StringType> getGiven() { 480 if (this.given == null) 481 this.given = new ArrayList<StringType>(); 482 return this.given; 483 } 484 485 public boolean hasGiven() { 486 if (this.given == null) 487 return false; 488 for (StringType item : this.given) 489 if (!item.isEmpty()) 490 return true; 491 return false; 492 } 493 494 /** 495 * @return {@link #given} (Given name.) 496 */ 497 // syntactic sugar 498 public StringType addGivenElement() {// 2 499 StringType t = new StringType(); 500 if (this.given == null) 501 this.given = new ArrayList<StringType>(); 502 this.given.add(t); 503 return t; 504 } 505 506 /** 507 * @param value 508 * {@link #given} (Given name.) 509 */ 510 public HumanName addGiven(String value) { // 1 511 StringType t = new StringType(); 512 t.setValue(value); 513 if (this.given == null) 514 this.given = new ArrayList<StringType>(); 515 this.given.add(t); 516 return this; 517 } 518 519 /** 520 * @param value 521 * {@link #given} (Given name.) 522 */ 523 public boolean hasGiven(String value) { 524 if (this.given == null) 525 return false; 526 for (StringType v : this.given) 527 if (v.equals(value)) // string 528 return true; 529 return false; 530 } 531 532 /** 533 * @return {@link #prefix} (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.) 534 */ 535 public List<StringType> getPrefix() { 536 if (this.prefix == null) 537 this.prefix = new ArrayList<StringType>(); 538 return this.prefix; 539 } 540 541 public boolean hasPrefix() { 542 if (this.prefix == null) 543 return false; 544 for (StringType item : this.prefix) 545 if (!item.isEmpty()) 546 return true; 547 return false; 548 } 549 550 /** 551 * @return {@link #prefix} (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.) 552 */ 553 // syntactic sugar 554 public StringType addPrefixElement() {// 2 555 StringType t = new StringType(); 556 if (this.prefix == null) 557 this.prefix = new ArrayList<StringType>(); 558 this.prefix.add(t); 559 return t; 560 } 561 562 /** 563 * @param value 564 * {@link #prefix} (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.) 565 */ 566 public HumanName addPrefix(String value) { // 1 567 StringType t = new StringType(); 568 t.setValue(value); 569 if (this.prefix == null) 570 this.prefix = new ArrayList<StringType>(); 571 this.prefix.add(t); 572 return this; 573 } 574 575 /** 576 * @param value 577 * {@link #prefix} (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.) 578 */ 579 public boolean hasPrefix(String value) { 580 if (this.prefix == null) 581 return false; 582 for (StringType v : this.prefix) 583 if (v.equals(value)) // string 584 return true; 585 return false; 586 } 587 588 /** 589 * @return {@link #suffix} (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.) 590 */ 591 public List<StringType> getSuffix() { 592 if (this.suffix == null) 593 this.suffix = new ArrayList<StringType>(); 594 return this.suffix; 595 } 596 597 public boolean hasSuffix() { 598 if (this.suffix == null) 599 return false; 600 for (StringType item : this.suffix) 601 if (!item.isEmpty()) 602 return true; 603 return false; 604 } 605 606 /** 607 * @return {@link #suffix} (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.) 608 */ 609 // syntactic sugar 610 public StringType addSuffixElement() {// 2 611 StringType t = new StringType(); 612 if (this.suffix == null) 613 this.suffix = new ArrayList<StringType>(); 614 this.suffix.add(t); 615 return t; 616 } 617 618 /** 619 * @param value 620 * {@link #suffix} (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.) 621 */ 622 public HumanName addSuffix(String value) { // 1 623 StringType t = new StringType(); 624 t.setValue(value); 625 if (this.suffix == null) 626 this.suffix = new ArrayList<StringType>(); 627 this.suffix.add(t); 628 return this; 629 } 630 631 /** 632 * @param value 633 * {@link #suffix} (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.) 634 */ 635 public boolean hasSuffix(String value) { 636 if (this.suffix == null) 637 return false; 638 for (StringType v : this.suffix) 639 if (v.equals(value)) // string 640 return true; 641 return false; 642 } 643 644 /** 645 * @return {@link #period} (Indicates the period of time when this name was valid for the named person.) 646 */ 647 public Period getPeriod() { 648 if (this.period == null) 649 if (Configuration.errorOnAutoCreate()) 650 throw new Error("Attempt to auto-create HumanName.period"); 651 else if (Configuration.doAutoCreate()) 652 this.period = new Period(); // cc 653 return this.period; 654 } 655 656 public boolean hasPeriod() { 657 return this.period != null && !this.period.isEmpty(); 658 } 659 660 /** 661 * @param value 662 * {@link #period} (Indicates the period of time when this name was valid for the named person.) 663 */ 664 public HumanName setPeriod(Period value) { 665 this.period = value; 666 return this; 667 } 668 669 /** 670 * Returns all repetitions of {@link #getFamily() family name} as a space separated string 671 * 672 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 673 */ 674 public String getFamilyAsSingleString() { 675 return joinStringsSpaceSeparated(getFamily()); 676 } 677 678 /** 679 * Returns all repetitions of {@link #getGiven() given name} as a space separated string 680 * 681 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 682 */ 683 public String getGivenAsSingleString() { 684 return joinStringsSpaceSeparated(getGiven()); 685 } 686 687 /** 688 * Returns all repetitions of {@link #getPrefix() prefix name} as a space separated string 689 * 690 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 691 */ 692 public String getPrefixAsSingleString() { 693 return joinStringsSpaceSeparated(getPrefix()); 694 } 695 696 /** 697 * Returns all repetitions of {@link #getSuffix() suffix} as a space separated string 698 * 699 * @see DatatypeUtil#joinStringsSpaceSeparated(List) 700 */ 701 public String getSuffixAsSingleString() { 702 return joinStringsSpaceSeparated(getSuffix()); 703 } 704 705 /** 706 * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced 707 * string separating each part. 708 * <p> 709 * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. 710 * </p> 711 */ 712 public String getNameAsSingleString() { 713 List<StringType> nameParts = new ArrayList<StringType>(); 714 nameParts.addAll(getPrefix()); 715 nameParts.addAll(getGiven()); 716 nameParts.addAll(getFamily()); 717 nameParts.addAll(getSuffix()); 718 if (nameParts.size() > 0) { 719 return joinStringsSpaceSeparated(nameParts); 720 } else { 721 return getTextElement().getValue(); 722 } 723 } 724 725 /** 726 * Joins a list of strings with a single space (' ') between each string 727 * 728 * TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4 729 */ 730 private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) { 731 StringBuilder b = new StringBuilder(); 732 for (IPrimitiveType<String> next : theStrings) { 733 if (next.isEmpty()) { 734 continue; 735 } 736 if (b.length() > 0) { 737 b.append(' '); 738 } 739 b.append(next.getValue()); 740 } 741 return b.toString(); 742 } 743 744 protected void listChildren(List<Property> childrenList) { 745 super.listChildren(childrenList); 746 childrenList.add(new Property("use", "code", "Identifies the purpose for this name.", 0, java.lang.Integer.MAX_VALUE, use)); 747 childrenList.add(new Property("text", "string", "A full text representation of the name.", 0, java.lang.Integer.MAX_VALUE, text)); 748 childrenList.add(new Property("family", "string", "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.", 0, 749 java.lang.Integer.MAX_VALUE, family)); 750 childrenList.add(new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given)); 751 childrenList 752 .add(new Property("prefix", "string", "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.", 753 0, java.lang.Integer.MAX_VALUE, prefix)); 754 childrenList 755 .add(new Property("suffix", "string", "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.", 756 0, java.lang.Integer.MAX_VALUE, suffix)); 757 childrenList.add(new Property("period", "Period", "Indicates the period of time when this name was valid for the named person.", 0, java.lang.Integer.MAX_VALUE, period)); 758 } 759 760 @Override 761 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 762 switch (hash) { 763 case 116103: 764 /* use */ return this.use == null ? new Base[0] : new Base[] { this.use }; // Enumeration<NameUse> 765 case 3556653: 766 /* text */ return this.text == null ? new Base[0] : new Base[] { this.text }; // StringType 767 case -1281860764: 768 /* family */ return this.family == null ? new Base[0] : this.family.toArray(new Base[this.family.size()]); // StringType 769 case 98367357: 770 /* given */ return this.given == null ? new Base[0] : this.given.toArray(new Base[this.given.size()]); // StringType 771 case -980110702: 772 /* prefix */ return this.prefix == null ? new Base[0] : this.prefix.toArray(new Base[this.prefix.size()]); // StringType 773 case -891422895: 774 /* suffix */ return this.suffix == null ? new Base[0] : this.suffix.toArray(new Base[this.suffix.size()]); // StringType 775 case -991726143: 776 /* period */ return this.period == null ? new Base[0] : new Base[] { this.period }; // Period 777 default: 778 return super.getProperty(hash, name, checkValid); 779 } 780 781 } 782 783 @Override 784 public void setProperty(int hash, String name, Base value) throws FHIRException { 785 switch (hash) { 786 case 116103: // use 787 this.use = new NameUseEnumFactory().fromType(value); // Enumeration<NameUse> 788 break; 789 case 3556653: // text 790 this.text = castToString(value); // StringType 791 break; 792 case -1281860764: // family 793 this.getFamily().add(castToString(value)); // StringType 794 break; 795 case 98367357: // given 796 this.getGiven().add(castToString(value)); // StringType 797 break; 798 case -980110702: // prefix 799 this.getPrefix().add(castToString(value)); // StringType 800 break; 801 case -891422895: // suffix 802 this.getSuffix().add(castToString(value)); // StringType 803 break; 804 case -991726143: // period 805 this.period = castToPeriod(value); // Period 806 break; 807 default: 808 super.setProperty(hash, name, value); 809 } 810 811 } 812 813 @Override 814 public void setProperty(String name, Base value) throws FHIRException { 815 if (name.equals("use")) 816 this.use = new NameUseEnumFactory().fromType(value); // Enumeration<NameUse> 817 else if (name.equals("text")) 818 this.text = castToString(value); // StringType 819 else if (name.equals("family")) 820 this.getFamily().add(castToString(value)); 821 else if (name.equals("given")) 822 this.getGiven().add(castToString(value)); 823 else if (name.equals("prefix")) 824 this.getPrefix().add(castToString(value)); 825 else if (name.equals("suffix")) 826 this.getSuffix().add(castToString(value)); 827 else if (name.equals("period")) 828 this.period = castToPeriod(value); // Period 829 else 830 super.setProperty(name, value); 831 } 832 833 @Override 834 public Base makeProperty(int hash, String name) throws FHIRException { 835 switch (hash) { 836 case 116103: 837 throw new FHIRException("Cannot make property use as it is not a complex type"); // Enumeration<NameUse> 838 case 3556653: 839 throw new FHIRException("Cannot make property text as it is not a complex type"); // StringType 840 case -1281860764: 841 throw new FHIRException("Cannot make property family as it is not a complex type"); // StringType 842 case 98367357: 843 throw new FHIRException("Cannot make property given as it is not a complex type"); // StringType 844 case -980110702: 845 throw new FHIRException("Cannot make property prefix as it is not a complex type"); // StringType 846 case -891422895: 847 throw new FHIRException("Cannot make property suffix as it is not a complex type"); // StringType 848 case -991726143: 849 return getPeriod(); // Period 850 default: 851 return super.makeProperty(hash, name); 852 } 853 854 } 855 856 @Override 857 public Base addChild(String name) throws FHIRException { 858 if (name.equals("use")) { 859 throw new FHIRException("Cannot call addChild on a primitive type HumanName.use"); 860 } else if (name.equals("text")) { 861 throw new FHIRException("Cannot call addChild on a primitive type HumanName.text"); 862 } else if (name.equals("family")) { 863 throw new FHIRException("Cannot call addChild on a primitive type HumanName.family"); 864 } else if (name.equals("given")) { 865 throw new FHIRException("Cannot call addChild on a primitive type HumanName.given"); 866 } else if (name.equals("prefix")) { 867 throw new FHIRException("Cannot call addChild on a primitive type HumanName.prefix"); 868 } else if (name.equals("suffix")) { 869 throw new FHIRException("Cannot call addChild on a primitive type HumanName.suffix"); 870 } else if (name.equals("period")) { 871 this.period = new Period(); 872 return this.period; 873 } else 874 return super.addChild(name); 875 } 876 877 public String fhirType() { 878 return "HumanName"; 879 880 } 881 882 public HumanName copy() { 883 HumanName dst = new HumanName(); 884 copyValues(dst); 885 dst.use = use == null ? null : use.copy(); 886 dst.text = text == null ? null : text.copy(); 887 if (family != null) { 888 dst.family = new ArrayList<StringType>(); 889 for (StringType i : family) 890 dst.family.add(i.copy()); 891 } 892 ; 893 if (given != null) { 894 dst.given = new ArrayList<StringType>(); 895 for (StringType i : given) 896 dst.given.add(i.copy()); 897 } 898 ; 899 if (prefix != null) { 900 dst.prefix = new ArrayList<StringType>(); 901 for (StringType i : prefix) 902 dst.prefix.add(i.copy()); 903 } 904 ; 905 if (suffix != null) { 906 dst.suffix = new ArrayList<StringType>(); 907 for (StringType i : suffix) 908 dst.suffix.add(i.copy()); 909 } 910 ; 911 dst.period = period == null ? null : period.copy(); 912 return dst; 913 } 914 915 protected HumanName typedCopy() { 916 return copy(); 917 } 918 919 @Override 920 public boolean equalsDeep(Base other) { 921 if (!super.equalsDeep(other)) 922 return false; 923 if (!(other instanceof HumanName)) 924 return false; 925 HumanName o = (HumanName) other; 926 return compareDeep(use, o.use, true) && compareDeep(text, o.text, true) && compareDeep(family, o.family, true) 927 && compareDeep(given, o.given, true) && compareDeep(prefix, o.prefix, true) && compareDeep(suffix, o.suffix, true) 928 && compareDeep(period, o.period, true); 929 } 930 931 @Override 932 public boolean equalsShallow(Base other) { 933 if (!super.equalsShallow(other)) 934 return false; 935 if (!(other instanceof HumanName)) 936 return false; 937 HumanName o = (HumanName) other; 938 return compareValues(use, o.use, true) && compareValues(text, o.text, true) && compareValues(family, o.family, true) 939 && compareValues(given, o.given, true) && compareValues(prefix, o.prefix, true) && compareValues(suffix, o.suffix, true); 940 } 941 942 public boolean isEmpty() { 943 boolean retVal = super.isEmpty(); 944 retVal &= (use == null || use.isEmpty()); 945 retVal &= (text == null || text.isEmpty()); 946 retVal &= (family == null || family.isEmpty()); 947 retVal &= (given == null || given.isEmpty()); 948 retVal &= (prefix == null || prefix.isEmpty()); 949 retVal &= (suffix == null || suffix.isEmpty()); 950 retVal &= (period == null || period.isEmpty()); 951 return retVal; 952 } 953 954}