@blackcode_sa/metaestetics-api 1.6.5 → 1.6.6

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/index.d.mts CHANGED
@@ -4437,6 +4437,7 @@ interface LinkedFormInfo {
4437
4437
  templateVersion: number;
4438
4438
  title: string;
4439
4439
  isUserForm: boolean;
4440
+ isRequired?: boolean;
4440
4441
  status: FilledDocumentStatus;
4441
4442
  path: string;
4442
4443
  submittedAt?: Timestamp;
@@ -4699,6 +4700,7 @@ declare const updateAppointmentSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
4699
4700
  templateVersion: z.ZodNumber;
4700
4701
  title: z.ZodString;
4701
4702
  isUserForm: z.ZodBoolean;
4703
+ isRequired: z.ZodOptional<z.ZodBoolean>;
4702
4704
  status: z.ZodNativeEnum<typeof FilledDocumentStatus>;
4703
4705
  path: z.ZodString;
4704
4706
  submittedAt: z.ZodOptional<z.ZodEffects<z.ZodAny, any, any>>;
@@ -4711,6 +4713,7 @@ declare const updateAppointmentSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
4711
4713
  templateId: string;
4712
4714
  templateVersion: number;
4713
4715
  formId: string;
4716
+ isRequired?: boolean | undefined;
4714
4717
  submittedAt?: any;
4715
4718
  completedAt?: any;
4716
4719
  }, {
@@ -4721,6 +4724,7 @@ declare const updateAppointmentSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
4721
4724
  templateId: string;
4722
4725
  templateVersion: number;
4723
4726
  formId: string;
4727
+ isRequired?: boolean | undefined;
4724
4728
  submittedAt?: any;
4725
4729
  completedAt?: any;
4726
4730
  }>, "many">, z.ZodAny]>>;
@@ -6007,6 +6011,8 @@ declare enum NotificationType {
6007
6011
  APPOINTMENT_STATUS_CHANGE = "appointmentStatusChange",// Generic for status changes like confirmed, checked-in etc.
6008
6012
  APPOINTMENT_RESCHEDULED_PROPOSAL = "appointmentRescheduledProposal",// When clinic proposes a new time
6009
6013
  APPOINTMENT_CANCELLED = "appointmentCancelled",// When an appointment is cancelled
6014
+ PRE_REQUIREMENT_INSTRUCTION_DUE = "preRequirementInstructionDue",
6015
+ POST_REQUIREMENT_INSTRUCTION_DUE = "postRequirementInstructionDue",
6010
6016
  REQUIREMENT_INSTRUCTION_DUE = "requirementInstructionDue",// For specific pre/post care instructions
6011
6017
  FORM_REMINDER = "formReminder",// Reminds user to fill a specific form
6012
6018
  FORM_SUBMISSION_CONFIRMATION = "formSubmissionConfirmation",// Confirms form was submitted
@@ -6072,7 +6078,7 @@ declare enum NotificationStatus {
6072
6078
  * Notifikacija za pre-requirement
6073
6079
  */
6074
6080
  interface PreRequirementNotification extends BaseNotification {
6075
- notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
6081
+ notificationType: NotificationType.PRE_REQUIREMENT_INSTRUCTION_DUE;
6076
6082
  /** ID tretmana za koji je vezan pre-requirement */
6077
6083
  treatmentId: string;
6078
6084
  /** Lista pre-requirements koji treba da se ispune */
@@ -6084,7 +6090,7 @@ interface PreRequirementNotification extends BaseNotification {
6084
6090
  * Notifikacija za post-requirement
6085
6091
  */
6086
6092
  interface PostRequirementNotification extends BaseNotification {
6087
- notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
6093
+ notificationType: NotificationType.POST_REQUIREMENT_INSTRUCTION_DUE;
6088
6094
  /** ID tretmana za koji je vezan post-requirement */
6089
6095
  treatmentId: string;
6090
6096
  /** Lista post-requirements koji treba da se ispune */
package/dist/index.d.ts CHANGED
@@ -4437,6 +4437,7 @@ interface LinkedFormInfo {
4437
4437
  templateVersion: number;
4438
4438
  title: string;
4439
4439
  isUserForm: boolean;
4440
+ isRequired?: boolean;
4440
4441
  status: FilledDocumentStatus;
4441
4442
  path: string;
4442
4443
  submittedAt?: Timestamp;
@@ -4699,6 +4700,7 @@ declare const updateAppointmentSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
4699
4700
  templateVersion: z.ZodNumber;
4700
4701
  title: z.ZodString;
4701
4702
  isUserForm: z.ZodBoolean;
4703
+ isRequired: z.ZodOptional<z.ZodBoolean>;
4702
4704
  status: z.ZodNativeEnum<typeof FilledDocumentStatus>;
4703
4705
  path: z.ZodString;
4704
4706
  submittedAt: z.ZodOptional<z.ZodEffects<z.ZodAny, any, any>>;
@@ -4711,6 +4713,7 @@ declare const updateAppointmentSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
4711
4713
  templateId: string;
4712
4714
  templateVersion: number;
4713
4715
  formId: string;
4716
+ isRequired?: boolean | undefined;
4714
4717
  submittedAt?: any;
4715
4718
  completedAt?: any;
4716
4719
  }, {
@@ -4721,6 +4724,7 @@ declare const updateAppointmentSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
4721
4724
  templateId: string;
4722
4725
  templateVersion: number;
4723
4726
  formId: string;
4727
+ isRequired?: boolean | undefined;
4724
4728
  submittedAt?: any;
4725
4729
  completedAt?: any;
4726
4730
  }>, "many">, z.ZodAny]>>;
@@ -6007,6 +6011,8 @@ declare enum NotificationType {
6007
6011
  APPOINTMENT_STATUS_CHANGE = "appointmentStatusChange",// Generic for status changes like confirmed, checked-in etc.
6008
6012
  APPOINTMENT_RESCHEDULED_PROPOSAL = "appointmentRescheduledProposal",// When clinic proposes a new time
6009
6013
  APPOINTMENT_CANCELLED = "appointmentCancelled",// When an appointment is cancelled
6014
+ PRE_REQUIREMENT_INSTRUCTION_DUE = "preRequirementInstructionDue",
6015
+ POST_REQUIREMENT_INSTRUCTION_DUE = "postRequirementInstructionDue",
6010
6016
  REQUIREMENT_INSTRUCTION_DUE = "requirementInstructionDue",// For specific pre/post care instructions
6011
6017
  FORM_REMINDER = "formReminder",// Reminds user to fill a specific form
6012
6018
  FORM_SUBMISSION_CONFIRMATION = "formSubmissionConfirmation",// Confirms form was submitted
@@ -6072,7 +6078,7 @@ declare enum NotificationStatus {
6072
6078
  * Notifikacija za pre-requirement
6073
6079
  */
6074
6080
  interface PreRequirementNotification extends BaseNotification {
6075
- notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
6081
+ notificationType: NotificationType.PRE_REQUIREMENT_INSTRUCTION_DUE;
6076
6082
  /** ID tretmana za koji je vezan pre-requirement */
6077
6083
  treatmentId: string;
6078
6084
  /** Lista pre-requirements koji treba da se ispune */
@@ -6084,7 +6090,7 @@ interface PreRequirementNotification extends BaseNotification {
6084
6090
  * Notifikacija za post-requirement
6085
6091
  */
6086
6092
  interface PostRequirementNotification extends BaseNotification {
6087
- notificationType: NotificationType.REQUIREMENT_INSTRUCTION_DUE;
6093
+ notificationType: NotificationType.POST_REQUIREMENT_INSTRUCTION_DUE;
6088
6094
  /** ID tretmana za koji je vezan post-requirement */
6089
6095
  treatmentId: string;
6090
6096
  /** Lista post-requirements koji treba da se ispune */
package/dist/index.js CHANGED
@@ -544,6 +544,7 @@ var linkedFormInfoSchema = import_zod2.z.object({
544
544
  templateVersion: import_zod2.z.number().int().positive("Template version must be a positive integer"),
545
545
  title: import_zod2.z.string().min(MIN_STRING_LENGTH, "Form title is required"),
546
546
  isUserForm: import_zod2.z.boolean(),
547
+ isRequired: import_zod2.z.boolean().optional(),
547
548
  status: filledDocumentStatusSchema,
548
549
  path: import_zod2.z.string().min(MIN_STRING_LENGTH, "Form path is required"),
549
550
  submittedAt: import_zod2.z.any().refine(
@@ -7505,6 +7506,8 @@ var NotificationType = /* @__PURE__ */ ((NotificationType3) => {
7505
7506
  NotificationType3["APPOINTMENT_STATUS_CHANGE"] = "appointmentStatusChange";
7506
7507
  NotificationType3["APPOINTMENT_RESCHEDULED_PROPOSAL"] = "appointmentRescheduledProposal";
7507
7508
  NotificationType3["APPOINTMENT_CANCELLED"] = "appointmentCancelled";
7509
+ NotificationType3["PRE_REQUIREMENT_INSTRUCTION_DUE"] = "preRequirementInstructionDue";
7510
+ NotificationType3["POST_REQUIREMENT_INSTRUCTION_DUE"] = "postRequirementInstructionDue";
7508
7511
  NotificationType3["REQUIREMENT_INSTRUCTION_DUE"] = "requirementInstructionDue";
7509
7512
  NotificationType3["FORM_REMINDER"] = "formReminder";
7510
7513
  NotificationType3["FORM_SUBMISSION_CONFIRMATION"] = "formSubmissionConfirmation";
package/dist/index.mjs CHANGED
@@ -311,6 +311,7 @@ var linkedFormInfoSchema = z2.object({
311
311
  templateVersion: z2.number().int().positive("Template version must be a positive integer"),
312
312
  title: z2.string().min(MIN_STRING_LENGTH, "Form title is required"),
313
313
  isUserForm: z2.boolean(),
314
+ isRequired: z2.boolean().optional(),
314
315
  status: filledDocumentStatusSchema,
315
316
  path: z2.string().min(MIN_STRING_LENGTH, "Form path is required"),
316
317
  submittedAt: z2.any().refine(
@@ -7469,6 +7470,8 @@ var NotificationType = /* @__PURE__ */ ((NotificationType3) => {
7469
7470
  NotificationType3["APPOINTMENT_STATUS_CHANGE"] = "appointmentStatusChange";
7470
7471
  NotificationType3["APPOINTMENT_RESCHEDULED_PROPOSAL"] = "appointmentRescheduledProposal";
7471
7472
  NotificationType3["APPOINTMENT_CANCELLED"] = "appointmentCancelled";
7473
+ NotificationType3["PRE_REQUIREMENT_INSTRUCTION_DUE"] = "preRequirementInstructionDue";
7474
+ NotificationType3["POST_REQUIREMENT_INSTRUCTION_DUE"] = "postRequirementInstructionDue";
7472
7475
  NotificationType3["REQUIREMENT_INSTRUCTION_DUE"] = "requirementInstructionDue";
7473
7476
  NotificationType3["FORM_REMINDER"] = "formReminder";
7474
7477
  NotificationType3["FORM_SUBMISSION_CONFIRMATION"] = "formSubmissionConfirmation";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.6.5",
4
+ "version": "1.6.6",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -0,0 +1,128 @@
1
+ # Appointment Aggregation Service (`appointment.aggregation.service.ts`)
2
+
3
+ This service is responsible for handling side effects and data aggregation tasks related to the lifecycle of appointments within the system. It is primarily designed to be invoked by Firestore triggers (`onCreate`, `onUpdate`, `onDelete`) for the `appointments` collection.
4
+
5
+ ## Core Responsibilities
6
+
7
+ - Managing denormalized data links (e.g., patient-clinic, patient-practitioner).
8
+ - Creating and updating `PatientRequirementInstance` documents based on appointment status and associated procedure requirements.
9
+ - Orchestrating notifications (email and push) to patients, practitioners, and clinic admins at various stages of the appointment lifecycle.
10
+ - Interfacing with other admin services like `AppointmentMailingService`, `NotificationsAdmin`, and `CalendarAdminService` (though calendar interactions are mostly TODOs).
11
+
12
+ ## Implemented Functionality
13
+
14
+ ### Constructor
15
+
16
+ - Initializes with a Firestore instance and a Mailgun client.
17
+ - Sets up instances of dependent services: `AppointmentMailingService`, `NotificationsAdmin`, `CalendarAdminService`, and `PatientRequirementsAdminService`.
18
+ - **Note**: `PatientRequirementsAdminService` is initialized but its methods are not (and should not be) directly called by this aggregation service for creating/managing requirement instances. That logic is correctly handled by local private methods in this service.
19
+
20
+ ### `handleAppointmentCreate(appointment: Appointment)`
21
+
22
+ - **Patient-Clinic-Practitioner Links**: Calls `managePatientClinicPractitionerLinks` to add links.
23
+ - **Data Fetching**: Fetches `PatientProfile`, `PatientSensitiveInfo`, `PractitionerProfile`, and `Clinic` data.
24
+ - **Status: `CONFIRMED`**
25
+ - Creates pre-appointment requirement instances via `createPreAppointmentRequirementInstances()`.
26
+ - Sends confirmation email to patient via `appointmentMailingService.sendAppointmentConfirmedEmail()`.
27
+ - Sends confirmation email to practitioner via `appointmentMailingService.sendAppointmentConfirmedEmail()`.
28
+ - Initiates confirmed push notification to patient via `notificationsAdmin.sendAppointmentConfirmedPush()`.
29
+ - **Status: `PENDING`**
30
+ - Sends appointment requested email to clinic admin via `appointmentMailingService.sendAppointmentRequestedEmailToClinic()`.
31
+
32
+ ### `handleAppointmentUpdate(before: Appointment, after: Appointment)`
33
+
34
+ - **Data Fetching**: Fetches `PatientProfile`, `PatientSensitiveInfo`, `PractitionerProfile`, and `Clinic` data for the `after` state.
35
+ - **Status Change: `PENDING -> CONFIRMED`**
36
+ - Creates pre-appointment requirement instances via `createPreAppointmentRequirementInstances(after)`.
37
+ - Sends confirmation email to patient.
38
+ - Sends confirmation email to practitioner.
39
+ - Initiates confirmed push notification to patient.
40
+ - **Status Change: `Any -> CANCELLED_*` (includes `NO_SHOW`)**
41
+ - Updates related patient requirement instances to `CANCELLED_APPOINTMENT` via `updateRelatedPatientRequirementInstances()`.
42
+ - Removes patient-clinic-practitioner links via `managePatientClinicPractitionerLinks()`.
43
+ - Sends cancellation email to patient.
44
+ - Sends cancellation email to practitioner.
45
+ - **Status Change: `Any -> COMPLETED`**
46
+ - Creates post-appointment requirement instances via `createPostAppointmentRequirementInstances(after)`.
47
+ - Sends review request email to patient.
48
+ - **Status Change: `Any -> RESCHEDULED_BY_CLINIC`**
49
+ - Updates related (old) patient requirement instances to `SUPERSEDED_RESCHEDULE`.
50
+ - Sends reschedule proposal email to patient.
51
+
52
+ ### `handleAppointmentDelete(deletedAppointment: Appointment)`
53
+
54
+ - Updates related patient requirement instances to `CANCELLED_APPOINTMENT`.
55
+ - Removes patient-clinic-practitioner links.
56
+
57
+ ### Helper Methods
58
+
59
+ - **`createPreAppointmentRequirementInstances(appointment: Appointment)`**:
60
+ - Creates `PatientRequirementInstance` documents for pre-appointment requirements based on `appointment.preProcedureRequirements`.
61
+ - Calculates due times for instructions based on `appointment.appointmentStartTime`.
62
+ - Sets `actionableWindow` with a placeholder value (TODO noted).
63
+ - Batch writes instances to Firestore.
64
+ - **`createPostAppointmentRequirementInstances(appointment: Appointment)`**:
65
+ - Creates `PatientRequirementInstance` documents for post-appointment requirements based on `appointment.postProcedureRequirements`.
66
+ - Calculates due times for instructions based on `appointment.appointmentEndTime`.
67
+ - Sets `actionableWindow` with a placeholder value (TODO noted).
68
+ - Batch writes instances to Firestore.
69
+ - **`updateRelatedPatientRequirementInstances(appointment: Appointment, newOverallStatus: PatientRequirementOverallStatus)`**:
70
+ - Queries for all `PatientRequirementInstance` documents linked to the appointment.
71
+ - Batch updates their `overallStatus` and `updatedAt` fields.
72
+ - **`managePatientClinicPractitionerLinks(appointment: Appointment, action: "create" | "cancel")`**:
73
+ - Adds/removes the patient's ID from `patientIds` arrays on the respective clinic and practitioner documents using `FieldValue.arrayUnion` or `FieldValue.arrayRemove`.
74
+ - **Data Fetching Helpers (`fetchPatientProfile`, `fetchPatientSensitiveInfo`, `fetchPractitionerProfile`, `fetchClinicInfo`)**:
75
+ - Basic methods to retrieve documents from Firestore by ID.
76
+
77
+ ## Pending `TODO` Items & Areas for Future Work
78
+
79
+ ### General / Cross-Cutting
80
+
81
+ - **Type Imports for Email Data Objects**:
82
+ - Throughout `handleAppointmentCreate` and `handleAppointmentUpdate`, calls to the `appointmentMailingService` use `as any` for the data payload (e.g., `emailData as any`).
83
+ - `TODO`: Properly import `PatientProfileInfo`, `PractitionerProfileInfo`, `ClinicInfo` from a shared location (e.g., `Api/src/types/profile.ts` or `Api/src/types/index.ts`) and ensure these types are correctly used, removing the `as any` casts. This may require exporting these types if they are not already.
84
+ - **`actionableWindow` in Requirement Instances**:
85
+ - In `createPreAppointmentRequirementInstances` and `createPostAppointmentRequirementInstances`, the `actionableWindow` for instructions is currently a placeholder (e.g., based on importance or a fixed value like 24 hours).
86
+ - `TODO`: Determine the correct logic or source for `actionableWindow` based on business requirements or template definitions.
87
+ - **Error Handling**: Enhance error handling in various methods to potentially update appointment status to an error state or implement more sophisticated retry mechanisms if critical operations fail.
88
+
89
+ ### `handleAppointmentCreate(appointment: Appointment)`
90
+
91
+ - **Push Notifications**:
92
+ - `TODO`: Implement sending appointment confirmed push to practitioner (if they have expo tokens).
93
+ - `TODO`: Implement sending pending appointment push notification to clinic admin (if applicable).
94
+
95
+ ### `handleAppointmentUpdate(before: Appointment, after: Appointment)`
96
+
97
+ - **Push Notifications**:
98
+ - For `PENDING -> CONFIRMED`: `TODO`: Send appointment confirmed push to practitioner.
99
+ - For `Any -> CANCELLED_*`: `TODO`: Send cancellation push notifications to patient and practitioner.
100
+ - For `Any -> COMPLETED`: `TODO`: Send review request push notification to patient.
101
+ - For `Any -> RESCHEDULED_BY_CLINIC`: `TODO`: Send reschedule proposal push notifications to patient (and practitioner if applicable).
102
+ - **Calendar Event Updates**:
103
+ - For `Any -> CANCELLED_*`: `TODO`: Update/cancel calendar event via `calendarAdminService.updateAppointmentCalendarEventStatus(after, CalendarEventStatus.CANCELED)` (or similar method).
104
+ - For `Any -> RESCHEDULED_BY_CLINIC`: `TODO`: Update calendar event to reflect proposed new time via `calendarAdminService`.
105
+ - **Reschedule Logic for Requirements (`RESCHEDULED_BY_CLINIC`)**:
106
+ - `TODO`: Handle RESCHEDULE logic for `PatientRequirementInstance` creation/cancellation more carefully based on the specific confirmation flow of a reschedule. For instance, when are new pre-requirements created if it's just a proposal?
107
+ - **Reschedule Notification to Practitioner (`RESCHEDULED_BY_CLINIC`)**:
108
+ - `TODO`: Implement sending reschedule proposal email/notification to the practitioner.
109
+ - **Independent Time Change**:
110
+ - `TODO`: Fully implement logic for when `appointmentStartTime` or `appointmentEndTime` changes without an accompanying status change. This might involve updating requirements and calendar events.
111
+ - `Logger.warn` currently flags this scenario.
112
+ - **Payment Status Change**:
113
+ - `TODO`: Implement logic for `before.paymentStatus !== after.paymentStatus`. This could involve sending payment confirmation notifications (email/push).
114
+ - **Review Added**:
115
+ - `TODO`: Implement logic for when `!before.reviewInfo && after.reviewInfo`. This could involve notifying the clinic admin or practitioner.
116
+
117
+ ### `handleAppointmentDelete(deletedAppointment: Appointment)`
118
+
119
+ - **Notifications**: `TODO`: Send cancellation/deletion notifications if appropriate (though data is gone, so context might be limited).
120
+ - **Calendar Events**: Placeholder comment `// await this.calendarAdminService.deleteAppointmentCalendarEvents(deletedAppointment);` exists.
121
+ - `TODO`: Implement actual call to delete associated calendar events.
122
+
123
+ ### `managePatientClinicPractitionerLinks(...)`
124
+
125
+ - **Robust Removal Logic**:
126
+ - `TODO`: For the 'cancel' action, implement more robust removal logic. Currently, it removes the patient ID regardless. It should ideally only remove the link if this was the last active/confirmed appointment connecting the patient to the practitioner/clinic.
127
+
128
+ This README should serve as a good guide to the current state and future development of the `AppointmentAggregationService`.