import client from '../client'; import type { PaginatedResponse } from '../types'; // --- Types --- export interface VitalSigns { id: string; patient_id: string; record_date: string; systolic_bp_morning?: number; diastolic_bp_morning?: number; systolic_bp_evening?: number; diastolic_bp_evening?: number; heart_rate?: number; weight?: number; blood_sugar?: number; water_intake_ml?: number; urine_output_ml?: number; notes?: string; created_at: string; updated_at: string; version: number; } export interface CreateVitalSignsReq { record_date: string; systolic_bp_morning?: number; diastolic_bp_morning?: number; systolic_bp_evening?: number; diastolic_bp_evening?: number; heart_rate?: number; weight?: number; blood_sugar?: number; water_intake_ml?: number; urine_output_ml?: number; notes?: string; } export interface LabReport { id: string; patient_id: string; report_date: string; report_type: string; indicators?: Record; image_urls?: string[]; doctor_interpretation?: string; created_at: string; updated_at: string; version: number; } export interface CreateLabReportReq { report_date: string; report_type: string; indicators?: Record; image_urls?: string[]; doctor_interpretation?: string; } export interface HealthRecord { id: string; patient_id: string; record_type: string; record_date: string; content?: string; attachment_urls?: string[]; created_at: string; updated_at: string; version: number; } export interface CreateHealthRecordReq { record_type: string; record_date: string; content?: string; attachment_urls?: string[]; } export interface TrendData { id: string; patient_id: string; indicator: string; trend_data: { date: string; value: number }[]; generated_at: string; } // --- API --- export const healthDataApi = { // Vital Signs listVitalSigns: async ( patientId: string, params: { page?: number; page_size?: number }, ) => { const { data } = await client.get<{ success: boolean; data: PaginatedResponse; }>(`/health/patients/${patientId}/vital-signs`, { params }); return data.data; }, createVitalSigns: async (patientId: string, req: CreateVitalSignsReq) => { const { data } = await client.post<{ success: boolean; data: VitalSigns; }>(`/health/patients/${patientId}/vital-signs`, req); return data.data; }, updateVitalSigns: async ( patientId: string, id: string, req: Partial & { version: number }, ) => { const { data } = await client.put<{ success: boolean; data: VitalSigns; }>(`/health/patients/${patientId}/vital-signs/${id}`, req); return data.data; }, deleteVitalSigns: async (patientId: string, id: string) => { await client.delete(`/health/patients/${patientId}/vital-signs/${id}`); }, // Lab Reports listLabReports: async ( patientId: string, params: { page?: number; page_size?: number }, ) => { const { data } = await client.get<{ success: boolean; data: PaginatedResponse; }>(`/health/patients/${patientId}/lab-reports`, { params }); return data.data; }, createLabReport: async (patientId: string, req: CreateLabReportReq) => { const { data } = await client.post<{ success: boolean; data: LabReport; }>(`/health/patients/${patientId}/lab-reports`, req); return data.data; }, updateLabReport: async ( patientId: string, id: string, req: Partial & { version: number }, ) => { const { data } = await client.put<{ success: boolean; data: LabReport; }>(`/health/patients/${patientId}/lab-reports/${id}`, req); return data.data; }, deleteLabReport: async (patientId: string, id: string) => { await client.delete(`/health/patients/${patientId}/lab-reports/${id}`); }, // Health Records listHealthRecords: async ( patientId: string, params: { page?: number; page_size?: number }, ) => { const { data } = await client.get<{ success: boolean; data: PaginatedResponse; }>(`/health/patients/${patientId}/health-records`, { params }); return data.data; }, createHealthRecord: async ( patientId: string, req: CreateHealthRecordReq, ) => { const { data } = await client.post<{ success: boolean; data: HealthRecord; }>(`/health/patients/${patientId}/health-records`, req); return data.data; }, updateHealthRecord: async ( patientId: string, id: string, req: Partial & { version: number }, ) => { const { data } = await client.put<{ success: boolean; data: HealthRecord; }>(`/health/patients/${patientId}/health-records/${id}`, req); return data.data; }, deleteHealthRecord: async (patientId: string, id: string) => { await client.delete(`/health/patients/${patientId}/health-records/${id}`); }, // Trends listTrends: async (patientId: string) => { const { data } = await client.get<{ success: boolean; data: TrendData[]; }>(`/health/patients/${patientId}/trends`); return data.data; }, generateTrend: async (patientId: string) => { const { data } = await client.post<{ success: boolean; data: TrendData[]; }>(`/health/patients/${patientId}/trends/generate`); return data.data; }, getIndicatorTimeseries: async (patientId: string, indicator: string) => { const { data } = await client.get<{ success: boolean; data: { date: string; value: number }[]; }>(`/health/patients/${patientId}/trends/${encodeURIComponent(indicator)}`); return data.data; }, // Mini program endpoints getMiniTrend: async (params: { indicator?: string; days?: number }) => { const { data } = await client.get<{ success: boolean; data: { date: string; value: number }[]; }>('/health/vital-signs/trend', { params }); return data.data; }, getMiniToday: async () => { const { data } = await client.get<{ success: boolean; data: VitalSigns | null; }>('/health/vital-signs/today'); return data.data; }, };