@blackcode_sa/metaestetics-api 1.6.24 → 1.6.26

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.
@@ -455,6 +455,19 @@ declare enum TreatmentBenefit {
455
455
  CIRCULATION_IMPROVEMENT = "circulation_improvement"
456
456
  }
457
457
 
458
+ /**
459
+ * Reference to a documentation template with metadata
460
+ * @property templateId - ID of the documentation template
461
+ * @property isUserForm - Whether this template is filled by users
462
+ * @property isRequired - Whether this template is required
463
+ * @property sortingOrder - The display order of this template
464
+ */
465
+ interface TechnologyDocumentationTemplate {
466
+ templateId: string;
467
+ isUserForm: boolean;
468
+ isRequired: boolean;
469
+ sortingOrder: number;
470
+ }
458
471
  /**
459
472
  * Technology used in medical procedures
460
473
  * Technologies are now a top-level collection that reference their full path in the hierarchy
@@ -472,7 +485,7 @@ declare enum TreatmentBenefit {
472
485
  * @property contraindications - List of conditions requiring special attention
473
486
  * @property benefits - List of expected benefits from the procedure
474
487
  * @property certificationRequirement - Required certification level and specialties
475
- * @property documentationTemplates - List of documentation templates required for this technology
488
+ * @property documentationTemplates - List of documentation template references
476
489
  * @property isActive - Whether the technology is active in the system
477
490
  * @property createdAt - Creation date
478
491
  * @property updatedAt - Last update date
@@ -493,7 +506,7 @@ interface Technology {
493
506
  contraindications: Contraindication[];
494
507
  benefits: TreatmentBenefit[];
495
508
  certificationRequirement: CertificationRequirement;
496
- documentationTemplates?: DocumentTemplate[];
509
+ documentationTemplates?: TechnologyDocumentationTemplate[];
497
510
  isActive: boolean;
498
511
  createdAt: Date;
499
512
  updatedAt: Date;
@@ -597,7 +610,7 @@ interface Procedure {
597
610
  /** Certification requirements for performing this procedure */
598
611
  certificationRequirement: CertificationRequirement;
599
612
  /** Documentation templates required for this procedure */
600
- documentationTemplates: DocumentTemplate[];
613
+ documentationTemplates: TechnologyDocumentationTemplate[];
601
614
  /** ID of the practitioner who performs this procedure */
602
615
  practitionerId: string;
603
616
  /** ID of the clinic branch where this procedure is performed */
@@ -2518,6 +2531,21 @@ declare class DocumentManagerAdminService {
2518
2531
  * @returns An object containing initializedFormsInfo, pendingUserFormsIds, and allLinkedTemplateIds.
2519
2532
  */
2520
2533
  batchInitializeAppointmentForms(dbBatch: admin.firestore.WriteBatch, appointmentId: string, procedureIdForForms: string, procedureTemplates: DocumentTemplate[], patientId: string, practitionerId: string, clinicId: string, nowMillis: number): InitializeAppointmentFormsResult;
2534
+ /**
2535
+ * Adds operations to a Firestore batch to initialize all linked forms for a new appointment
2536
+ * using the TechnologyDocumentationTemplate references.
2537
+ *
2538
+ * @param dbBatch - The Firestore batch to add operations to.
2539
+ * @param appointmentId - The ID of the newly created appointment.
2540
+ * @param procedureIdForForms - The ID of the procedure associated with this appointment.
2541
+ * @param technologyTemplates - Array of technology documentation template references.
2542
+ * @param patientId - ID of the patient.
2543
+ * @param practitionerId - ID of the practitioner associated with the procedure.
2544
+ * @param clinicId - ID of the clinic where the procedure is performed.
2545
+ * @param nowMillis - Current timestamp in milliseconds for createdAt/updatedAt.
2546
+ * @returns An object containing initializedFormsInfo, pendingUserFormsIds, and allLinkedTemplateIds.
2547
+ */
2548
+ batchInitializeAppointmentFormsFromTechnologyTemplates(dbBatch: admin.firestore.WriteBatch, appointmentId: string, procedureIdForForms: string, technologyTemplates: TechnologyDocumentationTemplate[], patientId: string, practitionerId: string, clinicId: string, nowMillis: number): Promise<InitializeAppointmentFormsResult>;
2521
2549
  }
2522
2550
 
2523
2551
  /**
@@ -455,6 +455,19 @@ declare enum TreatmentBenefit {
455
455
  CIRCULATION_IMPROVEMENT = "circulation_improvement"
456
456
  }
457
457
 
458
+ /**
459
+ * Reference to a documentation template with metadata
460
+ * @property templateId - ID of the documentation template
461
+ * @property isUserForm - Whether this template is filled by users
462
+ * @property isRequired - Whether this template is required
463
+ * @property sortingOrder - The display order of this template
464
+ */
465
+ interface TechnologyDocumentationTemplate {
466
+ templateId: string;
467
+ isUserForm: boolean;
468
+ isRequired: boolean;
469
+ sortingOrder: number;
470
+ }
458
471
  /**
459
472
  * Technology used in medical procedures
460
473
  * Technologies are now a top-level collection that reference their full path in the hierarchy
@@ -472,7 +485,7 @@ declare enum TreatmentBenefit {
472
485
  * @property contraindications - List of conditions requiring special attention
473
486
  * @property benefits - List of expected benefits from the procedure
474
487
  * @property certificationRequirement - Required certification level and specialties
475
- * @property documentationTemplates - List of documentation templates required for this technology
488
+ * @property documentationTemplates - List of documentation template references
476
489
  * @property isActive - Whether the technology is active in the system
477
490
  * @property createdAt - Creation date
478
491
  * @property updatedAt - Last update date
@@ -493,7 +506,7 @@ interface Technology {
493
506
  contraindications: Contraindication[];
494
507
  benefits: TreatmentBenefit[];
495
508
  certificationRequirement: CertificationRequirement;
496
- documentationTemplates?: DocumentTemplate[];
509
+ documentationTemplates?: TechnologyDocumentationTemplate[];
497
510
  isActive: boolean;
498
511
  createdAt: Date;
499
512
  updatedAt: Date;
@@ -597,7 +610,7 @@ interface Procedure {
597
610
  /** Certification requirements for performing this procedure */
598
611
  certificationRequirement: CertificationRequirement;
599
612
  /** Documentation templates required for this procedure */
600
- documentationTemplates: DocumentTemplate[];
613
+ documentationTemplates: TechnologyDocumentationTemplate[];
601
614
  /** ID of the practitioner who performs this procedure */
602
615
  practitionerId: string;
603
616
  /** ID of the clinic branch where this procedure is performed */
@@ -2518,6 +2531,21 @@ declare class DocumentManagerAdminService {
2518
2531
  * @returns An object containing initializedFormsInfo, pendingUserFormsIds, and allLinkedTemplateIds.
2519
2532
  */
2520
2533
  batchInitializeAppointmentForms(dbBatch: admin.firestore.WriteBatch, appointmentId: string, procedureIdForForms: string, procedureTemplates: DocumentTemplate[], patientId: string, practitionerId: string, clinicId: string, nowMillis: number): InitializeAppointmentFormsResult;
2534
+ /**
2535
+ * Adds operations to a Firestore batch to initialize all linked forms for a new appointment
2536
+ * using the TechnologyDocumentationTemplate references.
2537
+ *
2538
+ * @param dbBatch - The Firestore batch to add operations to.
2539
+ * @param appointmentId - The ID of the newly created appointment.
2540
+ * @param procedureIdForForms - The ID of the procedure associated with this appointment.
2541
+ * @param technologyTemplates - Array of technology documentation template references.
2542
+ * @param patientId - ID of the patient.
2543
+ * @param practitionerId - ID of the practitioner associated with the procedure.
2544
+ * @param clinicId - ID of the clinic where the procedure is performed.
2545
+ * @param nowMillis - Current timestamp in milliseconds for createdAt/updatedAt.
2546
+ * @returns An object containing initializedFormsInfo, pendingUserFormsIds, and allLinkedTemplateIds.
2547
+ */
2548
+ batchInitializeAppointmentFormsFromTechnologyTemplates(dbBatch: admin.firestore.WriteBatch, appointmentId: string, procedureIdForForms: string, technologyTemplates: TechnologyDocumentationTemplate[], patientId: string, practitionerId: string, clinicId: string, nowMillis: number): Promise<InitializeAppointmentFormsResult>;
2521
2549
  }
2522
2550
 
2523
2551
  /**
@@ -127,6 +127,7 @@ var MediaType = /* @__PURE__ */ ((MediaType2) => {
127
127
  var APPOINTMENTS_COLLECTION = "appointments";
128
128
 
129
129
  // src/types/documentation-templates/index.ts
130
+ var DOCUMENTATION_TEMPLATES_COLLECTION = "documentation-templates";
130
131
  var USER_FORMS_SUBCOLLECTION = "user-forms";
131
132
  var DOCTOR_FORMS_SUBCOLLECTION = "doctor-forms";
132
133
 
@@ -202,9 +203,9 @@ var Logger = class {
202
203
 
203
204
  // src/admin/notifications/notifications.admin.ts
204
205
  var NotificationsAdmin = class {
205
- constructor(firestore12) {
206
+ constructor(firestore13) {
206
207
  this.expo = new import_expo_server_sdk.Expo();
207
- this.db = firestore12 || admin.firestore();
208
+ this.db = firestore13 || admin.firestore();
208
209
  }
209
210
  /**
210
211
  * Dohvata notifikaciju po ID-u
@@ -923,8 +924,8 @@ var ClinicAggregationService = class {
923
924
  * Constructor for ClinicAggregationService.
924
925
  * @param firestore Optional Firestore instance. If not provided, it uses the default admin SDK instance.
925
926
  */
926
- constructor(firestore12) {
927
- this.db = firestore12 || admin3.firestore();
927
+ constructor(firestore13) {
928
+ this.db = firestore13 || admin3.firestore();
928
929
  }
929
930
  /**
930
931
  * Adds clinic information to a clinic group when a new clinic is created
@@ -1398,8 +1399,8 @@ var ClinicAggregationService = class {
1398
1399
  var admin4 = __toESM(require("firebase-admin"));
1399
1400
  var CALENDAR_SUBCOLLECTION_ID2 = "calendar";
1400
1401
  var PractitionerAggregationService = class {
1401
- constructor(firestore12) {
1402
- this.db = firestore12 || admin4.firestore();
1402
+ constructor(firestore13) {
1403
+ this.db = firestore13 || admin4.firestore();
1403
1404
  }
1404
1405
  /**
1405
1406
  * Adds practitioner information to a clinic when a new practitioner is created
@@ -1734,8 +1735,8 @@ var PractitionerAggregationService = class {
1734
1735
  var admin5 = __toESM(require("firebase-admin"));
1735
1736
  var CALENDAR_SUBCOLLECTION_ID3 = "calendar";
1736
1737
  var ProcedureAggregationService = class {
1737
- constructor(firestore12) {
1738
- this.db = firestore12 || admin5.firestore();
1738
+ constructor(firestore13) {
1739
+ this.db = firestore13 || admin5.firestore();
1739
1740
  }
1740
1741
  /**
1741
1742
  * Adds procedure information to a practitioner when a new procedure is created
@@ -2119,8 +2120,8 @@ var ProcedureAggregationService = class {
2119
2120
  var admin6 = __toESM(require("firebase-admin"));
2120
2121
  var CALENDAR_SUBCOLLECTION_ID4 = "calendar";
2121
2122
  var PatientAggregationService = class {
2122
- constructor(firestore12) {
2123
- this.db = firestore12 || admin6.firestore();
2123
+ constructor(firestore13) {
2124
+ this.db = firestore13 || admin6.firestore();
2124
2125
  }
2125
2126
  // --- Methods for Patient Creation --- >
2126
2127
  // No specific aggregations defined for patient creation in the plan.
@@ -2252,8 +2253,8 @@ var PATIENT_REQUIREMENTS_SUBCOLLECTION_NAME = "patientRequirements";
2252
2253
  // src/admin/requirements/patient-requirements.admin.service.ts
2253
2254
  var admin7 = __toESM(require("firebase-admin"));
2254
2255
  var PatientRequirementsAdminService = class {
2255
- constructor(firestore12) {
2256
- this.db = firestore12 || admin7.firestore();
2256
+ constructor(firestore13) {
2257
+ this.db = firestore13 || admin7.firestore();
2257
2258
  this.notificationsAdmin = new NotificationsAdmin(this.db);
2258
2259
  }
2259
2260
  /**
@@ -2581,8 +2582,8 @@ var PatientRequirementsAdminService = class {
2581
2582
  // src/admin/calendar/calendar.admin.service.ts
2582
2583
  var admin8 = __toESM(require("firebase-admin"));
2583
2584
  var CalendarAdminService = class {
2584
- constructor(firestore12) {
2585
- this.db = firestore12 || admin8.firestore();
2585
+ constructor(firestore13) {
2586
+ this.db = firestore13 || admin8.firestore();
2586
2587
  Logger.info("[CalendarAdminService] Initialized.");
2587
2588
  }
2588
2589
  /**
@@ -2699,9 +2700,9 @@ var BaseMailingService = class {
2699
2700
  * @param firestore Firestore instance provided by the caller
2700
2701
  * @param mailgunClient Mailgun client instance (mailgun.js v10+) provided by the caller
2701
2702
  */
2702
- constructor(firestore12, mailgunClient) {
2703
+ constructor(firestore13, mailgunClient) {
2703
2704
  var _a;
2704
- this.db = firestore12;
2705
+ this.db = firestore13;
2705
2706
  this.mailgunClient = mailgunClient;
2706
2707
  if (!this.db) {
2707
2708
  Logger.error("[BaseMailingService] No Firestore instance provided");
@@ -2845,8 +2846,8 @@ var BaseMailingService = class {
2845
2846
  var patientAppointmentConfirmedTemplate = "<h1>Appointment Confirmed</h1><p>Dear {{patientName}},</p><p>Your appointment for {{procedureName}} on {{appointmentDate}} at {{appointmentTime}} with {{practitionerName}} at {{clinicName}} has been confirmed.</p><p>Thank you!</p>";
2846
2847
  var clinicAppointmentRequestedTemplate = "<h1>New Appointment Request</h1><p>Hello {{clinicName}} Admin,</p><p>A new appointment for {{procedureName}} has been requested by {{patientName}} for {{appointmentDate}} at {{appointmentTime}} with {{practitionerName}}.</p><p>Please review and confirm in the admin panel.</p>";
2847
2848
  var AppointmentMailingService = class extends BaseMailingService {
2848
- constructor(firestore12, mailgunClient) {
2849
- super(firestore12, mailgunClient);
2849
+ constructor(firestore13, mailgunClient) {
2850
+ super(firestore13, mailgunClient);
2850
2851
  this.DEFAULT_MAILGUN_DOMAIN = "mg.metaesthetics.net";
2851
2852
  Logger.info("[AppointmentMailingService] Initialized.");
2852
2853
  }
@@ -2995,8 +2996,8 @@ var AppointmentAggregationService = class {
2995
2996
  * @param mailgunClient - An initialized Mailgun client instance.
2996
2997
  * @param firestore Optional Firestore instance. If not provided, it uses the default admin SDK instance.
2997
2998
  */
2998
- constructor(mailgunClient, firestore12) {
2999
- this.db = firestore12 || admin10.firestore();
2999
+ constructor(mailgunClient, firestore13) {
3000
+ this.db = firestore13 || admin10.firestore();
3000
3001
  this.appointmentMailingService = new AppointmentMailingService(
3001
3002
  this.db,
3002
3003
  mailgunClient
@@ -4006,8 +4007,8 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
4006
4007
  * @param firestore Firestore instance provided by the caller
4007
4008
  * @param mailgunClient Mailgun client instance (mailgun.js v10+) provided by the caller
4008
4009
  */
4009
- constructor(firestore12, mailgunClient) {
4010
- super(firestore12, mailgunClient);
4010
+ constructor(firestore13, mailgunClient) {
4011
+ super(firestore13, mailgunClient);
4011
4012
  this.DEFAULT_REGISTRATION_URL = "https://metaesthetics.net/register";
4012
4013
  this.DEFAULT_SUBJECT = "You've Been Invited to Join as a Practitioner";
4013
4014
  this.DEFAULT_MAILGUN_DOMAIN = "mg.metaesthetics.net";
@@ -4245,7 +4246,7 @@ var PractitionerInviteMailingService = class extends BaseMailingService {
4245
4246
  };
4246
4247
 
4247
4248
  // src/admin/booking/booking.admin.ts
4248
- var admin11 = __toESM(require("firebase-admin"));
4249
+ var admin12 = __toESM(require("firebase-admin"));
4249
4250
 
4250
4251
  // src/admin/booking/booking.calculator.ts
4251
4252
  var import_firestore2 = require("firebase/firestore");
@@ -4679,9 +4680,10 @@ var BookingAvailabilityCalculator = class {
4679
4680
  BookingAvailabilityCalculator.DEFAULT_INTERVAL_MINUTES = 15;
4680
4681
 
4681
4682
  // src/admin/documentation-templates/document-manager.admin.ts
4683
+ var admin11 = __toESM(require("firebase-admin"));
4682
4684
  var DocumentManagerAdminService = class {
4683
- constructor(firestore12) {
4684
- this.db = firestore12;
4685
+ constructor(firestore13) {
4686
+ this.db = firestore13;
4685
4687
  }
4686
4688
  /**
4687
4689
  * Adds operations to a Firestore batch to initialize all linked forms for a new appointment
@@ -4755,6 +4757,92 @@ var DocumentManagerAdminService = class {
4755
4757
  }
4756
4758
  return { initializedFormsInfo, pendingUserFormsIds, allLinkedTemplateIds };
4757
4759
  }
4760
+ /**
4761
+ * Adds operations to a Firestore batch to initialize all linked forms for a new appointment
4762
+ * using the TechnologyDocumentationTemplate references.
4763
+ *
4764
+ * @param dbBatch - The Firestore batch to add operations to.
4765
+ * @param appointmentId - The ID of the newly created appointment.
4766
+ * @param procedureIdForForms - The ID of the procedure associated with this appointment.
4767
+ * @param technologyTemplates - Array of technology documentation template references.
4768
+ * @param patientId - ID of the patient.
4769
+ * @param practitionerId - ID of the practitioner associated with the procedure.
4770
+ * @param clinicId - ID of the clinic where the procedure is performed.
4771
+ * @param nowMillis - Current timestamp in milliseconds for createdAt/updatedAt.
4772
+ * @returns An object containing initializedFormsInfo, pendingUserFormsIds, and allLinkedTemplateIds.
4773
+ */
4774
+ async batchInitializeAppointmentFormsFromTechnologyTemplates(dbBatch, appointmentId, procedureIdForForms, technologyTemplates, patientId, practitionerId, clinicId, nowMillis) {
4775
+ const initializedFormsInfo = [];
4776
+ const pendingUserFormsIds = [];
4777
+ const allLinkedTemplateIds = [];
4778
+ if (!technologyTemplates || technologyTemplates.length === 0) {
4779
+ console.log(
4780
+ `[DocManagerAdmin] No document templates to initialize for appointment ${appointmentId}.`
4781
+ );
4782
+ return {
4783
+ initializedFormsInfo,
4784
+ pendingUserFormsIds,
4785
+ allLinkedTemplateIds
4786
+ };
4787
+ }
4788
+ const templateIds = technologyTemplates.map((t) => t.templateId);
4789
+ const templatesSnapshot = await this.db.collection(DOCUMENTATION_TEMPLATES_COLLECTION).where(admin11.firestore.FieldPath.documentId(), "in", templateIds).get();
4790
+ const templatesMap = /* @__PURE__ */ new Map();
4791
+ templatesSnapshot.forEach((doc) => {
4792
+ templatesMap.set(doc.id, doc.data());
4793
+ });
4794
+ for (const templateRef of technologyTemplates) {
4795
+ const template = templatesMap.get(templateRef.templateId);
4796
+ if (!template) {
4797
+ console.warn(
4798
+ `[DocManagerAdmin] Template ${templateRef.templateId} not found in Firestore.`
4799
+ );
4800
+ continue;
4801
+ }
4802
+ const isUserForm = templateRef.isUserForm;
4803
+ const isRequired = templateRef.isRequired;
4804
+ const formSubcollectionPath = isUserForm ? USER_FORMS_SUBCOLLECTION : DOCTOR_FORMS_SUBCOLLECTION;
4805
+ const filledDocumentId = this.db.collection(APPOINTMENTS_COLLECTION).doc(appointmentId).collection(formSubcollectionPath).doc().id;
4806
+ if (isUserForm && isRequired) {
4807
+ pendingUserFormsIds.push(filledDocumentId);
4808
+ }
4809
+ allLinkedTemplateIds.push(filledDocumentId);
4810
+ const initialStatus = "pending" /* PENDING */;
4811
+ const filledDocumentData = {
4812
+ id: filledDocumentId,
4813
+ templateId: templateRef.templateId,
4814
+ templateVersion: template.version,
4815
+ isUserForm,
4816
+ isRequired,
4817
+ appointmentId,
4818
+ procedureId: procedureIdForForms,
4819
+ patientId,
4820
+ practitionerId,
4821
+ clinicId,
4822
+ createdAt: nowMillis,
4823
+ updatedAt: nowMillis,
4824
+ values: {},
4825
+ status: initialStatus
4826
+ };
4827
+ const docRef = this.db.collection(APPOINTMENTS_COLLECTION).doc(appointmentId).collection(formSubcollectionPath).doc(filledDocumentId);
4828
+ dbBatch.set(docRef, filledDocumentData);
4829
+ const linkedForm = {
4830
+ formId: filledDocumentData.id,
4831
+ templateId: template.id,
4832
+ templateVersion: template.version,
4833
+ title: template.title,
4834
+ isUserForm: filledDocumentData.isUserForm,
4835
+ isRequired: filledDocumentData.isRequired,
4836
+ status: filledDocumentData.status,
4837
+ path: docRef.path
4838
+ };
4839
+ initializedFormsInfo.push(linkedForm);
4840
+ console.log(
4841
+ `[DocManagerAdmin] Added FilledDocument ${filledDocumentId} (template: ${template.id}) and its LinkedFormInfo to batch for appointment ${appointmentId}.`
4842
+ );
4843
+ }
4844
+ return { initializedFormsInfo, pendingUserFormsIds, allLinkedTemplateIds };
4845
+ }
4758
4846
  };
4759
4847
 
4760
4848
  // src/admin/booking/booking.admin.ts
@@ -4763,8 +4851,8 @@ var BookingAdmin = class {
4763
4851
  * Creates a new BookingAdmin instance
4764
4852
  * @param firestore - Firestore instance provided by the caller
4765
4853
  */
4766
- constructor(firestore12) {
4767
- this.db = firestore12 || admin11.firestore();
4854
+ constructor(firestore13) {
4855
+ this.db = firestore13 || admin12.firestore();
4768
4856
  this.documentManagerAdmin = new DocumentManagerAdminService(this.db);
4769
4857
  }
4770
4858
  /**
@@ -4781,8 +4869,8 @@ var BookingAdmin = class {
4781
4869
  console.log(
4782
4870
  `[BookingAdmin] Getting available slots for clinic ${clinicId}, practitioner ${practitionerId}, procedure ${procedureId}`
4783
4871
  );
4784
- const start = timeframe.start instanceof Date ? admin11.firestore.Timestamp.fromDate(timeframe.start) : timeframe.start;
4785
- const end = timeframe.end instanceof Date ? admin11.firestore.Timestamp.fromDate(timeframe.end) : timeframe.end;
4872
+ const start = timeframe.start instanceof Date ? admin12.firestore.Timestamp.fromDate(timeframe.start) : timeframe.start;
4873
+ const end = timeframe.end instanceof Date ? admin12.firestore.Timestamp.fromDate(timeframe.end) : timeframe.end;
4786
4874
  const clinicDoc = await this.db.collection("clinics").doc(clinicId).get();
4787
4875
  if (!clinicDoc.exists) {
4788
4876
  throw new Error(`Clinic ${clinicId} not found`);
@@ -4821,7 +4909,7 @@ var BookingAdmin = class {
4821
4909
  const result = BookingAvailabilityCalculator.calculateSlots(request);
4822
4910
  return {
4823
4911
  availableSlots: result.availableSlots.map((slot) => ({
4824
- start: admin11.firestore.Timestamp.fromMillis(slot.start.toMillis())
4912
+ start: admin12.firestore.Timestamp.fromMillis(slot.start.toMillis())
4825
4913
  }))
4826
4914
  };
4827
4915
  } catch (error) {
@@ -4919,13 +5007,12 @@ var BookingAdmin = class {
4919
5007
  * @returns Promise resolving to an object indicating success, and appointmentId or an error message.
4920
5008
  */
4921
5009
  async orchestrateAppointmentCreation(data, authenticatedUserId) {
4922
- var _a;
4923
5010
  console.log(
4924
5011
  `[BookingAdmin] Orchestrating appointment creation for patient ${data.patientId} by user ${authenticatedUserId}`
4925
5012
  );
4926
5013
  const batch = this.db.batch();
4927
- const adminTsNow = admin11.firestore.Timestamp.now();
4928
- const serverTimestampValue = admin11.firestore.FieldValue.serverTimestamp();
5014
+ const adminTsNow = admin12.firestore.Timestamp.now();
5015
+ const serverTimestampValue = admin12.firestore.FieldValue.serverTimestamp();
4929
5016
  try {
4930
5017
  if (!data.patientId || !data.procedureId || !data.appointmentStartTime || !data.appointmentEndTime) {
4931
5018
  return {
@@ -5022,61 +5109,9 @@ var BookingAdmin = class {
5022
5109
  fullName: `${(patientSensitiveData == null ? void 0 : patientSensitiveData.firstName) || ""} ${(patientSensitiveData == null ? void 0 : patientSensitiveData.lastName) || ""}`.trim() || patientProfileData.displayName,
5023
5110
  email: (patientSensitiveData == null ? void 0 : patientSensitiveData.email) || "",
5024
5111
  phone: (patientSensitiveData == null ? void 0 : patientSensitiveData.phoneNumber) || patientProfileData.phoneNumber || null,
5025
- dateOfBirth: (patientSensitiveData == null ? void 0 : patientSensitiveData.dateOfBirth) || patientProfileData.dateOfBirth || admin11.firestore.Timestamp.now(),
5112
+ dateOfBirth: (patientSensitiveData == null ? void 0 : patientSensitiveData.dateOfBirth) || patientProfileData.dateOfBirth || admin12.firestore.Timestamp.now(),
5026
5113
  gender: (patientSensitiveData == null ? void 0 : patientSensitiveData.gender) || "other" /* OTHER */
5027
5114
  };
5028
- const procedureCategory = procedure.category;
5029
- const procedureSubCategory = procedure.subcategory;
5030
- const procedureTechnology = procedure.technology;
5031
- const procedureProduct = procedure.product;
5032
- const procedureInfo = {
5033
- id: procedure.id,
5034
- name: procedure.name,
5035
- description: procedure.description,
5036
- family: procedure.family,
5037
- categoryName: (procedureCategory == null ? void 0 : procedureCategory.name) || "",
5038
- subcategoryName: (procedureSubCategory == null ? void 0 : procedureSubCategory.name) || "",
5039
- technologyName: (procedureTechnology == null ? void 0 : procedureTechnology.name) || "",
5040
- price: procedure.price,
5041
- pricingMeasure: procedure.pricingMeasure,
5042
- currency: procedure.currency,
5043
- duration: procedure.duration,
5044
- clinicId: procedure.clinicBranchId,
5045
- clinicName: clinicData.name,
5046
- practitionerId: procedure.practitionerId,
5047
- practitionerName: `${practitionerData.basicInfo.firstName} ${practitionerData.basicInfo.lastName}`,
5048
- photo: ((_a = procedure.photos) == null ? void 0 : _a[0]) || "",
5049
- brandName: (procedureProduct == null ? void 0 : procedureProduct.brandName) || "",
5050
- productName: (procedureProduct == null ? void 0 : procedureProduct.name) || ""
5051
- };
5052
- const procedureExtendedInfo = {
5053
- id: procedure.id,
5054
- name: procedure.name,
5055
- description: procedure.description,
5056
- cost: procedure.price,
5057
- duration: procedure.duration,
5058
- procedureFamily: procedure.family,
5059
- procedureCategoryId: (procedureCategory == null ? void 0 : procedureCategory.id) || "",
5060
- procedureCategoryName: (procedureCategory == null ? void 0 : procedureCategory.name) || "",
5061
- procedureSubCategoryId: (procedureSubCategory == null ? void 0 : procedureSubCategory.id) || "",
5062
- procedureSubCategoryName: (procedureSubCategory == null ? void 0 : procedureSubCategory.name) || "",
5063
- procedureTechnologyId: (procedureTechnology == null ? void 0 : procedureTechnology.id) || "",
5064
- procedureTechnologyName: (procedureTechnology == null ? void 0 : procedureTechnology.name) || "",
5065
- procedureProductBrandId: procedureProduct.brandId || "",
5066
- procedureProductBrandName: procedureProduct.brandName || "",
5067
- procedureProductId: procedureProduct.id || "",
5068
- procedureProductName: procedureProduct.name || ""
5069
- };
5070
- let pendingUserFormsIds = [];
5071
- let linkedFormIds = [];
5072
- if (procedure.documentationTemplates && Array.isArray(procedure.documentationTemplates)) {
5073
- pendingUserFormsIds = procedure.documentationTemplates.filter(
5074
- (template) => template.isUserForm && template.isRequired
5075
- ).map((template) => template.id);
5076
- linkedFormIds = procedure.documentationTemplates.map(
5077
- (template) => template.id
5078
- );
5079
- }
5080
5115
  const newAppointmentId = this.db.collection(APPOINTMENTS_COLLECTION).doc().id;
5081
5116
  const eventTimeForCalendarEvents = {
5082
5117
  start: data.appointmentStartTime,
@@ -5162,7 +5197,7 @@ var BookingAdmin = class {
5162
5197
  let pendingUserFormTemplateIds = [];
5163
5198
  let allLinkedFormTemplateIds = [];
5164
5199
  if (procedure.documentationTemplates && Array.isArray(procedure.documentationTemplates) && procedure.documentationTemplates.length > 0) {
5165
- const formInitResult = this.documentManagerAdmin.batchInitializeAppointmentForms(
5200
+ const formInitResult = await this.documentManagerAdmin.batchInitializeAppointmentFormsFromTechnologyTemplates(
5166
5201
  batch,
5167
5202
  newAppointmentId,
5168
5203
  procedure.id,