75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use App\Helpers\Response;
|
|
use App\Helpers\Validator;
|
|
use App\Middleware\JwtAuthMiddleware;
|
|
use App\Models\SoapNote;
|
|
use App\Services\AuditLogger;
|
|
use App\Services\HisConnector;
|
|
|
|
/**
|
|
* Class ClinicalController
|
|
* Clinical Assessment & SOAP Note REST API Controller
|
|
*
|
|
* @package App\Controllers
|
|
*/
|
|
class ClinicalController
|
|
{
|
|
private SoapNote $soapModel;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->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,
|
|
]);
|
|
}
|
|
}
|