fix(generalOPD): replace RuntimeException with IEMRException and add unit tests#209
Conversation
…unit tests - Replace all bare RuntimeException/Exception throws in saveNurseData, saveDoctorData, and updateGeneralOPDDoctorData with descriptive IEMRException - Update GeneralOPDService interface to explicitly declare IEMRException - Add 14 unit tests for NCDScreeningServiceImpl (all 6 screening save methods) - Add 9 unit tests for IemrMmuLoginServiceImpl (all 4 login methods) - All 23 new tests pass (0 failures, 0 errors)
|
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 (2)
📝 WalkthroughWalkthroughThis PR standardizes exception handling in GeneralOPD service operations by replacing generic ChangesGeneralOPD Exception Handling Standardization
New Test Coverage for Login and NCD Screening Services
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/test/java/com/iemr/hwc/service/login/IemrMmuLoginServiceImplTest.java (1)
91-97: ⚡ Quick winPrefer structural JSON assertions over
String.contains(...)checks.These checks are fragile; parsing the response and asserting key presence/value types will make tests more reliable against formatting/noise changes while still validating behavior.
Also applies to: 123-127, 152-157, 180-185
🤖 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/test/java/com/iemr/hwc/service/login/IemrMmuLoginServiceImplTest.java` around lines 91 - 97, The test uses fragile String.contains assertions for the response from getUserServicePointVanDetails; instead parse the result into a JSON object (e.g., Jackson ObjectMapper -> JsonNode) and replace the assertTrue(result.contains(...)) checks with structural assertions such as node.has("userVanDetails"), node.has("userSpDetails"), node.has("parkingPlaceLocationList") and, where appropriate, assert the expected node types (array/object) or values; apply the same change pattern to the other similar assertions mentioned (the blocks around lines 123-127, 152-157, 180-185) in IemrMmuLoginServiceImplTest so tests validate JSON structure rather than string formatting.src/test/java/com/iemr/hwc/service/ncdscreening/NCDScreeningServiceImplTest.java (1)
173-247: ⚡ Quick winAdd missing
null idfailure-path tests for remaining save methods.Line 173 onward covers
repo returns nullfor oral/breast/cervical/cbac, but not thesave()returns entity withnullid` scenario that you already test for diabetes/hypertension. Add that case for parity and regression protection.🤖 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/test/java/com/iemr/hwc/service/ncdscreening/NCDScreeningServiceImplTest.java` around lines 173 - 247, Add tests that cover the "repo returns entity with null id" failure path for saveOralCancerDetails, saveBreastCancerDetails, saveCervicalDetails and saveCbacDetails (similar to the diabetes/hypertension null-id tests). For each method, mock the corresponding repo (oralCancerScreeningRepo, breastCancerScreeningRepo, cervicalCancerScreeningRepo, cbacDetailsRepo) to return the entity instance whose getId() returns null, then assertThrows(IEMRException.class, () -> ncdScreeningService.saveXxxDetails(...)) and verify the exception message matches the existing failure messages ("Error while saving oral screening", "Error while saving breast cancer screening", "Error while saving cervical screening", "Error while saving Cbac details"). Ensure you add one test per save method using the same naming pattern as the other tests.
🤖 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.
Inline comments:
In `@src/main/java/com/iemr/hwc/service/generalOPD/GeneralOPDServiceImpl.java`:
- Line 814: The null-input branch in saveDoctorData currently returns a null
saveSuccessFlag; instead throw new IEMRException("Invalid input") when
requestOBJ == null to honor the declared exception contract and keep behavior
deterministic; update the similar null-input branch later in the file (the
corresponding doctor save/update method around the second occurrence) to throw
the same IEMRException rather than returning null so both code paths
consistently signal invalid input.
- Line 1450: The method updateGeneralOPDDoctorData currently returns a null
updateSuccessFlag when requestOBJ is null; instead detect a missing/null
requestOBJ at the top of updateGeneralOPDDoctorData and throw an IEMRException
with a clear message (e.g., "Missing doctor update input") rather than returning
null; apply the same change to the other update method in this class that
follows the same pattern (the later update method that also returns
updateSuccessFlag) so any null requestOBJ consistently raises IEMRException.
---
Nitpick comments:
In `@src/test/java/com/iemr/hwc/service/login/IemrMmuLoginServiceImplTest.java`:
- Around line 91-97: The test uses fragile String.contains assertions for the
response from getUserServicePointVanDetails; instead parse the result into a
JSON object (e.g., Jackson ObjectMapper -> JsonNode) and replace the
assertTrue(result.contains(...)) checks with structural assertions such as
node.has("userVanDetails"), node.has("userSpDetails"),
node.has("parkingPlaceLocationList") and, where appropriate, assert the expected
node types (array/object) or values; apply the same change pattern to the other
similar assertions mentioned (the blocks around lines 123-127, 152-157, 180-185)
in IemrMmuLoginServiceImplTest so tests validate JSON structure rather than
string formatting.
In
`@src/test/java/com/iemr/hwc/service/ncdscreening/NCDScreeningServiceImplTest.java`:
- Around line 173-247: Add tests that cover the "repo returns entity with null
id" failure path for saveOralCancerDetails, saveBreastCancerDetails,
saveCervicalDetails and saveCbacDetails (similar to the diabetes/hypertension
null-id tests). For each method, mock the corresponding repo
(oralCancerScreeningRepo, breastCancerScreeningRepo,
cervicalCancerScreeningRepo, cbacDetailsRepo) to return the entity instance
whose getId() returns null, then assertThrows(IEMRException.class, () ->
ncdScreeningService.saveXxxDetails(...)) and verify the exception message
matches the existing failure messages ("Error while saving oral screening",
"Error while saving breast cancer screening", "Error while saving cervical
screening", "Error while saving Cbac details"). Ensure you add one test per save
method using the same naming pattern as the other tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5120f863-bbaf-462c-925f-7cb655fb54de
📒 Files selected for processing (4)
src/main/java/com/iemr/hwc/service/generalOPD/GeneralOPDService.javasrc/main/java/com/iemr/hwc/service/generalOPD/GeneralOPDServiceImpl.javasrc/test/java/com/iemr/hwc/service/login/IemrMmuLoginServiceImplTest.javasrc/test/java/com/iemr/hwc/service/ncdscreening/NCDScreeningServiceImplTest.java
IEMRException extends Exception so declaring both is a SonarQube code smell. Revert interface/impl throws clauses to Exception while keeping IEMRException as the thrown type in the method bodies for specificity.
…and updateGeneralOPDDoctorData
Replace the silent null-return else branch with IEMRException("Invalid input")
so callers receive a meaningful error instead of a null Long, consistent with
the exception contract already declared on both methods.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|



Summary
RuntimeExceptionand genericExceptionthrows with domain-specificIEMRExceptionin General OPD serviceTest plan
NCDScreeningServiceImplTest— all 14 tests passIemrMmuLoginServiceImplTest— all 9 tests passsaveNurseData,saveDoctorData,updateGeneralOPDDoctorDatathrowIEMRExceptionon failure instead of leaking as unhandled 500 errors