Files
kartoteka/app/Http/Controllers/MedicalHistoryController.php
brusnitsyn 47543fedba
Some checks failed
Build and Push Docker Image / test (push) Failing after 3s
Build and Push Docker Image / build (push) Has been cancelled
Рефакторинг
2026-02-27 15:36:32 +09:00

54 lines
2.2 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 && $patient->archiveInfo->foxpro_history_id) {
$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' => $journalHistory ? ArchiveHistoryResource::collection($journalHistory) : [],
'archiveInfo' => $archiveInfo ? ArchiveInfoResource::make($archiveInfo) : null
];
return response()->json($patientInfo);
}
}