90 lines
3.8 KiB
PHP
90 lines
3.8 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
/**
|
|
* Class SoapNote
|
|
* Clinical SOAP Note & Assessment Model (VAS Pain Score, ROM, Digital Signature)
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class SoapNote extends Model
|
|
{
|
|
protected string $table = 'soap_notes';
|
|
|
|
/**
|
|
* Find SOAP Note by Queue ID
|
|
*/
|
|
public function findByQueueId(int $queueId): ?array
|
|
{
|
|
return $this->firstWhere(['queue_id' => $queueId]);
|
|
}
|
|
|
|
/**
|
|
* Get Clinical History for Patient
|
|
*/
|
|
public function getPatientHistory(int $patientId, int $limit = 20): array
|
|
{
|
|
$sql = "SELECT s.*, q.queue_no, q.queue_date,
|
|
CONCAT(u.title, u.first_name, ' ', u.last_name) AS therapist_name,
|
|
svc.name_th AS service_name
|
|
FROM `{$this->table}` s
|
|
JOIN `queues` q ON s.queue_id = q.id
|
|
LEFT JOIN `therapists` t ON s.therapist_id = t.id
|
|
LEFT JOIN `users` u ON t.user_id = u.id
|
|
LEFT JOIN `services` svc ON q.service_id = svc.id
|
|
WHERE s.patient_id = :pid
|
|
ORDER BY q.queue_date DESC, s.id DESC
|
|
LIMIT :lim";
|
|
$stmt = self::getDB()->prepare($sql);
|
|
$stmt->bindValue(':pid', $patientId, \PDO::PARAM_INT);
|
|
$stmt->bindValue(':lim', $limit, \PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* Save Clinical Assessment & Sign Consent
|
|
*/
|
|
public function storeAssessment(array $data): int
|
|
{
|
|
$existing = $this->findByQueueId((int)$data['queue_id']);
|
|
if ($existing) {
|
|
$this->update((int)$existing['id'], [
|
|
'subjective_symptoms' => $data['subjective_symptoms'] ?? null,
|
|
'objective_signs' => $data['objective_signs'] ?? null,
|
|
'pre_pain_score' => isset($data['pre_pain_score']) ? (int)$data['pre_pain_score'] : null,
|
|
'post_pain_score' => isset($data['post_pain_score']) ? (int)$data['post_pain_score'] : null,
|
|
'pre_rom' => $data['pre_rom'] ?? null,
|
|
'post_rom' => $data['post_rom'] ?? null,
|
|
'assessment_diag' => $data['assessment_diag'] ?? null,
|
|
'treatment_plan' => $data['treatment_plan'] ?? null,
|
|
'thai_med_outcome' => $data['thai_med_outcome'] ?? 'Stable',
|
|
'digital_signature_url' => $data['digital_signature_url'] ?? null,
|
|
'patient_consent_signed_at' => !empty($data['digital_signature_url']) ? date('Y-m-d H:i:s') : null,
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
return (int)$existing['id'];
|
|
}
|
|
|
|
return $this->create([
|
|
'queue_id' => (int)$data['queue_id'],
|
|
'patient_id' => (int)$data['patient_id'],
|
|
'therapist_id' => (int)$data['therapist_id'],
|
|
'doctor_id' => !empty($data['doctor_id']) ? (int)$data['doctor_id'] : null,
|
|
'subjective_symptoms' => $data['subjective_symptoms'] ?? null,
|
|
'objective_signs' => $data['objective_signs'] ?? null,
|
|
'pre_pain_score' => isset($data['pre_pain_score']) ? (int)$data['pre_pain_score'] : null,
|
|
'post_pain_score' => isset($data['post_pain_score']) ? (int)$data['post_pain_score'] : null,
|
|
'pre_rom' => $data['pre_rom'] ?? null,
|
|
'post_rom' => $data['post_rom'] ?? null,
|
|
'assessment_diag' => $data['assessment_diag'] ?? null,
|
|
'treatment_plan' => $data['treatment_plan'] ?? null,
|
|
'thai_med_outcome' => $data['thai_med_outcome'] ?? 'Stable',
|
|
'digital_signature_url' => $data['digital_signature_url'] ?? null,
|
|
'patient_consent_signed_at' => !empty($data['digital_signature_url']) ? date('Y-m-d H:i:s') : null,
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
}
|