1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.metadata;
17
18 import ca.uhn.hl7v2.model.v25.datatype.CE;
19 import org.apache.commons.lang3.StringUtils;
20 import org.openehealth.ipf.commons.ihe.xds.core.metadata.jaxbadapters.LocalizedStringAdapter;
21
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAttribute;
25 import javax.xml.bind.annotation.XmlType;
26 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27 import java.util.Objects;
28
29
30
31
32
33
34
35
36 @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
37 @XmlType(name = "Code", propOrder = {"code", "schemeName", "displayName"})
38 public class Code extends Hl7v2Based<CE> {
39 private static final long serialVersionUID = 7603534956639945984L;
40
41 private LocalizedString localizedString;
42
43
44
45
46
47 public Code() {
48 super(new CE(MESSAGE));
49 }
50
51
52
53
54 public Code(CE ce) {
55 super(ce);
56 }
57
58
59
60
61
62
63
64
65
66
67 public Code(String code, LocalizedString displayName, String schemeName) {
68 this();
69 setCode(code);
70 setDisplayName(displayName);
71 setSchemeName(schemeName);
72 }
73
74
75
76
77 @XmlAttribute
78 public String getCode() {
79 return getHapiObject().getCe1_Identifier().getValue();
80 }
81
82
83
84
85
86 public void setCode(String code) {
87 setValue(getHapiObject().getCe1_Identifier(), code);
88 }
89
90
91
92
93 @XmlAttribute
94 @XmlJavaTypeAdapter(value = LocalizedStringAdapter.class)
95 public LocalizedString getDisplayName() {
96 String value = getHapiObject().getCe2_Text().getValue();
97
98 if (StringUtils.isEmpty(value)) {
99 localizedString = null;
100 }
101 else if (localizedString != null) {
102 localizedString.setValue(value);
103 }
104 else {
105 localizedString = new LocalizedString(value);
106 }
107
108 return localizedString;
109 }
110
111
112
113
114
115 public void setDisplayName(LocalizedString displayName) {
116 this.localizedString = displayName;
117 if (displayName != null) {
118 setValue(getHapiObject().getCe2_Text(), displayName.getValue());
119 } else {
120 getHapiObject().getCe2_Text().clear();
121 }
122 }
123
124
125
126
127 @XmlAttribute(name = "codeSystemName")
128 public String getSchemeName() {
129 return getHapiObject().getCe3_NameOfCodingSystem().getValue();
130 }
131
132
133
134
135
136 public void setSchemeName(String schemeName) {
137 setValue(getHapiObject().getCe3_NameOfCodingSystem(), schemeName);
138 }
139
140 @Override
141 public boolean equals(Object o) {
142 if (this == o) return true;
143 if (o == null || getClass() != o.getClass()) return false;
144 Code that = (Code) o;
145 return Objects.equals(getCode(), that.getCode()) &&
146 Objects.equals(getDisplayName(), that.getDisplayName()) &&
147 Objects.equals(getSchemeName(), that.getSchemeName());
148 }
149
150 @Override
151 public int hashCode() {
152 return Objects.hash(getCode(), getDisplayName(), getSchemeName());
153 }
154
155 @Override
156 public String toString() {
157 return "Code(" +
158 "code=" + getCode() +
159 ", displayName=" + getDisplayName() +
160 ", schemeName=" + getSchemeName() +
161 ')';
162 }
163 }