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 Sun, May 6, 2018 17:51-0400 for FHIR v3.4.0 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 * 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. 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="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." ) 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} (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.). 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} (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.). 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 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. 360 */ 361 public String getText() { 362 return this.text == null ? null : this.text.getValue(); 363 } 364 365 /** 366 * @param value 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. 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.getValue().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.getValue().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.getValue().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> children) { 702 super.listChildren(children); 703 children.add(new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use)); 704 children.add(new Property("text", "string", "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.", 0, 1, text)); 705 children.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, 1, family)); 706 children.add(new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given)); 707 children.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 children.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 children.add(new Property("period", "Period", "Indicates the period of time when this name was valid for the named person.", 0, 1, period)); 710 } 711 712 @Override 713 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 714 switch (_hash) { 715 case 116103: /*use*/ return new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use); 716 case 3556653: /*text*/ return new Property("text", "string", "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.", 0, 1, text); 717 case -1281860764: /*family*/ return 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, 1, family); 718 case 98367357: /*given*/ return new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given); 719 case -980110702: /*prefix*/ return 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); 720 case -891422895: /*suffix*/ return 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); 721 case -991726143: /*period*/ return new Property("period", "Period", "Indicates the period of time when this name was valid for the named person.", 0, 1, period); 722 default: return super.getNamedProperty(_hash, _name, _checkValid); 723 } 724 725 } 726 727 @Override 728 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 729 switch (hash) { 730 case 116103: /*use*/ return this.use == null ? new Base[0] : new Base[] {this.use}; // Enumeration<NameUse> 731 case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType 732 case -1281860764: /*family*/ return this.family == null ? new Base[0] : new Base[] {this.family}; // StringType 733 case 98367357: /*given*/ return this.given == null ? new Base[0] : this.given.toArray(new Base[this.given.size()]); // StringType 734 case -980110702: /*prefix*/ return this.prefix == null ? new Base[0] : this.prefix.toArray(new Base[this.prefix.size()]); // StringType 735 case -891422895: /*suffix*/ return this.suffix == null ? new Base[0] : this.suffix.toArray(new Base[this.suffix.size()]); // StringType 736 case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // Period 737 default: return super.getProperty(hash, name, checkValid); 738 } 739 740 } 741 742 @Override 743 public Base setProperty(int hash, String name, Base value) throws FHIRException { 744 switch (hash) { 745 case 116103: // use 746 value = new NameUseEnumFactory().fromType(castToCode(value)); 747 this.use = (Enumeration) value; // Enumeration<NameUse> 748 return value; 749 case 3556653: // text 750 this.text = castToString(value); // StringType 751 return value; 752 case -1281860764: // family 753 this.family = castToString(value); // StringType 754 return value; 755 case 98367357: // given 756 this.getGiven().add(castToString(value)); // StringType 757 return value; 758 case -980110702: // prefix 759 this.getPrefix().add(castToString(value)); // StringType 760 return value; 761 case -891422895: // suffix 762 this.getSuffix().add(castToString(value)); // StringType 763 return value; 764 case -991726143: // period 765 this.period = castToPeriod(value); // Period 766 return value; 767 default: return super.setProperty(hash, name, value); 768 } 769 770 } 771 772 @Override 773 public Base setProperty(String name, Base value) throws FHIRException { 774 if (name.equals("use")) { 775 value = new NameUseEnumFactory().fromType(castToCode(value)); 776 this.use = (Enumeration) value; // Enumeration<NameUse> 777 } else if (name.equals("text")) { 778 this.text = castToString(value); // StringType 779 } else if (name.equals("family")) { 780 this.family = castToString(value); // StringType 781 } else if (name.equals("given")) { 782 this.getGiven().add(castToString(value)); 783 } else if (name.equals("prefix")) { 784 this.getPrefix().add(castToString(value)); 785 } else if (name.equals("suffix")) { 786 this.getSuffix().add(castToString(value)); 787 } else if (name.equals("period")) { 788 this.period = castToPeriod(value); // Period 789 } else 790 return super.setProperty(name, value); 791 return value; 792 } 793 794 @Override 795 public Base makeProperty(int hash, String name) throws FHIRException { 796 switch (hash) { 797 case 116103: return getUseElement(); 798 case 3556653: return getTextElement(); 799 case -1281860764: return getFamilyElement(); 800 case 98367357: return addGivenElement(); 801 case -980110702: return addPrefixElement(); 802 case -891422895: return addSuffixElement(); 803 case -991726143: return getPeriod(); 804 default: return super.makeProperty(hash, name); 805 } 806 807 } 808 809 @Override 810 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 811 switch (hash) { 812 case 116103: /*use*/ return new String[] {"code"}; 813 case 3556653: /*text*/ return new String[] {"string"}; 814 case -1281860764: /*family*/ return new String[] {"string"}; 815 case 98367357: /*given*/ return new String[] {"string"}; 816 case -980110702: /*prefix*/ return new String[] {"string"}; 817 case -891422895: /*suffix*/ return new String[] {"string"}; 818 case -991726143: /*period*/ return new String[] {"Period"}; 819 default: return super.getTypesForProperty(hash, name); 820 } 821 822 } 823 824 @Override 825 public Base addChild(String name) throws FHIRException { 826 if (name.equals("use")) { 827 throw new FHIRException("Cannot call addChild on a primitive type HumanName.use"); 828 } 829 else if (name.equals("text")) { 830 throw new FHIRException("Cannot call addChild on a primitive type HumanName.text"); 831 } 832 else if (name.equals("family")) { 833 throw new FHIRException("Cannot call addChild on a primitive type HumanName.family"); 834 } 835 else if (name.equals("given")) { 836 throw new FHIRException("Cannot call addChild on a primitive type HumanName.given"); 837 } 838 else if (name.equals("prefix")) { 839 throw new FHIRException("Cannot call addChild on a primitive type HumanName.prefix"); 840 } 841 else if (name.equals("suffix")) { 842 throw new FHIRException("Cannot call addChild on a primitive type HumanName.suffix"); 843 } 844 else if (name.equals("period")) { 845 this.period = new Period(); 846 return this.period; 847 } 848 else 849 return super.addChild(name); 850 } 851 852 public String fhirType() { 853 return "HumanName"; 854 855 } 856 857 public HumanName copy() { 858 HumanName dst = new HumanName(); 859 copyValues(dst); 860 dst.use = use == null ? null : use.copy(); 861 dst.text = text == null ? null : text.copy(); 862 dst.family = family == null ? null : family.copy(); 863 if (given != null) { 864 dst.given = new ArrayList<StringType>(); 865 for (StringType i : given) 866 dst.given.add(i.copy()); 867 }; 868 if (prefix != null) { 869 dst.prefix = new ArrayList<StringType>(); 870 for (StringType i : prefix) 871 dst.prefix.add(i.copy()); 872 }; 873 if (suffix != null) { 874 dst.suffix = new ArrayList<StringType>(); 875 for (StringType i : suffix) 876 dst.suffix.add(i.copy()); 877 }; 878 dst.period = period == null ? null : period.copy(); 879 return dst; 880 } 881 882 protected HumanName typedCopy() { 883 return copy(); 884 } 885 886 @Override 887 public boolean equalsDeep(Base other_) { 888 if (!super.equalsDeep(other_)) 889 return false; 890 if (!(other_ instanceof HumanName)) 891 return false; 892 HumanName o = (HumanName) other_; 893 return compareDeep(use, o.use, true) && compareDeep(text, o.text, true) && compareDeep(family, o.family, true) 894 && compareDeep(given, o.given, true) && compareDeep(prefix, o.prefix, true) && compareDeep(suffix, o.suffix, true) 895 && compareDeep(period, o.period, true); 896 } 897 898 @Override 899 public boolean equalsShallow(Base other_) { 900 if (!super.equalsShallow(other_)) 901 return false; 902 if (!(other_ instanceof HumanName)) 903 return false; 904 HumanName o = (HumanName) other_; 905 return compareValues(use, o.use, true) && compareValues(text, o.text, true) && compareValues(family, o.family, true) 906 && compareValues(given, o.given, true) && compareValues(prefix, o.prefix, true) && compareValues(suffix, o.suffix, true) 907 ; 908 } 909 910 public boolean isEmpty() { 911 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(use, text, family, given 912 , prefix, suffix, period); 913 } 914 915 916} 917