Files
clinicpro/migrations/Version20260718184932.php
T
hamed b3a5cda808 Refactor insurance share calculation logic in PatientService
- Consolidated the calculation of patient and insurance shares into a single method using BillingCalculator.
- Introduced new fields in PatientSession to store breakdown of insurance shares and patient share.
- Updated the API responses to include the new fields for consistency across payment, invoice, and claims dashboard.
- Added migration to backfill existing sessions with appropriate values for the new fields.
- Implemented tests to ensure the correctness of the new logic and verify that the breakdown sums to the gross total.
- Redesigned the claims dashboard to provide a more user-friendly overview of patient claims and their statuses.
2026-07-18 22:56:46 +03:30

48 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Persist the insurance share breakdown on patient sessions so the payment page,
* the invoice modal and the claims dashboard all read the same numbers instead of
* each deriving their own.
*/
final class Version20260718184932 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add insurance share breakdown columns to patient_sessions';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE patient_sessions '
. 'ADD gross_total_rials INT DEFAULT 0 NOT NULL, '
. 'ADD base_insurance_rials INT DEFAULT 0 NOT NULL, '
. 'ADD supplementary_insurance_rials INT DEFAULT 0 NOT NULL, '
. 'ADD patient_share_rials INT DEFAULT 0 NOT NULL');
// Existing sessions were computed without an insurance breakdown: the whole
// amount was the patient's share. Backfilling this way keeps their totals unchanged.
$this->addSql('UPDATE patient_sessions SET '
. 'patient_share_rials = final_price_rials, '
. 'gross_total_rials = final_price_rials, '
. 'base_insurance_rials = 0, '
. 'supplementary_insurance_rials = 0');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE patient_sessions '
. 'DROP gross_total_rials, '
. 'DROP base_insurance_rials, '
. 'DROP supplementary_insurance_rials, '
. 'DROP patient_share_rials');
}
}