001package org.hl7.fhir.r4.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 Thu, Sep 13, 2018 09:04-0400 for FHIR v3.5.0 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> children) { 176 super.listChildren(children); 177 children.add(new Property("name", "string", "The name of an individual to contact.", 0, 1, name)); 178 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)); 179 } 180 181 @Override 182 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 183 switch (_hash) { 184 case 3373707: /*name*/ return new Property("name", "string", "The name of an individual to contact.", 0, 1, name); 185 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); 186 default: return super.getNamedProperty(_hash, _name, _checkValid); 187 } 188 189 } 190 191 @Override 192 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 193 switch (hash) { 194 case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // StringType 195 case -1429363305: /*telecom*/ return this.telecom == null ? new Base[0] : this.telecom.toArray(new Base[this.telecom.size()]); // ContactPoint 196 default: return super.getProperty(hash, name, checkValid); 197 } 198 199 } 200 201 @Override 202 public Base setProperty(int hash, String name, Base value) throws FHIRException { 203 switch (hash) { 204 case 3373707: // name 205 this.name = castToString(value); // StringType 206 return value; 207 case -1429363305: // telecom 208 this.getTelecom().add(castToContactPoint(value)); // ContactPoint 209 return value; 210 default: return super.setProperty(hash, name, value); 211 } 212 213 } 214 215 @Override 216 public Base setProperty(String name, Base value) throws FHIRException { 217 if (name.equals("name")) { 218 this.name = castToString(value); // StringType 219 } else if (name.equals("telecom")) { 220 this.getTelecom().add(castToContactPoint(value)); 221 } else 222 return super.setProperty(name, value); 223 return value; 224 } 225 226 @Override 227 public Base makeProperty(int hash, String name) throws FHIRException { 228 switch (hash) { 229 case 3373707: return getNameElement(); 230 case -1429363305: return addTelecom(); 231 default: return super.makeProperty(hash, name); 232 } 233 234 } 235 236 @Override 237 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 238 switch (hash) { 239 case 3373707: /*name*/ return new String[] {"string"}; 240 case -1429363305: /*telecom*/ return new String[] {"ContactPoint"}; 241 default: return super.getTypesForProperty(hash, name); 242 } 243 244 } 245 246 @Override 247 public Base addChild(String name) throws FHIRException { 248 if (name.equals("name")) { 249 throw new FHIRException("Cannot call addChild on a primitive type ContactDetail.name"); 250 } 251 else if (name.equals("telecom")) { 252 return addTelecom(); 253 } 254 else 255 return super.addChild(name); 256 } 257 258 public String fhirType() { 259 return "ContactDetail"; 260 261 } 262 263 public ContactDetail copy() { 264 ContactDetail dst = new ContactDetail(); 265 copyValues(dst); 266 dst.name = name == null ? null : name.copy(); 267 if (telecom != null) { 268 dst.telecom = new ArrayList<ContactPoint>(); 269 for (ContactPoint i : telecom) 270 dst.telecom.add(i.copy()); 271 }; 272 return dst; 273 } 274 275 protected ContactDetail typedCopy() { 276 return copy(); 277 } 278 279 @Override 280 public boolean equalsDeep(Base other_) { 281 if (!super.equalsDeep(other_)) 282 return false; 283 if (!(other_ instanceof ContactDetail)) 284 return false; 285 ContactDetail o = (ContactDetail) other_; 286 return compareDeep(name, o.name, true) && compareDeep(telecom, o.telecom, true); 287 } 288 289 @Override 290 public boolean equalsShallow(Base other_) { 291 if (!super.equalsShallow(other_)) 292 return false; 293 if (!(other_ instanceof ContactDetail)) 294 return false; 295 ContactDetail o = (ContactDetail) other_; 296 return compareValues(name, o.name, true); 297 } 298 299 public boolean isEmpty() { 300 return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(name, telecom); 301 } 302 303 304} 305