import { api } from './request'; // ── Dashboard ────────────────────────────────────── export interface DoctorDashboard { total_patients: number; active_sessions: number; unread_messages: number; pending_follow_ups: number; today_consultations: number; pending_dialysis_review: number; pending_lab_review: number; today_appointments: number; } export async function getDashboard() { return api.get('/health/doctor/dashboard'); } // ── Patient (doctor view) ────────────────────────── export interface PatientItem { id: string; name: string; gender?: string; birth_date?: string; phone?: string; status?: string; tags?: { id: string; name: string; color?: string }[]; last_visit_date?: string; version: number; } export interface PatientDetail extends PatientItem { blood_type?: string; allergy_history?: string; medical_history_summary?: string; emergency_contact_name?: string; emergency_contact_phone?: string; source?: string; notes?: string; } export interface HealthSummary { patient_id: string; latest_vital_signs?: { record_date: string; systolic_bp?: number; diastolic_bp?: number; heart_rate?: number; weight?: number; blood_sugar?: number; } | null; latest_lab_report?: { id: string; report_date: string; report_type: string; abnormal_count?: number; } | null; pending_follow_ups?: number; upcoming_appointments?: number; } export interface PatientTag { id: string; name: string; color?: string; is_system?: boolean; } export async function listPatients(params?: { page?: number; page_size?: number; search?: string; tag_id?: string; }) { return api.get<{ data: PatientItem[]; total: number }>('/health/patients', params); } export async function getPatient(id: string) { return api.get(`/health/patients/${id}`); } export async function getHealthSummary(patientId: string) { return api.get(`/health/patients/${patientId}/health-summary`); } export async function listPatientTags() { return api.get<{ data: PatientTag[]; total: number }>('/health/patient-tags'); } // ── Consultation (doctor view) ───────────────────── export interface ConsultationSession { id: string; patient_id: string; patient_name?: string; doctor_id: string | null; consultation_type: string; status: string; subject: string | null; last_message: string | null; last_message_at: string | null; unread_count_doctor?: number; created_at: string; } export interface ConsultationMessage { id: string; session_id: string; sender_id: string; sender_role: string; content_type: string; content: string; created_at: string; } export async function listSessions(params?: { page?: number; page_size?: number; status?: string; }) { return api.get<{ data: ConsultationSession[]; total: number }>( '/health/consultation-sessions', params, ); } export async function getSession(id: string) { return api.get(`/health/consultation-sessions/${id}`); } export async function listMessages(sessionId: string, params?: { page?: number; page_size?: number; after_id?: string }) { return api.get<{ data: ConsultationMessage[]; total: number }>( `/health/consultation-sessions/${sessionId}/messages`, params, ); } export async function sendMessage(sessionId: string, content: string, contentType = 'text') { return api.post('/health/consultation-messages', { session_id: sessionId, content_type: contentType, content, }); } export async function markSessionRead(sessionId: string) { return api.put(`/health/consultation-sessions/${sessionId}/read`); } export async function closeSession(sessionId: string) { return api.put(`/health/consultation-sessions/${sessionId}/close`); } // ── Follow-up (doctor view) ──────────────────────── export interface FollowUpTask { id: string; patient_id: string; patient_name?: string; assigned_to?: string; follow_up_type: string; planned_date: string; content_template?: string; status: string; created_at: string; version: number; } export interface FollowUpRecord { id: string; task_id: string; executed_by?: string; executed_date: string; result?: string; patient_condition?: string; medical_advice?: string; next_follow_up_date?: string; created_at: string; } export async function listFollowUpTasks(params?: { page?: number; page_size?: number; status?: string; patient_id?: string; }) { return api.get<{ data: FollowUpTask[]; total: number }>('/health/follow-up-tasks', params); } export async function getFollowUpTask(id: string) { return api.get(`/health/follow-up-tasks/${id}`); } export async function updateFollowUpTask(id: string, data: Record, version: number) { return api.put(`/health/follow-up-tasks/${id}`, { ...data, version }); } export async function createFollowUpRecord(taskId: string, data: { result?: string; patient_condition?: string; medical_advice?: string; next_follow_up_date?: string; }) { return api.post(`/health/follow-up-tasks/${taskId}/records`, { task_id: taskId, ...data }); } export async function listFollowUpRecords(params?: { task_id?: string; page?: number }) { return api.get<{ data: FollowUpRecord[]; total: number }>('/health/follow-up-records', params); } // ── Lab Report (doctor view) ─────────────────────── export interface LabReportItem { id: string; report_date: string; report_type: string; status: string; abnormal_count?: number; reviewed_by?: string; reviewed_at?: string; doctor_notes?: string; version: number; } export interface LabReportDetail extends LabReportItem { items?: { name: string; value: number; unit?: string; reference_min?: number; reference_max?: number; is_abnormal?: boolean; }[]; image_urls?: string[]; } export async function listLabReports(patientId: string, params?: { page?: number; page_size?: number }) { return api.get<{ data: LabReportItem[]; total: number }>( `/health/patients/${patientId}/lab-reports`, params, ); } export async function getLabReport(patientId: string, reportId: string) { return api.get(`/health/patients/${patientId}/lab-reports/${reportId}`); } export async function reviewLabReport( patientId: string, reportId: string, data: { doctor_notes?: string; version: number }, ) { return api.put( `/health/patients/${patientId}/lab-reports/${reportId}/review`, data, ); } // ── Appointments (doctor view) ───────────────────── export async function listAppointments(params?: { page?: number; page_size?: number; status?: string; date?: string; }) { return api.get<{ data: any[]; total: number }>('/health/appointments', params); } // ── Statistics ───────────────────────────────────── export interface PatientStats { total_patients: number; new_this_month: number; new_this_week: number; active_this_month: number; } export interface ConsultationStats { total_sessions: number; pending_reply: number; avg_response_time_minutes?: number | null; this_month: number; } export interface FollowUpStats { total_tasks: number; completed: number; pending: number; overdue: number; completion_rate?: number; } export async function getPatientStats() { return api.get('/health/admin/statistics/patients'); } export async function getConsultationStats() { return api.get('/health/admin/statistics/consultations'); } export async function getFollowUpStats() { return api.get('/health/admin/statistics/follow-ups'); } // ── Alerts (doctor view) ──────────────────────────── export interface Alert { id: string; patient_id: string; rule_id: string; severity: string; title: string; detail?: Record; status: string; acknowledged_by?: string; acknowledged_at?: string; resolved_at?: string; created_at: string; version: number; } export async function listAlerts(params?: { patient_id?: string; status?: string; page?: number; page_size?: number; }) { return api.get<{ data: Alert[]; total: number }>('/health/alerts', params); } export async function acknowledgeAlert(id: string, version: number) { return api.put(`/health/alerts/${id}/acknowledge`, { version }); } export async function dismissAlert(id: string, version: number) { return api.put(`/health/alerts/${id}/dismiss`, { version }); } export async function resolveAlert(id: string, version: number) { return api.put(`/health/alerts/${id}/resolve`, { version }); }