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.HD;
19  
20  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlAttribute;
23  import javax.xml.bind.annotation.XmlType;
24  import java.util.Objects;
25  
26  /**
27   * Assigning Authority for the CXi data type, allowing both the Namespace ID and the
28   * combination of Universal ID and Universal ID Type.
29   * <p>
30   * All members of this class are allowed to be <code>null</code>. When transforming
31   * to HL7 this indicates that the values are empty. Trailing empty values are
32   * removed from the HL7 string.
33   *
34   * @author Jens Riemschneider
35   * @author Dmytro Rud
36   */
37  @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
38  @XmlType(name = "CXiAssigningAuthority", propOrder = {"namespaceId"})
39  public class CXiAssigningAuthority extends AssigningAuthority {
40  
41      public CXiAssigningAuthority() {
42          super();
43      }
44  
45      public CXiAssigningAuthority(Holder<HD> hdHolder) {
46          super(hdHolder);
47      }
48  
49      public CXiAssigningAuthority(HD hd) {
50          super(hd);
51      }
52  
53      /**
54       * Constructs an assigning authority.
55       * @param namespaceId
56       *          the namespace ID (HD.1).
57       * @param universalId
58       *          the universal ID (HD.2).
59       * @param universalIdType
60       *          the type of the universal ID (HD.3).
61       */
62      public CXiAssigningAuthority(String namespaceId, String universalId, String universalIdType) {
63          super(universalId, universalIdType);
64          setNamespaceId(namespaceId);
65      }
66  
67      /**
68       * @return the namespace ID (HD.1).
69       */
70      @XmlAttribute
71      public String getNamespaceId() {
72          return getHapiObject().getInternal().getHd1_NamespaceID().getValue();
73      }
74  
75      /**
76       * @param namespaceId
77       *          the namespace ID (HD.1).
78       */
79      public void setNamespaceId(String namespaceId) {
80          setValue(getHapiObject().getInternal().getHd1_NamespaceID(), namespaceId);
81      }
82  
83      @Override
84      public boolean equals(Object o) {
85          if (this == o) return true;
86          if (o == null || getClass() != o.getClass()) return false;
87          if (!super.equals(o)) return false;
88  
89          CXiAssigningAuthority that = (CXiAssigningAuthority) o;
90  
91          return Objects.equals(getNamespaceId(), that.getNamespaceId());
92      }
93  
94      @Override
95      public int hashCode() {
96          return Objects.hash(super.hashCode(), getNamespaceId());
97      }
98  
99      @Override
100     public String toString() {
101         return "CXiAssigningAuthority(" +
102                 "super=" + super.toString() +
103                 "namespaceId=" + getNamespaceId() +
104                 ')';
105     }
106 }