@blackcode_sa/metaestetics-api 1.6.2 → 1.6.4

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.
Files changed (37) hide show
  1. package/dist/admin/index.d.mts +228 -25
  2. package/dist/admin/index.d.ts +228 -25
  3. package/dist/admin/index.js +35867 -2493
  4. package/dist/admin/index.mjs +35856 -2464
  5. package/dist/backoffice/index.d.mts +252 -1
  6. package/dist/backoffice/index.d.ts +252 -1
  7. package/dist/backoffice/index.js +86 -12
  8. package/dist/backoffice/index.mjs +86 -13
  9. package/dist/index.d.mts +1417 -554
  10. package/dist/index.d.ts +1417 -554
  11. package/dist/index.js +1393 -687
  12. package/dist/index.mjs +1423 -711
  13. package/package.json +1 -1
  14. package/src/admin/index.ts +15 -1
  15. package/src/admin/notifications/notifications.admin.ts +1 -1
  16. package/src/admin/requirements/README.md +128 -0
  17. package/src/admin/requirements/patient-requirements.admin.service.ts +482 -0
  18. package/src/index.ts +16 -1
  19. package/src/services/appointment/appointment.service.ts +315 -86
  20. package/src/services/clinic/clinic-admin.service.ts +3 -0
  21. package/src/services/clinic/clinic-group.service.ts +8 -0
  22. package/src/services/documentation-templates/documentation-template.service.ts +24 -16
  23. package/src/services/documentation-templates/filled-document.service.ts +253 -136
  24. package/src/services/patient/patient.service.ts +31 -1
  25. package/src/services/patient/patientRequirements.service.ts +285 -0
  26. package/src/services/patient/utils/practitioner.utils.ts +79 -1
  27. package/src/types/appointment/index.ts +134 -10
  28. package/src/types/documentation-templates/index.ts +34 -2
  29. package/src/types/notifications/README.md +77 -0
  30. package/src/types/notifications/index.ts +154 -27
  31. package/src/types/patient/index.ts +6 -0
  32. package/src/types/patient/patient-requirements.ts +81 -0
  33. package/src/validations/appointment.schema.ts +300 -62
  34. package/src/validations/documentation-templates/template.schema.ts +55 -0
  35. package/src/validations/documentation-templates.schema.ts +9 -14
  36. package/src/validations/notification.schema.ts +3 -3
  37. package/src/validations/patient/patient-requirements.schema.ts +75 -0
@@ -17,6 +17,7 @@ declare enum DocumentElementType {
17
17
  TEXT_INPUT = "text_input",
18
18
  DATE_PICKER = "date_picker",
19
19
  SIGNATURE = "signature",
20
+ DITIGAL_SIGNATURE = "digital_signature",
20
21
  FILE_UPLOAD = "file_upload"
21
22
  }
22
23
  /**
@@ -164,6 +165,9 @@ interface DocumentTemplate {
164
165
  createdBy: string;
165
166
  elements: DocumentElement[];
166
167
  tags?: string[];
168
+ isUserForm?: boolean;
169
+ isRequired?: boolean;
170
+ sortingOrder?: number;
167
171
  version: number;
168
172
  isActive: boolean;
169
173
  }
@@ -1118,10 +1122,19 @@ declare enum UserRole {
1118
1122
  * Enumeracija koja definiše sve moguće tipove notifikacija
1119
1123
  */
1120
1124
  declare enum NotificationType {
1121
- PRE_REQUIREMENT = "preRequirement",
1122
- POST_REQUIREMENT = "postRequirement",
1123
- APPOINTMENT_REMINDER = "appointmentReminder",
1124
- APPOINTMENT_NOTIFICATION = "appointmentNotification"
1125
+ APPOINTMENT_REMINDER = "appointmentReminder",// For upcoming appointments
1126
+ APPOINTMENT_STATUS_CHANGE = "appointmentStatusChange",// Generic for status changes like confirmed, checked-in etc.
1127
+ APPOINTMENT_RESCHEDULED_PROPOSAL = "appointmentRescheduledProposal",// When clinic proposes a new time
1128
+ APPOINTMENT_CANCELLED = "appointmentCancelled",// When an appointment is cancelled
1129
+ REQUIREMENT_INSTRUCTION_DUE = "requirementInstructionDue",// For specific pre/post care instructions
1130
+ FORM_REMINDER = "formReminder",// Reminds user to fill a specific form
1131
+ FORM_SUBMISSION_CONFIRMATION = "formSubmissionConfirmation",// Confirms form was submitted
1132
+ REVIEW_REQUEST = "reviewRequest",// Request for patient review post-appointment
1133
+ PAYMENT_DUE = "paymentDue",
1134
+ PAYMENT_CONFIRMATION = "paymentConfirmation",
1135
+ PAYMENT_FAILED = "paymentFailed",
1136
+ GENERAL_MESSAGE = "generalMessage",// For general announcements or direct messages
1137
+ ACCOUNT_NOTIFICATION = "accountNotification"
1125
1138
  }
1126
1139
  declare const NOTIFICATIONS_COLLECTION = "notifications";
1127
1140
  /**
@@ -1156,14 +1169,22 @@ interface BaseNotification {
1156
1169
  isRead: boolean;
1157
1170
  /** Uloga korisnika kome je namenjena notifikacija */
1158
1171
  userRole: UserRole;
1172
+ appointmentId?: string;
1173
+ patientRequirementInstanceId?: string;
1174
+ instructionId?: string;
1175
+ formId?: string;
1176
+ originalRequirementId?: string;
1177
+ transactionId?: string;
1159
1178
  }
1160
1179
  /**
1161
1180
  * Status notifikacije
1162
1181
  */
1163
1182
  declare enum NotificationStatus {
1164
1183
  PENDING = "pending",
1184
+ PROCESSING = "processing",
1165
1185
  SENT = "sent",
1166
1186
  FAILED = "failed",
1187
+ DELIVERED = "delivered",
1167
1188
  CANCELLED = "cancelled",
1168
1189
  PARTIAL_SUCCESS = "partialSuccess"
1169
1190
  }
@@ -1171,7 +1192,7 @@ declare enum NotificationStatus {
1171
1192
  * Notifikacija za pre-requirement
1172
1193
  */
1173
1194
  interface PreRequirementNotification extends BaseNotification {
1174
- notificationType: NotificationType.PRE_REQUIREMENT;
1195
+ notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
1175
1196
  /** ID tretmana za koji je vezan pre-requirement */
1176
1197
  treatmentId: string;
1177
1198
  /** Lista pre-requirements koji treba da se ispune */
@@ -1183,7 +1204,7 @@ interface PreRequirementNotification extends BaseNotification {
1183
1204
  * Notifikacija za post-requirement
1184
1205
  */
1185
1206
  interface PostRequirementNotification extends BaseNotification {
1186
- notificationType: NotificationType.POST_REQUIREMENT;
1207
+ notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
1187
1208
  /** ID tretmana za koji je vezan post-requirement */
1188
1209
  treatmentId: string;
1189
1210
  /** Lista post-requirements koji treba da se ispune */
@@ -1192,37 +1213,108 @@ interface PostRequirementNotification extends BaseNotification {
1192
1213
  deadline: Timestamp;
1193
1214
  }
1194
1215
  /**
1195
- * Notifikacija za podsetnik o zakazanom terminu
1216
+ * Notification for a specific instruction from a PatientRequirementInstance.
1217
+ * Example: "Do not eat 2 hours before your [Procedure Name] appointment."
1218
+ */
1219
+ interface RequirementInstructionDueNotification extends BaseNotification {
1220
+ notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
1221
+ appointmentId: string;
1222
+ patientRequirementInstanceId: string;
1223
+ instructionId: string;
1224
+ }
1225
+ /**
1226
+ * Notification reminding about an upcoming appointment.
1227
+ * Example: "Reminder: Your appointment for [Procedure Name] is at [Time] today."
1196
1228
  */
1197
1229
  interface AppointmentReminderNotification extends BaseNotification {
1198
1230
  notificationType: NotificationType.APPOINTMENT_REMINDER;
1199
- /** ID zakazanog termina */
1200
1231
  appointmentId: string;
1201
- /** Vreme termina */
1202
1232
  appointmentTime: Timestamp;
1203
- /** Tip tretmana */
1204
- treatmentType: string;
1205
- /** Ime doktora */
1206
- doctorName: string;
1233
+ procedureName?: string;
1234
+ practitionerName?: string;
1235
+ clinicName?: string;
1236
+ }
1237
+ /**
1238
+ * Notification about a change in appointment status (e.g., confirmed, checked-in).
1239
+ * Excludes cancellations and reschedule proposals, which have their own types.
1240
+ * Example: "Your appointment for [Procedure Name] has been Confirmed."
1241
+ */
1242
+ interface AppointmentStatusChangeNotification extends BaseNotification {
1243
+ notificationType: NotificationType.APPOINTMENT_STATUS_CHANGE;
1244
+ appointmentId: string;
1245
+ newStatus: string;
1246
+ previousStatus?: string;
1247
+ procedureName?: string;
1207
1248
  }
1208
1249
  /**
1209
- * Notifikacija o promeni statusa termina
1250
+ * Notification informing the patient that the clinic has proposed a new time for their appointment.
1251
+ * Example: "Action Required: [Clinic Name] has proposed a new time for your [Procedure Name] appointment."
1210
1252
  */
1211
- interface AppointmentNotification extends BaseNotification {
1212
- notificationType: NotificationType.APPOINTMENT_NOTIFICATION;
1213
- /** ID zakazanog termina */
1253
+ interface AppointmentRescheduledProposalNotification extends BaseNotification {
1254
+ notificationType: NotificationType.APPOINTMENT_RESCHEDULED_PROPOSAL;
1255
+ appointmentId: string;
1256
+ newProposedStartTime: Timestamp;
1257
+ newProposedEndTime: Timestamp;
1258
+ procedureName?: string;
1259
+ }
1260
+ /**
1261
+ * Notification informing about a cancelled appointment.
1262
+ * Example: "Your appointment for [Procedure Name] on [Date] has been cancelled."
1263
+ */
1264
+ interface AppointmentCancelledNotification extends BaseNotification {
1265
+ notificationType: NotificationType.APPOINTMENT_CANCELLED;
1214
1266
  appointmentId: string;
1215
- /** Novi status termina */
1216
- appointmentStatus: string;
1217
- /** Prethodni status termina */
1218
- previousStatus: string;
1219
- /** Razlog promene (opciono) */
1220
1267
  reason?: string;
1268
+ cancelledByRole?: UserRole;
1269
+ procedureName?: string;
1270
+ }
1271
+ /**
1272
+ * Notification reminding a user to fill a specific form.
1273
+ * Example: "Reminder: Please complete the '[Form Name]' form for your upcoming appointment."
1274
+ */
1275
+ interface FormReminderNotification extends BaseNotification {
1276
+ notificationType: NotificationType.FORM_REMINDER;
1277
+ appointmentId: string;
1278
+ formId: string;
1279
+ formName: string;
1280
+ formDeadline?: Timestamp;
1281
+ }
1282
+ /**
1283
+ * Notification confirming a form submission.
1284
+ * Example: "Thank you! Your '[Form Name]' form has been submitted successfully."
1285
+ */
1286
+ interface FormSubmissionConfirmationNotification extends BaseNotification {
1287
+ notificationType: NotificationType.FORM_SUBMISSION_CONFIRMATION;
1288
+ appointmentId?: string;
1289
+ formId: string;
1290
+ formName: string;
1291
+ }
1292
+ /**
1293
+ * Notification requesting a patient to leave a review after an appointment.
1294
+ * Example: "Hope you had a great experience! Would you like to share your feedback for your visit on [Date]?"
1295
+ */
1296
+ interface ReviewRequestNotification extends BaseNotification {
1297
+ notificationType: NotificationType.REVIEW_REQUEST;
1298
+ appointmentId: string;
1299
+ practitionerName?: string;
1300
+ procedureName?: string;
1301
+ }
1302
+ /**
1303
+ * Generic notification for direct messages or announcements.
1304
+ */
1305
+ interface GeneralMessageNotification extends BaseNotification {
1306
+ notificationType: NotificationType.GENERAL_MESSAGE;
1307
+ }
1308
+ interface PaymentConfirmationNotification extends BaseNotification {
1309
+ notificationType: NotificationType.PAYMENT_CONFIRMATION;
1310
+ transactionId: string;
1311
+ appointmentId?: string;
1312
+ amount: string;
1221
1313
  }
1222
1314
  /**
1223
1315
  * Unija svih tipova notifikacija
1224
1316
  */
1225
- type Notification = PreRequirementNotification | PostRequirementNotification | AppointmentReminderNotification | AppointmentNotification;
1317
+ type Notification = PreRequirementNotification | PostRequirementNotification | RequirementInstructionDueNotification | AppointmentReminderNotification | AppointmentStatusChangeNotification | AppointmentRescheduledProposalNotification | AppointmentCancelledNotification | FormReminderNotification | FormSubmissionConfirmationNotification | ReviewRequestNotification | GeneralMessageNotification | PaymentConfirmationNotification;
1226
1318
 
1227
1319
  declare class NotificationsAdmin {
1228
1320
  private expo;
@@ -1243,7 +1335,7 @@ declare class NotificationsAdmin {
1243
1335
  /**
1244
1336
  * Ažurira status notifikacije
1245
1337
  */
1246
- private updateNotificationStatus;
1338
+ updateNotificationStatus(notificationId: string, status: NotificationStatus, error?: string): Promise<void>;
1247
1339
  /**
1248
1340
  * Šalje notifikaciju kroz Expo servis sa boljim error handlingom
1249
1341
  */
@@ -1686,6 +1778,117 @@ declare class BookingAdmin {
1686
1778
  private getPractitionerCalendarEvents;
1687
1779
  }
1688
1780
 
1781
+ /**
1782
+ * Defines the status of a specific instruction within a PatientRequirementInstance.
1783
+ * This helps track each actionable item for the patient.
1784
+ */
1785
+ declare enum PatientInstructionStatus {
1786
+ PENDING_NOTIFICATION = "pendingNotification",// Notification is scheduled but not yet due/sent
1787
+ ACTION_DUE = "actionDue",// The time for this instruction/notification has arrived
1788
+ ACTION_TAKEN = "actionTaken",// Patient has acknowledged or completed this specific instruction
1789
+ MISSED = "missed",// The due time for this instruction passed without action
1790
+ CANCELLED = "cancelled",// This specific instruction was cancelled (e.g., requirement changed)
1791
+ SKIPPED = "skipped"
1792
+ }
1793
+ /**
1794
+ * Represents a single, timed instruction or notification point derived from a Requirement's timeframe.
1795
+ */
1796
+ interface PatientRequirementInstruction {
1797
+ instructionId: string;
1798
+ instructionText: string;
1799
+ dueTime: Timestamp;
1800
+ actionableWindow: number;
1801
+ status: PatientInstructionStatus;
1802
+ originalNotifyAtValue: number;
1803
+ originalTimeframeUnit: TimeFrame["unit"];
1804
+ notificationId?: string;
1805
+ actionTakenAt?: Timestamp;
1806
+ updatedAt: Timestamp;
1807
+ }
1808
+ /**
1809
+ * Defines the overall status of a PatientRequirementInstance.
1810
+ */
1811
+ declare enum PatientRequirementOverallStatus {
1812
+ ACTIVE = "active",// Requirement instance is active, instructions are pending or due.
1813
+ ALL_INSTRUCTIONS_MET = "allInstructionsMet",// All instructions actioned/completed by the patient.
1814
+ PARTIALLY_COMPLETED = "partiallyCompleted",// Some instructions met, some missed or pending.
1815
+ FAILED = "failed",// The patient failed to complete the requirement on time and above treashold of 60%
1816
+ CANCELLED_APPOINTMENT = "cancelledAppointment",// Entire requirement instance cancelled due to appointment cancellation.
1817
+ SUPERSEDED_RESCHEDULE = "supersededReschedule",// This instance was replaced by a new one due to appointment reschedule.
1818
+ FAILED_TO_PROCESS = "failedToProcess"
1819
+ }
1820
+ /**
1821
+ * Represents an instance of a backoffice Requirement, tailored to a specific patient and appointment.
1822
+ * This document lives in the patient's subcollection: `patients/{patientId}/patientRequirements/{instanceId}`.
1823
+ */
1824
+ interface PatientRequirementInstance {
1825
+ id: string;
1826
+ patientId: string;
1827
+ appointmentId: string;
1828
+ originalRequirementId: string;
1829
+ requirementType: RequirementType;
1830
+ requirementName: string;
1831
+ requirementDescription: string;
1832
+ requirementImportance: RequirementImportance;
1833
+ overallStatus: PatientRequirementOverallStatus;
1834
+ instructions: PatientRequirementInstruction[];
1835
+ createdAt: Timestamp;
1836
+ updatedAt: Timestamp;
1837
+ }
1838
+ /**
1839
+ * Firestore subcollection name for patient requirement instances.
1840
+ */
1841
+ declare const PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME = "patientRequirements";
1842
+
1843
+ /**
1844
+ * @class PatientRequirementsAdminService
1845
+ * @description Handles administrative tasks for patient requirement instances, primarily managing associated notifications.
1846
+ * This service is intended to be used by Cloud Functions triggered by changes to PatientRequirementInstance documents.
1847
+ */
1848
+ declare class PatientRequirementsAdminService {
1849
+ private db;
1850
+ private notificationsAdmin;
1851
+ constructor(firestore?: admin.firestore.Firestore);
1852
+ /**
1853
+ * Processes a newly created or updated PatientRequirementInstance to schedule notifications for its instructions.
1854
+ * It will also cancel pre-existing notifications if due times have changed significantly.
1855
+ *
1856
+ * @param patientId - The ID of the patient.
1857
+ * @param instance - The PatientRequirementInstance data (either new or updated).
1858
+ * @param previousInstanceData - Optional. The previous state of the instance data if it's an update.
1859
+ * Used to determine if notifications need to be cancelled/rescheduled.
1860
+ * @returns {Promise<void>} A promise that resolves when processing is complete.
1861
+ */
1862
+ processRequirementInstanceAndScheduleNotifications(patientId: string, instance: PatientRequirementInstance, previousInstanceData?: PatientRequirementInstance): Promise<void>;
1863
+ /**
1864
+ * Cancels all PENDING notifications associated with a specific PatientRequirementInstance.
1865
+ * Typically called when the instance itself is deleted or its overall status becomes CANCELLED.
1866
+ *
1867
+ * @param instance - The PatientRequirementInstance.
1868
+ * @returns {Promise<void>}
1869
+ */
1870
+ cancelAllNotificationsForInstance(instance: PatientRequirementInstance): Promise<void>;
1871
+ /**
1872
+ * (Optional - For a cron job)
1873
+ * Scans for instructions that are past their due time but not yet actioned, and updates their status to MISSED.
1874
+ * This would typically be called by a scheduled Cloud Function.
1875
+ *
1876
+ * @param patientId - The ID of the patient.
1877
+ * @param instanceId - The ID of the PatientRequirementInstance.
1878
+ * @returns {Promise<void>}
1879
+ */
1880
+ updateMissedInstructions(patientId: string, instanceId: string): Promise<void>;
1881
+ /**
1882
+ * Calculates and updates the overallStatus of a PatientRequirementInstance
1883
+ * based on the statuses of its individual instructions.
1884
+ *
1885
+ * @param patientId - The ID of the patient.
1886
+ * @param instanceId - The ID of the PatientRequirementInstance to update.
1887
+ * @returns {Promise<void>} A promise that resolves when processing is complete.
1888
+ */
1889
+ updateOverallInstanceStatus(patientId: string, instanceId: string): Promise<void>;
1890
+ }
1891
+
1689
1892
  /**
1690
1893
  * Request parameters for calculating available booking slots
1691
1894
  */
@@ -1729,4 +1932,4 @@ interface TimeInterval {
1729
1932
  end: Timestamp;
1730
1933
  }
1731
1934
 
1732
- export { type AppointmentNotification, type AppointmentReminderNotification, type AvailableSlot, BaseMailingService, type BaseNotification, BookingAdmin, type BookingAvailabilityRequest, type BookingAvailabilityResponse, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, type PatientProfile as Patient, PatientAggregationService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, PractitionerInviteMailingService, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, type TimeInterval, UserRole };
1935
+ export { type AppointmentReminderNotification, type AvailableSlot, BaseMailingService, type BaseNotification, BookingAdmin, type BookingAvailabilityRequest, type BookingAvailabilityResponse, type Clinic, ClinicAggregationService, type ClinicInfo, type ClinicLocation, type DoctorInfo, NOTIFICATIONS_COLLECTION, type Notification, NotificationStatus, NotificationType, NotificationsAdmin, PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME, type PatientProfile as Patient, PatientAggregationService, PatientInstructionStatus, type PatientRequirementInstance, type PatientRequirementInstruction, PatientRequirementOverallStatus, PatientRequirementsAdminService, type PostRequirementNotification, type Practitioner, PractitionerAggregationService, PractitionerInviteMailingService, type PractitionerToken, PractitionerTokenStatus, type PreRequirementNotification, type Procedure, ProcedureAggregationService, type ProcedureSummaryInfo, type TimeInterval, UserRole };