View Javadoc
1   /*
2    * Copyright 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.metadata;
17  
18  import ca.uhn.hl7v2.model.v25.datatype.XTN;
19  
20  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlElement;
23  import javax.xml.bind.annotation.XmlTransient;
24  import javax.xml.bind.annotation.XmlType;
25  import java.util.Objects;
26  
27  /**
28   * Represents a telecommunication address.
29   * <p>
30   * This class contains members from the HL7 v.2.5 XTN data type.
31   * <p>
32   * All members of this class are allowed to be <code>null</code>.
33   * When transforming to HL7 this indicates that the values are empty.
34   * Trailing empty values are removed from the HL7 string.
35   *
36   * @author Dmytro Rud
37   */
38  @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
39  @XmlType(name = "Telecom", propOrder = {"use", "type", "email", "countryCode",
40          "areaCityCode", "localNumber", "extension", "unformattedPhoneNumber"})
41  public class Telecom extends Hl7v2Based<XTN> {
42      private static final long serialVersionUID = 526836203236101658L;
43  
44      public Telecom() {
45          super(new XTN(MESSAGE));
46      }
47  
48      public Telecom(XTN xtn) {
49          super(xtn);
50      }
51  
52      @Deprecated
53      public Telecom(String address, String addressType) {
54          this();
55          setAddress(address);
56          setAddressType(addressType);
57      }
58  
59      /**
60       * Creates a telecom object containing an E-mail address.
61       *
62       * @param email E-mail address (XTN-4).
63       */
64      public Telecom(String email) {
65          this();
66          setUse("NET");
67          setType("Internet");
68          setEmail(email);
69      }
70  
71      /**
72       * Creates a telecom object containing a phone number.
73       *
74       * @param countryCode  country code of phone number (XTN-5), can be <code>null</code>.
75       * @param areaCityCode area/city code of phone number (XTN-6), can be <code>null</code>.
76       * @param localNumber  local part of the phone number (XTN-7).
77       * @param extension    extension of the phone number (XTN-8), can be <code>null</code>.
78       */
79      public Telecom(Long countryCode, Long areaCityCode, Long localNumber, Long extension) {
80          this();
81          setUse("PRN");
82          setType("PH");
83          setCountryCode(countryCode);
84          setAreaCityCode(areaCityCode);
85          setLocalNumber(localNumber);
86          setExtension(extension);
87      }
88  
89      /**
90       * @param countryCode
91       * @param areaCityCode
92       * @param localNumber
93       * @param extension
94       * @deprecated
95       */
96      public Telecom(Integer countryCode, Integer areaCityCode, Integer localNumber, Integer extension) {
97          this(
98                  countryCode == null ? null : countryCode.longValue(),
99                  areaCityCode == null ? null : areaCityCode.longValue(),
100                 localNumber == null ? null : localNumber.longValue(),
101                 extension == null ? null : extension.longValue());
102     }
103 
104     /**
105      * @return telecom use code (XTN-2) according to HL7 v.2.5 Table 0201.
106      */
107     @XmlElement(name = "use")
108     public String getUse() {
109         return getHapiObject().getXtn2_TelecommunicationUseCode().getValue();
110     }
111 
112     /**
113      * @param use telecom use code (XTN-2) according to HL7 v.2.5 Table 0201.
114      */
115     public void setUse(String use) {
116         setValue(getHapiObject().getXtn2_TelecommunicationUseCode(), use);
117     }
118 
119     /**
120      * @return telecom type (XTN-3) according to HL7 v.2.5 Table 0202.
121      */
122     @XmlElement(name = "type")
123     public String getType() {
124         return getHapiObject().getXtn3_TelecommunicationEquipmentType().getValue();
125     }
126 
127     /**
128      * @param type telecom type (XTN-3) according to HL7 v.2.5 Table 0202.
129      */
130     public void setType(String type) {
131         setValue(getHapiObject().getXtn3_TelecommunicationEquipmentType(), type);
132     }
133 
134     /**
135      * @return telecommunication equipment type (XTN-3) according to HL7 v.2.5 Table 0202.
136      * @deprecated use {@link #getType()} instead.
137      */
138     @Deprecated
139     @XmlTransient
140     public String getAddressType() {
141         return getType();
142     }
143 
144     /**
145      * @param addressType telecommunication equipment type (XTN-3) according to HL7 v.2.5 Table 0202.
146      * @deprecated use {@link #setType(String)} instead.
147      */
148     @Deprecated
149     public void setAddressType(String addressType) {
150         setType(addressType);
151     }
152 
153     /**
154      * @return E-mail address (XTN-4).
155      */
156     @XmlElement(name = "email")
157     public String getEmail() {
158         return getHapiObject().getXtn4_EmailAddress().getValue();
159     }
160 
161     /**
162      * @param email E-mail address (XTN-4).
163      */
164     public void setEmail(String email) {
165         setValue(getHapiObject().getXtn4_EmailAddress(), email);
166     }
167 
168     /**
169      * @return E-mail address (XTN-4).
170      * @deprecated use {@link #getEmail()} instead.
171      */
172     @Deprecated
173     @XmlTransient
174     public String getAddress() {
175         return getEmail();
176     }
177 
178     /**
179      * @param address E-mail address (XTN-4).
180      * @deprecated use {@link #setEmail(String)} instead.
181      */
182     @Deprecated
183     public void setAddress(String address) {
184         setEmail(address);
185     }
186 
187     /**
188      * @return country code of phone number (XTN-5).
189      */
190     @XmlElement(name = "countryCode")
191     public Long getCountryCode() {
192         return getLongValue(getHapiObject().getXtn5_CountryCode());
193     }
194 
195     /**
196      * @param countryCode country code of phone number (XTN-5).
197      */
198     public void setCountryCode(Long countryCode) {
199         setValue(getHapiObject().getXtn5_CountryCode(), countryCode == null ? null : countryCode.toString());
200     }
201 
202     /**
203      * @return area/city code of phone number (XTN-6).
204      */
205     @XmlElement(name = "areaCityCode")
206     public Long getAreaCityCode() {
207         return getLongValue(getHapiObject().getXtn6_AreaCityCode());
208     }
209 
210     /**
211      * @param areaCityCode area/city code of phone number (XTN-6).
212      */
213     public void setAreaCityCode(Long areaCityCode) {
214         setValue(getHapiObject().getXtn6_AreaCityCode(), areaCityCode == null ? null : areaCityCode.toString());
215     }
216 
217     /**
218      * @return local part of the phone number (XTN-7).
219      */
220     @XmlElement(name = "localNumber")
221     public Long getLocalNumber() {
222         return getLongValue(getHapiObject().getXtn7_LocalNumber());
223     }
224 
225     /**
226      * @param localNumber local part of the phone number (XTN-7).
227      */
228     public void setLocalNumber(Long localNumber) {
229         setValue(getHapiObject().getXtn7_LocalNumber(), localNumber == null ? null : localNumber.toString() );
230     }
231 
232     /**
233      * @return extension of the phone number (XTN-8).
234      */
235     @XmlElement(name = "extension")
236     public Long getExtension() {
237         return getLongValue(getHapiObject().getXtn8_Extension());
238     }
239 
240     /**
241      * @param extension extension of the phone number (XTN-8).
242      */
243     public void setExtension(Long extension) {
244         setValue(getHapiObject().getXtn8_Extension(), extension == null ? null : extension.toString());
245     }
246 
247     /**
248      * @return unformatted phone number (XTN-12).
249      */
250     @XmlElement(name = "unformattedPhoneNumber")
251     public String getUnformattedPhoneNumber() {
252         return getHapiObject().getXtn12_UnformattedTelephoneNumber().getValue();
253     }
254 
255     /**
256      * @param unformattedPhoneNumber unformatted the phone number (XTN-12).
257      */
258     public void setUnformattedPhoneNumber(String unformattedPhoneNumber) {
259         setValue(getHapiObject().getXtn12_UnformattedTelephoneNumber(), unformattedPhoneNumber);
260     }
261 
262     @Override
263     public boolean equals(Object o) {
264         if (this == o) return true;
265         if (o == null || getClass() != o.getClass()) return false;
266         Telecom that = (Telecom) o;
267         return Objects.equals(getUse(), that.getUse()) &&
268                 Objects.equals(getType(), that.getType()) &&
269                 Objects.equals(getEmail(), that.getEmail()) &&
270                 Objects.equals(getCountryCode(), that.getCountryCode()) &&
271                 Objects.equals(getAreaCityCode(), that.getAreaCityCode()) &&
272                 Objects.equals(getLocalNumber(), that.getLocalNumber()) &&
273                 Objects.equals(getExtension(), that.getExtension()) &&
274                 Objects.equals(getUnformattedPhoneNumber(), that.getUnformattedPhoneNumber());
275     }
276 
277     @Override
278     public int hashCode() {
279         return Objects.hash(getUse(), getType(), getEmail(), getCountryCode(),
280                 getAreaCityCode(), getLocalNumber(), getExtension(), getUnformattedPhoneNumber());
281     }
282 
283     @Override
284     public String toString() {
285         return "Telecom(" +
286                 "use=" + getUse() +
287                 ", type=" + getType() +
288                 ", email=" + getEmail() +
289                 ", countryCode=" + getCountryCode() +
290                 ", areaCityCode=" + getAreaCityCode() +
291                 ", localNumber=" + getLocalNumber() +
292                 ", extension=" + getExtension() +
293                 ", unformattedPhoneNumber=" + getUnformattedPhoneNumber() +
294                 ')';
295     }
296 }