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