View Javadoc
1   package ca.uhn.fhir.model.base.composite;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.commons.lang3.builder.ToStringBuilder;
27  import org.apache.commons.lang3.builder.ToStringStyle;
28  
29  import ca.uhn.fhir.model.api.BaseIdentifiableElement;
30  import ca.uhn.fhir.model.primitive.StringDt;
31  import ca.uhn.fhir.util.DatatypeUtil;
32  
33  public abstract class BaseHumanNameDt extends BaseIdentifiableElement {
34  
35  	private static final long serialVersionUID = 2765500013165698259L;
36  
37  	/**
38  	 * Gets the value(s) for <b>family</b> (Family name (often called 'Surname')). creating it if it does not exist. Will not return <code>null</code>.
39  	 *
40  	 * <p>
41  	 * <b>Definition:</b> 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.
42  	 * </p>
43  	 */
44  	public abstract java.util.List<StringDt> getFamily();
45  
46  	/**
47  	 * Returns all repetitions of {@link #getFamily() family name} as a space separated string
48  	 * 
49  	 * @see DatatypeUtil#joinStringsSpaceSeparated(List)
50  	 */
51  	public String getFamilyAsSingleString() {
52  		return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getFamily());
53  	}
54  
55  	/**
56  	 * Gets the value(s) for <b>given</b> (Given names (not always 'first'). Includes middle names). creating it if it does not exist. Will not return <code>null</code>.
57  	 *
58  	 * <p>
59  	 * <b>Definition:</b> Given name
60  	 * </p>
61  	 */
62  	public abstract java.util.List<StringDt> getGiven();
63  
64  	/**
65  	 * Returns all repetitions of {@link #getGiven() given name} as a space separated string
66  	 * 
67  	 * @see DatatypeUtil#joinStringsSpaceSeparated(List)
68  	 */
69  	public String getGivenAsSingleString() {
70  		return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getGiven());
71  	}
72  
73  	/**
74  	 * Gets the value(s) for <b>prefix</b> (Parts that come before the name). creating it if it does not exist. Will not return <code>null</code>.
75  	 *
76  	 * <p>
77  	 * <b>Definition:</b> 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
78  	 * </p>
79  	 */
80  	public abstract java.util.List<StringDt> getPrefix();
81  
82  	/**
83  	 * Returns all repetitions of {@link #getPrefix() prefix name} as a space separated string
84  	 * 
85  	 * @see DatatypeUtil#joinStringsSpaceSeparated(List)
86  	 */
87  	public String getPrefixAsSingleString() {
88  		return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getPrefix());
89  	}
90  
91  	/**
92  	 * Gets the value(s) for <b>suffix</b> (Parts that come after the name). creating it if it does not exist. Will not return <code>null</code>.
93  	 *
94  	 * <p>
95  	 * <b>Definition:</b> 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
96  	 * </p>
97  	 */
98  	public abstract java.util.List<StringDt> getSuffix();
99  
100 	/**
101 	 * Returns all repetitions of {@link #getSuffix() suffix} as a space separated string
102 	 * 
103 	 * @see DatatypeUtil#joinStringsSpaceSeparated(List)
104 	 */
105 	public String getSuffixAsSingleString() {
106 		return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getSuffix());
107 	}
108 
109 	/**
110 	 * Gets the value(s) for <b>text</b> (Text representation of the full name). creating it if it does not exist. Will not return <code>null</code>.
111 	 *
112 	 * <p>
113 	 * <b>Definition:</b> A full text representation of the name
114 	 * </p>
115 	 */
116 	public abstract StringDt getTextElement();
117 
118 	/**
119 	 * Sets the value(s) for <b>text</b> (Text representation of the full name)
120 	 *
121 	 * <p>
122 	 * <b>Definition:</b> A full text representation of the name
123 	 * </p>
124 	 */
125 	public abstract BaseHumanNameDt setText(StringDt theValue);
126 
127 	@Override
128 	public String toString() {
129 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
130 		b.append("family", getFamilyAsSingleString());
131 		b.append("given", getGivenAsSingleString());
132 		return b.toString();
133 	}
134 
135 	/**
136 	 * Returns all of the components of the name (prefix, given, family, suffix) as a 
137 	 * single string with a single spaced string separating each part. 
138 	 * <p>
139 	 * If none of the parts are populated, returns the {@link #getTextElement() text}
140 	 * element value instead.
141 	 * </p>
142 	 */
143 	public String getNameAsSingleString() {
144 		List<StringDt> nameParts = new ArrayList<StringDt>();
145 		nameParts.addAll(getPrefix());
146 		nameParts.addAll(getGiven());
147 		nameParts.addAll(getFamily());
148 		nameParts.addAll(getSuffix());
149 		if (nameParts.size() > 0) {
150 			return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(nameParts);
151 		}
152 		return getTextElement().getValue();
153 	}
154 
155 }