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