-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAbstractEncounter.java
More file actions
244 lines (189 loc) · 6.84 KB
/
AbstractEncounter.java
File metadata and controls
244 lines (189 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package org.avni.server.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import org.avni.server.common.dbSchema.ColumnNames;
import org.avni.server.framework.hibernate.JodaDateTimeConverter;
import org.avni.server.framework.hibernate.ObservationCollectionUserType;
import org.avni.server.geo.Point;
import org.avni.server.geo.PointType;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import java.util.Objects;
@MappedSuperclass
public class AbstractEncounter extends SyncAttributeEntity {
@Column
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@NotNull
@JoinColumn(name = "encounter_type_id")
private EncounterType encounterType;
@Column
@Convert(converter = JodaDateTimeConverter.class)
private DateTime earliestVisitDateTime;
@Column
@Convert(converter = JodaDateTimeConverter.class)
private DateTime maxVisitDateTime;
@Column(name = ColumnNames.EncounterDateTime)
@Convert(converter = JodaDateTimeConverter.class)
private DateTime encounterDateTime;
@Column(name = ColumnNames.EncounterObservations)
@Type(value = ObservationCollectionUserType.class)
private ObservationCollection observations;
@Column(name = ColumnNames.EncounterCancelDateTime)
@Convert(converter = JodaDateTimeConverter.class)
private DateTime cancelDateTime;
@Column(name = ColumnNames.EncounterCancelObservations)
@Type(value = ObservationCollectionUserType.class)
private ObservationCollection cancelObservations;
@Type(value = PointType.class)
@Column
private Point encounterLocation;
@Type(value = PointType.class)
@Column
private Point cancelLocation;
@Column
private String legacyId;
@Column(name = "address_id")
private Long addressId;
@JoinColumn(name = "filled_by_id")
@ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)
private User filledBy;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "created_by_id")
private User createdBy;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "last_modified_by_id")
private User lastModifiedBy;
@Column(updatable = false)
private boolean syncDisabled;
public EncounterType getEncounterType() {
return encounterType;
}
public void setEncounterType(EncounterType encounterType) {
this.encounterType = encounterType;
}
public DateTime getEncounterDateTime() {
return encounterDateTime;
}
public void setEncounterDateTime(DateTime encounterDateTime, User currentUser) {
if (this.encounterDateTime == null && encounterDateTime != null) {
this.filledBy = currentUser;
}
this.encounterDateTime = encounterDateTime;
}
public ObservationCollection getObservations() {
return observations;
}
public void setObservations(ObservationCollection observations) {
this.observations = observations;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public DateTime getEarliestVisitDateTime() {
return earliestVisitDateTime;
}
public void setEarliestVisitDateTime(DateTime earliestVisitDateTime) {
this.earliestVisitDateTime = earliestVisitDateTime;
}
public DateTime getMaxVisitDateTime() {
return maxVisitDateTime;
}
public void setMaxVisitDateTime(DateTime maxVisitDateTime) {
this.maxVisitDateTime = maxVisitDateTime;
}
public DateTime getCancelDateTime() {
return cancelDateTime;
}
public boolean isCancelled() {
return cancelDateTime != null;
}
public void setCancelDateTime(DateTime cancelDateTime) {
this.cancelDateTime = cancelDateTime;
}
public ObservationCollection getCancelObservations() {
return cancelObservations;
}
public void setCancelObservations(ObservationCollection cancelObservations) {
this.cancelObservations = cancelObservations;
}
public Point getEncounterLocation() {
return encounterLocation;
}
public void setEncounterLocation(Point encounterLocation) {
this.encounterLocation = encounterLocation;
}
public Point getCancelLocation() {
return cancelLocation;
}
public void setCancelLocation(Point cancelLocation) {
this.cancelLocation = cancelLocation;
}
public boolean isCompleted() {
return getEncounterDateTime() != null;
}
public boolean matches(String encounterTypeName, String encounterName) {
return Objects.equals(this.getEncounterType().getName(), encounterTypeName) && Objects.equals(this.getName(), encounterName);
}
public boolean dateFallsWithIn(DateTime encounterDateTime) {
return encounterDateTime.isAfter(this.getEarliestVisitDateTime()) && encounterDateTime.isBefore(this.getMaxVisitDateTime());
}
public boolean isEncounteredOrCancelledBetween(DateTime startDate, DateTime endDate) {
return (getEncounterDateTime() != null && isAfterOrEqual(getEncounterDateTime(), startDate) && isBeforeOrEqual(getEncounterDateTime(), endDate)) ||
(getCancelDateTime() != null && isAfterOrEqual(getCancelDateTime(), startDate) && isBeforeOrEqual(getCancelDateTime(), endDate));
}
private boolean isAfterOrEqual(DateTime d1, DateTime d2) {
return d1.equals(d2) || d1.isAfter(d2);
}
private boolean isBeforeOrEqual(DateTime d1, DateTime d2) {
return d1.equals(d2) || d1.isBefore(d2);
}
public String getLegacyId() {
return legacyId;
}
public void setLegacyId(String legacyId) {
this.legacyId = legacyId;
}
public void validate() throws ValidationException {
if (encounterDateTime == null && earliestVisitDateTime == null) {
throw new ValidationException("Both encounter datetime and earliest visit datetime cannot be null");
}
}
@JsonIgnore
public Long getAddressId() {
return addressId;
}
public void setAddressId(Long addressId) {
this.addressId = addressId;
}
@JsonIgnore
public User getFilledBy() {
return filledBy;
}
public void setFilledBy(User filledBy) {
this.filledBy = filledBy;
}
@JsonIgnore
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
@JsonIgnore
public User getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(User lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
public boolean isSyncDisabled() {
return syncDisabled;
}
public void setSyncDisabled(boolean syncDisabled) {
this.syncDisabled = syncDisabled;
}
}