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