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.Composite;
19  import org.openehealth.ipf.commons.ihe.xds.core.metadata.jaxbadapters.NameAdapter;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlType;
25  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
26  import java.util.Objects;
27  
28  /**
29   * This class represents a name.
30   * <p>
31   * It is derived from the HL7v2 data types XPN and XCN. It only contains
32   * naming related fields of these data types.
33   * <p>
34   * All members of this class are allowed to be <code>null</code>. When transforming
35   * to HL7 this indicates that the values are empty. Trailing empty values are 
36   * removed from the HL7 string.
37   * @author Jens Riemschneider
38   * @author Dmytro Rud
39   */
40  @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
41  @XmlJavaTypeAdapter(value = NameAdapter.class)
42  @XmlType(name = "Name", propOrder = {"prefix", "givenName", "secondAndFurtherGivenNames",
43          "familyName", "suffix", "degree"})
44  public abstract class Name<T extends Composite> extends Hl7v2Based<T> {
45      private static final long serialVersionUID = -3455779057944896901L;
46  
47      protected Name() {
48      }
49  
50      protected Name(T hapiObject) {
51          super(hapiObject);
52      }
53  
54  
55      @XmlElement(name = "family")
56      abstract public String getFamilyName();                  // XCN.2.1, XPN.1.1
57      @XmlElement(name = "given")
58      abstract public String getGivenName();                   // XCN.3, XPN.2
59      @XmlElement(name = "secondAndFurtherGiven")
60      abstract public String getSecondAndFurtherGivenNames();  // XCN.4, XPN.3
61      abstract public String getSuffix();                      // XCN.5, XPN.4
62      abstract public String getPrefix();                      // XCN.6, XPN.5
63      abstract public String getDegree();                      // XCN.7, XPN.6
64  
65      abstract public void setFamilyName(String value);                  // XCN.2.1, XPN.1.1
66      abstract public void setGivenName(String value);                   // XCN.3, XPN.2
67      abstract public void setSecondAndFurtherGivenNames(String value);  // XCN.4, XPN.3
68      abstract public void setSuffix(String value);                      // XCN.5, XPN.4
69      abstract public void setPrefix(String value);                      // XCN.6, XPN.5
70      abstract public void setDegree(String value);                      // XCN.7, XPN.6
71  
72  
73      @Override
74      public boolean equals(Object o) {
75          if (this == o) return true;
76          if (o == null || !(o instanceof Name)) return false;
77          Name<?> that = (Name<?>) o;
78          return Objects.equals(getFamilyName(), that.getFamilyName()) &&
79                  Objects.equals(getGivenName(), that.getGivenName()) &&
80                  Objects.equals(getSecondAndFurtherGivenNames(), that.getSecondAndFurtherGivenNames()) &&
81                  Objects.equals(getSuffix(), that.getSuffix()) &&
82                  Objects.equals(getPrefix(), that.getPrefix()) &&
83                  Objects.equals(getDegree(), that.getDegree());
84      }
85  
86      @Override
87      public int hashCode() {
88          return Objects.hash(getFamilyName(), getGivenName(), getSecondAndFurtherGivenNames(),
89                  getSuffix(), getPrefix(), getDegree());
90      }
91  
92      @Override
93      public String toString() {
94          return "Name(" +
95                  "familyName=" + getFamilyName() +
96                  ", givenName=" + getGivenName() +
97                  ", secondAndFurtherGivenNames=" + getSecondAndFurtherGivenNames() +
98                  ", suffix=" + getSuffix() +
99                  ", prefix=" + getPrefix() +
100                 ", degree=" + getDegree() +
101                 ')';
102     }
103 }