fix: return correct HTTP status codes and remove patient data logging in GeneralOPDController#211
Conversation
…in GeneralOPDController
📝 WalkthroughWalkthroughThe ChangesNurse OPD Save Endpoint
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/iemr/hwc/controller/generalOPD/GeneralOPDController.java (1)
84-109:⚠️ Potential issue | 🟠 Major | ⚡ Quick winMove JSON parsing inside the try-catch block.
requestObjis parsed at lines 91–92 before thetryblock (which starts at line 94), so malformed JSON or non-object payloads throwJsonSyntaxExceptionorIllegalStateExceptionbefore reaching the error handler. These exceptions propagate uncaught and return a default 500 error instead of the structured error response. Wrap the parse andgetAsJsonObject()calls inside the try-catch so exceptions are caught and handled viaresponse.setError(), then properly serialized bytoStringWithHttpStatus().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/com/iemr/hwc/controller/generalOPD/GeneralOPDController.java` around lines 84 - 109, The JSON parsing (JsonParser/JsonElement and jsnOBJ = jsnElmnt.getAsJsonObject()) must be moved inside the existing try block in saveBenGenOPDNurseData so JsonSyntaxException/IllegalStateException are caught and turned into a structured error via response.setError(...) before returning response.toStringWithHttpStatus(); ensure jsnOBJ is declared outside the try so it can still be passed to generalOPDServiceImpl.deleteVisitDetails(jsnOBJ) in the catch, and do not let parsing occur prior to the try that would bypass the error handler.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/main/java/com/iemr/hwc/controller/generalOPD/GeneralOPDController.java`:
- Around line 84-109: The JSON parsing (JsonParser/JsonElement and jsnOBJ =
jsnElmnt.getAsJsonObject()) must be moved inside the existing try block in
saveBenGenOPDNurseData so JsonSyntaxException/IllegalStateException are caught
and turned into a structured error via response.setError(...) before returning
response.toStringWithHttpStatus(); ensure jsnOBJ is declared outside the try so
it can still be passed to generalOPDServiceImpl.deleteVisitDetails(jsnOBJ) in
the catch, and do not let parsing occur prior to the try that would bypass the
error handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 723aa9f4-e80d-4aa5-8a6e-b48def05add8
📒 Files selected for processing (1)
src/main/java/com/iemr/hwc/controller/generalOPD/GeneralOPDController.java
|
Hi @drtechie and @sharma-sugurthi
This is intentionally scoped to one method as a proof of concept. |



📋 Description
Proof of concept fix for the HTTP status code and patient data logging issues identified in PSMRI/AMRIT#153.
Problem 1: Always HTTP 200
Every controller method returned
Stringinstead ofResponseEntity, meaning the HTTP status was always 200 — even on failures. The error details were buried in the JSON body, forcing clients to parse the body to detect failures instead of using standard HTTP semantics. The fix already existed —OutputResponse.toStringWithHttpStatus()was implemented but never used. This PR uses it.Problem 2: Patient data in logs
Every controller logged the full raw
requestObjat INFO level. These request bodies contain patient vitals, medical history, examination details and prescriptions. INFO logs are always-on in production — meaning sensitive patient data was being stored in plain text logs. Replaced with a generic log message containing no patient data.Fixes: PSMRI/AMRIT#153
✅ Type of Change
ℹ️ Additional Information
Scope: One method in GeneralOPDController as proof of concept.
Changes made:
String→ResponseEntity<String>response.toString()→response.toStringWithHttpStatus()Next steps if approved:
@ControllerAdviceglobal exception handlerSummary by CodeRabbit