-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work on asha update profile and get profile , lmp date #10
base: develop
Are you sure you want to change the base?
Changes from all commits
c1f861c
de16a1d
5d3b666
b8b5cec
6edc661
8b79640
5206cc3
ea65636
0a786a7
ce8674a
b6a2352
ad5c00e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,26 @@ fhir-url=<Enter your socket address here>/fhirapi-v1.0 | |
tm-url=<Enter your socket address here>/tmapi-v1.0 | ||
##--------------------------------------------## Primary db------------------------------------------------------------------- | ||
|
||
spring.datasource.url=<Enter AMRIT DB_IEMR URL here> | ||
spring.datasource.username=<Enter your AMRIT DB_IEMR username> | ||
spring.datasource.password=<Enter your AMRIT DB_IEMR password> | ||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver | ||
server.port=8082 | ||
|
||
spring.datasource.url=jdbc:mysql://localhost:3306/db_iemr | ||
spring.datasource.username=root | ||
spring.datasource.password=YesBank@123# | ||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
|
||
##--------------------------------------------## Secondary db------------------------------------------------------------------- | ||
|
||
secondary.datasource.username=<Enter your DB_REPORTING username> | ||
secondary.datasource.password=<Enter your DB_REPORTING password> | ||
secondary.datasource.url=<Enter DB_REPORTING URL here> | ||
secondary.datasource.driver-class-name=com.mysql.jdbc.Driver | ||
secondary.datasource.url=jdbc:mysql://localhost:3306/db_identity | ||
secondary.datasource.username=root | ||
secondary.datasource.password=YesBank@123# | ||
secondary.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
|
||
springdoc.api-docs.enabled=true | ||
springdoc.swagger-ui.enabled=true | ||
springdoc.swagger-ui.enabled=true | ||
|
||
spring.session.store-type=redis | ||
spring.redis.host=localhost | ||
spring.redis.password=123456 | ||
spring.redis.port=6379 | ||
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Redis configuration needs improvement. The Redis password is weak and the configuration lacks SSL settings.
|
||
jakarta.persistence.schema-generation.database.action=create | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning: Schema generation action set to 'create'. Setting Change this to |
||
spring.jpa.defer-datasource-initialization=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.iemr.flw.controller; | ||
|
||
import com.iemr.flw.domain.iemr.AshaWorker; | ||
import com.iemr.flw.domain.iemr.M_User; | ||
import com.iemr.flw.dto.iemr.UserServiceRoleDTO; | ||
import com.iemr.flw.repo.iemr.UserServiceRoleRepo; | ||
import com.iemr.flw.service.AshaProfileService; | ||
import com.iemr.flw.service.EmployeeMasterInter; | ||
import com.iemr.flw.service.UserService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
@RestController | ||
@RequestMapping(value = "/asha", headers = "Authorization", produces = "application/json") | ||
public class AshaProfileController { | ||
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName()); | ||
@Autowired | ||
AshaProfileService ashaProfileService; | ||
private Map<String,Object> response = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix critical issues in error handling and response management. Several critical issues need to be addressed:
- private Map<String,Object> response = new HashMap<>();
+ private static final Logger logger = LoggerFactory.getLogger(AshaProfileController.class);
@RequestMapping(value = "editProfile", method = { RequestMethod.POST })
public ResponseEntity<Map<String,Object>> editEmployee(@RequestBody AshaWorker editEmployee) {
+ Map<String,Object> response = new HashMap<>();
try {
- System.out.println(editEmployee.toString());
+ logger.debug("Editing employee profile: {}", editEmployee);
AshaWorker editdata1 = ashaProfileService.saveEditData(editEmployee);
response.put("data", editdata1);
response.put("statusCode", 200);
response.put("status", "Success");
response.put("errorMessage", "Success");
+ return ResponseEntity.ok().body(response);
} catch (Exception e) {
logger.error("Unexpected error:", e);
- ResponseEntity.status(500).body(e.getMessage());
+ response.put("statusCode", 500);
+ response.put("status", "Error");
+ response.put("errorMessage", e.getMessage());
+ return ResponseEntity.status(500).body(response);
}
- return ResponseEntity.ok().body(response);
} Also applies to: 39-56 |
||
|
||
@Autowired | ||
private EmployeeMasterInter employeeMasterInter; | ||
@CrossOrigin() | ||
@Operation(summary = "Edit Asha Profile") | ||
|
||
|
||
@RequestMapping(value = "editProfile", method = { RequestMethod.POST }, produces = { | ||
"application/json" },consumes = "application/json" ) | ||
public ResponseEntity<Map<String,Object>> editEmployee(@RequestBody AshaWorker editEmployee) { | ||
|
||
try { | ||
System.out.println(editEmployee.toString()); | ||
|
||
|
||
AshaWorker ashaWorker = ashaProfileService.saveEditData(editEmployee); | ||
response.put("data",ashaWorker); | ||
response.put("statusCode",200); | ||
response.put("status","Success"); | ||
response.put("errorMessage","Success"); | ||
|
||
|
||
|
||
|
||
} catch (Exception e) { | ||
logger.error("Unexpected error:", e); | ||
ResponseEntity.status(500).body(e.getMessage()); | ||
|
||
} | ||
|
||
return ResponseEntity.ok().body(response); | ||
|
||
} | ||
@Operation(summary = "Profile Detail") | ||
@RequestMapping(value = "getProfile",method = RequestMethod.GET ,headers = "Authorization" ) | ||
public ResponseEntity<Map<String,Object>> getProfile(@RequestParam ("employeeId")Integer employeeId){ | ||
try { | ||
AshaWorker ashaWorker = ashaProfileService.getProfileData(employeeId); | ||
if(ashaWorker!=null){ | ||
response.put("data",ashaWorker); | ||
response.put("statusCode",200); | ||
response.put("status","Success"); | ||
response.put("errorMessage","Success"); | ||
}else { | ||
response.put("data",ashaWorker); | ||
response.put("statusCode",200); | ||
response.put("status","Success"); | ||
response.put("errorMessage","Asha profile not found"); | ||
} | ||
|
||
}catch (Exception e) { | ||
logger.error("Unexpected error:", e); | ||
ResponseEntity.status(500).body(e.getMessage()); | ||
|
||
} | ||
|
||
return ResponseEntity.ok().body(response); | ||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,93 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package com.iemr.flw.controller; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.flw.domain.iemr.OtpBeneficiary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.flw.dto.iemr.OTPRequestParsor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.flw.dto.iemr.OtpRequestDTO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.flw.mapper.InputMapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.flw.service.OTPHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.flw.utils.response.OutputResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.lettuce.core.dynamic.annotation.Param; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import io.swagger.v3.oas.annotations.Operation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.json.JSONObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.beans.factory.annotation.Autowired; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.web.bind.annotation.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import javax.ws.rs.core.MediaType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@RestController | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@RequestMapping("/beneficiary") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class BeneficiaryOTPGatewayController { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private OTPHandler otpHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Operation(summary = "Send OTP") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@RequestMapping(value = "/sendOTP", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON,headers = "Authorization") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public String sendOTP(@RequestParam String phoneNumber) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OutputResponse response = new OutputResponse(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String success = otpHandler.sendOTP(phoneNumber); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (success.contains("success")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setResponse(success); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setError(5000, "failure"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("error in sending OTP : " + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setError(5000, "error : " + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+28
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add input validation for phone number. The phone number parameter should be validated before processing to ensure it meets the required format and length. @RequestMapping(value = "/sendOTP", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON,headers = "Authorization")
public String sendOTP(@RequestParam String phoneNumber) {
OutputResponse response = new OutputResponse();
try {
+ if (phoneNumber == null || !phoneNumber.matches("^\\d{10}$")) {
+ response.setError(4000, "Invalid phone number format");
+ return response.toString();
+ }
String success = otpHandler.sendOTP(phoneNumber); π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@CrossOrigin() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Operation(summary = "Validate OTP") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@RequestMapping(value = "/validateOTP", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,headers = "Authorization") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public String validateOTP(@RequestBody OtpRequestDTO requestOBJ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OutputResponse response = new OutputResponse(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// OTPRequestParsor obj = InputMapper.gson().fromJson(requestOBJ, OTPRequestParsor.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JSONObject responseOBJ = otpHandler.validateOTP(requestOBJ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (responseOBJ != null) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setResponse(responseOBJ.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setError(5000, "failure"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("error in validating OTP : " + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setError(5000, "error : " + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+48
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Enhance error handling for OTP validation. The error handling should be more specific and provide better error messages. @RequestMapping(value = "/validateOTP", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,headers = "Authorization")
public String validateOTP(@RequestBody OtpRequestDTO requestOBJ) {
OutputResponse response = new OutputResponse();
try {
+ if (requestOBJ == null) {
+ response.setError(4000, "Invalid request: Request body is missing");
+ return response.toString();
+ }
JSONObject responseOBJ = otpHandler.validateOTP(requestOBJ);
if (responseOBJ != null)
response.setResponse(responseOBJ.toString());
else
- response.setError(5000, "failure");
+ response.setError(5000, "OTP validation failed");
} catch (Exception e) {
logger.error("error in validating OTP : " + e);
- response.setError(5000, "error : " + e);
+ response.setError(5000, "Error during OTP validation: " + e.getMessage());
}
return response.toString(); π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@CrossOrigin() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Operation(summary = "Resend OTP") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@RequestMapping(value = "/resendOTP", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON,headers = "Authorization") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public String resendOTP(@RequestParam String phoneNumber) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OutputResponse response = new OutputResponse(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
String success = otpHandler.resendOTP(phoneNumber); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (success.contains("success")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setResponse(success); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setError(5000, "failure"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("error in re-sending OTP : " + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
response.setError(5000, "error : " + e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response.toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,20 @@ | |
import com.google.gson.Gson; | ||
import com.iemr.flw.dto.identity.GetBenRequestHandler; | ||
import com.iemr.flw.dto.iemr.*; | ||
import com.iemr.flw.service.ChildService; | ||
import com.iemr.flw.service.DeliveryOutcomeService; | ||
import com.iemr.flw.service.InfantService; | ||
import com.iemr.flw.service.MaternalHealthService; | ||
import com.iemr.flw.service.*; | ||
import com.iemr.flw.utils.response.OutputResponse; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
|
||
import jakarta.validation.Valid; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
|
@@ -24,6 +26,8 @@ | |
public class MaternalHealthController { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(CoupleController.class); | ||
@Autowired | ||
FileStorageService fileStorageService; | ||
|
||
@Autowired | ||
private MaternalHealthService maternalHealthService; | ||
|
@@ -108,6 +112,49 @@ public String saveANCVisit(@RequestBody List<ANCVisitDTO> ancVisitDTOs, | |
return response.toString(); | ||
} | ||
|
||
@CrossOrigin() | ||
@Operation(summary = "save ANC visit details with file") | ||
@RequestMapping(value = {"/ancVisit/saveAll"}, method = {RequestMethod.POST}, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}) | ||
public ResponseEntity<OutputResponse> saveANCVisit( | ||
@RequestPart("ancVisitDTOs") @Valid @RequestBody List<ANCVisitDTO> ancVisitDTOs, | ||
@RequestPart(value = "file", required = false) MultipartFile file, | ||
@RequestHeader(value = "Authorization") String Authorization) { | ||
|
||
OutputResponse response = new OutputResponse(); | ||
try { | ||
if (ancVisitDTOs.isEmpty()) { | ||
response.setError(5000, "Invalid/NULL request obj"); | ||
return ResponseEntity.badRequest().body(response); | ||
} | ||
|
||
// Save File if provided | ||
String filePath = null; | ||
if (file != null && !file.isEmpty()) { | ||
filePath = fileStorageService.storeFile(file); // Save the file | ||
} | ||
|
||
// Set the filePath in DTOs | ||
for (ANCVisitDTO dto : ancVisitDTOs) { | ||
dto.setFilePath(filePath); | ||
} | ||
|
||
logger.info("Saving ANC visits with timestamp : " + new Timestamp(System.currentTimeMillis())); | ||
String s = maternalHealthService.saveANCVisit(ancVisitDTOs); | ||
|
||
if (s != null) { | ||
response.setResponse(s); | ||
return ResponseEntity.ok(response); | ||
} else { | ||
response.setError(5000, "Saving ANC data to DB failed"); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); | ||
} | ||
} catch (Exception e) { | ||
logger.error("Error in saving ANC visit details : " + e); | ||
response.setError(5000, "Error in saving ANC visit details: " + e.getMessage()); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); | ||
} | ||
} | ||
Comment on lines
+115
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Validate file content type and size. |
||
|
||
@CrossOrigin() | ||
@Operation(summary = "get anc visit details") | ||
@RequestMapping(value = {"/ancVisit/getAll"}, method = {RequestMethod.POST}) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||
package com.iemr.flw.controller; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import com.iemr.flw.domain.iemr.MicroBirthPlan; | ||||||||||||||||||||||||||||
import com.iemr.flw.service.MicroBirthPlanService; | ||||||||||||||||||||||||||||
import io.swagger.v3.oas.annotations.Operation; | ||||||||||||||||||||||||||||
import org.springframework.beans.factory.annotation.Autowired; | ||||||||||||||||||||||||||||
import org.springframework.http.ResponseEntity; | ||||||||||||||||||||||||||||
import org.springframework.web.bind.annotation.*; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@RestController | ||||||||||||||||||||||||||||
@RequestMapping(value = "/micro-birthPlan",headers = "Authorization", produces = "application/json") | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Consider removing 'headers = "Authorization"' from @RequestMapping. Instead of enforcing Authorization header at the mapping level, consider using Spring Security or an interceptor for authentication/authorization. -@RequestMapping(value = "/micro-birthPlan",headers = "Authorization", produces = "application/json")
+@RequestMapping(value = "/micro-birthPlan", produces = "application/json") π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
public class MicroBirthPlanController { | ||||||||||||||||||||||||||||
@Autowired | ||||||||||||||||||||||||||||
private MicroBirthPlanService service; | ||||||||||||||||||||||||||||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Replace field injection with constructor injection. Field injection using @Autowired is discouraged as it makes the class harder to test and hides dependencies. - @Autowired
- private MicroBirthPlanService service;
+ private final MicroBirthPlanService service;
+
+ public MicroBirthPlanController(MicroBirthPlanService service) {
+ this.service = service;
+ } π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
@CrossOrigin() | ||||||||||||||||||||||||||||
@Operation(summary = "Micro BirthPlan") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@RequestMapping(value = "save",method = RequestMethod.POST) | ||||||||||||||||||||||||||||
public ResponseEntity<MicroBirthPlan> createMicroBirthPlan(@RequestBody MicroBirthPlan birthPlan) { | ||||||||||||||||||||||||||||
return ResponseEntity.ok(service.createMicroBirthPlan(birthPlan)); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Add input validation and proper error handling. The endpoint should validate the input and handle potential errors gracefully. @RequestMapping(value = "save",method = RequestMethod.POST)
- public ResponseEntity<MicroBirthPlan> createMicroBirthPlan(@RequestBody MicroBirthPlan birthPlan) {
- return ResponseEntity.ok(service.createMicroBirthPlan(birthPlan));
+ public ResponseEntity<MicroBirthPlan> createMicroBirthPlan(@Valid @RequestBody MicroBirthPlan birthPlan) {
+ try {
+ MicroBirthPlan created = service.createMicroBirthPlan(birthPlan);
+ return ResponseEntity.ok(created);
+ } catch (Exception e) {
+ return ResponseEntity.badRequest().build();
+ }
} π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@RequestMapping(value = "downSync",method = RequestMethod.GET) | ||||||||||||||||||||||||||||
public ResponseEntity<List<MicroBirthPlan>> getAllMicroBirthPlans() { | ||||||||||||||||||||||||||||
return ResponseEntity.ok(service.getAllMicroBirthPlans()); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@RequestMapping(value = "getAllMicroBirthPlansBy{id}",method = RequestMethod.GET) | ||||||||||||||||||||||||||||
public ResponseEntity<MicroBirthPlan> getMicroBirthPlanById(@PathVariable Long id) { | ||||||||||||||||||||||||||||
return service.getMicroBirthPlanById(id) | ||||||||||||||||||||||||||||
.map(ResponseEntity::ok) | ||||||||||||||||||||||||||||
.orElse(ResponseEntity.notFound().build()); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,7 +32,7 @@ public ResponseEntity<?> getUserDetail(@RequestParam(value = "userId") Integer u | |||||
return new ResponseEntity<>( | ||||||
new ApiResponse(true, null, result), HttpStatus.ACCEPTED); | ||||||
} catch (Exception e) { | ||||||
logger.error("Error in fetching user role, " + e); | ||||||
logger.error("Error in fetching user role, " + e.getMessage()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Improve error logging. Error logging should include the stack trace for better debugging while keeping the user-facing message concise. Apply this diff: - logger.error("Error in fetching user role, " + e.getMessage());
+ logger.error("Error in fetching user role for userId: {}", userId, e); π Committable suggestion
Suggested change
|
||||||
return new ResponseEntity<>( | ||||||
new ApiResponse(false, "Error in fetching user role, " + e.getMessage(), null), HttpStatus.INTERNAL_SERVER_ERROR); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security: Database credentials should not be hardcoded.
Database credentials should be externalized and not committed to version control.
Use environment variables or a secure configuration management system instead of hardcoding credentials.