care icon indicating copy to clipboard operation
care copied to clipboard

Data points for patient level report builder

Open nandkishorr opened this issue 1 week ago • 2 comments

Proposed Changes

  • Added Data points For Patient Level Report

Patient details,active account,invoices,charge items,payment reconciliations

Architecture changes

  • Remove this section if not used

Merge Checklist

  • [ ] Tests added/fixed
  • [ ] Update docs in /docs
  • [ ] Linting Complete
  • [ ] Any other necessary step

Only 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

  • New Features
    • Discharge Bill report type now available for patients
    • Enhanced reporting capabilities with account-level data including invoices, charge items, and payment reconciliation tracking
    • Improved patient context in reports with comprehensive account and billing information
    • Streamlined authorization for discharge bill access

✏️ Tip: You can customize this high-level summary in your review settings.

nandkishorr avatar Dec 16 '25 20:12 nandkishorr

📝 Walkthrough

Walkthrough

This PR adds invoice filter cleanup, introduces authorization and context builder infrastructure for patient and account reports, registers two new report types (patient summary and account report), and implements comprehensive data point context builders for accounts, invoices, charge items, payment reconciliations, and monetary components.

Changes

Cohort / File(s) Summary
Invoice Filter Removal
care/emr/api/viewsets/invoice.py
Removed the encounter__external_id UUID filter from InvoiceFilters.
Authorization Authorizers
care/emr/reports/authorizers/patient.py, care/emr/reports/authorizers/account.py
Added two new authorizer classes: PatientReportAuthorizer (delegates to can_view_clinical_data and can_write_patient_obj) and AccountReportAuthorizer (delegates to can_read_account_in_facility and can_update_account_in_facility).
Authorization Exports
care/emr/reports/authorizers/__init__.py
Exported AccountReportAuthorizer and PatientReportAuthorizer; reformatted DischargeSummaryReportAuthorizer import.
Report Type Registry
care/emr/reports/report_types.py
Registered two new report types: patient_summary (Patient + PatientReportAuthorizer) and account_report (Account + AccountReportAuthorizer).
Context Builder Module Exports
care/emr/reports/context_builder/__init__.py
Added re-exports from patient and account data_points modules alongside existing encounter exports.
Account Data Points
care/emr/reports/context_builder/data_points/account.py
Introduced BaseAccountContextBuilder and AccountContextBuilder with 15 fields (name, status, billing_status, description, totals, components, invoices, charge items, payment reconciliations, dates), plus PatientAccountContextBuilder subclass.
Patient Data Points
care/emr/reports/context_builder/data_points/patient.py
Added PatientContextBuilderBase extending SingleObjectContextBuilder with name, gender, age, and accounts fields; registered with DataPointRegistry.
Invoice Data Points
care/emr/reports/context_builder/data_points/invoice.py
Introduced InvoiceReportFilter with status, title, and number filters; defined InvoiceContextBuilder and AccountInvoiceContextBuilder with six fields (title, status, number, total_net, total_gross, total_price_components).
Charge Item Data Points
care/emr/reports/context_builder/data_points/charge_items.py
Added ChargeItemReportFilter and ChargeItemContextBuilder with eight fields; defined AccountChargeItemContextBuilder filtering by account.
Payment Reconciliation Data Points
care/emr/reports/context_builder/data_points/payment_reconciliation.py
Introduced PaymentReconciliationReportFilter and PaymentReconciliationContextBuilder with nine fields (status, type, amount, reference number, kind, credit note flag, issuer type, outcome, method) and display mappings.
Monetary Component Data Points
care/emr/reports/context_builder/data_points/monetary_component.py
Added MonetaryComponentContextBuilder and UnitPriceMonetaryComponentContextBuilder with four fields (type, code, factor, amount) and type display mapping.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Authorization implementations (patient.py, account.py): Verify correct AuthorizationController action names and object retrieval logic
  • Data point context builders (multiple data_points/ files): Examine field definitions, filtering logic, parent_context relationships, and display mappings—especially cross-references between contexts (e.g., AccountContextBuilder→AccountInvoiceContextBuilder, charge items, payment reconciliations)
  • Report type registration (report_types.py): Confirm model imports and correct wiring to authorizer classes
  • Context builder re-exports (__init__.py): Validate that all necessary data point builders are properly exposed

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description covers proposed changes and mentions key data points added, but the merge checklist remains incomplete with unchecked boxes and no evidence of test coverage or documentation updates provided. Provide details on test cases added, documentation updates in /docs, and confirmation that linting passed before merging.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding data points for patient-level report builders, which aligns with the substantial new modules and context builders introduced.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch datapoint/patient

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 16 '25 20:12 coderabbitai[bot]

Codecov Report

:x: Patch coverage is 90.28571% with 17 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 74.72%. Comparing base (d423145) to head (d75afa0).

Files with missing lines Patch % Lines
care/emr/reports/authorizers/account.py 63.63% 4 Missing :warning:
care/emr/reports/authorizers/patient.py 63.63% 4 Missing :warning:
...emr/reports/context_builder/data_points/account.py 94.44% 2 Missing :warning:
...eports/context_builder/data_points/charge_items.py 92.30% 2 Missing :warning:
...emr/reports/context_builder/data_points/invoice.py 91.30% 2 Missing :warning:
.../context_builder/data_points/monetary_component.py 83.33% 2 Missing :warning:
...text_builder/data_points/payment_reconciliation.py 96.55% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3419      +/-   ##
===========================================
+ Coverage    74.60%   74.72%   +0.12%     
===========================================
  Files          449      457       +8     
  Lines        20646    20819     +173     
  Branches      2141     2141              
===========================================
+ Hits         15402    15558     +156     
- Misses        4782     4799      +17     
  Partials       462      462              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 16 '25 20:12 codecov[bot]