Repository navigation
fix: return correct HTTP status codes and remove patient data logging in GeneralOPDController - #211
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
📝 Walkthrough
🚥 Pre-merge checks | ✅ 5
✨ Finishing Touches
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. |
|
hiii...
|
|
This issue is a core design desicion,recommend to wait until approval of approaches from atleast now,if not this may waste lots of time on unwanted things and makes things messy.. |
|
Hi @sharma-sugurthi, thanks for looking at this! The JSON parsing point is valid -> moving it inside the try block On scope, that was intentional -> one method to validate the approach On tests -> fair, I'll add one verifying the ResponseEntity return. And agreed on waiting for architectural sign-off before going further. @drtechie -- whenever you get a chance, happy to hear your thoughts |
vanitha1822
left a comment
There was a problem hiding this comment.
Need to have change from HWC-UI
…in GeneralOPDController
Malformed or non-object JSON now returns a structured 400 response instead of an uncaught exception. Tests cover success (200), service failure (500 with visit rollback), malformed JSON (400) and non-object JSON (400).
e3250b8 to
0cb91e3
Compare
|
@vanitha1822 the UI side is in PSMRI/HWC-UI#290. Once this returns real HTTP status codes, a failed nurse save goes to the error callback, and #290 shows the server's @sharma-sugurthi both of your points are now pushed (rebased on main, 0cb91e3):
|
|



📋 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