001/*
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.model.base.composite;
021
022import java.util.ArrayList;
023import java.util.List;
024
025import org.apache.commons.lang3.builder.ToStringBuilder;
026import org.apache.commons.lang3.builder.ToStringStyle;
027
028import ca.uhn.fhir.model.api.BaseIdentifiableElement;
029import ca.uhn.fhir.model.primitive.StringDt;
030import ca.uhn.fhir.util.DatatypeUtil;
031
032public abstract class BaseHumanNameDt extends BaseIdentifiableElement {
033
034        private static final long serialVersionUID = 2765500013165698259L;
035
036        /**
037         * 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>.
038         *
039         * <p>
040         * <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.
041         * </p>
042         */
043        public abstract java.util.List<StringDt> getFamily();
044
045        /**
046         * Returns all repetitions of {@link #getFamily() family name} as a space separated string
047         * 
048         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
049         */
050        public String getFamilyAsSingleString() {
051                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getFamily());
052        }
053
054        /**
055         * 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>.
056         *
057         * <p>
058         * <b>Definition:</b> Given name
059         * </p>
060         */
061        public abstract java.util.List<StringDt> getGiven();
062
063        /**
064         * Returns all repetitions of {@link #getGiven() given name} as a space separated string
065         * 
066         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
067         */
068        public String getGivenAsSingleString() {
069                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getGiven());
070        }
071
072        /**
073         * 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>.
074         *
075         * <p>
076         * <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
077         * </p>
078         */
079        public abstract java.util.List<StringDt> getPrefix();
080
081        /**
082         * Returns all repetitions of {@link #getPrefix() prefix name} as a space separated string
083         * 
084         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
085         */
086        public String getPrefixAsSingleString() {
087                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getPrefix());
088        }
089
090        /**
091         * 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>.
092         *
093         * <p>
094         * <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
095         * </p>
096         */
097        public abstract java.util.List<StringDt> getSuffix();
098
099        /**
100         * Returns all repetitions of {@link #getSuffix() suffix} as a space separated string
101         * 
102         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
103         */
104        public String getSuffixAsSingleString() {
105                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getSuffix());
106        }
107
108        /**
109         * 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>.
110         *
111         * <p>
112         * <b>Definition:</b> A full text representation of the name
113         * </p>
114         */
115        public abstract StringDt getTextElement();
116
117        /**
118         * Sets the value(s) for <b>text</b> (Text representation of the full name)
119         *
120         * <p>
121         * <b>Definition:</b> A full text representation of the name
122         * </p>
123         */
124        public abstract BaseHumanNameDt setText(StringDt theValue);
125
126        @Override
127        public String toString() {
128                ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
129                b.append("family", getFamilyAsSingleString());
130                b.append("given", getGivenAsSingleString());
131                return b.toString();
132        }
133
134        /**
135         * Returns all of the components of the name (prefix, given, family, suffix) as a 
136         * single string with a single spaced string separating each part. 
137         * <p>
138         * If none of the parts are populated, returns the {@link #getTextElement() text}
139         * element value instead.
140         * </p>
141         */
142        public String getNameAsSingleString() {
143                List<StringDt> nameParts = new ArrayList<StringDt>();
144                nameParts.addAll(getPrefix());
145                nameParts.addAll(getGiven());
146                nameParts.addAll(getFamily());
147                nameParts.addAll(getSuffix());
148                if (nameParts.size() > 0) {
149                        return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(nameParts);
150                }
151                return getTextElement().getValue();
152        }
153
154}