-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathAntenatalCareController.java
More file actions
474 lines (410 loc) · 17 KB
/
Copy pathAntenatalCareController.java
File metadata and controls
474 lines (410 loc) · 17 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/*
* 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.controller.anc;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.iemr.tm.service.anc.ANCServiceImpl;
import com.iemr.tm.utils.response.OutputResponse;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.v3.oas.annotations.Operation;
/**
* @Objective Saving ANC data for Nurse and Doctor.
*/
@RestController
@RequestMapping(value = "/ANC", headers = "Authorization", consumes = "application/json", produces = "application/json")
public class AntenatalCareController {
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
private ANCServiceImpl ancServiceImpl;
@Autowired
public void setAncServiceImpl(ANCServiceImpl ancServiceImpl) {
this.ancServiceImpl = ancServiceImpl;
}
/**
* @Objective Save ANC data for nurse.
* @param JSON requestObj
* @return success or failure response
* @throws Exception
*/
@Operation(summary = "Save ANC nurse data")
@PostMapping(value = { "/save/nurseData" })
@PreAuthorize("hasRole('NURSE') ")
public String saveBenANCNurseData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) throws Exception {
OutputResponse response = new OutputResponse();
if (null != requestObj) {
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
try {
logger.info("Request object for ANC nurse data saving :" + requestObj);
if (jsnOBJ != null) {
String ancRes = ancServiceImpl.saveANCNurseData(jsnOBJ, Authorization);
response.setResponse(ancRes);
} else {
response.setError(5000, "Invalid request");
}
} catch (Exception e) {
logger.error("Error while saving nurse data:" + e.getMessage());
ancServiceImpl.deleteVisitDetails(jsnOBJ);
response.setError(5000, e.getMessage());
}
}
return response.toString();
}
@Operation(summary = "Save ANC doctor data")
@PostMapping(value = { "/save/doctorData" })
@PreAuthorize("hasRole('DOCTOR') ")
public String saveBenANCDoctorData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) {
OutputResponse response = new OutputResponse();
try {
logger.info("Request object for ANC doctor data saving :" + requestObj);
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
if (jsnOBJ != null) {
Long r = ancServiceImpl.saveANCDoctorData(jsnOBJ, Authorization);
if (r != null && r > 0) {
response.setResponse("Data saved successfully");
} else {
// something went wrong
response.setError(5000, "Unable to save data");
}
} else {
// data is null
response.setError(5000, "Invalid request");
}
} catch (Exception e) {
logger.error("Error while saving doctor data:" + e.getMessage());
response.setError(5000, e.getMessage());
}
return response.toString();
}
@Operation(summary = "Get ANC beneficiary visit details from nurse")
@PostMapping(value = { "/getBenVisitDetailsFrmNurseANC" })
@Transactional(rollbackFor = Exception.class)
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String getBenVisitDetailsFrmNurseANC(
@Param(value = "{\"benRegID\":\"Long\", \"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.length() > 1) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancServiceImpl.getBenVisitDetailsFrmNurseANC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
}
logger.info("ANC visit data fetching Response:" + response);
} catch (Exception e) {
response.setError(5000, "Error while getting beneficiary visit data");
logger.error("Error while getting beneficiary visit data:" + e);
}
return response.toString();
}
@Operation(summary = "Get ANC beneficiary details from nurse")
@PostMapping(value = { "/getBenANCDetailsFrmNurseANC" })
@Transactional(rollbackFor = Exception.class)
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String getBenANCDetailsFrmNurseANC(
@Param(value = "{\"benRegID\":\"Long\", \"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancServiceImpl.getBenANCDetailsFrmNurseANC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
}
logger.info("ANC Care data fetching response :" + response);
} catch (Exception e) {
response.setError(5000, "Error while getting beneficiary ANC care data");
logger.error("Error while getting beneficiary ANC care data:" + e);
}
return response.toString();
}
@Operation(summary = "Get ANC beneficiary history from nurse")
@PostMapping(value = { "/getBenANCHistoryDetails" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String getBenANCHistoryDetails(
@Param(value = "{\"benRegID\":\"Long\", \"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String s = ancServiceImpl.getBenANCHistoryDetails(benRegID, visitCode);
response.setResponse(s);
} else {
response.setError(5000, "Invalid request");
}
logger.info("ANC history data fetching Response:" + response);
} catch (Exception e) {
response.setError(5000, "Error while getting beneficiary history data");
logger.error("Error while getting beneficiary history data :" + e);
}
return response.toString();
}
@Operation(summary = "Get ANC beneficiary vitals from nurse")
@PostMapping(value = { "/getBenANCVitalDetailsFrmNurseANC" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String getBenANCVitalDetailsFrmNurseANC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancServiceImpl.getBeneficiaryVitalDetails(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
}
logger.info("ANC vital data fetching Response:" + response);
} catch (Exception e) {
response.setError(5000, "Error while getting beneficiary vital data");
logger.error("Error while getting beneficiary vital data :" + e);
}
return response.toString();
}
@Operation(summary = "Get ANC beneficiary examination details from nurse")
@PostMapping(value = { "/getBenExaminationDetailsANC" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String getBenExaminationDetailsANC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String s = ancServiceImpl.getANCExaminationDetailsData(benRegID, visitCode);
response.setResponse(s);
} else {
response.setError(5000, "Invalid request");
}
logger.info("ANC examination data fetching Response:" + response);
} catch (Exception e) {
response.setError(5000, "Error while getting beneficiary examination data");
logger.error("Error while getting beneficiary examination data :" + e);
}
return response.toString();
}
@Operation(summary = "Get ANC beneficiary case record")
@PostMapping(value = { "/getBenCaseRecordFromDoctorANC" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
@Transactional(rollbackFor = Exception.class)
public String getBenCaseRecordFromDoctorANC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (null != obj && obj.length() > 1 && obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancServiceImpl.getBenCaseRecordFromDoctorANC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
}
logger.info("ANC doctor data fetching Response:" + response);
} catch (Exception e) {
response.setError(5000, "Error while getting beneficiary doctor data");
logger.error("Error while getting beneficiary doctor data :" + e);
}
return response.toString();
}
@Operation(summary = "Check high risk pregnancy status for ANC beneficiary")
@PostMapping(value = { "/getHRPStatus" })
@Transactional(rollbackFor = Exception.class)
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String getHRPStatus(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
try {
JSONObject obj = new JSONObject(comingRequest);
if (null != obj && obj.length() > 1 && obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancServiceImpl.getHRPStatus(benRegID, visitCode);
if (res != null)
response.setResponse(res);
else
response.setError(5000, "error in getting HRP status");
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
}
} catch (Exception e) {
response.setError(5000, "error in getting HRP status");
logger.error("error in getting HRP status : " + e);
}
return response.toString();
}
@Operation(summary = "Update ANC beneficiary data")
@PostMapping(value = { "/update/ANCScreen" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String updateANCCareNurse(@RequestBody String requestObj) {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC Care data updating :" + requestObj);
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
try {
int result = ancServiceImpl.updateBenANCDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
}
logger.info("ANC Care data update Response:" + response);
} catch (Exception e) {
response.setError(5000, "Unable to modify data");
logger.error("Error while updating beneficiary ANC care data :" + e);
}
return response.toString();
}
@Operation(summary = "Update ANC beneficiary history")
@PostMapping(value = { "/update/historyScreen" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String updateANCHistoryNurse(@RequestBody String requestObj) {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC history data updating :" + requestObj);
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
try {
int result = ancServiceImpl.updateBenANCHistoryDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
}
logger.info("ANC history data update Response:" + response);
} catch (Exception e) {
response.setError(5000, "Unable to modify data");
logger.error("Error while updating beneficiary history data :" + e);
}
return response.toString();
}
@Operation(summary = "Update ANC beneficiary vitals")
@PostMapping(value = { "/update/vitalScreen" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String updateANCVitalNurse(@RequestBody String requestObj) {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC Vital data updating :" + requestObj);
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
try {
int result = ancServiceImpl.updateBenANCVitalDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
}
logger.info("ANC vital data update Response:" + response);
} catch (Exception e) {
response.setError(5000, "Unable to modify data");
logger.error("Error while updating beneficiary vital data :" + e);
}
return response.toString();
}
@Operation(summary = "Update ANC examination data")
@PostMapping(value = { "/update/examinationScreen" })
@PreAuthorize("hasRole('NURSE') || hasRole('DOCTOR') ")
public String updateANCExaminationNurse(@RequestBody String requestObj) {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC examination data updating :" + requestObj);
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
try {
int result = ancServiceImpl.updateBenANCExaminationDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
}
logger.info("ANC examination data update Response:" + response);
} catch (Exception e) {
response.setError(5000, "Unable to modify data");
logger.error("Error while updating beneficiary examination data :" + e);
}
return response.toString();
}
@Operation(summary = "Update ANC doctor data")
@PostMapping(value = { "/update/doctorData" })
@PreAuthorize("hasRole('DOCTOR') ")
public String updateANCDoctorData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC doctor data updating :" + requestObj);
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(requestObj);
jsnOBJ = jsnElmnt.getAsJsonObject();
try {
Long result = ancServiceImpl.updateANCDoctorData(jsnOBJ, Authorization);
if (null != result && result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
}
logger.info("ANC doctor data update Response:" + response);
} catch (Exception e) {
logger.error("Unable to modify data. " + e.getMessage());
response.setError(5000, e.getMessage());
}
return response.toString();
}
}