<?php

namespace App\Services;

class ClinicalService
{
    public function recordEncounter(int $visitId, int $patientId, int $practitionerId, array $data): int
    {
        $db = db_connect();
        $db->table('clinical_notes')->insert([
            'visit_id'=>$visitId,'patient_id'=>$patientId,'practitioner_id'=>$practitionerId,
            'subjective'=>$data['subjective'] ?? null,'objective'=>$data['objective'] ?? null,
            'assessment'=>$data['assessment'] ?? null,'plan'=>$data['plan'] ?? null,
            'is_locked'=>0,'created_at'=>date('Y-m-d H:i:s')
        ]);
        (new AuditService())->log('clinical_note.created','clinical_note',(int)$db->insertID(),['visit_id'=>$visitId]);
        return (int)$db->insertID();
    }
}
