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