Project

General

Profile

Actions

Feature #344

open
NP NP

Canteen: Patient charges Task 1 -- fix DietChargeAccrualJobs hospital-scoping bug

Feature #344: Canteen: Patient charges Task 1 -- fix DietChargeAccrualJobs hospital-scoping bug

Added by Navya P. about 1 month ago. Updated about 1 month ago.

Status:
Resolved
Priority:
Normal
Assignee:
Target version:
-
Start date:
10/12/2026
Due date:
% Done:

0%

Estimated time:
Resolved By:

Description

DietChargeAccrualService.PostAsync reads hospitalId from CurrentHospitalId (IHospitalContext, HttpContext-based), but DietChargeAccrualJob has no HttpContext -- every accrual the job writes gets HospitalId 0, and every Billing call inside PostAsync runs with hospitalId 0 too, so GetChargeByCodeAsync almost certainly finds nothing and PostAsync throws DietChargeNotConfigured, silently caught per-order, every cycle, forever. Found while tracing the Patient charges read path on 2026-10-12.

Fix: extract the jobs per-hospital loop body into IDietChargeAccrualService.AccrueActiveOrdersAsync(DateOnly serviceDate, ct), which reads CurrentHospitalId like every other method on the service (works correctly once the caller sets it). DietChargeAccrualJob pushes a synthetic HttpContext.Items["CurrentHospitalId"] per hospital before calling it, per iteration -- the exact pattern nuvita-ipd/BedDayChargeJob.cs already uses for the identical problem. One method then serves both the nightly job and the portals manual post-pending button (#next task) -- no duplicate loop.

Test fix: DietChargeAccrualJobTests.cs currently registers a fixed IHospitalContext stub (TestDoubles.HospitalContext), which is exactly what masks this bug -- rewrite its harness to use the real HospitalContext + IHttpContextAccessor (mirrors nuvita-ipd BedDayChargeJobTests), so the regression test actually fails before the fix and passes after.

NP Updated by Navya P. about 1 month ago Actions #1

  • Status changed from New to In Progress

NP Updated by Navya P. about 1 month ago Actions #2

  • Status changed from In Progress to Resolved
  • Resolved By set to Navya P.

Done. Extracted AccrueActiveOrdersAsync onto IDietChargeAccrualService; DietChargeAccrualJob now pushes a synthetic HttpContext per hospital (mirrors nuvita-ipd BedDayChargeJob). Rewrote DietChargeAccrualJobTests.cs to use the real HospitalContext + IHttpContextAccessor; new two-hospital regression test verified by hand to fail without the fix (0 accruals instead of 2) and pass with it. 563 unit + 813/815 integration (2 pre-existing unrelated Coupon_liability failures). nuvita-canteen-management@b98e924, pushed to integration/canteen-v1.

NP Updated by Navya P. about 1 month ago Actions #3

  • Assignee set to Navya P.
Actions

Also available in: PDF Atom