View Javadoc
1   /*
2    * Copyright 2009 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.XAD;
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.XmlType;
24  import java.util.Objects;
25  
26  /**
27   * Represents the address of a patient.
28   * <p>
29   * This class contains a subset of the fields from the HL7v2.5 XAD data type.
30   * <p>
31   * All members of this class are allowed to be <code>null</code>. When transforming
32   * to HL7 this indicates that the values are empty. Trailing empty values are 
33   * removed from the HL7 string.
34   * @author Jens Riemschneider
35   * @author Dmytro Rud
36   */
37  @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
38  @XmlType(name = "Address", propOrder = {
39          "streetAddress", "otherDesignation", "city", "countyParishCode", "stateOrProvince", "country", 
40          "zipOrPostalCode"})
41  public class Address extends Hl7v2Based<XAD> {
42      private static final long serialVersionUID = -5050715144917393181L;
43  
44      public Address() {
45          super(new XAD(MESSAGE));
46      }
47  
48      public Address(XAD xad) {
49          super(xad);
50      }
51  
52  
53      /**
54       * @return the street address (XAD.1).
55       */
56      public String getStreetAddress() {
57          return getHapiObject().getXad1_StreetAddress().getSad1_StreetOrMailingAddress().getValue();
58      }
59  
60      /**
61       * @param streetAddress
62       *          the street address (XAD.1).
63       */
64      public void setStreetAddress(String streetAddress) {
65          setValue(getHapiObject().getXad1_StreetAddress().getSad1_StreetOrMailingAddress(), streetAddress);
66      }
67  
68      /**
69       * @return the other designation (XAD.2).
70       */
71      @XmlElement(name = "additionalLocator")
72      public String getOtherDesignation() {
73          return getHapiObject().getXad2_OtherDesignation().getValue();
74      }
75  
76      /**
77       * @param otherDesignation
78       *          the other designation (XAD.2).
79       */
80      public void setOtherDesignation(String otherDesignation) {
81          setValue(getHapiObject().getXad2_OtherDesignation(), otherDesignation);
82      }
83  
84      /**
85       * @return the city (XAD.3).
86       */
87      public String getCity() {
88          return getHapiObject().getXad3_City().getValue();
89      }
90  
91      /**
92       * @param city
93       *          the city (XAD.3).
94       */
95      public void setCity(String city) {
96          setValue(getHapiObject().getXad3_City(), city);
97      }
98  
99      /**
100      * @return the state or province (XAD.4).
101      */
102     @XmlElement(name = "state")
103     public String getStateOrProvince() {
104         return getHapiObject().getXad4_StateOrProvince().getValue();
105     }
106 
107     /**
108      * @param stateOrProvince
109      *          the state or province (XAD.4).
110      */
111     public void setStateOrProvince(String stateOrProvince) {
112         setValue(getHapiObject().getXad4_StateOrProvince(), stateOrProvince);
113     }
114 
115     /**
116      * @return the zip or postal code (XAD.5).
117      */
118     @XmlElement(name = "postalCode")
119     public String getZipOrPostalCode() {
120         return getHapiObject().getXad5_ZipOrPostalCode().getValue();
121     }
122 
123     /**
124      * @param zipOrPostalCode
125      *          the zip or postal code (XAD.5).
126      */
127     public void setZipOrPostalCode(String zipOrPostalCode) {
128         setValue(getHapiObject().getXad5_ZipOrPostalCode(), zipOrPostalCode);
129     }
130 
131     /**
132      * @return the country (XAD.6).
133      */
134     public String getCountry() {
135         return getHapiObject().getXad6_Country().getValue();
136     }
137 
138     /**
139      * @param country
140      *          the country (XAD.6).
141      */
142     public void setCountry(String country) {
143         setValue(getHapiObject().getXad6_Country(), country);
144     }
145 
146     /**
147      * @return the county parish code (XAD.9).
148      */
149     @XmlElement(name = "county")
150     public String getCountyParishCode() {
151         return getHapiObject().getXad9_CountyParishCode().getValue();
152     }
153 
154     /**
155      * @param countyParishCode
156      *          the county parish code (XAD.9).
157      */
158     public void setCountyParishCode(String countyParishCode) {
159         setValue(getHapiObject().getXad9_CountyParishCode(), countyParishCode);
160     }
161 
162     @Override
163     public boolean equals(Object o) {
164         if (this == o) return true;
165         if (o == null || getClass() != o.getClass()) return false;
166         Address that = (Address) o;
167         return Objects.equals(getCity(), that.getCity()) &&
168                 Objects.equals(getCountry(), that.getCountry()) &&
169                 Objects.equals(getCountyParishCode(), that.getCountyParishCode()) &&
170                 Objects.equals(getOtherDesignation(), that.getOtherDesignation()) &&
171                 Objects.equals(getStateOrProvince(), that.getStateOrProvince()) &&
172                 Objects.equals(getStreetAddress(), that.getStreetAddress()) &&
173                 Objects.equals(getZipOrPostalCode(), that.getZipOrPostalCode());
174     }
175 
176     @Override
177     public int hashCode() {
178         return Objects.hash(
179                 getCity(), getCountry(), getCountyParishCode(), getOtherDesignation(),
180                 getStateOrProvince(), getStreetAddress(), getZipOrPostalCode());
181     }
182 
183     @Override
184     public String toString() {
185         return "Address(" +
186                 "streetAddress=" + getStreetAddress() +
187                 ", otherDesignation=" + getOtherDesignation() +
188                 ", city=" + getCity() +
189                 ", stateOrProvince=" + getStateOrProvince() +
190                 ", zipOrPostalCode=" + getZipOrPostalCode() +
191                 ", country=" + getCountry() +
192                 ", countyParishCode=" + getCountyParishCode() +
193                 ')';
194     }
195 }