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.XCN;
19 import org.apache.commons.beanutils.BeanUtils;
20
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlType;
24 import java.util.Objects;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
40 @XmlType(name = "Person", propOrder = {"id", "name"})
41 public class Person extends Hl7v2Based<XCN> {
42 private static final long serialVersionUID = 1775227207521668959L;
43
44
45
46
47 public Person() {
48 super(new XCN(MESSAGE));
49 }
50
51
52
53
54
55 public Person(XCN xcn) {
56 super(xcn);
57 }
58
59
60
61
62
63
64
65
66
67 public Person(Identifiable id, Name name) {
68 this();
69 setId(id);
70 setName(name);
71 }
72
73
74
75
76 public Identifiable getId() {
77 return new Identifiable(
78 getHapiObject().getXcn1_IDNumber().getValue(),
79 new AssigningAuthority(getHapiObject().getXcn9_AssigningAuthority()));
80 }
81
82
83
84
85
86 public void setId(Identifiable id) {
87 if (id != null) {
88 setValue(getHapiObject().getXcn1_IDNumber(), id.getId());
89 setAssigningAuthority(id.getAssigningAuthority(), getHapiObject().getXcn9_AssigningAuthority());
90 } else {
91 getHapiObject().getXcn1_IDNumber().clear();
92 getHapiObject().getXcn9_AssigningAuthority().clear();
93 }
94 }
95
96
97
98
99 public Name getName() {
100 XcnName name = new XcnName(getHapiObject());
101 return name.isEmpty() ? null : name;
102 }
103
104
105
106
107
108 public void setName(Name name) {
109 if (name != null) {
110 try {
111 Name thisName = new XcnName(getHapiObject());
112 BeanUtils.copyProperties(thisName, name);
113 } catch (Exception e) {
114 throw new RuntimeException("Could not copy properties");
115 }
116 }
117 else {
118 XCN xcn = getHapiObject();
119 xcn.getXcn2_FamilyName().clear();
120 xcn.getXcn3_GivenName().clear();
121 xcn.getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof().clear();
122 xcn.getXcn5_SuffixEgJRorIII().clear();
123 xcn.getXcn6_PrefixEgDR().clear();
124 xcn.getXcn7_DegreeEgMD().clear();
125 }
126 }
127
128 @Override
129 public boolean equals(Object o) {
130 if (this == o) return true;
131 if (o == null || getClass() != o.getClass()) return false;
132 Person that = (Person) o;
133 return Objects.equals(getId(), that.getId()) &&
134 Objects.equals(getName(), that.getName());
135 }
136
137 @Override
138 public int hashCode() {
139 return Objects.hash(getId(), getName());
140 }
141
142 @Override
143 public String toString() {
144 return "Person(" +
145 "id=" + getId() +
146 ", name=" + getName() +
147 ')';
148 }
149 }