@blackcode_sa/metaestetics-api 1.7.47 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/index.d.mts +999 -959
- package/dist/admin/index.d.ts +999 -959
- package/dist/admin/index.js +69 -69
- package/dist/admin/index.mjs +67 -69
- package/dist/index.d.mts +14675 -13040
- package/dist/index.d.ts +14675 -13040
- package/dist/index.js +12224 -14615
- package/dist/index.mjs +12452 -14968
- package/package.json +5 -5
- package/src/admin/index.ts +8 -1
- package/src/index.backup.ts +407 -0
- package/src/index.ts +5 -406
- package/src/services/PATIENTAUTH.MD +197 -0
- package/src/services/__tests__/auth/auth.setup.ts +2 -2
- package/src/services/__tests__/auth.service.test.ts +1 -1
- package/src/services/__tests__/user.service.test.ts +1 -1
- package/src/services/appointment/index.ts +1 -2
- package/src/services/{auth.service.ts → auth/auth.service.ts} +36 -22
- package/src/services/{auth.v2.service.ts → auth/auth.v2.service.ts} +17 -17
- package/src/services/auth/index.ts +2 -16
- package/src/services/calendar/calendar-refactored.service.ts +1 -1
- package/src/services/calendar/index.ts +5 -0
- package/src/services/clinic/index.ts +4 -0
- package/src/services/index.ts +14 -0
- package/src/services/media/index.ts +1 -0
- package/src/services/notifications/index.ts +1 -0
- package/src/services/patient/README.md +48 -0
- package/src/services/patient/To-Do.md +43 -0
- package/src/services/patient/index.ts +2 -0
- package/src/services/patient/patient.service.ts +289 -34
- package/src/services/patient/utils/index.ts +9 -0
- package/src/services/patient/utils/medical.utils.ts +114 -157
- package/src/services/patient/utils/profile.utils.ts +9 -0
- package/src/services/patient/utils/sensitive.utils.ts +79 -14
- package/src/services/patient/utils/token.utils.ts +211 -0
- package/src/services/practitioner/index.ts +1 -0
- package/src/services/procedure/index.ts +1 -0
- package/src/services/reviews/index.ts +1 -0
- package/src/services/user/index.ts +1 -0
- package/src/services/{user.service.ts → user/user.service.ts} +61 -12
- package/src/services/{user.v2.service.ts → user/user.v2.service.ts} +12 -12
- package/src/types/index.ts +42 -42
- package/src/types/patient/index.ts +33 -6
- package/src/types/patient/token.types.ts +61 -0
- package/src/types/user/index.ts +38 -0
- package/src/utils/index.ts +1 -0
- package/src/validations/calendar.schema.ts +6 -45
- package/src/validations/documentation-templates/index.ts +1 -0
- package/src/validations/documentation-templates.schema.ts +1 -1
- package/src/validations/index.ts +20 -0
- package/src/validations/patient/token.schema.ts +29 -0
- package/src/validations/patient.schema.ts +23 -6
- package/src/validations/profile-info.schema.ts +1 -1
- package/src/validations/schemas.ts +24 -24
package/src/index.ts
CHANGED
|
@@ -1,406 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
searchAppointmentsSchema,
|
|
7
|
-
} from "./validations/appointment.schema";
|
|
8
|
-
|
|
9
|
-
// Firebase
|
|
10
|
-
export {
|
|
11
|
-
initializeFirebase,
|
|
12
|
-
getFirebaseInstance,
|
|
13
|
-
getFirebaseAuth,
|
|
14
|
-
getFirebaseDB,
|
|
15
|
-
getFirebaseApp,
|
|
16
|
-
} from "./config/firebase";
|
|
17
|
-
|
|
18
|
-
// Services
|
|
19
|
-
export { AuthService } from "./services/auth.service";
|
|
20
|
-
export { UserService } from "./services/user.service";
|
|
21
|
-
export { NotificationService } from "./services/notifications/notification.service";
|
|
22
|
-
export { PatientService } from "./services/patient/patient.service";
|
|
23
|
-
export { PractitionerService } from "./services/practitioner/practitioner.service";
|
|
24
|
-
export { ProcedureService } from "./services/procedure/procedure.service";
|
|
25
|
-
export { ClinicService } from "./services/clinic/clinic.service";
|
|
26
|
-
export { ClinicAdminService } from "./services/clinic/clinic-admin.service";
|
|
27
|
-
export { ClinicGroupService } from "./services/clinic/clinic-group.service";
|
|
28
|
-
export { PractitionerInviteService } from "./services/clinic/practitioner-invite.service";
|
|
29
|
-
export {
|
|
30
|
-
DocumentationTemplateService,
|
|
31
|
-
FilledDocumentService,
|
|
32
|
-
} from "./services/documentation-templates";
|
|
33
|
-
export { CalendarServiceV2 } from "./services/calendar/calendar-refactored.service";
|
|
34
|
-
export { CalendarServiceV3 } from "./services/calendar/calendar.v3.service";
|
|
35
|
-
export { SyncedCalendarsService } from "./services/calendar/synced-calendars.service";
|
|
36
|
-
export { ReviewService } from "./services/reviews/reviews.service";
|
|
37
|
-
export { AppointmentService } from "./services/appointment/appointment.service";
|
|
38
|
-
export { PatientRequirementsService } from "./services/patient/patientRequirements.service";
|
|
39
|
-
export { MediaService } from "./services/media/media.service";
|
|
40
|
-
|
|
41
|
-
// Backoffice services
|
|
42
|
-
export { BrandService } from "./backoffice/services/brand.service";
|
|
43
|
-
export { CategoryService } from "./backoffice/services/category.service";
|
|
44
|
-
export { SubcategoryService } from "./backoffice/services/subcategory.service";
|
|
45
|
-
export { TechnologyService } from "./backoffice/services/technology.service";
|
|
46
|
-
export { ProductService } from "./backoffice/services/product.service";
|
|
47
|
-
|
|
48
|
-
// Types
|
|
49
|
-
export type { User, UserRole, CreateUserData, FirebaseUser } from "./types";
|
|
50
|
-
export { AUTH_ERRORS } from "./errors/auth.errors";
|
|
51
|
-
export { USER_ERRORS } from "./errors/user.errors";
|
|
52
|
-
export type { AuthError } from "./errors/auth.errors";
|
|
53
|
-
export * from "./validations/schemas";
|
|
54
|
-
export * from "./validations/notification.schema";
|
|
55
|
-
export * from "./validations/patient.schema";
|
|
56
|
-
export * from "./validations/practitioner.schema";
|
|
57
|
-
export * from "./validations/clinic.schema";
|
|
58
|
-
export * from "./validations/patient/medical-info.schema";
|
|
59
|
-
export * from "./validations/documentation-templates.schema";
|
|
60
|
-
export * from "./validations/calendar.schema";
|
|
61
|
-
export {
|
|
62
|
-
practitionerProfileInfoSchema,
|
|
63
|
-
patientProfileInfoSchema,
|
|
64
|
-
} from "./validations/profile-info.schema";
|
|
65
|
-
export { FirebaseErrorCode } from "./errors/firebase.errors";
|
|
66
|
-
|
|
67
|
-
// Appointment schemas
|
|
68
|
-
export {
|
|
69
|
-
appointmentCreateSchema as createAppointmentSchema,
|
|
70
|
-
appointmentUpdateSchema as updateAppointmentSchema,
|
|
71
|
-
searchAppointmentsSchema,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Notification types
|
|
75
|
-
export type {
|
|
76
|
-
Notification,
|
|
77
|
-
BaseNotification,
|
|
78
|
-
PreRequirementNotification,
|
|
79
|
-
PostRequirementNotification,
|
|
80
|
-
AppointmentReminderNotification,
|
|
81
|
-
} from "./types/notifications";
|
|
82
|
-
export { NotificationType, NotificationStatus } from "./types/notifications";
|
|
83
|
-
|
|
84
|
-
// Patient types
|
|
85
|
-
export type {
|
|
86
|
-
PatientProfile,
|
|
87
|
-
CreatePatientProfileData,
|
|
88
|
-
UpdatePatientProfileData,
|
|
89
|
-
PatientLocationInfo,
|
|
90
|
-
CreatePatientLocationInfoData,
|
|
91
|
-
UpdatePatientLocationInfoData,
|
|
92
|
-
AddressData,
|
|
93
|
-
LocationData,
|
|
94
|
-
GamificationInfo,
|
|
95
|
-
EmergencyContact,
|
|
96
|
-
PatientDoctor,
|
|
97
|
-
PatientSensitiveInfo,
|
|
98
|
-
CreatePatientSensitiveInfoData,
|
|
99
|
-
UpdatePatientSensitiveInfoData,
|
|
100
|
-
PatientClinic,
|
|
101
|
-
PatientMedicalInfo,
|
|
102
|
-
CreatePatientMedicalInfoData,
|
|
103
|
-
UpdatePatientMedicalInfoData,
|
|
104
|
-
VitalStats,
|
|
105
|
-
UpdateVitalStatsData,
|
|
106
|
-
AddAllergyData,
|
|
107
|
-
UpdateAllergyData,
|
|
108
|
-
AddBlockingConditionData,
|
|
109
|
-
UpdateBlockingConditionData,
|
|
110
|
-
AddContraindicationData,
|
|
111
|
-
UpdateContraindicationData,
|
|
112
|
-
AddMedicationData,
|
|
113
|
-
UpdateMedicationData,
|
|
114
|
-
Allergy,
|
|
115
|
-
PatientProfileComplete,
|
|
116
|
-
SearchPatientsParams,
|
|
117
|
-
RequesterInfo,
|
|
118
|
-
PatientProfileForDoctor,
|
|
119
|
-
} from "./types/patient";
|
|
120
|
-
export {
|
|
121
|
-
Gender,
|
|
122
|
-
PATIENTS_COLLECTION,
|
|
123
|
-
PATIENT_MEDICAL_INFO_COLLECTION,
|
|
124
|
-
PATIENT_SENSITIVE_INFO_COLLECTION,
|
|
125
|
-
PATIENT_LOCATION_INFO_COLLECTION,
|
|
126
|
-
PATIENT_MEDICAL_HISTORY_COLLECTION,
|
|
127
|
-
PATIENT_APPOINTMENTS_COLLECTION,
|
|
128
|
-
} from "./types/patient";
|
|
129
|
-
|
|
130
|
-
// Appointment types
|
|
131
|
-
export type {
|
|
132
|
-
Appointment,
|
|
133
|
-
CreateAppointmentData,
|
|
134
|
-
CreateAppointmentHttpData,
|
|
135
|
-
UpdateAppointmentData,
|
|
136
|
-
SearchAppointmentsParams,
|
|
137
|
-
AppointmentMetadata,
|
|
138
|
-
BeforeAfterPerZone,
|
|
139
|
-
BillingPerZone,
|
|
140
|
-
FinalBilling,
|
|
141
|
-
} from "./types/appointment";
|
|
142
|
-
export {
|
|
143
|
-
AppointmentStatus,
|
|
144
|
-
PaymentStatus,
|
|
145
|
-
APPOINTMENTS_COLLECTION,
|
|
146
|
-
} from "./types/appointment";
|
|
147
|
-
|
|
148
|
-
// Allergy tipovi
|
|
149
|
-
export type {
|
|
150
|
-
AllergyTypeWithSubtype,
|
|
151
|
-
AllergySubtype,
|
|
152
|
-
} from "./types/patient/allergies";
|
|
153
|
-
|
|
154
|
-
export {
|
|
155
|
-
AllergyType,
|
|
156
|
-
MedicationAllergySubtype,
|
|
157
|
-
FoodAllergySubtype,
|
|
158
|
-
EnvironmentalAllergySubtype,
|
|
159
|
-
CosmeticAllergySubtype,
|
|
160
|
-
} from "./types/patient/allergies";
|
|
161
|
-
|
|
162
|
-
// Practitioner types
|
|
163
|
-
export type {
|
|
164
|
-
Practitioner,
|
|
165
|
-
PractitionerBasicInfo,
|
|
166
|
-
PractitionerCertification,
|
|
167
|
-
CreatePractitionerData,
|
|
168
|
-
UpdatePractitionerData,
|
|
169
|
-
PractitionerClinicProcedures,
|
|
170
|
-
PractitionerWorkingHours,
|
|
171
|
-
PractitionerClinicWorkingHours,
|
|
172
|
-
CreateDraftPractitionerData,
|
|
173
|
-
PractitionerToken,
|
|
174
|
-
CreatePractitionerTokenData,
|
|
175
|
-
} from "./types/practitioner";
|
|
176
|
-
export {
|
|
177
|
-
PRACTITIONERS_COLLECTION,
|
|
178
|
-
REGISTER_TOKENS_COLLECTION,
|
|
179
|
-
PractitionerStatus,
|
|
180
|
-
PractitionerTokenStatus,
|
|
181
|
-
} from "./types/practitioner";
|
|
182
|
-
|
|
183
|
-
// Clinic types
|
|
184
|
-
export type {
|
|
185
|
-
Clinic,
|
|
186
|
-
ClinicGroup,
|
|
187
|
-
ClinicAdmin,
|
|
188
|
-
CreateClinicData,
|
|
189
|
-
UpdateClinicData,
|
|
190
|
-
CreateClinicGroupData,
|
|
191
|
-
UpdateClinicGroupData,
|
|
192
|
-
CreateClinicAdminData,
|
|
193
|
-
UpdateClinicAdminData,
|
|
194
|
-
ClinicLocation,
|
|
195
|
-
ClinicContactInfo,
|
|
196
|
-
WorkingHours,
|
|
197
|
-
ClinicTags,
|
|
198
|
-
ClinicAdminSignupData,
|
|
199
|
-
ContactPerson,
|
|
200
|
-
AdminToken,
|
|
201
|
-
AdminInfo,
|
|
202
|
-
CreateAdminTokenData,
|
|
203
|
-
DoctorInfo,
|
|
204
|
-
CreateDefaultClinicGroupData,
|
|
205
|
-
ClinicGroupSetupData,
|
|
206
|
-
ClinicBranchSetupData,
|
|
207
|
-
PractitionerInvite,
|
|
208
|
-
CreatePractitionerInviteData,
|
|
209
|
-
UpdatePractitionerInviteData,
|
|
210
|
-
PractitionerInviteFilters,
|
|
211
|
-
ProposedWorkingHours,
|
|
212
|
-
} from "./types/clinic";
|
|
213
|
-
export {
|
|
214
|
-
CLINICS_COLLECTION,
|
|
215
|
-
CLINIC_GROUPS_COLLECTION,
|
|
216
|
-
CLINIC_ADMINS_COLLECTION,
|
|
217
|
-
PRACTITIONER_INVITES_COLLECTION,
|
|
218
|
-
PracticeType,
|
|
219
|
-
Language,
|
|
220
|
-
ClinicTag,
|
|
221
|
-
ClinicPhotoTag,
|
|
222
|
-
AdminTokenStatus,
|
|
223
|
-
SubscriptionModel,
|
|
224
|
-
PractitionerInviteStatus,
|
|
225
|
-
} from "./types/clinic";
|
|
226
|
-
|
|
227
|
-
// Profile info types
|
|
228
|
-
export type {
|
|
229
|
-
ClinicInfo,
|
|
230
|
-
PractitionerProfileInfo,
|
|
231
|
-
PatientProfileInfo,
|
|
232
|
-
} from "./types/profile";
|
|
233
|
-
|
|
234
|
-
// Calendar types
|
|
235
|
-
export type {
|
|
236
|
-
CalendarEvent,
|
|
237
|
-
CalendarEventTime,
|
|
238
|
-
CreateCalendarEventData,
|
|
239
|
-
UpdateCalendarEventData,
|
|
240
|
-
TimeSlot,
|
|
241
|
-
ProcedureInfo,
|
|
242
|
-
ProcedureCategorization,
|
|
243
|
-
SyncedCalendarEvent,
|
|
244
|
-
CreateAppointmentParams,
|
|
245
|
-
UpdateAppointmentParams,
|
|
246
|
-
CreateBlockingEventParams,
|
|
247
|
-
UpdateBlockingEventParams,
|
|
248
|
-
} from "./types/calendar";
|
|
249
|
-
|
|
250
|
-
export {
|
|
251
|
-
CalendarEventStatus,
|
|
252
|
-
CalendarEventType,
|
|
253
|
-
CalendarSyncStatus,
|
|
254
|
-
SearchLocationEnum,
|
|
255
|
-
DateRange,
|
|
256
|
-
SearchCalendarEventsParams,
|
|
257
|
-
CALENDAR_COLLECTION,
|
|
258
|
-
} from "./types/calendar";
|
|
259
|
-
|
|
260
|
-
// Synced calendar types
|
|
261
|
-
export type {
|
|
262
|
-
SyncedCalendar,
|
|
263
|
-
CreateSyncedCalendarData,
|
|
264
|
-
UpdateSyncedCalendarData,
|
|
265
|
-
} from "./types/calendar/synced-calendar.types";
|
|
266
|
-
|
|
267
|
-
export {
|
|
268
|
-
SyncedCalendarProvider,
|
|
269
|
-
SYNCED_CALENDARS_COLLECTION,
|
|
270
|
-
} from "./types/calendar/synced-calendar.types";
|
|
271
|
-
|
|
272
|
-
// Certification types
|
|
273
|
-
|
|
274
|
-
// Brand types
|
|
275
|
-
export type { Brand } from "./backoffice/types/brand.types";
|
|
276
|
-
|
|
277
|
-
// Category types
|
|
278
|
-
export type { Category } from "./backoffice/types/category.types";
|
|
279
|
-
|
|
280
|
-
// Product types
|
|
281
|
-
export type { Product } from "./backoffice/types/product.types";
|
|
282
|
-
|
|
283
|
-
// Requirement types
|
|
284
|
-
export type { Requirement } from "./backoffice/types/requirement.types";
|
|
285
|
-
|
|
286
|
-
// Subcategory types
|
|
287
|
-
export type { Subcategory } from "./backoffice/types/subcategory.types";
|
|
288
|
-
|
|
289
|
-
// Technology types
|
|
290
|
-
export type {
|
|
291
|
-
Technology,
|
|
292
|
-
TechnologyDocumentationTemplate,
|
|
293
|
-
} from "./backoffice/types/technology.types";
|
|
294
|
-
|
|
295
|
-
// Pricing enums
|
|
296
|
-
export {
|
|
297
|
-
PricingMeasure,
|
|
298
|
-
Currency,
|
|
299
|
-
} from "./backoffice/types/static/pricing.types";
|
|
300
|
-
|
|
301
|
-
// Static types
|
|
302
|
-
export { BlockingCondition } from "./backoffice/types/static/blocking-condition.types";
|
|
303
|
-
export {
|
|
304
|
-
CertificationSpecialty,
|
|
305
|
-
CertificationLevel,
|
|
306
|
-
} from "./backoffice/types/static/certification.types";
|
|
307
|
-
export { Contraindication } from "./backoffice/types/static/contraindication.types";
|
|
308
|
-
export { ProcedureFamily } from "./backoffice/types/static/procedure-family.types";
|
|
309
|
-
export { TreatmentBenefit } from "./backoffice/types/static/treatment-benefit.types";
|
|
310
|
-
export {
|
|
311
|
-
RequirementType,
|
|
312
|
-
TimeUnit,
|
|
313
|
-
} from "./backoffice/types/requirement.types";
|
|
314
|
-
|
|
315
|
-
// Media types
|
|
316
|
-
export type {
|
|
317
|
-
MediaMetadata,
|
|
318
|
-
MediaResource,
|
|
319
|
-
} from "./services/media/media.service";
|
|
320
|
-
export { MEDIA_METADATA_COLLECTION } from "./services/media/media.service";
|
|
321
|
-
export { MediaAccessLevel } from "./services/media/media.service";
|
|
322
|
-
// Documentation Templates types
|
|
323
|
-
export type {
|
|
324
|
-
DocumentTemplate,
|
|
325
|
-
CreateDocumentTemplateData,
|
|
326
|
-
UpdateDocumentTemplateData,
|
|
327
|
-
DocumentElement,
|
|
328
|
-
FilledDocument,
|
|
329
|
-
BaseDocumentElement,
|
|
330
|
-
HeadingElement,
|
|
331
|
-
ParagraphElement,
|
|
332
|
-
ListElement,
|
|
333
|
-
DynamicTextElement,
|
|
334
|
-
BinaryChoiceElement,
|
|
335
|
-
MultipleChoiceElement,
|
|
336
|
-
SingleChoiceElement,
|
|
337
|
-
RatingScaleElement,
|
|
338
|
-
TextInputElement,
|
|
339
|
-
DatePickerElement,
|
|
340
|
-
SignatureElement,
|
|
341
|
-
DigitalSignatureElement,
|
|
342
|
-
FileUploadElement,
|
|
343
|
-
} from "./types/documentation-templates";
|
|
344
|
-
export {
|
|
345
|
-
DocumentElementType,
|
|
346
|
-
HeadingLevel,
|
|
347
|
-
ListType,
|
|
348
|
-
DynamicVariable,
|
|
349
|
-
FilledDocumentStatus,
|
|
350
|
-
FilledDocumentFileValue,
|
|
351
|
-
DOCUMENTATION_TEMPLATES_COLLECTION,
|
|
352
|
-
FILLED_DOCUMENTS_COLLECTION,
|
|
353
|
-
USER_FORMS_SUBCOLLECTION,
|
|
354
|
-
DOCTOR_FORMS_SUBCOLLECTION,
|
|
355
|
-
} from "./types/documentation-templates";
|
|
356
|
-
|
|
357
|
-
// Procedure types
|
|
358
|
-
export type {
|
|
359
|
-
Procedure,
|
|
360
|
-
CreateProcedureData,
|
|
361
|
-
UpdateProcedureData,
|
|
362
|
-
} from "./types/procedure";
|
|
363
|
-
export { PROCEDURES_COLLECTION } from "./types/procedure";
|
|
364
|
-
|
|
365
|
-
// Review types
|
|
366
|
-
export type {
|
|
367
|
-
ClinicReview,
|
|
368
|
-
PractitionerReview,
|
|
369
|
-
ProcedureReview,
|
|
370
|
-
ClinicReviewInfo,
|
|
371
|
-
PractitionerReviewInfo,
|
|
372
|
-
ProcedureReviewInfo,
|
|
373
|
-
Review,
|
|
374
|
-
} from "./types/reviews";
|
|
375
|
-
|
|
376
|
-
export { REVIEWS_COLLECTION } from "./types/reviews/index";
|
|
377
|
-
|
|
378
|
-
// Review schemas
|
|
379
|
-
export {
|
|
380
|
-
clinicReviewSchema,
|
|
381
|
-
createClinicReviewSchema,
|
|
382
|
-
practitionerReviewSchema,
|
|
383
|
-
createPractitionerReviewSchema,
|
|
384
|
-
procedureReviewSchema,
|
|
385
|
-
createProcedureReviewSchema,
|
|
386
|
-
clinicReviewInfoSchema,
|
|
387
|
-
practitionerReviewInfoSchema,
|
|
388
|
-
procedureReviewInfoSchema,
|
|
389
|
-
reviewSchema,
|
|
390
|
-
createReviewSchema,
|
|
391
|
-
} from "./validations/reviews.schema";
|
|
392
|
-
|
|
393
|
-
// Patient Requirement Types
|
|
394
|
-
export type {
|
|
395
|
-
PatientRequirementInstance,
|
|
396
|
-
PatientRequirementInstruction,
|
|
397
|
-
} from "./types/patient/patient-requirements";
|
|
398
|
-
export {
|
|
399
|
-
PatientInstructionStatus,
|
|
400
|
-
PatientRequirementOverallStatus,
|
|
401
|
-
PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME,
|
|
402
|
-
} from "./types/patient/patient-requirements";
|
|
403
|
-
|
|
404
|
-
// Patient Requirement Validation Schemas (if they exist and are for client use)
|
|
405
|
-
// Assuming the path, add if it exists and is needed:
|
|
406
|
-
// export * from "./validations/patient/patient-requirements.schema";
|
|
1
|
+
export * from "./services";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./validations";
|
|
4
|
+
export * from "./utils";
|
|
5
|
+
export * from "./config/firebase";
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Patient Authentication and Profile Claiming Flow
|
|
2
|
+
|
|
3
|
+
This document outlines the different methods for patient authentication, including standard sign-up, anonymous user conversion, and the process for claiming a pre-existing patient profile created by a clinic administrator.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Standard Patient Sign-Up
|
|
8
|
+
|
|
9
|
+
A new user can register directly as a patient. This flow creates a new `User` record in Firebase Authentication and Firestore, along with a corresponding `PatientProfile`.
|
|
10
|
+
|
|
11
|
+
### Flow:
|
|
12
|
+
|
|
13
|
+
1. The client application calls the `AuthService.signUp` method with the user's email and password.
|
|
14
|
+
2. The system creates a new Firebase user.
|
|
15
|
+
3. A new `User` document and a `PatientProfile` document are created and linked together.
|
|
16
|
+
|
|
17
|
+
### Example:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// In your client-side code
|
|
21
|
+
import { authService } from "./services"; // Assuming you have an initialized authService
|
|
22
|
+
|
|
23
|
+
async function registerPatient(email, password) {
|
|
24
|
+
try {
|
|
25
|
+
const user = await authService.signUp(email, password, UserRole.PATIENT);
|
|
26
|
+
console.log("Patient registered successfully:", user);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("Registration failed:", error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A similar flow exists for social providers like Google using `signInWithGoogle`.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 2. Standard Patient Sign-In
|
|
38
|
+
|
|
39
|
+
Existing users can sign in using their credentials.
|
|
40
|
+
|
|
41
|
+
### Flow:
|
|
42
|
+
|
|
43
|
+
1. The client application calls `AuthService.signIn` with the user's email and password.
|
|
44
|
+
2. Firebase authenticates the user.
|
|
45
|
+
3. The application receives the user's profile data.
|
|
46
|
+
|
|
47
|
+
### Example:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// In your client-side code
|
|
51
|
+
async function loginPatient(email, password) {
|
|
52
|
+
try {
|
|
53
|
+
const user = await authService.signIn(email, password);
|
|
54
|
+
console.log("Patient signed in successfully:", user);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("Sign-in failed:", error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 3. Anonymous User Flow
|
|
64
|
+
|
|
65
|
+
Users can start using the application without creating a full account. They are assigned an anonymous user profile which can be converted to a permanent account later.
|
|
66
|
+
|
|
67
|
+
### Flow:
|
|
68
|
+
|
|
69
|
+
1. **Initial Anonymous Sign-In:** The client calls `AuthService.signInAnonymously()`. This creates an anonymous Firebase user and a corresponding `User` and `PatientProfile` in Firestore.
|
|
70
|
+
2. **Upgrading the Account:** When the user decides to create a permanent account, the client calls one of the upgrade methods, such as `AuthService.upgradeAnonymousUser(email, password)`.
|
|
71
|
+
3. The anonymous account is linked to the new credentials (e.g., email/password). The `isAnonymous` flag on the `User` document is set to `false`. The existing `PatientProfile` is retained.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 4. Claiming a Manually Created Profile
|
|
76
|
+
|
|
77
|
+
This flow is for patients whose profiles are created in advance by a clinic administrator. This allows clinics to manage patient records before the patient has registered on the platform.
|
|
78
|
+
|
|
79
|
+
### Step 1: Admin Creates Profile and Invite Token
|
|
80
|
+
|
|
81
|
+
1. **Create Manual Patient:** A clinic admin uses `PatientService.createManualPatient()` to create a patient profile. This profile is not linked to any user (`userRef` is empty) and is marked with `isManual: true`.
|
|
82
|
+
2. **Create Invite Token:** The admin then calls `PatientService.createPatientToken()` for the newly created patient. This generates a unique, short-lived token and stores it in the `inviteTokens` subcollection of the patient's profile.
|
|
83
|
+
3. **Send Invitation:** The token is sent to the patient (e.g., via email). This is typically handled by a Cloud Function that triggers when a new token is created.
|
|
84
|
+
|
|
85
|
+
### Example (Admin Action):
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// In an admin panel or backend service
|
|
89
|
+
import { patientService } from "./services";
|
|
90
|
+
|
|
91
|
+
async function invitePatient(patientData, adminId) {
|
|
92
|
+
// 1. Create the manual patient profile
|
|
93
|
+
const manualProfile = await patientService.createManualPatient(patientData, {
|
|
94
|
+
id: adminId,
|
|
95
|
+
role: "clinic_admin",
|
|
96
|
+
associatedClinicId: patientData.clinicId,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 2. Create an invitation token for the new profile
|
|
100
|
+
const tokenData = {
|
|
101
|
+
patientId: manualProfile.id,
|
|
102
|
+
clinicId: patientData.clinicId,
|
|
103
|
+
email: patientData.email,
|
|
104
|
+
};
|
|
105
|
+
const inviteToken = await patientService.createPatientToken(
|
|
106
|
+
tokenData,
|
|
107
|
+
adminId
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
console.log(`Invite token created: ${inviteToken.token}`);
|
|
111
|
+
// (An automated process would now email this token to the patient)
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Step 2: Patient Signs Up with the Invite Token
|
|
116
|
+
|
|
117
|
+
The patient uses the standard sign-up flow but includes the invitation token.
|
|
118
|
+
|
|
119
|
+
1. **Sign-Up with Token:** The patient goes to the registration page and signs up using email/password (`AuthService.signUp`) or a social provider (`AuthService.signInWithGoogle`). They provide the `patientInviteToken` they received.
|
|
120
|
+
2. **Profile Claiming:**
|
|
121
|
+
- The system validates the token.
|
|
122
|
+
- If valid, it finds the corresponding `PatientProfile` that was manually created.
|
|
123
|
+
- It links the new `User` account to this existing `PatientProfile` by setting the `userRef`.
|
|
124
|
+
- It updates the profile's `isManual` flag to `false`.
|
|
125
|
+
- The invitation token is marked as `USED`.
|
|
126
|
+
|
|
127
|
+
### Example (Patient Action):
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// In your client-side code during registration
|
|
131
|
+
import { authService } from "./services";
|
|
132
|
+
|
|
133
|
+
async function registerAndClaimProfile(email, password, inviteToken) {
|
|
134
|
+
try {
|
|
135
|
+
const user = await authService.signUp(email, password, UserRole.PATIENT, {
|
|
136
|
+
patientInviteToken: inviteToken,
|
|
137
|
+
});
|
|
138
|
+
console.log("Successfully registered and claimed profile:", user);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error("Claiming profile failed:", error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 5. Retrieving Invite Tokens (For Admins)
|
|
148
|
+
|
|
149
|
+
Clinic administrators can retrieve a list of all active, unexpired invitation tokens for their clinic. This is useful for assisting patients in person who may not have access to their email.
|
|
150
|
+
|
|
151
|
+
### Flow:
|
|
152
|
+
|
|
153
|
+
1. An authenticated clinic administrator makes a request to an endpoint that calls `PatientService.getActiveInviteTokensByClinic(clinicId)`.
|
|
154
|
+
2. The service performs a secure query to find all tokens associated with the admin's clinic that are currently active.
|
|
155
|
+
3. The list of tokens is returned to the admin.
|
|
156
|
+
|
|
157
|
+
### Example (Admin Action):
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// In a secure admin-only part of the application
|
|
161
|
+
import { patientService } from "./services";
|
|
162
|
+
|
|
163
|
+
async function fetchActiveTokens(clinicId) {
|
|
164
|
+
try {
|
|
165
|
+
// The backend must verify that the user is an admin for this clinicId
|
|
166
|
+
const tokens = await patientService.getActiveInviteTokensByClinic(clinicId);
|
|
167
|
+
console.log("Active tokens for the clinic:", tokens);
|
|
168
|
+
// The admin can now read the token to the patient
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error("Failed to fetch tokens:", error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Admins can also retrieve tokens for a specific patient.
|
|
176
|
+
|
|
177
|
+
### Example (Admin Action for a specific patient):
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// In a secure admin-only part of the application
|
|
181
|
+
import { patientService } from "./services";
|
|
182
|
+
|
|
183
|
+
async function fetchTokensForPatient(patientId) {
|
|
184
|
+
try {
|
|
185
|
+
// The backend must verify that the user is an admin and has
|
|
186
|
+
// permission to view this patient's details.
|
|
187
|
+
const tokens = await patientService.getActiveInviteTokensByPatient(
|
|
188
|
+
patientId
|
|
189
|
+
);
|
|
190
|
+
console.log(`Active tokens for patient ${patientId}:`, tokens);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error("Failed to fetch tokens for patient:", error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
This ensures a seamless experience where the patient's pre-existing data is automatically linked to their new account.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { User, UserRole } from "../../../types";
|
|
2
|
-
import { AuthService } from "../../auth.service";
|
|
2
|
+
import { AuthService } from "../../auth/auth.service";
|
|
3
3
|
import {
|
|
4
4
|
FacebookAuthProvider,
|
|
5
5
|
OAuthProvider,
|
|
@@ -9,7 +9,7 @@ import { FirebaseApp } from "firebase/app";
|
|
|
9
9
|
import { Firestore } from "firebase/firestore";
|
|
10
10
|
import { Auth } from "firebase/auth";
|
|
11
11
|
import { Analytics } from "firebase/analytics";
|
|
12
|
-
import { UserService } from "../../user.service";
|
|
12
|
+
import { UserService } from "../../user/user.service";
|
|
13
13
|
import { initializeFirebase } from "../../../config/firebase";
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
import { AUTH_ERRORS } from "../../../errors/auth.errors";
|
|
@@ -119,7 +119,7 @@ jest.mock("../../config/firebase", () => ({
|
|
|
119
119
|
}),
|
|
120
120
|
}));
|
|
121
121
|
|
|
122
|
-
import { AuthService } from "../auth.service";
|
|
122
|
+
import { AuthService } from "../auth/auth.service";
|
|
123
123
|
import { User as FirebaseUser } from "firebase/auth";
|
|
124
124
|
import { UserRole } from "../../types";
|
|
125
125
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserService } from "../user.service";
|
|
1
|
+
import { UserService } from "../user/user.service";
|
|
2
2
|
import { User, UserRole, USERS_COLLECTION } from "../../types";
|
|
3
3
|
import { USER_ERRORS } from "../../errors/user.errors";
|
|
4
4
|
import { AUTH_ERRORS } from "../../errors/auth.errors";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "../../types/appointment";
|
|
1
|
+
export * from "./appointment.service";
|