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