-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathCommonBenStatusFlowServiceImpl.java
More file actions
339 lines (287 loc) · 12.4 KB
/
Copy pathCommonBenStatusFlowServiceImpl.java
File metadata and controls
339 lines (287 loc) · 12.4 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.tm.service.benFlowStatus;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.Period;
import java.util.ArrayList;
import java.util.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.iemr.tm.data.benFlowStatus.BeneficiaryFlowStatus;
import com.iemr.tm.repo.benFlowStatus.BeneficiaryFlowStatusRepo;
import com.iemr.tm.repo.nurse.BenVisitDetailRepo;
import com.iemr.tm.utils.mapper.InputMapper;
@Service
public class CommonBenStatusFlowServiceImpl implements CommonBenStatusFlowService {
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
private BeneficiaryFlowStatusRepo beneficiaryFlowStatusRepo;
private BenVisitDetailRepo benVisitDetailRepo;
@Value("${nurseWL}")
private Integer nurseWL;
@Autowired
public void setBenVisitDetailRepo(BenVisitDetailRepo benVisitDetailRepo) {
this.benVisitDetailRepo = benVisitDetailRepo;
}
@Autowired
public void setBeneficiaryFlowStatusRepo(BeneficiaryFlowStatusRepo beneficiaryFlowStatusRepo) {
this.beneficiaryFlowStatusRepo = beneficiaryFlowStatusRepo;
}
public int createBenFlowRecord(String requestOBJ, Long beneficiaryRegID, Long beneficiaryID) {
BeneficiaryFlowStatus objRS = null;
int returnOBJ = 0;
try {
BeneficiaryFlowStatus obj = getBenFlowRecordObj(requestOBJ, beneficiaryRegID, beneficiaryID);
if (beneficiaryRegID != null && beneficiaryID != null && beneficiaryRegID > 0 && beneficiaryID > 0) {
objRS = beneficiaryFlowStatusRepo.save(obj);
if (objRS != null)
returnOBJ = 1;
else
returnOBJ = 0;
} else {
Calendar cal = Calendar.getInstance();
if (nurseWL != null && nurseWL > 0 && nurseWL <= 30)
cal.add(Calendar.DAY_OF_YEAR, -nurseWL);
else
cal.add(Calendar.DAY_OF_YEAR, -7);
long sevenDaysAgo = cal.getTimeInMillis();
ArrayList<Long> benFlowIDList = beneficiaryFlowStatusRepo.checkBenAlreadyInNurseWorkList(
obj.getBeneficiaryRegID(), obj.getProviderServiceMapID(), obj.getVanID(),new Timestamp(sevenDaysAgo));
if (benFlowIDList != null && benFlowIDList.size() > 0) {
// update i_ben_flow table for updated beneficiary id
returnOBJ = 3;
} else {
objRS = beneficiaryFlowStatusRepo.save(obj);
if (objRS != null)
returnOBJ = 1;
else
returnOBJ = 0;
}
}
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
}
return returnOBJ;
}
public int updateBenFlowNurseAfterNurseActivity(Long benFlowID, Long benRegID, Long benVisitID, String visitReason,
String visitCategory, Short nurseFlag, Short docFlag, Short labIteration, Short radiologistFlag,
Short oncologistFlag, Long visitCode, Integer vanID, Short specialistFlag, Timestamp tcDate,
Integer tcSpecialistUserID) {
int i = 0;
try {
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterNurseActivity(benFlowID, benRegID, benVisitID,
visitReason, visitCategory, nurseFlag, docFlag, labIteration, radiologistFlag, oncologistFlag,
visitCode, vanID, specialistFlag, tcDate, tcSpecialistUserID);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
}
return i;
}
public int updateBenFlowNurseAfterNurseActivityANC(Long benFlowID, Long benRegID, Long benVisitID, String visitReason,
String visitCategory, Short nurseFlag, Short docFlag, Short labIteration, Short radiologistFlag,
Short oncologistFlag, Long visitCode, Integer vanID, Short specialistFlag, Timestamp tcDate,
Integer tcSpecialistUserID,Short labTechnician) {
int i = 0;
try {
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterNurseActivityANC(benFlowID, benRegID, benVisitID,
visitReason, visitCategory, nurseFlag, docFlag, labIteration, radiologistFlag, oncologistFlag,
visitCode, vanID, specialistFlag, tcDate, tcSpecialistUserID,labTechnician);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
}
return i;
}
public int updateBenFlowNurseAfterNurseUpdateNCD_Screening(Long benFlowID, Long benRegID, Short nurseFlag) {
int i = 0;
try {
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterNurseDataUpdateNCD_Screening(benFlowID, benRegID,
nurseFlag);
} catch (Exception e) {
logger.error("Error in ben flow updatation after nurse update NCD - screening = " + e);
}
return i;
}
private BeneficiaryFlowStatus getBenFlowRecordObj(String requestOBJ, Long beneficiaryRegID, Long beneficiaryID)
throws Exception {
BeneficiaryFlowStatus obj = InputMapper.gson().fromJson(requestOBJ, BeneficiaryFlowStatus.class);
if (obj.getI_bendemographics().getDistrictID() != null)
obj.setDistrictID(obj.getI_bendemographics().getDistrictID());
if (obj.getI_bendemographics().getDistrictName() != null)
obj.setDistrictName(obj.getI_bendemographics().getDistrictName());
if (obj.getI_bendemographics().getDistrictBranchID() != null)
obj.setVillageID(obj.getI_bendemographics().getDistrictBranchID());
if (obj.getI_bendemographics().getDistrictBranchName() != null)
obj.setVillageName(obj.getI_bendemographics().getDistrictBranchName());
if (obj.getI_bendemographics().getServicePointID() != null)
obj.setServicePointID(obj.getI_bendemographics().getServicePointID());
if (obj.getI_bendemographics().getServicePointName() != null)
obj.setServicePointName(obj.getI_bendemographics().getServicePointName());
if (beneficiaryRegID != null && obj.getBeneficiaryRegID() == null)
obj.setBeneficiaryRegID(beneficiaryRegID);
if (beneficiaryID != null && obj.getBeneficiaryID() == null)
obj.setBeneficiaryID(beneficiaryID);
if (obj.getBenPhoneMaps() != null && obj.getBenPhoneMaps().size() > 0
&& obj.getBenPhoneMaps().get(0).getPhoneNo() != null)
obj.setPreferredPhoneNum(obj.getBenPhoneMaps().get(0).getPhoneNo());
if (obj.getGenderID() == null)
{
if(obj.getM_gender() !=null)
obj.setGenderID(obj.getM_gender().getGenderID());
}
if (obj.getGenderName() == null)
obj.setGenderName(obj.getM_gender().getGenderName());
String ageDetails = "";
int age_val = 0;
if (obj.getdOB() != null) {
Date date = new Date(obj.getdOB().getTime());
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
java.time.LocalDate todayDate = java.time.LocalDate.now();
java.time.LocalDate birthdate = java.time.LocalDate.of(year, month, day);
Period p = Period.between(birthdate, todayDate);
int d = p.getDays();
int m = p.getMonths();
int y = p.getYears();
// System.out.println("helloo...");
if (y > 0) {
ageDetails = y + " years - " + m + " months";
age_val = y;
} else {
if (m > 0) {
ageDetails = m + " months - " + d + " days";
} else {
ageDetails = d + " days";
}
}
}
obj.setAge(ageDetails);
obj.setBen_age_val(age_val);
if (obj.getLastName() != null)
obj.setBenName(obj.getFirstName() + " " + obj.getLastName());
else
obj.setBenName(obj.getFirstName());
Short benVisitCount = benVisitDetailRepo.getVisitCountForBeneficiary(obj.getBeneficiaryRegID());
if (benVisitCount != null && benVisitCount >= 0) {
benVisitCount = (short) (benVisitCount + 1);
} else {
benVisitCount = 1;
}
obj.setBenVisitNo(benVisitCount);
obj.setNurseFlag((short) 1);
obj.setDoctorFlag((short) 0);
obj.setPharmacist_flag((short) 0);
obj.setAgentId(obj.getCreatedBy());
if (obj.getCreatedDate() != null)
obj.setRegistrationDate(obj.getCreatedDate());
else
obj.setRegistrationDate(new Timestamp(System.currentTimeMillis()));
return obj;
}
public int updateBenFlowAfterDocData(Long benFlowID, Long benRegID, Long benID, Long benVisitID, short docFlag,
short pharmaFlag, short oncologistFlag, short tcSpecialistFlag, int tcUserID, Timestamp tcDate,short labTechnicianFlag, Boolean signatureFlag) {
int i = 0;
try {
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivity(benFlowID, benRegID, benID, docFlag,
pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate,labTechnicianFlag, signatureFlag);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
}
return i;
}
public int updateBenFlowAfterDocDataFromSpecialist(Long benFlowID, Long benRegID, Long benID, Long benVisitID,
short docFlag, short pharmaFlag, short oncologistFlag, short tcSpecialistFlag,short labTechnicianFlag, Boolean signatureFlag) {
int i = 0;
try {
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivitySpecialist(benFlowID, benRegID, benID,
docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, labTechnicianFlag, signatureFlag);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
}
return i;
}
public int updateBenFlowAfterDocDataFromSpecialistANC(Long benFlowID, Long benRegID, Long benID, Long benVisitID,
short docFlag, short pharmaFlag, short oncologistFlag, short tcSpecialistFlag,short labTechnicianFlag, Boolean signatureFlag) {
int i = 0;
try {
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivitySpecialistANC(benFlowID, benRegID, benID,
docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, labTechnicianFlag, signatureFlag);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
}
return i;
}
public int updateBenFlowAfterDocDataUpdate(Long benFlowID, Long benRegID, Long benID, Long benVisitID,
short docFlag, short pharmaFlag, short oncologistFlag, short tcSpecialistFlag, int tcUserID,
Timestamp tcDate,short labTechnicianFlag, Boolean signatureFlag) throws Exception {
int i = 0;
try {
Short pharmaF = beneficiaryFlowStatusRepo.getPharmaFlag(benFlowID);
Short pharmaF1;
if (pharmaF != null && pharmaF == 1)
pharmaF1 = pharmaF;
else
pharmaF1 = pharmaFlag;
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivity(benFlowID, benRegID, benID, docFlag,
pharmaF1, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, labTechnicianFlag, signatureFlag);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
throw new Exception(e);
}
return i;
}
public int updateBenFlowAfterDocDataUpdateTCSpecialist(Long benFlowID, Long benRegID, Long benID, Long benVisitID,
short docFlag, short pharmaFlag, short oncologistFlag, short tcSpecialistFlag, int tcUserID,
Timestamp tcDate, short labTechnicianFlag, Boolean signatureFlag) throws Exception {
int i = 0;
try {
Short pharmaF = beneficiaryFlowStatusRepo.getPharmaFlag(benFlowID);
Short pharmaF1;
if (pharmaF != null && pharmaF == 1)
pharmaF1 = pharmaF;
else
pharmaF1 = pharmaFlag;
i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivityTCSpecialist(benFlowID, benRegID, benID,
pharmaF1, oncologistFlag, tcSpecialistFlag, labTechnicianFlag, signatureFlag);
} catch (Exception e) {
logger.error("Error in ben flow creation = " + e);
throw new Exception(e);
}
return i;
}
public int updateFlowAfterLabResultEntry(Long benFlowID, Long benRegID, Long benVisitID, Short nurseFlag,
Short doctorFlag, Short labFlag) {
int i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterLabResultEntry(benFlowID, benRegID, nurseFlag,
doctorFlag);
return i;
}
public int updateFlowAfterLabResultEntryForTCSpecialist(Long benFlowID, Long benRegID, Short specialistFlag) {
int i = beneficiaryFlowStatusRepo.updateBenFlowStatusAfterLabResultEntryForSpecialist(benFlowID, benRegID,
specialistFlag);
return i;
}
}