-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathChildhoodAdolescenceController.java
More file actions
312 lines (294 loc) · 13.9 KB
/
ChildhoodAdolescenceController.java
File metadata and controls
312 lines (294 loc) · 13.9 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
/*
* 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.adolescent;
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.JsonObject;
import com.google.gson.JsonParser;
import com.iemr.hwc.data.nurse.CommonUtilityClass;
import com.iemr.hwc.service.adolescent.AdolescentAndChildCareService;
import com.iemr.hwc.utils.exception.IEMRException;
import com.iemr.hwc.utils.response.OutputResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
@RestController
@RequestMapping(value = "/child-adolescent-care", headers = "Authorization")
public class ChildhoodAdolescenceController {
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
@Autowired
private AdolescentAndChildCareService adolescentAndChildCareService;
/**
* @Objective Save child-adolescent-care data for nurse.
* @param requestObj
* @return success or failure response with visit code
* @throws Exception
*/
@Operation(summary = "Save child adolescent care (CAC) nurse data")
@PostMapping(value = { "/save/nurseData" })
public ResponseEntity<String> saveBenNurseDataCAC(@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 child-adolescent-care nurse data saving :" + requestObj);
String genOPDRes = adolescentAndChildCareService.saveNurseData(jsnOBJ, Authorization);
response.setResponse(genOPDRes);
} else {
response.setResponse("Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
return ResponseEntity.ok(response.toString());
}
@Operation(summary = "Save child adolescent care doctor data")
@PostMapping(value = { "save/doctorData" })
public ResponseEntity<String> saveDoctorDataCAC(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for child-adolescent-care doctor data saving :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
if (jsnOBJ != null) {
int i = adolescentAndChildCareService.saveDoctorDataCAC(jsnOBJ, Authorization);
if (i == 1)
response.setResponse("Data saved successfully");
} else {
response.setError(5000, "Invalid request object : NULL");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary visit details entered by nurse.
* @param comingRequest
* @return visit details in JSON format
*/
@Operation(summary = "Get beneficiary visit details from nurse for child adolescent care")
@PostMapping(value = { "/getBenVisitDetailsFrmNurseCAC" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getBenVisitDetailsFrmNurseCAC(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request obj to fetch CAC visit details :" + 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 = adolescentAndChildCareService.getBenVisitDetailsFrmNurseCAC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid Request Data.");
response.setError(5000, "Invalid request : missing visit information");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("getBenVisitDetailsFrmNurseCAC response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary history details entered by nurse.
* @param comingRequest
* @return history details in JSON format
*/
@Operation(summary = "Get child adolescent care beneficiary history")
@PostMapping(value = { "/getBenHistoryDetails" })
public ResponseEntity<String> getBenHistoryDetails(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody CommonUtilityClass commonUtilityClass)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("getBenHistoryDetails request:" + commonUtilityClass.toString());
if (commonUtilityClass.getBenRegID() != null) {
String s = adolescentAndChildCareService.getBirthAndImmuniHistory(commonUtilityClass.getBenRegID(),
commonUtilityClass.getVisitCode());
response.setResponse(s);
} else {
response.setError(5000, "Invalid request : missing ben information");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("getBenHistoryDetails response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary vital details entered by nurse.
* @param comingRequest
* @return vital details in JSON format
*/
@Operation(summary = "Get child adolescent care beneficiary vitals from nurse")
@PostMapping(value = { "/getBenVitalDetailsFrmNurse" })
public ResponseEntity<String> getBenVitalDetailsFrmNurse(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("getBenVitalDetailsFrmNurse request:" + 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 = adolescentAndChildCareService.getBeneficiaryVitalDetails(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid Request Data.");
response.setError(5000, "Invalid request : visit information missing");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("getBenVitalDetailsFrmNurse response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary immunization service entered by nurse.
* @param { "benRegID": "274685", "benVisitID": "171431", "visitCode":
* "30022000171431" }
* @return immunization service details in JSON format
*/
@Operation(summary = "Get child adolescent care beneficiary immunization details")
@PostMapping(value = { "/getBenImmunizationServiceDetails" })
public ResponseEntity<String> getBenImmunizationServiceDetails(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody CommonUtilityClass commonUtilityClass)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("getBenImmunizationServiceDetails request:" + commonUtilityClass.toString());
if (commonUtilityClass.getBenRegID() != null && commonUtilityClass.getVisitCode() != null) {
String s = adolescentAndChildCareService.getBeneficiaryImmunizationServiceDetails(
commonUtilityClass.getBenRegID(), commonUtilityClass.getVisitCode());
response.setResponse(s);
} else {
response.setError(5000, "Invalid request : missing ben information");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("getBenImmunizationServiceDetails response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Fetching beneficiary doctor details.
* @param comingRequest
* @return doctor details in JSON format
*/
@Operation(summary = "Get child adolescent care beneficiary details entered by doctor")
@PostMapping(value = { "/getBenCaseRecordFromDoctor" })
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> getBenCaseRecordFromDoctor(
@Param(value = "{\"benRegID\":\"Long\",\"visitCode\":\"Long\"}") @RequestBody String comingRequest)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("getBenCaseRecordFromDoctor CAC request:" + 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 = adolescentAndChildCareService.getBenCaseRecordFromDoctorCAC(benRegID, visitCode);
response.setResponse(res);
} else {
logger.info("Invalid Request Data.");
response.setError(5000, "Invalid request");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.toString());
}
logger.info("getBenCaseRecordFromDoctor CAC response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Updating beneficiary vital details entered by nurse.
* @param comingRequest
* @return vital details in JSON format
*/
@Operation(summary = "Update child adolescent care beneficiary vitals")
@PostMapping(value = { "/update/vitalScreen" })
public ResponseEntity<String> updateVitalNurseCAC(@RequestBody String requestObj) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for CAC Vital data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int i = adolescentAndChildCareService.updateBenVitalDetailsCAC(jsnOBJ);
if (i == 1) {
response.setResponse("Data updated successfully");
} else {
response.setError(500, "Unable to modify data, please contact administrator");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response.toString());
}
logger.info("CAC vital data update Response:" + response);
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Updating beneficiary history details entered by nurse.
* @param comingRequest
* @return history details in JSON format
*/
@Operation(summary = "Update birth and immunization history")
@PostMapping(value = { "/update/BirthAndImmunizationHistoryScreen" })
public ResponseEntity<String> updateBirthAndImmunizationHistoryNurse(@RequestBody String requestObj)
throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for CAC data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int i = adolescentAndChildCareService.updateBenHistoryDetails(jsnOBJ);
if (i > 0)
response.setResponse("data updated successfully");
else
throw new IEMRException("error in updating data. please contact administrator");
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Updating beneficiary immunization service entered by nurse.
* @param { "benRegID": "274685", "benVisitID": "171431", "visitCode":
* "30022000171431" }
* @return immunization service details in JSON format
*/
@Operation(summary = "Update immunization service data")
@PostMapping(value = { "/update/ImmunizationServicesScreen" })
public ResponseEntity<String> updateImmunizationServicesNurse(@RequestBody String requestObj) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for CAC data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
int i = adolescentAndChildCareService.updateBenImmunServiceDetailsCAC(jsnOBJ);
if (i > 0)
response.setResponse("data updated successfully");
else
throw new IEMRException("error in updating data, please contact administrator");
return ResponseEntity.ok(response.toString());
}
/**
* @Objective Updating beneficiary doctor details.
* @param comingRequest
* @return doctor details in JSON format
*/
@Operation(summary = "Update child adolescent care doctor data")
@PostMapping(value = { "/update/doctorData" })
public ResponseEntity<String> updateCACDoctorData(@RequestBody String requestObj,
@RequestHeader(value = "Authorization") String Authorization) throws Exception {
OutputResponse response = new OutputResponse();
logger.info("Request object for doctor data updating :" + requestObj);
JsonObject jsnOBJ = JsonParser.parseString(requestObj).getAsJsonObject();
Long result = adolescentAndChildCareService.updateDoctorDataCAC(jsnOBJ, Authorization);
if (null != result && result > 0) {
response.setResponse("Data updated successfully");
} else
throw new IEMRException("error in updating data - NULL");
logger.info("Doctor data update response:" + response);
return ResponseEntity.ok(response.toString());
}
}