fix(patient): populate auto-created session from the confirmed appointment

When an appointment is confirmed, the auto-created PatientSession was saved
empty: session_at null, visit_price_rials 0, no service line items, totals 0.
Now it copies the visit datetime from the appointment slot, the visit price
(falling back to the tenant free-visit price), a SessionService line per
appointment service (price snapshot from the service), and computes
services_total_rials / final_price_rials. Verified end-to-end.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-17 11:38:13 +03:30
co-authored by Claude Fable 5
parent 49b2ca60d7
commit 8c39d720b5
2 changed files with 29 additions and 0 deletions
+27
View File
@@ -131,7 +131,34 @@ class PatientService
}
$session = new PatientSession($record, $appointment);
// زمان مراجعه = زمان واقعی نوبت.
$session->setSessionAt($appointment->getSlotStart());
// هزینه ویزیت: از نوبت، در نبود آن از «قیمت ویزیت آزاد» تنظیمات همین tenant.
$visitPrice = (int) ($appointment->getVisitPriceRials()
?? $this->pricingRepo->findOneForInsurance($entityType, $entityId, null)?->getPatientShareRials()
?? 0);
$session->setVisitPriceRials($visitPrice);
// خطوط هزینه‌ی سرویس (قیمت snapshot از خود سرویس، بدون ورود دستی).
$servicesTotal = 0;
$lines = [];
foreach ($appointment->getServiceItems() as $item) {
$line = new SessionService($session, $item, null, 1);
$lines[] = $line;
$servicesTotal += $line->getLineTotalRials();
}
$session->setServicesTotalRials($servicesTotal);
$session->setFinalPriceRials($servicesTotal + $visitPrice);
$this->sessionRepo->save($session);
foreach ($lines as $line) {
$this->sessionServiceRepo->save($line);
$session->addService($line);
}
}
public function createSession(