soapModel = new SoapNote(); } /** * POST /api/v1/clinical/soap - Store or Update SOAP Note with VAS Pain Score & ROM */ public function storeSoap(): void { $user = JwtAuthMiddleware::handle(); $input = json_decode(file_get_contents('php://input'), true) ?? $_POST; $validator = Validator::make($input, [ 'queue_id' => 'required|numeric', 'patient_id' => 'required|numeric', 'pre_pain_score' => 'vas_score', 'post_pain_score' => 'vas_score', ]); if ($validator->fails()) { Response::error('ข้อมูลการประเมินทางคลินิกไม่ถูกต้อง', 422, $validator->getErrors()); } $input['therapist_id'] = $input['therapist_id'] ?? $user['id']; $noteId = $this->soapModel->storeAssessment($input); AuditLogger::logSoapNote($noteId, (int)$input['queue_id'], (int)$input['patient_id']); // ส่งข้อมูลการรักษากลับไปยังระบบ HIS โรงพยาบาล (new HisConnector())->sendTreatmentResult((int)$input['patient_id'], $input); Response::success('บันทึกเวชระเบียน SOAP Note และส่งข้อมูลเข้า HIS สำเร็จ', [ 'soap_note_id' => $noteId, 'queue_id' => (int)$input['queue_id'], 'status' => 'Saved', ], 201); } /** * GET /api/v1/clinical/patient/{id} - Get Clinical History of Patient */ public function getPatientHistory(int $patientId): void { JwtAuthMiddleware::handle(); $history = $this->soapModel->getPatientHistory($patientId); Response::success('ประวัติการรักษาและเวชระเบียนผู้ป่วย', [ 'patient_id' => $patientId, 'total_records' => count($history), 'history' => $history, ]); } }