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.XON;
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 an organization.
28   * <p>
29   * This class contains members from the HL7v2.5 XON 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 = "Organization", propOrder = {"idNumber", "assigningAuthority", "organizationName"})
39  public class Organization extends Hl7v2Based<XON> {
40      private static final long serialVersionUID = 8283797476558181158L;
41  
42      /**
43       * Constructs the organization.
44       */
45      public Organization() {
46          super(new XON(MESSAGE));
47      }
48  
49      /**
50       * Constructs the organization.
51       * @param xon
52       *          parsed HL7 v2 element.
53       */
54      public Organization(XON xon) {
55          super(xon);
56      }
57  
58      /**
59       * Constructs the organization.
60       * @param organizationName
61       *          the name of the organization (XON.1).
62       */
63      public Organization(String organizationName) {
64          this();
65          setOrganizationName(organizationName);
66      }
67  
68      /**
69       * Constructs the organization.
70       * @param organizationName
71       *          the name of the organization (XON.1).
72       * @param idNumber
73       *          the id of the organization (XON.10).
74       * @param assigningAuthority
75       *          the assigning authority (XON.6).
76       */
77      public Organization(String organizationName, String idNumber, AssigningAuthority assigningAuthority) {
78          this();
79          setOrganizationName(organizationName);
80          setIdNumber(idNumber);
81          setAssigningAuthority(assigningAuthority);
82      }
83  
84      /**
85       * @return the assigning authority (XON.6).
86       */
87      public AssigningAuthority getAssigningAuthority() {
88          AssigningAuthority authority = new AssigningAuthority(getHapiObject().getXon6_AssigningAuthority());
89          return authority.isEmpty() ? null : authority;
90      }
91      
92      /**
93       * @param assigningAuthority
94       *          the assigning authority (XON.6).
95       */
96      public void setAssigningAuthority(AssigningAuthority assigningAuthority) {
97          setAssigningAuthority(assigningAuthority, getHapiObject().getXon6_AssigningAuthority());
98      }
99  
100     /**
101      * @return the name of the organization (XON.1).
102      */
103     @XmlElement(name = "name")
104     public String getOrganizationName() {
105         return getHapiObject().getXon1_OrganizationName().getValue();
106     }
107 
108     /**
109      * @param organizationName
110      *          the name of the organization (XON.1).
111      */
112     public void setOrganizationName(String organizationName) {
113         setValue(getHapiObject().getXon1_OrganizationName(), organizationName);
114     }
115 
116     /**
117      * @return the id of the organization (XON.10).
118      */
119     public String getIdNumber() {
120         return getHapiObject().getXon10_OrganizationIdentifier().getValue();
121     }
122 
123     /**
124      * @param idNumber
125      *          the id of the organization (XON.10).
126      */
127     public void setIdNumber(String idNumber) {
128         setValue(getHapiObject().getXon10_OrganizationIdentifier(), idNumber);
129     }
130 
131     @Override
132     public boolean equals(Object o) {
133         if (this == o) return true;
134         if (o == null || getClass() != o.getClass()) return false;
135         Organization that = (Organization) o;
136         return Objects.equals(getAssigningAuthority(), that.getAssigningAuthority()) &&
137                 Objects.equals(getOrganizationName(), that.getOrganizationName()) &&
138                 Objects.equals(getIdNumber(), that.getIdNumber());
139     }
140 
141     @Override
142     public int hashCode() {
143         return Objects.hash(getAssigningAuthority(), getOrganizationName(), getIdNumber());
144     }
145 
146     @Override
147     public String toString() {
148         return "Organization(" +
149                 "assigningAuthority=" + getAssigningAuthority() +
150                 ", organizationName=" + getOrganizationName() +
151                 ", idNumber=" + getIdNumber() +
152                 ')';
153     }
154 }