View Javadoc
1   /*
2    * Copyright 2013 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.CX;
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   * Represents a reference ID.
28   * <p>
29   * This class is derived from an HL7v2 CX data type ("CXi" in IHE ITI TF-3).
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   *
35   * @author Jens Riemschneider
36   * @author Dmytro Rud
37   */
38  @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
39  @XmlType(name = "ReferenceId", propOrder = {"id", "assigningAuthority", "idTypeCode"})
40  public class ReferenceId extends Hl7v2Based<CX> {
41      private static final long serialVersionUID = 6615092850652668283L;
42  
43      public static final String ID_TYPE_CODE_UNIQUE_ID       = "urn:ihe:iti:xds:2013:uniqueId";
44      public static final String ID_TYPE_CODE_ACCESSION       = "urn:ihe:iti:xds:2013:accession";
45      public static final String ID_TYPE_CODE_REFERRAL        = "urn:ihe:iti:xds:2013:referral";
46      public static final String ID_TYPE_CODE_ORDER           = "urn:ihe:iti:xds:2013:order";
47      public static final String ID_TYPE_WORKFLOW_INSTANCE_ID = "urn:ihe:iti:xdw:2013:workflowInstanceId";
48      public static final String ID_TYPE_ENCOUNTER_ID         = "urn:ihe:iti:xds:2015:encounterId";
49      public static final String ID_TYPE_STUDY_INSTANCE_ID    = "urn:ihe:iti:xds:2016:studyInstanceUID";
50  
51      /**
52       * Constructs a reference ID.
53       */
54      public ReferenceId() {
55          super(new CX(MESSAGE));
56      }
57  
58  
59      /**
60       * Constructs a reference ID.
61       */
62      public ReferenceId(CX cx) {
63          super(cx);
64      }
65  
66  
67      /**
68       * Constructs a reference ID.
69       * @param id
70       *          the value of the id (CX.1).
71       * @param assigningAuthority
72       *          the assigning authority (CX.4).
73       * @param idTypeCode
74       *          the ID type code (CX.5).
75       */
76      public ReferenceId(String id, CXiAssigningAuthority assigningAuthority, String idTypeCode) {
77          this();
78          setId(id);
79          setAssigningAuthority(assigningAuthority);
80          setIdTypeCode(idTypeCode);
81      }
82  
83      /**
84       * @return the value of the id (CX.1).
85       */
86      @XmlAttribute
87      public String getId() {
88          return getHapiObject().getCx1_IDNumber().getValue();
89      }
90  
91      /**
92       * @param id
93       *          the value of the id (CX.1).
94       */
95      public void setId(String id) {
96          setValue(getHapiObject().getCx1_IDNumber(), id);
97      }
98  
99      /**
100      * @return the assigning authority (CX.4).
101      */
102     public CXiAssigningAuthority getAssigningAuthority() {
103         CXiAssigningAuthority assigningAuthority = new CXiAssigningAuthority(getHapiObject().getCx4_AssigningAuthority());
104         return assigningAuthority.isEmpty() ? null : assigningAuthority;
105     }
106 
107     /**
108      * @param assigningAuthority
109      *          the assigning authority (CX.4).
110      */
111     public void setAssigningAuthority(CXiAssigningAuthority assigningAuthority) {
112         setAssigningAuthority(assigningAuthority, getHapiObject().getCx4_AssigningAuthority());
113     }
114 
115     /**
116      * @return ID type code (CX.5).
117      */
118     @XmlAttribute
119     public String getIdTypeCode() {
120         return getHapiObject().getCx5_IdentifierTypeCode().getValue();
121     }
122 
123     /**
124      * @param idTypeCode
125      *          ID type code (CX.5).
126      */
127     public void setIdTypeCode(String idTypeCode) {
128         setValue(getHapiObject().getCx5_IdentifierTypeCode(), idTypeCode);
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         ReferenceId that = (ReferenceId) o;
136         return Objects.equals(getAssigningAuthority(), that.getAssigningAuthority()) &&
137                 Objects.equals(getId(), that.getId()) &&
138                 Objects.equals(getIdTypeCode(), that.getIdTypeCode());
139     }
140 
141     @Override
142     public int hashCode() {
143         return Objects.hash(getId(), getIdTypeCode(), getAssigningAuthority());
144     }
145 
146     @Override
147     public String toString() {
148         return "ReferenceId(" +
149                 "id=" + getId() +
150                 ", assigningAuthority=" + getAssigningAuthority() +
151                 ", idTypeCode=" + getIdTypeCode() +
152                 ')';
153     }
154 }