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