Base insurance is a percentage-only rule: patient share is now total minus the base share, and the contract franchise no longer inflates it (franchise stays meaningful for supplementary contracts only). Coverage percentages are managed centrally by admin per service category (outpatient/inpatient, extensible via the ServiceCategory enum). A tenant contract may override a category, otherwise it follows the admin default live — changing the central value immediately applies to every contract that did not override it. - add ServiceCategory enum + GET /api/v1/service-categories as the single source of the category list for every client - add insurance_coverage_defaults (+ GET/PUT admin coverage-defaults endpoints) and expose coverage_defaults on the insurance list and insurance-pricing - add tenant_insurance_category_coverage; tenant-insurances accepts optional category_coverages (needs insurances.update) and returns the effective percentages with their source - add service_items.service_category; visits always resolve as outpatient - drop the reverse-engineered percent from patient_share_rials in MyPatientsPage and align the client-side BillingCalculator mirror in CreateStep Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
91 lines
3.1 KiB
PHP
91 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\ClinicService;
|
|
|
|
use App\ClinicService\Entity\ServiceSection;
|
|
use App\Doctor\Entity\Doctor;
|
|
use App\Tests\ApiTestCase;
|
|
|
|
/**
|
|
* `service_category` classifies a service as outpatient/inpatient; the insurance
|
|
* coverage percentage is resolved per that value. The category list is served by the
|
|
* API so no client hardcodes the enum cases.
|
|
*/
|
|
class ServiceCategoryApiTest extends ApiTestCase
|
|
{
|
|
/** @return array{0: \App\Auth\Entity\User, 1: ServiceSection} */
|
|
private function makeDoctorAndSection(): array
|
|
{
|
|
$owner = $this->createUser(['ROLE_DOCTOR']);
|
|
$doctor = new Doctor($owner, 'دکتر تست نوع خدمت');
|
|
$this->em->persist($doctor);
|
|
$this->em->flush();
|
|
|
|
$section = new ServiceSection('doctor', $doctor->getId(), 'بخش');
|
|
$this->em->persist($section);
|
|
$this->em->flush();
|
|
|
|
return [$owner, $section];
|
|
}
|
|
|
|
public function testCategoryListIsServedByTheApi(): void
|
|
{
|
|
$owner = $this->createUser(['ROLE_DOCTOR']);
|
|
|
|
$body = $this->authJson('GET', '/api/v1/service-categories', $owner);
|
|
|
|
self::assertSame(200, $this->responseCode());
|
|
$keys = array_column($body['data']['data'], 'key');
|
|
self::assertContains('outpatient', $keys);
|
|
self::assertContains('inpatient', $keys);
|
|
}
|
|
|
|
public function testServiceDefaultsToOutpatient(): void
|
|
{
|
|
[$owner, $section] = $this->makeDoctorAndSection();
|
|
|
|
$created = $this->authJson('POST', '/api/v1/service-item', $owner, [
|
|
'section_uuid' => $section->getUuid(),
|
|
'name' => 'ویزیت سرپایی',
|
|
'price_rials' => 1_000,
|
|
]);
|
|
|
|
self::assertSame(201, $this->responseCode());
|
|
self::assertSame('outpatient', $created['data']['service_category']);
|
|
}
|
|
|
|
public function testCategoryIsStoredAndUpdatable(): void
|
|
{
|
|
[$owner, $section] = $this->makeDoctorAndSection();
|
|
|
|
$created = $this->authJson('POST', '/api/v1/service-item', $owner, [
|
|
'section_uuid' => $section->getUuid(),
|
|
'name' => 'جراحی',
|
|
'price_rials' => 5_952_000,
|
|
'service_category' => 'inpatient',
|
|
]);
|
|
self::assertSame(201, $this->responseCode());
|
|
self::assertSame('inpatient', $created['data']['service_category']);
|
|
self::assertSame('خدمات بستری', $created['data']['service_category_label']);
|
|
|
|
$updated = $this->authJson('PATCH', '/api/v1/service-item/' . $created['data']['uuid'], $owner, [
|
|
'service_category' => 'outpatient',
|
|
]);
|
|
self::assertSame(200, $this->responseCode());
|
|
self::assertSame('outpatient', $updated['data']['service_category']);
|
|
}
|
|
|
|
public function testInvalidCategoryIsRejected(): void
|
|
{
|
|
[$owner, $section] = $this->makeDoctorAndSection();
|
|
|
|
$this->authJson('POST', '/api/v1/service-item', $owner, [
|
|
'section_uuid' => $section->getUuid(),
|
|
'name' => 'خدمت نامعتبر',
|
|
'service_category' => 'dental',
|
|
]);
|
|
|
|
self::assertSame(422, $this->responseCode());
|
|
}
|
|
}
|