Files
kartoteka/app/Http/Controllers/MedicalHistoryController.php
2025-12-29 17:08:26 +09:00

54 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Resources\ArchiveHistoryResource;
use App\Http\Resources\ArchiveInfoResource;
use App\Http\Resources\PatientInfoResource;
use App\Http\Resources\SI\SttMedicalHistoryResource;
use App\Models\ArchiveInfo;
use App\Models\SI\SttMedicalHistory as SiSttMedicalHistory;
use App\Models\Mis\SttMedicalHistory as MisSttMedicalHistory;
use App\Repositories\MedicalHistoryRepository;
use Illuminate\Http\Request;
class MedicalHistoryController extends Controller
{
public function patient($id, Request $request)
{
$viewType = $request->get('view_type', 'mis');
$patientId = $request->get('patient_id');
if ($viewType == 'foxpro') $patient = SiSttMedicalHistory::where('keykarta', $id)->first();
else $patient = MisSttMedicalHistory::where('MedicalHistoryID', $id)->first();
if($patient instanceof MisSttMedicalHistory) {
if ($patient->archiveHistory->count() === 0) {
$foxproCardId = $patient->archiveInfo->foxpro_history_id;
$foxproPatient = SiSttMedicalHistory::where('keykarta', $foxproCardId)->first();
$journalHistory = $foxproPatient->archiveHistory;
} else {
$journalHistory = $patient->archiveHistory;
}
} else {
$journalHistory = $patient->archiveHistory;
}
$archiveInfo = $patient->archiveInfo ? $patient->archiveInfo : null;
$patientInfo = [
'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
'info' => [
'historyable_type' => $viewType == 'foxpro' ? SiSttMedicalHistory::class : MisSttMedicalHistory::class,
...PatientInfoResource::make($patient)->toArray(request()),
'can_be_issued' => $patient->canBeIssued()
],
'journal' => ArchiveHistoryResource::collection($journalHistory),
'archiveInfo' => $archiveInfo ? ArchiveInfoResource::make($archiveInfo) : null
];
return response()->json($patientInfo);
}
}