json([ ...$archiveHistory->toArray(), 'type' => $archiveHistory->historyType() ]); } public function moveStore(Request $request) { $data = $request->validate([ 'issue_at' => ['nullable', new DateTimeOrStringOrNumber], 'return_at' => ['nullable', new DateTimeOrStringOrNumber], 'org_id' => 'required|numeric', 'employee_name' => 'nullable|string', 'employee_post' => 'nullable|string', 'comment' => 'nullable|string', 'has_lost' => 'boolean', 'history_id' => 'required', 'type' => 'required|string', ]); // Преобразуем timestamp в дату, если пришли числа if (isset($data['issue_at']) && is_numeric($data['issue_at'])) { $data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at']) ->setTimezone(config('app.timezone')) ->format('Y-m-d'); } if (isset($data['return_at']) && is_numeric($data['return_at'])) { $data['return_at'] = Carbon::createFromTimestampMs($data['return_at']) ->setTimezone(config('app.timezone')) ->format('Y-m-d'); } if ($data['type'] === 'mis') { $patient = \App\Models\Mis\SttMedicalHistory::where('MedicalHistoryID', $data['history_id'])->first(); } else { $patient = \App\Models\Si\SttMedicalHistory::where('keykarta', $data['history_id'])->first(); } // $archiveInfo = ArchiveInfo::whereId($data['archive_info_id'])->first(); if ($data['type'] === 'mis') { $archiveHistory = $patient->archiveHistory()->create([ 'issue_at' => $data['issue_at'], 'return_at' => $data['return_at'], 'org_id' => $data['org_id'], 'employee_name' => $data['employee_name'], 'employee_post' => $data['employee_post'], 'comment' => $data['comment'], 'has_lost' => $data['has_lost'], 'mis_history_id' => $patient->MedicalHistoryID ]); } else { $archiveHistory = $patient->archiveHistory()->create([ 'issue_at' => $data['issue_at'], 'return_at' => $data['return_at'], 'org_id' => $data['org_id'], 'employee_name' => $data['employee_name'], 'employee_post' => $data['employee_post'], 'comment' => $data['comment'], 'has_lost' => $data['has_lost'], 'foxpro_history_id' => $patient->keykarta, ]); } return response()->json(ArchiveHistoryResource::make($archiveHistory)); } public function moveUpdate($id, Request $request) { $data = $request->validate([ 'issue_at' => ['nullable', new DateTimeOrStringOrNumber], 'return_at' => ['nullable', new DateTimeOrStringOrNumber], 'org_id' => 'required|numeric', 'employee_name' => 'nullable|string', 'employee_post' => 'nullable|string', 'comment' => 'nullable|string', 'has_lost' => 'boolean', 'type' => 'required|string', ]); // Преобразуем timestamp в дату, если пришли числа if (isset($data['issue_at']) && is_numeric($data['issue_at'])) { $data['issue_at'] = Carbon::createFromTimestampMs($data['issue_at']) ->setTimezone(config('app.timezone')) ->format('Y-m-d'); } if (isset($data['return_at']) && is_numeric($data['return_at'])) { $data['return_at'] = Carbon::createFromTimestampMs($data['return_at']) ->setTimezone(config('app.timezone')) ->format('Y-m-d'); } $archiveHistory = ArchiveHistory::find($id); $hasUpdated = $archiveHistory->update($data); return response()->json(ArchiveHistoryResource::make($archiveHistory)); } public function infoUpdate($patientId, Request $request) { $data = $request->validate([ 'id' => 'required|numeric', 'num' => 'nullable|string', 'post_in' => ['nullable', new DateTimeOrStringOrNumber], 'status' => 'nullable', 'type' => 'nullable' ]); // Преобразуем timestamp в дату, если пришли числа if (isset($data['post_in']) && is_numeric($data['post_in'])) { $data['post_in'] = Carbon::createFromTimestampMs($data['post_in'])->format('Y-m-d'); } $archiveInfo = ArchiveInfo::whereId($data['id'])->first(); $archiveInfo->update( [ 'archive_num' => $data['num'], 'post_in' => $data['post_in'], ] ); return response()->json()->setStatusCode(200); } }