feat: add lab tests, patient file management, and prescription improvements
This commit is contained in:
+22
-9
@@ -40,14 +40,27 @@
|
||||
})->name('sync.run');
|
||||
|
||||
Route::get('/admin/backup/download', function () {
|
||||
$data = [
|
||||
'exported_at' => now()->toDateTimeString(),
|
||||
'last_sync_id' => \App\Models\SyncLog::lastSyncId(),
|
||||
'changes' => \App\Models\SyncLog::all()->toArray(),
|
||||
];
|
||||
$filename = 'matab-backup-' . now()->format('Y-m-d_H-i-s') . '.json';
|
||||
return response()->streamDownload(function () use ($data) {
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
}, $filename, ['Content-Type' => 'application/json']);
|
||||
$dbPath = database_path('database.sqlite');
|
||||
|
||||
if (! file_exists($dbPath)) {
|
||||
abort(404, 'Database file not found.');
|
||||
}
|
||||
|
||||
$backupDir = storage_path('app/backups');
|
||||
|
||||
if (! is_dir($backupDir)) {
|
||||
mkdir($backupDir, 0755, true);
|
||||
}
|
||||
|
||||
foreach (glob($backupDir . '/matab-backup-*.sqlite') as $oldFile) {
|
||||
unlink($oldFile);
|
||||
}
|
||||
|
||||
$filename = 'matab-backup-' . now()->format('Y-m-d_H-i-s') . '.sqlite';
|
||||
$backupPath = $backupDir . '/' . $filename;
|
||||
|
||||
copy($dbPath, $backupPath);
|
||||
|
||||
return response()->json(['success' => true, 'filename' => $filename]);
|
||||
})->name('backup.download');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user