An appointment can now carry the insurance it is billed with: the service kind (outpatient/inpatient) and the basic insurance. Confirming it no longer hands the whole amount to the patient — the visit is split through BillingCalculator with the coverage percent of that service kind, and the choice travels to the encounter and the invoice built from it. The enabled service kinds are a tenant-wide setting (all of that tenant's insurances share it), so a tenant covering only one kind is never asked which one: the panel resolves it the same way the server does. - add tenant_service_category_settings + TenantServiceCategoryService, exposed on the existing insurance-pricing endpoint (service_categories, default_service_category); at least one kind must stay enabled - add appointments.insurance_service_category / insurance_base_id with AppointmentInsuranceService validating them against the tenant's own settings and active contracts (basic only), accepted by PATCH and by confirm - snapshot the kind on patient_sessions and invoices; the visit's coverage rule is resolved per kind (services keep using their own ServiceItem.service_category) - lib/insuranceShares becomes the single client-side mirror of BillingCalculator, shared by the confirm modal, the appointment edit page and the session form - surface the selection: confirm modal (with live shares), turns timeline chip, appointment edit page, patient record service card and invoice summary - the session form shows the insurance block whenever the tenant has an active contract and prefills the patient's own insurance, so it can be changed - fix: the confirm modal showed a zero visit price when the appointment had none — it now falls back to the tenant's free-visit price like the server - fix: useServiceCategories read one level too shallow, so Persian labels never arrived and raw enum keys leaked into the contract summary - fix: BlogsPage test asserted the public blogs endpoint after the page moved to the admin one Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
95 lines
3.5 KiB
PHP
95 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Insurance;
|
|
|
|
use App\Insurance\Enum\ServiceCategory;
|
|
use App\Insurance\Service\TenantServiceCategoryService;
|
|
use App\Shared\Exception\AppException;
|
|
use App\Tests\ApiTestCase;
|
|
|
|
/**
|
|
* The tenant-wide switch for insurance service kinds. A tenant with no stored rows
|
|
* keeps every kind enabled, and the last enabled kind can never be turned off.
|
|
*/
|
|
class TenantServiceCategoryServiceTest extends ApiTestCase
|
|
{
|
|
private TenantServiceCategoryService $service;
|
|
private int $entityId;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->service = static::getContainer()->get(TenantServiceCategoryService::class);
|
|
// db_test is never reset — a fresh id per test keeps rows from leaking across cases.
|
|
$this->entityId = random_int(100_000, 999_999);
|
|
}
|
|
|
|
public function testEveryKindIsEnabledWithoutStoredRows(): void
|
|
{
|
|
$this->assertSame(ServiceCategory::values(), $this->service->enabledKeys('doctor', $this->entityId));
|
|
$this->assertNull($this->service->defaultCategory('doctor', $this->entityId));
|
|
}
|
|
|
|
public function testSettingsRowsAlwaysCoverEveryKind(): void
|
|
{
|
|
$rows = $this->service->settingsRows('doctor', $this->entityId);
|
|
|
|
$this->assertSame(ServiceCategory::values(), array_column($rows, 'key'));
|
|
$this->assertSame([true, true], array_column($rows, 'enabled'));
|
|
}
|
|
|
|
public function testSingleEnabledKindBecomesTheDefault(): void
|
|
{
|
|
$this->service->save('doctor', $this->entityId, [
|
|
['key' => 'inpatient', 'enabled' => false],
|
|
]);
|
|
|
|
$this->assertSame(['outpatient'], $this->service->enabledKeys('doctor', $this->entityId));
|
|
$this->assertSame(ServiceCategory::Outpatient, $this->service->defaultCategory('doctor', $this->entityId));
|
|
$this->assertFalse($this->service->isEnabled('doctor', $this->entityId, ServiceCategory::Inpatient));
|
|
}
|
|
|
|
public function testBothEnabledLeavesTheChoiceToTheUser(): void
|
|
{
|
|
$this->service->save('doctor', $this->entityId, [
|
|
['key' => 'outpatient', 'enabled' => true],
|
|
['key' => 'inpatient', 'enabled' => true],
|
|
]);
|
|
|
|
$this->assertNull($this->service->defaultCategory('doctor', $this->entityId));
|
|
}
|
|
|
|
public function testDisablingEveryKindIsRejected(): void
|
|
{
|
|
$this->expectException(AppException::class);
|
|
|
|
$this->service->save('doctor', $this->entityId, [
|
|
['key' => 'outpatient', 'enabled' => false],
|
|
['key' => 'inpatient', 'enabled' => false],
|
|
]);
|
|
}
|
|
|
|
public function testDisablingTheLastRemainingKindIsRejected(): void
|
|
{
|
|
$this->service->save('doctor', $this->entityId, [['key' => 'inpatient', 'enabled' => false]]);
|
|
|
|
$this->expectException(AppException::class);
|
|
$this->service->save('doctor', $this->entityId, [['key' => 'outpatient', 'enabled' => false]]);
|
|
}
|
|
|
|
public function testUnknownKindIsRejected(): void
|
|
{
|
|
$this->expectException(AppException::class);
|
|
|
|
$this->service->save('doctor', $this->entityId, [['key' => 'dental', 'enabled' => true]]);
|
|
}
|
|
|
|
public function testSettingsAreIsolatedPerTenant(): void
|
|
{
|
|
$this->service->save('doctor', $this->entityId, [['key' => 'inpatient', 'enabled' => false]]);
|
|
|
|
$this->assertSame(['outpatient'], $this->service->enabledKeys('doctor', $this->entityId));
|
|
$this->assertSame(ServiceCategory::values(), $this->service->enabledKeys('clinic', $this->entityId));
|
|
}
|
|
}
|