fix(session): show and keep the doctor's insurance when editing an encounter
The encounter edit form asked for contracts in the panel's own environment, so inside a clinic it got an empty list: no insurance to choose, and the one already recorded on the encounter had no matching option to display. It now scopes the request by the encounter's doctor, the same way the confirm modal does, which is why the session payload's existing doctor_uuid is threaded through. Saving the form had the matching defect on the server. Recalculating the totals looked up the coverage percentage against the record's tenant rather than the contract's, so a single save on a correctly-billed encounter zeroed the insurance share and moved the whole amount back onto the patient. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -111,6 +111,34 @@ class ClinicAppointmentUsesDoctorContractTest extends ApiTestCase
|
||||
self::assertSame(990_000, $claims[0]->getTotalClaimedRials());
|
||||
}
|
||||
|
||||
/**
|
||||
* ویرایش دستیِ همان مراجعه هم نباید سهم بیمه را دور بیندازد: فرم ویرایش سرویسها
|
||||
* کل مبلغ را دوباره حساب میکند و اگر درصد را از محیط اشتباه بگیرد، مراجعهای که
|
||||
* درست ساخته شده بود با یک ذخیرهٔ ساده خراب میشود.
|
||||
*/
|
||||
public function testEditingTheSessionKeepsTheInsuranceShare(): void
|
||||
{
|
||||
[$owner, $doctor, $clinic, $insurance] = $this->scenario(30);
|
||||
$appointment = $this->appointment($doctor, $clinic, $insurance);
|
||||
|
||||
$session = static::getContainer()->get(PatientService::class)
|
||||
->autoCreateOnAppointmentConfirm($appointment);
|
||||
|
||||
$this->authJson('PATCH', '/api/v1/session/' . $session->getUuid(), $owner, [
|
||||
'visit_price_rials' => self::VISIT_PRICE,
|
||||
]);
|
||||
self::assertSame(200, $this->responseCode());
|
||||
|
||||
// درخواستِ کرنل روی EntityManager دیگری نوشت، پس ردیف دوباره خوانده میشود.
|
||||
$row = $this->em->getConnection()->fetchAssociative(
|
||||
'SELECT base_insurance_rials, patient_share_rials FROM patient_sessions WHERE uuid = ?',
|
||||
[$session->getUuid()],
|
||||
);
|
||||
|
||||
self::assertSame(990_000, (int) $row['base_insurance_rials']);
|
||||
self::assertSame(2_310_000, (int) $row['patient_share_rials']);
|
||||
}
|
||||
|
||||
/** نوبتِ بدون قرارداد، مثل قبل کاملاً سهم بیمار میماند. */
|
||||
public function testAnAppointmentWithoutAnyContractStillBillsThePatientInFull(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user