File size: 5,092 Bytes
4d39b50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
*/

// --- CORE & ACCESS ---

export type View = 'dashboard' | 'appointments' | 'find-doctor' | 'health-assistant' | 'accounting' | 'doctor-registration' | 'clinic-management' | 'medical-history';

export type Role = 'owner' | 'doctor' | 'staff' | 'patient';

// New types for clinic settings
export interface OperatingHours {
  monday: { active: boolean; start: string; end: string };
  tuesday: { active: boolean; start: string; end: string };
  wednesday: { active: boolean; start: string; end: string };
  thursday: { active: boolean; start: string; end: string };
  friday: { active: boolean; start: string; end: string };
  saturday: { active: boolean; start: string; end: string };
  sunday: { active: boolean; start: string; end: string };
}

export interface ClinicSettingsData {
  operating_hours: OperatingHours;
  online_booking: {
    enabled: boolean;
    auto_confirm: boolean;
    min_booking_notice_hours: number;
    cancellation_policy_hours: number;
  };
  financial: {
    currency: string;
    tax_rate_percent: number;
    invoice_footer: string;
  };
}


export interface Clinic {
  id: string; // UUID
  name: string;
  owner_id?: string; // UUID of the owner user
  created_at: string; // ISO 8601
  // Add new detailed profile fields
  address?: string;
  contact_phone?: string;
  contact_email?: string;
  website?: string;
  settings?: ClinicSettingsData;
}

export interface User {
  id: string; // UUID
  clinic_id: string; // Foreign Key to Clinic
  email: string;
  password_hash: string;
  role: Role;
  created_at: string; // ISO 8601
  schedule_id?: string; // FK to Schedule
}

// --- CLINIC OPERATIONS ---

export interface Patient {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  name: string;
  dob?: string; // YYYY-MM-DD
  gender?: string;
  contact_info?: Record<string, string>; // JSONB
  created_at: string; // ISO 8601
}

export interface Doctor {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  name: string;
  specialty?: string;
  created_at: string; // ISO 8601
  // Denormalized for UI convenience
  photo?: string;
}

export interface Service {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  name: string;
  price: number;
  duration_minutes: number;
  currency?: string;
}

export type AppointmentStatus = 'scheduled' | 'completed' | 'canceled';

export interface Appointment {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  patient_id: string; // FK to Patient
  doctor_id: string; // FK to Doctor
  service_id?: string; // FK to Service
  start_time: string; // ISO 8601
  status: AppointmentStatus;
}


// --- MEDICAL (EMR) ---

export interface Encounter {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  patient_id: string; // FK to Patient
  doctor_id: string; // FK to Doctor
  appointment_id?: string; // FK to Appointment
  notes?: string;
  vitals?: Record<string, any>; // JSONB
  created_at: string; // ISO 8601
}

export interface Problem {
    encounter_id: string; // UUID
    description: string;
}

export interface Allergy {
    patient_id: string;
    substance: string;
    reaction?: string;
}

export interface Medication {
    encounter_id: string; // UUID
    drug_name: string;
    dosage?: string;
    instructions?: string;
}


// --- FINANCIALS ---

export type InvoiceStatus = 'draft' | 'issued' | 'paid' | 'canceled';

export interface InvoiceLine {
    id: string; // UUID
    invoice_id: string;
    service_id?: string;
    quantity: number;
    price: number;
}

export interface Invoice {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  patient_id: string; // FK to Patient
  total: number;
  status: InvoiceStatus;
  issued_at: string; // ISO 8601
  invoice_lines: InvoiceLine[]; // Denormalized for UI
}

export interface Payment {
  id: string; // UUID
  invoice_id: string; // FK to Invoice
  amount: number;
  method?: string;
  paid_at: string; // ISO 8601
}

// --- UI SPECIFIC ---

// For doctor registration flow
export interface DoctorRegistrationData {
  user: Partial<User>;
  doctor: Partial<Doctor>;
}

// New type for schedule overrides
export interface DayOverride {
  date: string; // YYYY-MM-DD
  active: boolean;
  start?: string; // HH:mm, required if active
  end?: string; // HH:mm, required if active
}

// FIX: Define Schedule type for doctor schedule feature.
export interface Schedule {
  id: string; // UUID
  clinic_id: string; // FK to Clinic
  appointment_length_minutes: number;
  buffer_time_minutes: number;
  overrides: DayOverride[]; // Replaces holidays for more flexibility
  weekdays: {
    monday: { active: boolean; start: string; end: string };
    tuesday: { active: boolean; start: string; end: string };
    wednesday: { active: boolean; start: string; end: string };
    thursday: { active: boolean; start: string; end: string };
    friday: { active: boolean; start: string; end: string };
    saturday: { active: boolean; start: string; end: string };
    sunday: { active: boolean; start: string; end: string };
  };
}