001package org.hl7.fhir.r5.openehr;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.r5.openehr.Enumerations.*;
038import org.hl7.fhir.exceptions.FHIRException;
039import org.hl7.fhir.r5.model.*;
040import org.hl7.fhir.instance.model.api.ICompositeType;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.ChildOrder;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Description;
045import ca.uhn.fhir.model.api.annotation.Block;
046
047/**
048 * Description of a means of contact of a Party. Actual structure is archetyped.
049 */
050@DatatypeDef(name="CONTACT")
051public class CONTACT extends LOCATABLE implements ICompositeType {
052
053    /**
054     * A set of address alternatives for this contact purpose and time validity combination.
055     */
056    @Child(name = "addresses", type = {ADDRESS.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
057    @Description(shortDefinition="A set of address alternatives for this contact purpose and time validity combination", formalDefinition="A set of address alternatives for this contact purpose and time validity combination." )
058    protected List<ADDRESS> addressesList;
059
060    /**
061     * Valid time interval for this contact descriptor.
062     */
063    @Child(name = "time_validity", type = {DV_INTERVAL.class}, order=1, min=0, max=1, modifier=false, summary=false)
064    @Description(shortDefinition="Valid time interval for this contact descriptor", formalDefinition="Valid time interval for this contact descriptor." )
065    protected DV_INTERVAL time_validity;
066
067    private static final long serialVersionUID = 1314053334L;
068
069  /**
070   * Constructor
071   */
072    public CONTACT() {
073      super();
074    }
075
076    /**
077     * @return {@link #addresses} (A set of address alternatives for this contact purpose and time validity combination.)
078     */
079    public List<ADDRESS> getAddressesList() { 
080      if (this.addressesList == null)
081        this.addressesList = new ArrayList<ADDRESS>();
082      return this.addressesList;
083    }
084
085    /**
086     * @return Returns a reference to <code>this</code> for easy method chaining
087     */
088    public CONTACT setAddressesList(List<ADDRESS> theAddresses) { 
089      this.addressesList = theAddresses;
090      return this;
091    }
092
093    public boolean hasAddresses() { 
094      if (this.addressesList == null)
095        return false;
096      for (ADDRESS item : this.addressesList)
097        if (!item.isEmpty())
098          return true;
099      return false;
100    }
101
102    public ADDRESS addAddresses() { //3a
103      ADDRESS t = new ADDRESS();
104      if (this.addressesList == null)
105        this.addressesList = new ArrayList<ADDRESS>();
106      this.addressesList.add(t);
107      return t;
108    }
109
110    public CONTACT addAddresses(ADDRESS t) { //3b
111      if (t == null)
112        return this;
113      if (this.addressesList == null)
114        this.addressesList = new ArrayList<ADDRESS>();
115      this.addressesList.add(t);
116      return this;
117    }
118
119    /**
120     * @return The first repetition of repeating field {@link #addresses}, creating it if it does not already exist {3}
121     */
122    public ADDRESS getAddressesFirstRep() { 
123      if (getAddressesList().isEmpty()) {
124        addAddresses();
125      }
126      return getAddressesList().get(0);
127    }
128
129    /**
130     * @return {@link #time_validity} (Valid time interval for this contact descriptor.)
131     */
132    public DV_INTERVAL getTime_validity() { 
133      if (this.time_validity == null)
134        if (Configuration.errorOnAutoCreate())
135          throw new Error("Attempt to auto-create CONTACT.time_validity");
136        else if (Configuration.doAutoCreate())
137          this.time_validity = new DV_INTERVAL(); // cc
138      return this.time_validity;
139    }
140
141    public boolean hasTime_validity() { 
142      return this.time_validity != null && !this.time_validity.isEmpty();
143    }
144
145    /**
146     * @param value {@link #time_validity} (Valid time interval for this contact descriptor.)
147     */
148    public CONTACT setTime_validity(DV_INTERVAL value) { 
149      this.time_validity = value;
150      return this;
151    }
152
153      protected void listChildren(List<Property> children) {
154        super.listChildren(children);
155        children.add(new Property("addresses", "http://openehr.org/fhir/StructureDefinition/ADDRESS", "A set of address alternatives for this contact purpose and time validity combination.", 0, java.lang.Integer.MAX_VALUE, addressesList));
156        children.add(new Property("time_validity", "http://openehr.org/fhir/StructureDefinition/DV-INTERVAL", "Valid time interval for this contact descriptor.", 0, 1, time_validity));
157      }
158
159      @Override
160      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
161        switch (_hash) {
162        case 874544034: /*addresses*/  return new Property("addresses", "http://openehr.org/fhir/StructureDefinition/ADDRESS", "A set of address alternatives for this contact purpose and time validity combination.", 0, java.lang.Integer.MAX_VALUE, addressesList);
163        case -1304171420: /*time_validity*/  return new Property("time_validity", "http://openehr.org/fhir/StructureDefinition/DV-INTERVAL", "Valid time interval for this contact descriptor.", 0, 1, time_validity);
164        default: return super.getNamedProperty(_hash, _name, _checkValid);
165        }
166
167      }
168
169      @Override
170      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
171        switch (hash) {
172        case 874544034: /*addresses*/ return this.addressesList == null ? new Base[0] : this.addressesList.toArray(new Base[this.addressesList.size()]); // ADDRESS
173        case -1304171420: /*time_validity*/ return this.time_validity == null ? new Base[0] : new Base[] {this.time_validity}; // DV_INTERVAL
174        default: return super.getProperty(hash, name, checkValid);
175        }
176
177      }
178
179      @Override
180      public Base setProperty(int hash, String name, Base value) throws FHIRException {
181        switch (hash) {
182        case 874544034: // addresses
183          this.getAddressesList().add((ADDRESS) value); // ADDRESS
184          return value;
185        case -1304171420: // time_validity
186          this.time_validity = (DV_INTERVAL) value; // DV_INTERVAL
187          return value;
188        default: return super.setProperty(hash, name, value);
189        }
190
191      }
192
193      @Override
194      public Base setProperty(String name, Base value) throws FHIRException {
195        if (name.equals("addresses")) {
196          this.getAddressesList().add((ADDRESS) value); // ADDRESS
197        } else if (name.equals("time_validity")) {
198          this.time_validity = (DV_INTERVAL) value; // DV_INTERVAL
199        } else
200          return super.setProperty(name, value);
201        return value;
202      }
203
204      @Override
205      public Base makeProperty(int hash, String name) throws FHIRException {
206        switch (hash) {
207        case 874544034:  return addAddresses(); 
208        case -1304171420:  return getTime_validity();
209        default: return super.makeProperty(hash, name);
210        }
211
212      }
213
214      @Override
215      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
216        switch (hash) {
217        case 874544034: /*addresses*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/ADDRESS"};
218        case -1304171420: /*time_validity*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-INTERVAL"};
219        default: return super.getTypesForProperty(hash, name);
220        }
221
222      }
223
224      @Override
225      public Base addChild(String name) throws FHIRException {
226        if (name.equals("addresses")) {
227          return addAddresses();
228        }
229        else if (name.equals("time_validity")) {
230          this.time_validity = new DV_INTERVAL();
231          return this.time_validity;
232        }
233        else
234          return super.addChild(name);
235      }
236
237  public String fhirType() {
238    return "CONTACT";
239
240  }
241
242      public CONTACT copy() {
243        CONTACT dst = new CONTACT();
244        copyValues(dst);
245        return dst;
246      }
247
248      public void copyValues(CONTACT dst) {
249        super.copyValues(dst);
250        if (addressesList != null) {
251          dst.addressesList = new ArrayList<ADDRESS>();
252          for (ADDRESS i : addressesList)
253            dst.addressesList.add(i.copy());
254        };
255        dst.time_validity = time_validity == null ? null : time_validity.copy();
256      }
257
258      protected CONTACT typedCopy() {
259        return copy();
260      }
261
262      @Override
263      public boolean equalsDeep(Base other_) {
264        if (!super.equalsDeep(other_))
265          return false;
266        if (!(other_ instanceof CONTACT))
267          return false;
268        CONTACT o = (CONTACT) other_;
269        return compareDeep(addressesList, o.addressesList, true) && compareDeep(time_validity, o.time_validity, true)
270          ;
271      }
272
273      @Override
274      public boolean equalsShallow(Base other_) {
275        if (!super.equalsShallow(other_))
276          return false;
277        if (!(other_ instanceof CONTACT))
278          return false;
279        CONTACT o = (CONTACT) other_;
280        return true;
281      }
282
283      public boolean isEmpty() {
284        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(addressesList, time_validity
285          );
286      }
287
288
289}
290