fix: enforce unique national ID validation and fix sync updated_at corruption
This commit is contained in:
@@ -195,7 +195,15 @@ public static function form(Schema $schema): Schema
|
||||
TextInput::make('icno')
|
||||
->label(__('patients.fields.icno'))
|
||||
->required()
|
||||
->maxLength(11),
|
||||
->maxLength(11)
|
||||
->unique(
|
||||
table: Patient::class,
|
||||
column: 'icno',
|
||||
ignorable: fn ($record) => $record,
|
||||
)
|
||||
->validationMessages([
|
||||
'unique' => __('patients.validation.icno_unique'),
|
||||
]),
|
||||
|
||||
TextInput::make('hand_phone')
|
||||
->label(__('patients.fields.hand_phone'))
|
||||
@@ -807,7 +815,7 @@ public static function table(Table $table): Table
|
||||
->iconColor(fn ($state) => $state ? 'success' : 'gray')
|
||||
->placeholder('-'),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->defaultSort('updated_at', 'desc')
|
||||
->recordActions([
|
||||
Action::make('surgeryAppointment')
|
||||
->label(__('patients.actions.surgery_appointment'))
|
||||
|
||||
@@ -26,81 +26,6 @@ public function checkPeerStatus(): void
|
||||
$this->peerPath = $result['path'];
|
||||
$this->peerChecked = true;
|
||||
}
|
||||
public function runBackup(): void
|
||||
{
|
||||
$dbPath = database_path('database.sqlite');
|
||||
|
||||
if (! file_exists($dbPath)) {
|
||||
Notification::make()
|
||||
->title(__('navigation.backup.failed'))
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$timestamp = now()->format('Y-m-d_H-i-s');
|
||||
$zipFilename = "matab-backup-{$timestamp}.zip";
|
||||
$zipPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $zipFilename;
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
|
||||
Notification::make()
|
||||
->title(__('navigation.backup.failed'))
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$noCompressExts = [
|
||||
'jpg', 'jpeg', 'png', 'gif', 'webp',
|
||||
'mp4', 'mov', 'avi', 'mkv', 'webm',
|
||||
'mp3', 'wav', 'ogg', 'opus', 'm4a',
|
||||
'zip', 'gz', 'rar', '7z',
|
||||
];
|
||||
|
||||
$addFile = function (string $realPath, string $zipEntry) use ($zip, $noCompressExts): void {
|
||||
$zip->addFile($realPath, $zipEntry);
|
||||
$index = $zip->locateName($zipEntry);
|
||||
$ext = strtolower(pathinfo($realPath, PATHINFO_EXTENSION));
|
||||
if (in_array($ext, $noCompressExts, true)) {
|
||||
$zip->setCompressionIndex($index, \ZipArchive::CM_STORE);
|
||||
} else {
|
||||
$zip->setCompressionIndex($index, \ZipArchive::CM_DEFLATE, 9);
|
||||
}
|
||||
};
|
||||
|
||||
$addFile($dbPath, 'database/database.sqlite');
|
||||
|
||||
$publicPath = storage_path('app/public');
|
||||
foreach (['files', 'initials'] as $folder) {
|
||||
$folderPath = $publicPath . '/' . $folder;
|
||||
if (! is_dir($folderPath)) {
|
||||
continue;
|
||||
}
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($folderPath, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::LEAVES_ONLY
|
||||
);
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile()) {
|
||||
$relativePath = str_replace('\\', '/', substr($file->getPathname(), strlen($folderPath) + 1));
|
||||
$addFile($file->getPathname(), $folder . '/' . $relativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
session(['backup_tmp_path' => $zipPath, 'backup_tmp_name' => $zipFilename]);
|
||||
|
||||
$this->dispatch('backup-ready', url: route('backup.download'));
|
||||
|
||||
Notification::make()
|
||||
->title(__('navigation.backup.success'))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
public function runSync(): void
|
||||
{
|
||||
$service = SyncService::fromConfig();
|
||||
|
||||
@@ -13,6 +13,7 @@ class Visit extends Model
|
||||
{
|
||||
use HasUserStamps;
|
||||
|
||||
protected $touches = ['patientRecord'];
|
||||
protected $fillable = [
|
||||
'patient',
|
||||
'visit_date',
|
||||
|
||||
@@ -38,8 +38,10 @@ public function updated(Model $model): void
|
||||
}
|
||||
|
||||
$changedData = [];
|
||||
foreach ($dirty as $field => $newValue) {
|
||||
$changedData[$field] = $model->getAttribute($field);
|
||||
foreach ($dirty as $field => $rawValue) {
|
||||
$changedData[$field] = $rawValue instanceof \BackedEnum
|
||||
? $rawValue->value
|
||||
: (is_object($rawValue) ? (string) $rawValue : $rawValue);
|
||||
}
|
||||
|
||||
SyncLog::create([
|
||||
|
||||
Reference in New Issue
Block a user