feat(patient): implement record number pattern management

- Add RecordNumberSettingsController for managing patient record number patterns.
- Create RecordNumberPattern entity to represent the pattern configuration.
- Implement RecordNumberPatternRepository for database interactions.
- Develop RecordNumberGenerator service for generating and validating record numbers.
- Add tests for record number generation, backfilling, and API interactions.
- Ensure proper access control for viewing and updating patterns based on user roles.
This commit is contained in:
hamed
2026-08-04 12:30:17 +03:30
parent 9b8eef9598
commit 85a27812c7
24 changed files with 2009 additions and 19 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* الگوی شمارهٔ پروندهٔ هر محیط + شمارندهٔ همان الگو.
*
* `diff` دو تغییر بی‌ربط را هم برداشته بود (جدول `messenger_messages` که خودِ
* transport می‌سازد، و rename یک ایندکس روی `clinic_resources` که drift قبلی است)؛
* هر دو حذف شدند تا این migration فقط همین قابلیت را حمل کند.
*/
final class Version20260804082035 extends AbstractMigration
{
public function getDescription(): string
{
return 'Per-tenant patient record number pattern with its own counter';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE TABLE record_number_patterns (
id INT AUTO_INCREMENT NOT NULL,
entity_type VARCHAR(10) NOT NULL,
entity_id INT NOT NULL,
enabled TINYINT DEFAULT 0 NOT NULL,
pattern VARCHAR(60) NOT NULL,
reset_policy VARCHAR(10) DEFAULT 'none' NOT NULL,
counter INT DEFAULT 0 NOT NULL,
counter_period VARCHAR(7) DEFAULT NULL,
updated_at INT NOT NULL,
UNIQUE INDEX uniq_record_number_pattern (entity_type, entity_id),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4
SQL);
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE record_number_patterns');
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* یکتایی شمارهٔ پرونده در هر محیط.
*
* پیش از اجرا روی دادهٔ واقعی بررسی شد که شمارهٔ تکراری وجود ندارد. چند `NULL` در
* unique index مجاز است، پس پرونده‌های بی‌شماره (که تا پیش از این قابلیت اکثریت‌اند)
* مانع نمی‌شوند.
*/
final class Version20260804082400 extends AbstractMigration
{
public function getDescription(): string
{
return 'Unique patient record number per tenant';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE UNIQUE INDEX uniq_patient_record_number ON patient_records (entity_type, entity_id, record_number)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX uniq_patient_record_number ON patient_records');
}
}