|
21 | 21 | */ |
22 | 22 | package com.iemr.hwc.controller.generalOPD; |
23 | 23 |
|
| 24 | +import java.util.ArrayList; |
| 25 | +import java.util.HashMap; |
| 26 | + |
24 | 27 | import org.json.JSONObject; |
25 | 28 | import org.slf4j.Logger; |
26 | 29 | import org.slf4j.LoggerFactory; |
|
35 | 38 | import org.springframework.web.bind.annotation.RequestMethod; |
36 | 39 | import org.springframework.web.bind.annotation.RestController; |
37 | 40 |
|
| 41 | +import com.google.gson.Gson; |
38 | 42 | import com.google.gson.JsonElement; |
39 | 43 | import com.google.gson.JsonObject; |
40 | 44 | import com.google.gson.JsonParser; |
41 | 45 | import com.iemr.hwc.service.generalOPD.GeneralOPDServiceImpl; |
42 | 46 | import com.iemr.hwc.utils.response.OutputResponse; |
43 | 47 |
|
| 48 | +import java.util.ArrayList; |
| 49 | +import java.util.HashMap; |
| 50 | +import java.util.List; |
| 51 | +import java.util.Map; |
| 52 | +import com.google.gson.Gson; |
| 53 | +import com.google.gson.JsonArray; |
| 54 | + |
44 | 55 | import io.swagger.v3.oas.annotations.Operation; |
45 | 56 |
|
46 | 57 | /*** |
@@ -118,7 +129,23 @@ public String saveBenGenOPDDoctorData(@RequestBody String requestObj, |
118 | 129 | if (jsnOBJ != null) { |
119 | 130 | Long genOPDRes = generalOPDServiceImpl.saveDoctorData(jsnOBJ, Authorization); |
120 | 131 | if (null != genOPDRes && genOPDRes > 0) { |
121 | | - response.setResponse("Data saved successfully"); |
| 132 | + // Extract drug IDs from JsonObject |
| 133 | + List<Long> prescribedDrugIDs = new ArrayList<>(); |
| 134 | + if (jsnOBJ.has("savedDrugIDs") && !jsnOBJ.get("savedDrugIDs").isJsonNull()) { |
| 135 | + JsonArray drugIDsArray = jsnOBJ.getAsJsonArray("savedDrugIDs"); |
| 136 | + for (int j = 0; j < drugIDsArray.size(); j++) { |
| 137 | + prescribedDrugIDs.add(drugIDsArray.get(j).getAsLong()); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + // Create response with message and IDs |
| 142 | + Map<String, Object> responseData = new HashMap<>(); |
| 143 | + responseData.put("message", "Data saved successfully"); |
| 144 | + responseData.put("prescribedDrugIDs", prescribedDrugIDs); |
| 145 | + |
| 146 | + Gson gson = new Gson(); |
| 147 | + String responseJson = gson.toJson(responseData); |
| 148 | + response.setResponse(responseJson); |
122 | 149 | } else { |
123 | 150 | response.setResponse("Unable to save data"); |
124 | 151 | } |
@@ -422,7 +449,23 @@ public String updateGeneralOPDDoctorData(@RequestBody String requestObj, |
422 | 449 | try { |
423 | 450 | Long result = generalOPDServiceImpl.updateGeneralOPDDoctorData(jsnOBJ, Authorization); |
424 | 451 | if (null != result && result > 0) { |
425 | | - response.setResponse("Data updated successfully"); |
| 452 | + // Extract drug IDs from JsonObject |
| 453 | + List<Long> prescribedDrugIDs = new ArrayList<>(); |
| 454 | + if (jsnOBJ.has("savedDrugIDs") && !jsnOBJ.get("savedDrugIDs").isJsonNull()) { |
| 455 | + JsonArray drugIDsArray = jsnOBJ.getAsJsonArray("savedDrugIDs"); |
| 456 | + for (int j = 0; j < drugIDsArray.size(); j++) { |
| 457 | + prescribedDrugIDs.add(drugIDsArray.get(j).getAsLong()); |
| 458 | + } |
| 459 | + } |
| 460 | + |
| 461 | + // Create response with message and IDs |
| 462 | + Map<String, Object> responseData = new HashMap<>(); |
| 463 | + responseData.put("message", "Data updated successfully"); |
| 464 | + responseData.put("prescribedDrugIDs", prescribedDrugIDs); |
| 465 | + |
| 466 | + Gson gson = new Gson(); |
| 467 | + String responseJson = gson.toJson(responseData); |
| 468 | + response.setResponse(responseJson); |
426 | 469 | } else { |
427 | 470 | response.setError(500, "Unable to modify data"); |
428 | 471 | } |
|
0 commit comments