001package ca.uhn.fhir.model.base.composite;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.apache.commons.lang3.builder.ToStringBuilder;
027import org.apache.commons.lang3.builder.ToStringStyle;
028
029import ca.uhn.fhir.model.api.BaseIdentifiableElement;
030import ca.uhn.fhir.model.primitive.StringDt;
031import ca.uhn.fhir.util.DatatypeUtil;
032
033public abstract class BaseHumanNameDt extends BaseIdentifiableElement {
034
035        private static final long serialVersionUID = 2765500013165698259L;
036
037        /**
038         * 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>.
039         *
040         * <p>
041         * <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.
042         * </p>
043         */
044        public abstract java.util.List<StringDt> getFamily();
045
046        /**
047         * Returns all repetitions of {@link #getFamily() family name} as a space separated string
048         * 
049         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
050         */
051        public String getFamilyAsSingleString() {
052                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getFamily());
053        }
054
055        /**
056         * 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>.
057         *
058         * <p>
059         * <b>Definition:</b> Given name
060         * </p>
061         */
062        public abstract java.util.List<StringDt> getGiven();
063
064        /**
065         * Returns all repetitions of {@link #getGiven() given name} as a space separated string
066         * 
067         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
068         */
069        public String getGivenAsSingleString() {
070                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getGiven());
071        }
072
073        /**
074         * 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>.
075         *
076         * <p>
077         * <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
078         * </p>
079         */
080        public abstract java.util.List<StringDt> getPrefix();
081
082        /**
083         * Returns all repetitions of {@link #getPrefix() prefix name} as a space separated string
084         * 
085         * @see DatatypeUtil#joinStringsSpaceSeparated(List)
086         */
087        public String getPrefixAsSingleString() {
088                return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(getPrefix());
089        }
090
091        /**
092         * 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>.
093         *
094         * <p>
095         * <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
096         * </p>
097         */
098        public abstract java.util.List<StringDt> getSuffix();
099
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}