feat: add lab tests, patient file management, and prescription improvements
This commit is contained in:
@@ -301,6 +301,53 @@ public function deletePatientMessages(string $phoneNumber, string $surgeryDate):
|
||||
}
|
||||
}
|
||||
|
||||
public static function cancelAppointmentMessages(string $phoneNumber, string $localSurgeryDate): void
|
||||
{
|
||||
try {
|
||||
$apiKey = \App\Models\OsurgInitial::val('sms_api_key', config('sms.api_key'));
|
||||
$apiUrl = \App\Models\OsurgInitial::val('sms_api_url', config('sms.api_url'));
|
||||
$localDate = \Carbon\Carbon::parse($localSurgeryDate)->format('Y-m-d');
|
||||
|
||||
$grouped = Http::timeout(10)
|
||||
->withHeader('X-API-Key', $apiKey)
|
||||
->get($apiUrl . '/sms-logs-grouped', [
|
||||
'phoneNumber' => $phoneNumber,
|
||||
'limit' => 200,
|
||||
])
|
||||
->json('data') ?? [];
|
||||
|
||||
$serverSurgeryDate = null;
|
||||
foreach ($grouped as $group) {
|
||||
if (($group['phone_number'] ?? '') !== $phoneNumber) {
|
||||
continue;
|
||||
}
|
||||
$groupDate = $group['surgery_date'] ?? '';
|
||||
if (! $groupDate) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (\Carbon\Carbon::parse($groupDate)->format('Y-m-d') === $localDate) {
|
||||
$serverSurgeryDate = $groupDate;
|
||||
break;
|
||||
}
|
||||
} catch (\Throwable) {}
|
||||
}
|
||||
|
||||
if (! $serverSurgeryDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
Http::timeout(10)
|
||||
->withHeader('X-API-Key', $apiKey)
|
||||
->asJson()
|
||||
->post($apiUrl . '/sms-logs/delete-patient', [
|
||||
'phoneNumber' => $phoneNumber,
|
||||
'surgeryDate' => $serverSurgeryDate,
|
||||
]);
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
}
|
||||
|
||||
public function toJalali(?string $dateStr, string $format = 'Y/m/d H:i'): string
|
||||
{
|
||||
if (! $dateStr) {
|
||||
|
||||
@@ -5,14 +5,17 @@
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\SyncLog;
|
||||
use App\Services\OsurgImportService;
|
||||
use App\Services\SyncService;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Livewire\WithFileUploads;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
class SyncPage extends Page
|
||||
{
|
||||
use WithFileUploads;
|
||||
protected string $view = 'filament.pages.sync-page';
|
||||
|
||||
protected static ?int $navigationSort = 99;
|
||||
@@ -37,7 +40,11 @@ public static function getNavigationGroup(): ?string
|
||||
return __('navigation.groups.system');
|
||||
}
|
||||
|
||||
public string $report = '';
|
||||
public string $report = '';
|
||||
public string $importReport = '';
|
||||
public bool $importing = false;
|
||||
|
||||
public $sqlFile = null;
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
@@ -64,6 +71,14 @@ public function getLastSyncTime(): string
|
||||
return Jalalian::fromCarbon($last->datetime->timezone('Asia/Tehran'))->format('Y/m/d H:i:s');
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'sqlFile' => ['required', 'file', 'max:307200'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
@@ -109,6 +124,37 @@ public function runSync(): void
|
||||
->send();
|
||||
}
|
||||
|
||||
|
||||
public function startImport(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$this->importing = true;
|
||||
|
||||
try {
|
||||
@set_time_limit(600);
|
||||
|
||||
$tmpPath = $this->sqlFile->getRealPath();
|
||||
|
||||
$service = new OsurgImportService();
|
||||
$result = $service->import($tmpPath);
|
||||
|
||||
$this->importReport = implode("\n", $result['report']);
|
||||
|
||||
Notification::make()
|
||||
->title($result['success']
|
||||
? __('navigation.import.success')
|
||||
: __('navigation.import.failed'))
|
||||
->body(__('navigation.sync.see_report'))
|
||||
->color($result['success'] ? 'success' : 'danger')
|
||||
->send();
|
||||
} finally {
|
||||
$this->sqlFile = null;
|
||||
$this->importing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function downloadBackup(): \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
{
|
||||
$data = [
|
||||
|
||||
Reference in New Issue
Block a user