001package org.hl7.fhir.r4.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r4
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
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
023/*
024  Copyright (c) 2011+, HL7, Inc.
025  All rights reserved.
026  
027  Redistribution and use in source and binary forms, with or without modification, 
028  are permitted provided that the following conditions are met:
029  
030   * Redistributions of source code must retain the above copyright notice, this 
031     list of conditions and the following disclaimer.
032   * Redistributions in binary form must reproduce the above copyright notice, 
033     this list of conditions and the following disclaimer in the documentation 
034     and/or other materials provided with the distribution.
035   * Neither the name of HL7 nor the names of its contributors may be used to 
036     endorse or promote products derived from this software without specific 
037     prior written permission.
038  
039  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
040  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
041  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
042  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
043  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
044  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
045  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
046  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
047  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
048  POSSIBILITY OF SUCH DAMAGE.
049  
050*/
051
052// Generated on Thu, Dec 13, 2018 14:07+1100 for FHIR v4.0.0
053import java.util.ArrayList;
054import java.util.List;
055
056import org.hl7.fhir.exceptions.FHIRException;
057import org.hl7.fhir.instance.model.api.ICompositeType;
058import org.hl7.fhir.utilities.Utilities;
059
060import ca.uhn.fhir.model.api.annotation.Child;
061import ca.uhn.fhir.model.api.annotation.DatatypeDef;
062import ca.uhn.fhir.model.api.annotation.Description;
063/**
064 * Specifies contact information for a person or organization.
065 */
066@DatatypeDef(name="ContactDetail")
067public class ContactDetail extends Type implements ICompositeType {
068
069    /**
070     * The name of an individual to contact.
071     */
072    @Child(name = "name", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
073    @Description(shortDefinition="Name of an individual to contact", formalDefinition="The name of an individual to contact." )
074    protected StringType name;
075
076    /**
077     * The contact details for the individual (if a name was provided) or the organization.
078     */
079    @Child(name = "telecom", type = {ContactPoint.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
080    @Description(shortDefinition="Contact details for individual or organization", formalDefinition="The contact details for the individual (if a name was provided) or the organization." )
081    protected List<ContactPoint> telecom;
082
083    private static final long serialVersionUID = 816838773L;
084
085  /**
086   * Constructor
087   */
088    public ContactDetail() {
089      super();
090    }
091
092    /**
093     * @return {@link #name} (The name of an individual to contact.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value
094     */
095    public StringType getNameElement() { 
096      if (this.name == null)
097        if (Configuration.errorOnAutoCreate())
098          throw new Error("Attempt to auto-create ContactDetail.name");
099        else if (Configuration.doAutoCreate())
100          this.name = new StringType(); // bb
101      return this.name;
102    }
103
104    public boolean hasNameElement() { 
105      return this.name != null && !this.name.isEmpty();
106    }
107
108    public boolean hasName() { 
109      return this.name != null && !this.name.isEmpty();
110    }
111
112    /**
113     * @param value {@link #name} (The name of an individual to contact.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value
114     */
115    public ContactDetail setNameElement(StringType value) { 
116      this.name = value;
117      return this;
118    }
119
120    /**
121     * @return The name of an individual to contact.
122     */
123    public String getName() { 
124      return this.name == null ? null : this.name.getValue();
125    }
126
127    /**
128     * @param value The name of an individual to contact.
129     */
130    public ContactDetail setName(String value) { 
131      if (Utilities.noString(value))
132        this.name = null;
133      else {
134        if (this.name == null)
135          this.name = new StringType();
136        this.name.setValue(value);
137      }
138      return this;
139    }
140
141    /**
142     * @return {@link #telecom} (The contact details for the individual (if a name was provided) or the organization.)
143     */
144    public List<ContactPoint> getTelecom() { 
145      if (this.telecom == null)
146        this.telecom = new ArrayList<ContactPoint>();
147      return this.telecom;
148    }
149
150    /**
151     * @return Returns a reference to <code>this</code> for easy method chaining
152     */
153    public ContactDetail setTelecom(List<ContactPoint> theTelecom) { 
154      this.telecom = theTelecom;
155      return this;
156    }
157
158    public boolean hasTelecom() { 
159      if (this.telecom == null)
160        return false;
161      for (ContactPoint item : this.telecom)
162        if (!item.isEmpty())
163          return true;
164      return false;
165    }
166
167    public ContactPoint addTelecom() { //3
168      ContactPoint t = new ContactPoint();
169      if (this.telecom == null)
170        this.telecom = new ArrayList<ContactPoint>();
171      this.telecom.add(t);
172      return t;
173    }
174
175    public ContactDetail addTelecom(ContactPoint t) { //3
176      if (t == null)
177        return this;
178      if (this.telecom == null)
179        this.telecom = new ArrayList<ContactPoint>();
180      this.telecom.add(t);
181      return this;
182    }
183
184    /**
185     * @return The first repetition of repeating field {@link #telecom}, creating it if it does not already exist
186     */
187    public ContactPoint getTelecomFirstRep() { 
188      if (getTelecom().isEmpty()) {
189        addTelecom();
190      }
191      return getTelecom().get(0);
192    }
193
194      protected void listChildren(List<Property> children) {
195        super.listChildren(children);
196        children.add(new Property("name", "string", "The name of an individual to contact.", 0, 1, name));
197        children.add(new Property("telecom", "ContactPoint", "The contact details for the individual (if a name was provided) or the organization.", 0, java.lang.Integer.MAX_VALUE, telecom));
198      }
199
200      @Override
201      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
202        switch (_hash) {
203        case 3373707: /*name*/  return new Property("name", "string", "The name of an individual to contact.", 0, 1, name);
204        case -1429363305: /*telecom*/  return new Property("telecom", "ContactPoint", "The contact details for the individual (if a name was provided) or the organization.", 0, java.lang.Integer.MAX_VALUE, telecom);
205        default: return super.getNamedProperty(_hash, _name, _checkValid);
206        }
207
208      }
209
210      @Override
211      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
212        switch (hash) {
213        case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType
214        case -1429363305: /*telecom*/ return this.telecom == null ? new Base[0] : this.telecom.toArray(new Base[this.telecom.size()]); // ContactPoint
215        default: return super.getProperty(hash, name, checkValid);
216        }
217
218      }
219
220      @Override
221      public Base setProperty(int hash, String name, Base value) throws FHIRException {
222        switch (hash) {
223        case 3373707: // name
224          this.name = castToString(value); // StringType
225          return value;
226        case -1429363305: // telecom
227          this.getTelecom().add(castToContactPoint(value)); // ContactPoint
228          return value;
229        default: return super.setProperty(hash, name, value);
230        }
231
232      }
233
234      @Override
235      public Base setProperty(String name, Base value) throws FHIRException {
236        if (name.equals("name")) {
237          this.name = castToString(value); // StringType
238        } else if (name.equals("telecom")) {
239          this.getTelecom().add(castToContactPoint(value));
240        } else
241          return super.setProperty(name, value);
242        return value;
243      }
244
245      @Override
246      public Base makeProperty(int hash, String name) throws FHIRException {
247        switch (hash) {
248        case 3373707:  return getNameElement();
249        case -1429363305:  return addTelecom(); 
250        default: return super.makeProperty(hash, name);
251        }
252
253      }
254
255      @Override
256      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
257        switch (hash) {
258        case 3373707: /*name*/ return new String[] {"string"};
259        case -1429363305: /*telecom*/ return new String[] {"ContactPoint"};
260        default: return super.getTypesForProperty(hash, name);
261        }
262
263      }
264
265      @Override
266      public Base addChild(String name) throws FHIRException {
267        if (name.equals("name")) {
268          throw new FHIRException("Cannot call addChild on a primitive type ContactDetail.name");
269        }
270        else if (name.equals("telecom")) {
271          return addTelecom();
272        }
273        else
274          return super.addChild(name);
275      }
276
277  public String fhirType() {
278    return "ContactDetail";
279
280  }
281
282      public ContactDetail copy() {
283        ContactDetail dst = new ContactDetail();
284        copyValues(dst);
285        dst.name = name == null ? null : name.copy();
286        if (telecom != null) {
287          dst.telecom = new ArrayList<ContactPoint>();
288          for (ContactPoint i : telecom)
289            dst.telecom.add(i.copy());
290        };
291        return dst;
292      }
293
294      protected ContactDetail typedCopy() {
295        return copy();
296      }
297
298      @Override
299      public boolean equalsDeep(Base other_) {
300        if (!super.equalsDeep(other_))
301          return false;
302        if (!(other_ instanceof ContactDetail))
303          return false;
304        ContactDetail o = (ContactDetail) other_;
305        return compareDeep(name, o.name, true) && compareDeep(telecom, o.telecom, true);
306      }
307
308      @Override
309      public boolean equalsShallow(Base other_) {
310        if (!super.equalsShallow(other_))
311          return false;
312        if (!(other_ instanceof ContactDetail))
313          return false;
314        ContactDetail o = (ContactDetail) other_;
315        return compareValues(name, o.name, true);
316      }
317
318      public boolean isEmpty() {
319        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(name, telecom);
320      }
321
322
323}
324