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 Mon, Apr 17, 2017 17:38-0400 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;
044/**
045 * Specifies contact information for a person or organization.
046 */
047@DatatypeDef(name="ContactDetail")
048public class ContactDetail extends Type implements ICompositeType {
049
050    /**
051     * The name of an individual to contact.
052     */
053    @Child(name = "name", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
054    @Description(shortDefinition="Name of an individual to contact", formalDefinition="The name of an individual to contact." )
055    protected StringType name;
056
057    /**
058     * The contact details for the individual (if a name was provided) or the organization.
059     */
060    @Child(name = "telecom", type = {ContactPoint.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
061    @Description(shortDefinition="Contact details for individual or organization", formalDefinition="The contact details for the individual (if a name was provided) or the organization." )
062    protected List<ContactPoint> telecom;
063
064    private static final long serialVersionUID = 816838773L;
065
066  /**
067   * Constructor
068   */
069    public ContactDetail() {
070      super();
071    }
072
073    /**
074     * @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
075     */
076    public StringType getNameElement() { 
077      if (this.name == null)
078        if (Configuration.errorOnAutoCreate())
079          throw new Error("Attempt to auto-create ContactDetail.name");
080        else if (Configuration.doAutoCreate())
081          this.name = new StringType(); // bb
082      return this.name;
083    }
084
085    public boolean hasNameElement() { 
086      return this.name != null && !this.name.isEmpty();
087    }
088
089    public boolean hasName() { 
090      return this.name != null && !this.name.isEmpty();
091    }
092
093    /**
094     * @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
095     */
096    public ContactDetail setNameElement(StringType value) { 
097      this.name = value;
098      return this;
099    }
100
101    /**
102     * @return The name of an individual to contact.
103     */
104    public String getName() { 
105      return this.name == null ? null : this.name.getValue();
106    }
107
108    /**
109     * @param value The name of an individual to contact.
110     */
111    public ContactDetail setName(String value) { 
112      if (Utilities.noString(value))
113        this.name = null;
114      else {
115        if (this.name == null)
116          this.name = new StringType();
117        this.name.setValue(value);
118      }
119      return this;
120    }
121
122    /**
123     * @return {@link #telecom} (The contact details for the individual (if a name was provided) or the organization.)
124     */
125    public List<ContactPoint> getTelecom() { 
126      if (this.telecom == null)
127        this.telecom = new ArrayList<ContactPoint>();
128      return this.telecom;
129    }
130
131    /**
132     * @return Returns a reference to <code>this</code> for easy method chaining
133     */
134    public ContactDetail setTelecom(List<ContactPoint> theTelecom) { 
135      this.telecom = theTelecom;
136      return this;
137    }
138
139    public boolean hasTelecom() { 
140      if (this.telecom == null)
141        return false;
142      for (ContactPoint item : this.telecom)
143        if (!item.isEmpty())
144          return true;
145      return false;
146    }
147
148    public ContactPoint addTelecom() { //3
149      ContactPoint t = new ContactPoint();
150      if (this.telecom == null)
151        this.telecom = new ArrayList<ContactPoint>();
152      this.telecom.add(t);
153      return t;
154    }
155
156    public ContactDetail addTelecom(ContactPoint t) { //3
157      if (t == null)
158        return this;
159      if (this.telecom == null)
160        this.telecom = new ArrayList<ContactPoint>();
161      this.telecom.add(t);
162      return this;
163    }
164
165    /**
166     * @return The first repetition of repeating field {@link #telecom}, creating it if it does not already exist
167     */
168    public ContactPoint getTelecomFirstRep() { 
169      if (getTelecom().isEmpty()) {
170        addTelecom();
171      }
172      return getTelecom().get(0);
173    }
174
175      protected void listChildren(List<Property> childrenList) {
176        super.listChildren(childrenList);
177        childrenList.add(new Property("name", "string", "The name of an individual to contact.", 0, java.lang.Integer.MAX_VALUE, name));
178        childrenList.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));
179      }
180
181      @Override
182      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
183        switch (hash) {
184        case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType
185        case -1429363305: /*telecom*/ return this.telecom == null ? new Base[0] : this.telecom.toArray(new Base[this.telecom.size()]); // ContactPoint
186        default: return super.getProperty(hash, name, checkValid);
187        }
188
189      }
190
191      @Override
192      public Base setProperty(int hash, String name, Base value) throws FHIRException {
193        switch (hash) {
194        case 3373707: // name
195          this.name = castToString(value); // StringType
196          return value;
197        case -1429363305: // telecom
198          this.getTelecom().add(castToContactPoint(value)); // ContactPoint
199          return value;
200        default: return super.setProperty(hash, name, value);
201        }
202
203      }
204
205      @Override
206      public Base setProperty(String name, Base value) throws FHIRException {
207        if (name.equals("name")) {
208          this.name = castToString(value); // StringType
209        } else if (name.equals("telecom")) {
210          this.getTelecom().add(castToContactPoint(value));
211        } else
212          return super.setProperty(name, value);
213        return value;
214      }
215
216      @Override
217      public Base makeProperty(int hash, String name) throws FHIRException {
218        switch (hash) {
219        case 3373707:  return getNameElement();
220        case -1429363305:  return addTelecom(); 
221        default: return super.makeProperty(hash, name);
222        }
223
224      }
225
226      @Override
227      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
228        switch (hash) {
229        case 3373707: /*name*/ return new String[] {"string"};
230        case -1429363305: /*telecom*/ return new String[] {"ContactPoint"};
231        default: return super.getTypesForProperty(hash, name);
232        }
233
234      }
235
236      @Override
237      public Base addChild(String name) throws FHIRException {
238        if (name.equals("name")) {
239          throw new FHIRException("Cannot call addChild on a primitive type ContactDetail.name");
240        }
241        else if (name.equals("telecom")) {
242          return addTelecom();
243        }
244        else
245          return super.addChild(name);
246      }
247
248  public String fhirType() {
249    return "ContactDetail";
250
251  }
252
253      public ContactDetail copy() {
254        ContactDetail dst = new ContactDetail();
255        copyValues(dst);
256        dst.name = name == null ? null : name.copy();
257        if (telecom != null) {
258          dst.telecom = new ArrayList<ContactPoint>();
259          for (ContactPoint i : telecom)
260            dst.telecom.add(i.copy());
261        };
262        return dst;
263      }
264
265      protected ContactDetail typedCopy() {
266        return copy();
267      }
268
269      @Override
270      public boolean equalsDeep(Base other) {
271        if (!super.equalsDeep(other))
272          return false;
273        if (!(other instanceof ContactDetail))
274          return false;
275        ContactDetail o = (ContactDetail) other;
276        return compareDeep(name, o.name, true) && compareDeep(telecom, o.telecom, true);
277      }
278
279      @Override
280      public boolean equalsShallow(Base other) {
281        if (!super.equalsShallow(other))
282          return false;
283        if (!(other instanceof ContactDetail))
284          return false;
285        ContactDetail o = (ContactDetail) other;
286        return compareValues(name, o.name, true);
287      }
288
289      public boolean isEmpty() {
290        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(name, telecom);
291      }
292
293
294}
295