fix(generalopd): return correct HTTP status codes and remove PII from logs#210
Conversation
…gs in GeneralOPD Addresses issues PSMRI#153 and PSMRI#115. Problems fixed: - All 8 GeneralOPDController methods returned String (always HTTP 200), even on error. Clients could not distinguish success from failure via HTTP semantics. - Every controller method logged the full raw requestObj at INFO level, exposing patient vitals, history, prescriptions, and examination details in production logs. - OutputResponse.BAD_REQUEST was set to 404 (Not Found) instead of 400. - SWYMED_EXCEPTION and TM_EXCEPTION both used error code 5010, making them indistinguishable in logs and client error handling. Changes: - Refactor all 8 methods to return ResponseEntity<String> using the existing toStringWithHttpStatus() method which was already implemented but unused. - Extend toStringWithHttpStatus() to map USERID/PASSWORD failures to 401, PRIVILEGE_FAILURE to 403, and parsing/object errors to 400, so clients receive semantically correct status codes. - Fix BAD_REQUEST constant from 404 to 400. - Fix TM_EXCEPTION constant from 5010 to 5011 to distinguish it from SWYMED_EXCEPTION. - Remove all logger.info() calls that concatenated raw requestObj (patient data). Error-level logging keeps the exception message only, not request payloads. - Add GlobalExceptionHandler (@RestControllerAdvice) to catch any exception that escapes individual controller try-catch blocks, preventing unstructured 500s. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|


Problem
Three separate but related issues in the GeneralOPD module:
All API endpoints always returned HTTP 200, even on errors.
GeneralOPDControllerwas callingresponse.toString()instead of the existingresponse.toStringWithHttpStatus()method — making it impossible for clients to distinguish success from failure without parsing the response body.Patient PII (vitals, prescriptions, history) was logged at INFO level via raw request-body string concatenation (
logger.info("Request object for ... :" + requestObj)). This violates HIPAA/data-protection principles and would appear in any log aggregation system.OutputResponsehad two constant bugs that caused the above to go unnoticed:BAD_REQUEST = 404(should be400)TM_EXCEPTION = 5010(duplicate ofSWYMED_EXCEPTION; should be5011)Relates to #153, #115
Changes
OutputResponse.javaBAD_REQUESTconstant:404→400TM_EXCEPTIONconstant:5010→5011(now distinct fromSWYMED_EXCEPTION)toStringWithHttpStatus()switch to correctly map all status codes to HTTP responses (400,401,403,500)GeneralOPDController.javaStringtoResponseEntity<String>return response.toString()toreturn response.toStringWithHttpStatus()logger.info("Request object for ... :" + requestObj)linesresponse.setError(5000, "Invalid request")toresponse.setError(OutputResponse.BAD_REQUEST, "Invalid request")logger.error("...: {}", e.getMessage())GlobalExceptionHandler.java(new file)@RestControllerAdviceto catch any exceptions that escape individual controller try-catch blocksIEMRException→ HTTP 401 with structured error bodyException→ HTTP 500 with structured error bodyTest plan
POST /generalOPD/save/nurseDatawith invalid JSON → returns HTTP 400POST /generalOPD/save/nurseDatawith valid data → returns HTTP 200POST /generalOPD/getBenVisitDetailsFrmNurseGOPDwith missing fields → returns HTTP 400OutputResponse.BAD_REQUESTis400in unit testsGlobalExceptionHandlerreturns HTTP 500🤖 Generated with Claude Code