[ENG-796] fix:added age range validation for monetary component - #3718
[ENG-796] fix:added age range validation for monetary component#3718nandkishorr wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughChangesPatient age validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThe PR strengthens patient-age condition validation.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| care/utils/evaluators/evaluation_metric/patient_age.py | Adds validation that resolves the previously reported inverted-range and unsupported-unit issues without exposing a distinct related failure. |
Reviews (2): Last reviewed commit: "fix:added review changes" | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@care/utils/evaluators/evaluation_metric/patient_age.py`:
- Around line 14-24: Update ValueSpec and RangeSpec to constrain value_type to
the supported units years, months, and days, then add a Pydantic 2 model
validator to RangeSpec that rejects configurations where min exceeds max. Add
validation tests covering unsupported units and inverted ranges.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0aec033b-038c-4825-a935-c9b49fa850ce
📒 Files selected for processing (1)
care/utils/evaluators/evaluation_metric/patient_age.py
There was a problem hiding this comment.
Pull request overview
This PR adds rule-level validation for the patient_age evaluation metric so that condition payloads used in qualified ranges / monetary components are checked earlier during spec validation.
Changes:
- Introduces Pydantic schemas for
patient_agerule payloads. - Adds
PatientAgeMetric.validate_rule()to validateequalityandin_rangecondition structures.
Comments suppressed due to low confidence (1)
care/utils/evaluators/evaluation_metric/patient_age.py:40
- New rule validation paths (
equalityandin_range) aren’t covered by tests. Adding API-level tests for invalidpatient_agecondition payloads (e.g., missing keys,min > max, invalidvalue_type) would help prevent regressions in monetary component / qualified range validation.
@classmethod
def validate_rule(cls, operation, value):
super().validate_rule(operation, value)
if operation == AllowedOperations.equality.value:
ValueSpec.model_validate(value)
elif operation == AllowedOperations.in_range.value:
RangeSpec.model_validate(value)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3718 +/- ##
===========================================
- Coverage 79.45% 79.44% -0.02%
===========================================
Files 480 480
Lines 23215 23240 +25
Branches 2420 2423 +3
===========================================
+ Hits 18446 18463 +17
- Misses 4165 4173 +8
Partials 604 604 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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)
care/utils/evaluators/evaluation_metric/patient_age.py (1)
47-53: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winWire
validate_ruleinto the runtime evaluation path.
interpretation_evaluator.pycallsapply_rule, whileEvaluationMetricBase.apply_ruledispatches directly toevaluate_*and does not invokevalidate_rule. Consequently, inverted ranges and unsupported units can still reach evaluation—the new validation is unfortunately decorative unless this method is called before dispatch. Invokevalidate_rulefromapply_ruleor validate the rule before calling it.🤖 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 `@care/utils/evaluators/evaluation_metric/patient_age.py` around lines 47 - 53, Invoke PatientAgeMetric.validate_rule through the runtime path before rule evaluation: update EvaluationMetricBase.apply_rule, or the caller immediately before it, so validation occurs before dispatching to evaluate_* methods. Preserve the existing apply_rule dispatch behavior while ensuring inverted ranges and unsupported units are rejected before evaluation.
🤖 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 `@care/utils/evaluators/evaluation_metric/patient_age.py`:
- Around line 47-53: Invoke PatientAgeMetric.validate_rule through the runtime
path before rule evaluation: update EvaluationMetricBase.apply_rule, or the
caller immediately before it, so validation occurs before dispatching to
evaluate_* methods. Preserve the existing apply_rule dispatch behavior while
ensuring inverted ranges and unsupported units are rejected before evaluation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e5e389c6-efaf-4564-8ec7-60e72e824851
📒 Files selected for processing (1)
care/utils/evaluators/evaluation_metric/patient_age.py
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
care/utils/evaluators/evaluation_metric/patient_age.py:35
- RangeSpec currently only checks that min <= max; it still allows negative min/max values, which would produce nonsensical age ranges (and can lead to confusing behavior when evaluating rules). Consider rejecting negative values as part of the range validation.
@model_validator(mode="after")
def validate_range(self):
if self.min > self.max:
raise ValueError("min value cannot be greater than max value")
return self
care/utils/evaluators/evaluation_metric/patient_age.py:24
- ValueSpec allows negative exact ages (equality). If the intent is to validate patient ages, it should reject negative values to avoid storing impossible rules.
class ValueSpec(BaseModel):
value: StrictInt
value_type: ValueType = ValueType.years
| @classmethod | ||
| def validate_rule(cls, operation, value): | ||
| super().validate_rule(operation, value) | ||
| if operation == AllowedOperations.equality.value: | ||
| ValueSpec.model_validate(value) | ||
| elif operation == AllowedOperations.in_range.value: | ||
| RangeSpec.model_validate(value) |
Proposed Changes
Associated Issue
Merge Checklist
/docsOnly PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit