feat: initialize Dr-Panel project with patient file number support
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\LabTest;
|
||||
use App\Models\Patient;
|
||||
use App\Models\Prescription;
|
||||
use Illuminate\Http\Request;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
class PrescriptionPrintController extends Controller
|
||||
{
|
||||
public function print(Request $request, Prescription $prescription)
|
||||
{
|
||||
$prescription->load('patientRecord');
|
||||
$type = $request->query('type', 'prescription');
|
||||
|
||||
$labContent = $prescription->lab_content ?? '';
|
||||
$labLines = [];
|
||||
if ($labContent) {
|
||||
preg_match_all('/<li[^>]*>(.*?)<\/li>/s', $labContent, $m);
|
||||
$labLines = $m[1] ?? [];
|
||||
if (empty($labLines)) {
|
||||
$cleaned = preg_replace('/<br\s*\/?>/i', "\n", $labContent);
|
||||
$labLines = explode("\n", strip_tags($cleaned));
|
||||
}
|
||||
$labLines = array_values(array_filter(
|
||||
array_map(fn ($l) => html_entity_decode(trim(strip_tags($l)), ENT_QUOTES, 'UTF-8'), $labLines)
|
||||
));
|
||||
}
|
||||
|
||||
return view('prints.prescription', [
|
||||
'prescription' => $prescription,
|
||||
'type' => $type,
|
||||
'labLines' => $labLines,
|
||||
]);
|
||||
}
|
||||
|
||||
public function printAdmission(Prescription $prescription)
|
||||
{
|
||||
$prescription->load('patientRecord');
|
||||
|
||||
$patient = $prescription->patientRecord;
|
||||
$appointment = $patient?->surgeryAppointment?->load('surgeryCenter');
|
||||
$centerName = '';
|
||||
$surgeryDate = '';
|
||||
|
||||
if ($appointment) {
|
||||
try {
|
||||
$surgeryDate = Jalalian::fromCarbon($appointment->surgery_date)->format('Y/m/d');
|
||||
} catch (\Throwable) {
|
||||
$surgeryDate = $appointment->surgery_date?->format('Y-m-d') ?? '';
|
||||
}
|
||||
$centerName = $appointment->surgeryCenter?->name ?? '';
|
||||
}
|
||||
|
||||
return view('prints.prescription-admission', [
|
||||
'prescription' => $prescription,
|
||||
'centerName' => $centerName,
|
||||
'surgeryDate' => $surgeryDate,
|
||||
]);
|
||||
}
|
||||
|
||||
public function printPatientLab(Patient $patient)
|
||||
{
|
||||
return view('prints.patient-lab', [
|
||||
'patient' => $patient,
|
||||
'issueDate' => Jalalian::now()->format('Y/m/d'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function printSurgeryAdmission(Patient $patient)
|
||||
{
|
||||
$appointment = $patient->surgeryAppointment?->load('surgeryCenter');
|
||||
|
||||
$surgeryDate = '';
|
||||
$centerName = '';
|
||||
|
||||
if ($appointment) {
|
||||
try {
|
||||
$surgeryDate = Jalalian::fromCarbon($appointment->surgery_date)->format('Y/m/d');
|
||||
} catch (\Throwable) {
|
||||
$surgeryDate = $appointment->surgery_date?->format('Y-m-d') ?? '';
|
||||
}
|
||||
$centerName = $appointment->surgeryCenter?->name ?? '';
|
||||
}
|
||||
|
||||
return view('prints.surgery-admission', [
|
||||
'patient' => $patient,
|
||||
'surgeryDate' => $surgeryDate,
|
||||
'centerName' => $centerName,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\OsurgInitial;
|
||||
use App\Models\SyncLog;
|
||||
use App\Services\SyncService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class SyncController extends Controller
|
||||
{
|
||||
protected function verifyToken(Request $request): bool
|
||||
{
|
||||
$token = OsurgInitial::val('sync_token', config('sync.token'));
|
||||
return $token !== '' && $request->header('X-Sync-Token') === $token;
|
||||
}
|
||||
|
||||
public function export(Request $request): JsonResponse
|
||||
{
|
||||
if (! $this->verifyToken($request)) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$since = $request->query('since') ?: null;
|
||||
|
||||
return response()->json([
|
||||
'changes' => SyncLog::changesSince($since),
|
||||
]);
|
||||
}
|
||||
|
||||
public function apply(Request $request): JsonResponse
|
||||
{
|
||||
if (! $this->verifyToken($request)) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$service = SyncService::fromConfig();
|
||||
$report = $service->applyChanges($request->input('changes', []));
|
||||
|
||||
return response()->json(['report' => $report]);
|
||||
}
|
||||
|
||||
public function downloadFile(Request $request): mixed
|
||||
{
|
||||
if (! $this->verifyToken($request)) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$path = $request->query('path');
|
||||
if (! $path || ! Storage::disk('public')->exists($path)) {
|
||||
return response()->json(['error' => 'File not found'], 404);
|
||||
}
|
||||
|
||||
return Storage::disk('public')->download($path);
|
||||
}
|
||||
|
||||
public function receiveFile(Request $request): JsonResponse
|
||||
{
|
||||
if (! $this->verifyToken($request)) {
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$path = $request->input('path');
|
||||
$file = $request->file('file');
|
||||
|
||||
if (! $path || ! $file) {
|
||||
return response()->json(['error' => 'Missing path or file'], 400);
|
||||
}
|
||||
|
||||
$path = ltrim(str_replace(['..', '\\'], ['', '/'], $path), '/');
|
||||
|
||||
Storage::disk('public')->put($path, file_get_contents($file->getRealPath()));
|
||||
|
||||
return response()->json(['success' => true, 'path' => $path]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user