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(Base code) throws FHIRException {
184          if (code == null)
185            return null;
186          if (code.isEmpty())
187            return new Enumeration<NameUse>(this);
188          String codeString = ((PrimitiveType) 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   * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced
672   * string separating each part.
673   * <p>
674   * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead.
675   * </p>
676   */
677  public String getNameAsSingleString() {
678    List<StringType> nameParts = new ArrayList<StringType>();
679    nameParts.addAll(getPrefix());
680    nameParts.addAll(getGiven());
681    nameParts.add(getFamilyElement());
682    nameParts.addAll(getSuffix());
683    if (nameParts.size() > 0) {
684      return joinStringsSpaceSeparated(nameParts);
685    } else {
686      return getTextElement().getValue();
687    }
688  }
689
690  /**
691   * Joins a list of strings with a single space (' ') between each string
692   * 
693   * TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
694   */
695  private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
696    StringBuilder b = new StringBuilder();
697    for (IPrimitiveType<String> next : theStrings) {
698      if (next.isEmpty()) {
699        continue;
700      }
701      if (b.length() > 0) {
702        b.append(' ');
703      }
704      b.append(next.getValue());
705    }
706    return b.toString();
707  }
708      protected void listChildren(List<Property> children) {
709        super.listChildren(children);
710        children.add(new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use));
711        children.add(new Property("text", "string", "A full text representation of the name.", 0, 1, text));
712        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));
713        children.add(new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given));
714        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));
715        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));
716        children.add(new Property("period", "Period", "Indicates the period of time when this name was valid for the named person.", 0, 1, period));
717      }
718
719      @Override
720      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
721        switch (_hash) {
722        case 116103: /*use*/  return new Property("use", "code", "Identifies the purpose for this name.", 0, 1, use);
723        case 3556653: /*text*/  return new Property("text", "string", "A full text representation of the name.", 0, 1, text);
724        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);
725        case 98367357: /*given*/  return new Property("given", "string", "Given name.", 0, java.lang.Integer.MAX_VALUE, given);
726        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);
727        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);
728        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);
729        default: return super.getNamedProperty(_hash, _name, _checkValid);
730        }
731
732      }
733
734      @Override
735      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
736        switch (hash) {
737        case 116103: /*use*/ return this.use == null ? new Base[0] : new Base[] {this.use}; // Enumeration<NameUse>
738        case 3556653: /*text*/ return this.text == null ? new Base[0] : new Base[] {this.text}; // StringType
739        case -1281860764: /*family*/ return this.family == null ? new Base[0] : new Base[] {this.family}; // StringType
740        case 98367357: /*given*/ return this.given == null ? new Base[0] : this.given.toArray(new Base[this.given.size()]); // StringType
741        case -980110702: /*prefix*/ return this.prefix == null ? new Base[0] : this.prefix.toArray(new Base[this.prefix.size()]); // StringType
742        case -891422895: /*suffix*/ return this.suffix == null ? new Base[0] : this.suffix.toArray(new Base[this.suffix.size()]); // StringType
743        case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // Period
744        default: return super.getProperty(hash, name, checkValid);
745        }
746
747      }
748
749      @Override
750      public Base setProperty(int hash, String name, Base value) throws FHIRException {
751        switch (hash) {
752        case 116103: // use
753          value = new NameUseEnumFactory().fromType(castToCode(value));
754          this.use = (Enumeration) value; // Enumeration<NameUse>
755          return value;
756        case 3556653: // text
757          this.text = castToString(value); // StringType
758          return value;
759        case -1281860764: // family
760          this.family = castToString(value); // StringType
761          return value;
762        case 98367357: // given
763          this.getGiven().add(castToString(value)); // StringType
764          return value;
765        case -980110702: // prefix
766          this.getPrefix().add(castToString(value)); // StringType
767          return value;
768        case -891422895: // suffix
769          this.getSuffix().add(castToString(value)); // StringType
770          return value;
771        case -991726143: // period
772          this.period = castToPeriod(value); // Period
773          return value;
774        default: return super.setProperty(hash, name, value);
775        }
776
777      }
778
779      @Override
780      public Base setProperty(String name, Base value) throws FHIRException {
781        if (name.equals("use")) {
782          value = new NameUseEnumFactory().fromType(castToCode(value));
783          this.use = (Enumeration) value; // Enumeration<NameUse>
784        } else if (name.equals("text")) {
785          this.text = castToString(value); // StringType
786        } else if (name.equals("family")) {
787          this.family = castToString(value); // StringType
788        } else if (name.equals("given")) {
789          this.getGiven().add(castToString(value));
790        } else if (name.equals("prefix")) {
791          this.getPrefix().add(castToString(value));
792        } else if (name.equals("suffix")) {
793          this.getSuffix().add(castToString(value));
794        } else if (name.equals("period")) {
795          this.period = castToPeriod(value); // Period
796        } else
797          return super.setProperty(name, value);
798        return value;
799      }
800
801      @Override
802      public Base makeProperty(int hash, String name) throws FHIRException {
803        switch (hash) {
804        case 116103:  return getUseElement();
805        case 3556653:  return getTextElement();
806        case -1281860764:  return getFamilyElement();
807        case 98367357:  return addGivenElement();
808        case -980110702:  return addPrefixElement();
809        case -891422895:  return addSuffixElement();
810        case -991726143:  return getPeriod(); 
811        default: return super.makeProperty(hash, name);
812        }
813
814      }
815
816      @Override
817      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
818        switch (hash) {
819        case 116103: /*use*/ return new String[] {"code"};
820        case 3556653: /*text*/ return new String[] {"string"};
821        case -1281860764: /*family*/ return new String[] {"string"};
822        case 98367357: /*given*/ return new String[] {"string"};
823        case -980110702: /*prefix*/ return new String[] {"string"};
824        case -891422895: /*suffix*/ return new String[] {"string"};
825        case -991726143: /*period*/ return new String[] {"Period"};
826        default: return super.getTypesForProperty(hash, name);
827        }
828
829      }
830
831      @Override
832      public Base addChild(String name) throws FHIRException {
833        if (name.equals("use")) {
834          throw new FHIRException("Cannot call addChild on a primitive type HumanName.use");
835        }
836        else if (name.equals("text")) {
837          throw new FHIRException("Cannot call addChild on a primitive type HumanName.text");
838        }
839        else if (name.equals("family")) {
840          throw new FHIRException("Cannot call addChild on a primitive type HumanName.family");
841        }
842        else if (name.equals("given")) {
843          throw new FHIRException("Cannot call addChild on a primitive type HumanName.given");
844        }
845        else if (name.equals("prefix")) {
846          throw new FHIRException("Cannot call addChild on a primitive type HumanName.prefix");
847        }
848        else if (name.equals("suffix")) {
849          throw new FHIRException("Cannot call addChild on a primitive type HumanName.suffix");
850        }
851        else if (name.equals("period")) {
852          this.period = new Period();
853          return this.period;
854        }
855        else
856          return super.addChild(name);
857      }
858
859  public String fhirType() {
860    return "HumanName";
861
862  }
863
864      public HumanName copy() {
865        HumanName dst = new HumanName();
866        copyValues(dst);
867        dst.use = use == null ? null : use.copy();
868        dst.text = text == null ? null : text.copy();
869        dst.family = family == null ? null : family.copy();
870        if (given != null) {
871          dst.given = new ArrayList<StringType>();
872          for (StringType i : given)
873            dst.given.add(i.copy());
874        };
875        if (prefix != null) {
876          dst.prefix = new ArrayList<StringType>();
877          for (StringType i : prefix)
878            dst.prefix.add(i.copy());
879        };
880        if (suffix != null) {
881          dst.suffix = new ArrayList<StringType>();
882          for (StringType i : suffix)
883            dst.suffix.add(i.copy());
884        };
885        dst.period = period == null ? null : period.copy();
886        return dst;
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}