001package org.hl7.fhir.dstu3.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// Generated on Fri, Mar 16, 2018 15:21+1100 for FHIR v3.0.x
035import java.util.ArrayList;
036import java.util.List;
037
038import org.hl7.fhir.exceptions.FHIRException;
039import org.hl7.fhir.instance.model.api.ICompositeType;
040import org.hl7.fhir.instance.model.api.IPrimitiveType;
041import org.hl7.fhir.utilities.Utilities;
042
043import ca.uhn.fhir.model.api.annotation.Child;
044import ca.uhn.fhir.model.api.annotation.DatatypeDef;
045import ca.uhn.fhir.model.api.annotation.Description;
046import ca.uhn.fhir.util.DatatypeUtil;
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);
188          String codeString = code.asStringValue();
189          if (codeString == null || "".equals(codeString))
190            return null;
191        if ("usual".equals(codeString))
192          return new Enumeration<NameUse>(this, NameUse.USUAL);
193        if ("official".equals(codeString))
194          return new Enumeration<NameUse>(this, NameUse.OFFICIAL);
195        if ("temp".equals(codeString))
196          return new Enumeration<NameUse>(this, NameUse.TEMP);
197        if ("nickname".equals(codeString))
198          return new Enumeration<NameUse>(this, NameUse.NICKNAME);
199        if ("anonymous".equals(codeString))
200          return new Enumeration<NameUse>(this, NameUse.ANONYMOUS);
201        if ("old".equals(codeString))
202          return new Enumeration<NameUse>(this, NameUse.OLD);
203        if ("maiden".equals(codeString))
204          return new Enumeration<NameUse>(this, NameUse.MAIDEN);
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     * A full text representation of the name.
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="A full text representation of the name." )
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} (A full text representation of the name.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
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} (A full text representation of the name.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
359     */
360    public HumanName setTextElement(StringType value) { 
361      this.text = value;
362      return this;
363    }
364
365    /**
366     * @return A full text representation of the name.
367     */
368    public String getText() { 
369      return this.text == null ? null : this.text.getValue();
370    }
371
372    /**
373     * @param value A full text representation of the name.
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   * <p>Returns the {@link #getTextElement() text} element value if it is not null.</p>
672
673   * <p>If the {@link #getTextElement() text} element value is null, returns all the components of the name (prefix,
674   * given, family, suffix) as a single string with a single spaced string separating each part. </p>
675   *
676   * @return the human name as a single string
677   */
678  public String getNameAsSingleString() {
679    if (hasText()) {
680      return getText().toString();
681    }
682
683    List<StringType> nameParts = new ArrayList<StringType>();
684    nameParts.addAll(getPrefix());
685    nameParts.addAll(getGiven());
686    if (hasFamilyElement()) {
687      nameParts.add(getFamilyElement());
688    }
689    nameParts.addAll(getSuffix());
690    if (nameParts.size() > 0) {
691      return joinStringsSpaceSeparated(nameParts);
692    } else {
693      return getTextElement().getValue();
694    }
695  }
696
697  /**
698   * Joins a list of strings with a single space (' ') between each string
699   * 
700   * TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
701   */
702  private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
703    StringBuilder stringBuilder = new StringBuilder();
704    for (IPrimitiveType<String> string : theStrings) {
705      if (string.isEmpty()) {
706        continue;
707      }
708      if (stringBuilder.length() > 0) {
709        stringBuilder.append(' ');
710      }
711      stringBuilder.append(string.getValue());
712    }
713    return stringBuilder.toString();
714  }
715      protected void listChildren(List<Property> children) {
716        super.listChildren(children);
717        children.add(new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use));
718        children.add(new Property("text", "string", "A full text representation of the name.", 0, 1, text));
719        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));
720        children.add(new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given));
721        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));
722        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));
723        children.add(new Property("period", "Period", "Indicates the period of time when this name was valid for the named person.", 0, 1, period));
724      }
725
726      @Override
727      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
728        switch (_hash) {
729        case 116103: /*use*/  return new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use);
730        case 3556653: /*text*/  return new Property("text", "string", "A full text representation of the name.", 0, 1, text);
731        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);
732        case 98367357: /*given*/  return new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given);
733        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);
734        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);
735        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);
736        default: return super.getNamedProperty(_hash, _name, _checkValid);
737        }
738
739      }
740
741      @Override
742      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
743        switch (hash) {
744        case 116103: /*use*/ return this.use == null ? new Base[0] : new Base[] {this.use}; // Enumeration<NameUse>
745        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
746        case -1281860764: /*family*/ return this.family == null ? new Base[0] : new Base[] {this.family}; // StringType
747        case 98367357: /*given*/ return this.given == null ? new Base[0] : this.given.toArray(new Base[this.given.size()]); // StringType
748        case -980110702: /*prefix*/ return this.prefix == null ? new Base[0] : this.prefix.toArray(new Base[this.prefix.size()]); // StringType
749        case -891422895: /*suffix*/ return this.suffix == null ? new Base[0] : this.suffix.toArray(new Base[this.suffix.size()]); // StringType
750        case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // Period
751        default: return super.getProperty(hash, name, checkValid);
752        }
753
754      }
755
756      @Override
757      public Base setProperty(int hash, String name, Base value) throws FHIRException {
758        switch (hash) {
759        case 116103: // use
760          value = new NameUseEnumFactory().fromType(castToCode(value));
761          this.use = (Enumeration) value; // Enumeration<NameUse>
762          return value;
763        case 3556653: // text
764          this.text = castToString(value); // StringType
765          return value;
766        case -1281860764: // family
767          this.family = castToString(value); // StringType
768          return value;
769        case 98367357: // given
770          this.getGiven().add(castToString(value)); // StringType
771          return value;
772        case -980110702: // prefix
773          this.getPrefix().add(castToString(value)); // StringType
774          return value;
775        case -891422895: // suffix
776          this.getSuffix().add(castToString(value)); // StringType
777          return value;
778        case -991726143: // period
779          this.period = castToPeriod(value); // Period
780          return value;
781        default: return super.setProperty(hash, name, value);
782        }
783
784      }
785
786      @Override
787      public Base setProperty(String name, Base value) throws FHIRException {
788        if (name.equals("use")) {
789          value = new NameUseEnumFactory().fromType(castToCode(value));
790          this.use = (Enumeration) value; // Enumeration<NameUse>
791        } else if (name.equals("text")) {
792          this.text = castToString(value); // StringType
793        } else if (name.equals("family")) {
794          this.family = castToString(value); // StringType
795        } else if (name.equals("given")) {
796          this.getGiven().add(castToString(value));
797        } else if (name.equals("prefix")) {
798          this.getPrefix().add(castToString(value));
799        } else if (name.equals("suffix")) {
800          this.getSuffix().add(castToString(value));
801        } else if (name.equals("period")) {
802          this.period = castToPeriod(value); // Period
803        } else
804          return super.setProperty(name, value);
805        return value;
806      }
807
808      @Override
809      public Base makeProperty(int hash, String name) throws FHIRException {
810        switch (hash) {
811        case 116103:  return getUseElement();
812        case 3556653:  return getTextElement();
813        case -1281860764:  return getFamilyElement();
814        case 98367357:  return addGivenElement();
815        case -980110702:  return addPrefixElement();
816        case -891422895:  return addSuffixElement();
817        case -991726143:  return getPeriod(); 
818        default: return super.makeProperty(hash, name);
819        }
820
821      }
822
823      @Override
824      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
825        switch (hash) {
826        case 116103: /*use*/ return new String[] {"code"};
827        case 3556653: /*text*/ return new String[] {"string"};
828        case -1281860764: /*family*/ return new String[] {"string"};
829        case 98367357: /*given*/ return new String[] {"string"};
830        case -980110702: /*prefix*/ return new String[] {"string"};
831        case -891422895: /*suffix*/ return new String[] {"string"};
832        case -991726143: /*period*/ return new String[] {"Period"};
833        default: return super.getTypesForProperty(hash, name);
834        }
835
836      }
837
838      @Override
839      public Base addChild(String name) throws FHIRException {
840        if (name.equals("use")) {
841          throw new FHIRException("Cannot call addChild on a singleton property HumanName.use");
842        }
843        else if (name.equals("text")) {
844          throw new FHIRException("Cannot call addChild on a singleton property HumanName.text");
845        }
846        else if (name.equals("family")) {
847          throw new FHIRException("Cannot call addChild on a singleton property HumanName.family");
848        }
849        else if (name.equals("given")) {
850          throw new FHIRException("Cannot call addChild on a singleton property HumanName.given");
851        }
852        else if (name.equals("prefix")) {
853          throw new FHIRException("Cannot call addChild on a singleton property HumanName.prefix");
854        }
855        else if (name.equals("suffix")) {
856          throw new FHIRException("Cannot call addChild on a singleton property HumanName.suffix");
857        }
858        else if (name.equals("period")) {
859          this.period = new Period();
860          return this.period;
861        }
862        else
863          return super.addChild(name);
864      }
865
866  public String fhirType() {
867    return "HumanName";
868
869  }
870
871      public HumanName copy() {
872        HumanName dst = new HumanName();
873        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        return dst;
894      }
895
896      protected HumanName typedCopy() {
897        return copy();
898      }
899
900      @Override
901      public boolean equalsDeep(Base other_) {
902        if (!super.equalsDeep(other_))
903          return false;
904        if (!(other_ instanceof HumanName))
905          return false;
906        HumanName o = (HumanName) other_;
907        return compareDeep(use, o.use, true) && compareDeep(text, o.text, true) && compareDeep(family, o.family, true)
908           && compareDeep(given, o.given, true) && compareDeep(prefix, o.prefix, true) && compareDeep(suffix, o.suffix, true)
909           && compareDeep(period, o.period, true);
910      }
911
912      @Override
913      public boolean equalsShallow(Base other_) {
914        if (!super.equalsShallow(other_))
915          return false;
916        if (!(other_ instanceof HumanName))
917          return false;
918        HumanName o = (HumanName) other_;
919        return compareValues(use, o.use, true) && compareValues(text, o.text, true) && compareValues(family, o.family, true)
920           && compareValues(given, o.given, true) && compareValues(prefix, o.prefix, true) && compareValues(suffix, o.suffix, true)
921          ;
922      }
923
924      public boolean isEmpty() {
925        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(use, text, family, given
926          , prefix, suffix, period);
927      }
928
929
930}