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