-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathAntenatalCareController.java
More file actions
435 lines (410 loc) · 18.1 KB
/
AntenatalCareController.java
File metadata and controls
435 lines (410 loc) · 18.1 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
/*
* 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.hwc.controller.anc;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
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.RestController;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.iemr.hwc.data.anc.HrpStatusAndReasonsRequestModel;
import com.iemr.hwc.data.anc.SysObstetricExamination;
import com.iemr.hwc.data.nurse.CommonUtilityClass;
import com.iemr.hwc.service.anc.ANCService;
import com.iemr.hwc.utils.response.OutputResponse;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
/**
*
* @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());
@Autowired
private ANCService ancService;
/**
* @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" })
public ResponseEntity<String> saveBenANCNurseData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) throws Exception {
OutputResponse response = new OutputResponse();
if (null != requestObj) {
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
logger.info("Request object for ANC nurse data saving :" + requestObj);
String ancRes = ancService.saveANCNurseData(jsnOBJ, Authorization);
response.setResponse(ancRes);
} else {
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Save ANC data for doctor.
* @param JSON requestObj
* @return success or failure response
*/
@Operation(summary = "Save ANC doctor data")
@PostMapping(value = { "/save/doctorData" })
public ResponseEntity<String> saveBenANCDoctorData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC doctor data saving :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
if (jsnOBJ != null) {
Long r = ancService.saveANCDoctorData(jsnOBJ, Authorization);
if (r != null && r > 0) {
response.setResponse("Data saved successfully");
} else {
response.setError(5000, "Unable to save data");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
} else {
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary visit details entered by nurse.
* @param benRegID and benVisitID
* @return visit details in JSON format
*/
@Operation(summary = "Get ANC beneficiary visit details from nurse")
@PostMapping(value = { "/getBenVisitDetailsFrmNurseANC" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getBenVisitDetailsFrmNurseANC(
@Param(value = "{\"benRegID\":\"Long\", \"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC visit data fetching :" + comingRequest);
JSONObject obj = new JSONObject(comingRequest);
if (obj.length() > 1 && obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancService.getBenVisitDetailsFrmNurseANC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("ANC visit data fetching Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary anc care details entered by nurse.
* @param benRegID and benVisitID
* @return anc care details in JSON format
*/
@Operation(summary = "Get ANC beneficiary details from nurse")
@PostMapping(value = { "/getBenANCDetailsFrmNurseANC" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getBenANCDetailsFrmNurseANC(
@Param(value = "{\"benRegID\":\"Long\", \"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC Care data fetching :" + comingRequest);
JSONObject obj = new JSONObject(comingRequest);
Long visitCode = null;
if (obj.has("benRegID") && !obj.isNull("benRegID")) {
Long benRegID = obj.getLong("benRegID");
if (obj.has("visitCode") && !obj.isNull("visitCode") && obj.get("visitCode") != null)
visitCode = obj.getLong("visitCode");
String res = ancService.getBenANCDetailsFrmNurseANC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request, Beneficiary information is NULL");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("ANC Care data fetching response :" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary history details entered by nurse.
* @param benRegID and benVisitID
* @return history details in JSON format
*/
@Operation(summary = "Get ANC beneficiary history from nurse")
@PostMapping(value = { "/getBenANCHistoryDetails" })
public ResponseEntity<String> getBenANCHistoryDetails(
@Param(value = "{\"benRegID\":\"Long\", \"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC history data fetching :" + comingRequest);
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String s = ancService.getBenANCHistoryDetails(benRegID, visitCode);
response.setResponse(s);
} else {
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("ANC history data fetching Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary vital details entered by nurse.
* @param benRegID and benVisitID
* @return vital details in JSON format
*/
@Operation(summary = "Get ANC beneficiary vitals from nurse")
@PostMapping(value = { "/getBenANCVitalDetailsFrmNurseANC" })
public ResponseEntity<String> getBenANCVitalDetailsFrmNurseANC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC vital data fetching :" + comingRequest);
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String res = ancService.getBeneficiaryVitalDetails(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("ANC vital data fetching Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary examination details entered by nurse.
* @param benRegID and benVisitID
* @return examination details in JSON format
*/
@Operation(summary = "Get ANC beneficiary examination details from nurse")
@PostMapping(value = { "/getBenExaminationDetailsANC" })
public ResponseEntity<String> getBenExaminationDetailsANC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC examination data fetching :" + comingRequest);
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("benRegID") && obj.has("visitCode")) {
Long benRegID = obj.getLong("benRegID");
Long visitCode = obj.getLong("visitCode");
String s = ancService.getANCExaminationDetailsData(benRegID, visitCode);
response.setResponse(s);
} else {
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("ANC examination data fetching Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary details entered by doctor.
* @param benRegID and benVisitID
* @return doctor entered details in JSON format
*/
@Operation(summary = "Get ANC beneficiary case record")
@PostMapping(value = { "/getBenCaseRecordFromDoctorANC" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getBenCaseRecordFromDoctorANC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for doctor data fetching :" + comingRequest);
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 = ancService.getBenCaseRecordFromDoctorANC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid request");
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("ANC doctor data fetching Response:" + response);
return ResponseEntity.ok(response.toString());
}
@Operation(summary = "Check high risk pregnancy status for ANC beneficiary")
@PostMapping(value = { "/getHRPStatus" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getHRPStatus(
@RequestBody HrpStatusAndReasonsRequestModel hrpStatusAndReasonsRequestModel) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for doctor data fetching :" + hrpStatusAndReasonsRequestModel.toString());
String res = ancService.getHRPStatus(hrpStatusAndReasonsRequestModel);
response.setResponse(res);
return ResponseEntity.ok(response.toString());
}
// changes for get HRP information - follow-up, can be used at other places also
@Autowired
private ANCService aNCService;
@Operation(summary = "Get high risk pregnancy information (status and reason) from obstetric history "
+ "as per the latest visit")
@PostMapping(value = { "/getHrpInformation" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getHrpInformation(
@Param(value = "{\"beneficiaryRegId\":\"Long\"}") @RequestBody CommonUtilityClass commonUtilityClass)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for getHrpInformation :" + commonUtilityClass.toString());
SysObstetricExamination sysObstetricExamination = aNCService
.getHRPInformation(commonUtilityClass.getBeneficiaryRegId());
if (sysObstetricExamination != null)
response.setResponse(new Gson().toJson(sysObstetricExamination));
else
response.setResponse("no information found");
return ResponseEntity.ok(response.toString());
}
/**
*
* @param requestObj
* @return success or failure response
* @objective Replace ANC Care Data entered by Nurse with the details entered by
* Doctor
*/
@Operation(summary = "Update ANC beneficiary data")
@PostMapping(value = { "/update/ANCScreen" })
public ResponseEntity<String> updateANCCareNurse(@RequestBody String requestObj) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC Care data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int result = ancService.updateBenANCDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
logger.info("ANC Care data update Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
*
* @param requestObj
* @return success or failure response
* @objective Replace ANC History Data entered by Nurse with the details entered
* by Doctor
*/
@Operation(summary = "Update ANC beneficiary history")
@PostMapping(value = { "/update/historyScreen" })
public ResponseEntity<String> updateANCHistoryNurse(@RequestBody String requestObj) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC history data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int result = ancService.updateBenANCHistoryDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
logger.info("ANC history data update Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
*
* @param requestObj
* @return success or failure response
* @objective Replace ANC Vital Data entered by Nurse with the details entered
* by Doctor
*/
@Operation(summary = "Update ANC beneficiary vitals")
@PostMapping(value = { "/update/vitalScreen" })
public ResponseEntity<String> updateANCVitalNurse(@RequestBody String requestObj) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC Vital data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int result = ancService.updateBenANCVitalDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
logger.info("ANC vital data update Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
*
* @param requestObj
* @return success or failure response
* @objective Replace ANC History Data entered by Nurse with the details entered
* by Doctor
*/
@Operation(summary = "Update ANC examination data")
@PostMapping(value = { "/update/examinationScreen" })
public ResponseEntity<String> updateANCExaminationNurse(@RequestBody String requestObj) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC examination data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int result = ancService.updateBenANCExaminationDetails(jsnOBJ);
if (result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
logger.info("ANC examination data update Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
*
* @param requestObj
* @return success or failure response
* @objective Replace ANC doctor data for the doctor next visit
*
*/
@Operation(summary = "Update ANC doctor data")
@PostMapping(value = { "/update/doctorData" })
public ResponseEntity<String> updateANCDoctorData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for ANC doctor data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
Long result = ancService.updateANCDoctorData(jsnOBJ, Authorization);
if (null != result && result > 0) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
logger.info("ANC doctor data update Response:" + response);
return ResponseEntity.ok(response.toString());
}
}