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