@blackcode_sa/metaestetics-api 1.6.24 → 1.6.25
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 +31 -3
- package/dist/admin/index.d.ts +31 -3
- package/dist/admin/index.js +126 -36
- package/dist/admin/index.mjs +126 -36
- package/dist/backoffice/index.d.mts +67 -54
- package/dist/backoffice/index.d.ts +67 -54
- package/dist/backoffice/index.js +19 -14
- package/dist/backoffice/index.mjs +19 -14
- package/dist/index.d.mts +271 -258
- package/dist/index.d.ts +271 -258
- package/dist/index.js +19 -14
- package/dist/index.mjs +19 -14
- package/package.json +1 -1
- package/src/admin/booking/booking.admin.ts +8 -5
- package/src/admin/documentation-templates/document-manager.admin.ts +128 -0
- package/src/backoffice/types/technology.types.ts +16 -2
- package/src/services/documentation-templates/documentation-template.service.ts +37 -21
- package/src/types/procedure/index.ts +5 -2
package/dist/admin/index.d.mts
CHANGED
|
@@ -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
|
|
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?:
|
|
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:
|
|
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
|
/**
|
package/dist/admin/index.d.ts
CHANGED
|
@@ -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
|
|
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?:
|
|
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:
|
|
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
|
/**
|
package/dist/admin/index.js
CHANGED
|
@@ -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(
|
|
206
|
+
constructor(firestore13) {
|
|
206
207
|
this.expo = new import_expo_server_sdk.Expo();
|
|
207
|
-
this.db =
|
|
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(
|
|
927
|
-
this.db =
|
|
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(
|
|
1402
|
-
this.db =
|
|
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(
|
|
1738
|
-
this.db =
|
|
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(
|
|
2123
|
-
this.db =
|
|
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(
|
|
2256
|
-
this.db =
|
|
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(
|
|
2585
|
-
this.db =
|
|
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(
|
|
2703
|
+
constructor(firestore13, mailgunClient) {
|
|
2703
2704
|
var _a;
|
|
2704
|
-
this.db =
|
|
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(
|
|
2849
|
-
super(
|
|
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,
|
|
2999
|
-
this.db =
|
|
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(
|
|
4010
|
-
super(
|
|
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
|
|
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(
|
|
4684
|
-
this.db =
|
|
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(
|
|
4767
|
-
this.db =
|
|
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 ?
|
|
4785
|
-
const end = timeframe.end instanceof Date ?
|
|
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:
|
|
4912
|
+
start: admin12.firestore.Timestamp.fromMillis(slot.start.toMillis())
|
|
4825
4913
|
}))
|
|
4826
4914
|
};
|
|
4827
4915
|
} catch (error) {
|
|
@@ -4924,8 +5012,8 @@ var BookingAdmin = class {
|
|
|
4924
5012
|
`[BookingAdmin] Orchestrating appointment creation for patient ${data.patientId} by user ${authenticatedUserId}`
|
|
4925
5013
|
);
|
|
4926
5014
|
const batch = this.db.batch();
|
|
4927
|
-
const adminTsNow =
|
|
4928
|
-
const serverTimestampValue =
|
|
5015
|
+
const adminTsNow = admin12.firestore.Timestamp.now();
|
|
5016
|
+
const serverTimestampValue = admin12.firestore.FieldValue.serverTimestamp();
|
|
4929
5017
|
try {
|
|
4930
5018
|
if (!data.patientId || !data.procedureId || !data.appointmentStartTime || !data.appointmentEndTime) {
|
|
4931
5019
|
return {
|
|
@@ -5022,7 +5110,7 @@ var BookingAdmin = class {
|
|
|
5022
5110
|
fullName: `${(patientSensitiveData == null ? void 0 : patientSensitiveData.firstName) || ""} ${(patientSensitiveData == null ? void 0 : patientSensitiveData.lastName) || ""}`.trim() || patientProfileData.displayName,
|
|
5023
5111
|
email: (patientSensitiveData == null ? void 0 : patientSensitiveData.email) || "",
|
|
5024
5112
|
phone: (patientSensitiveData == null ? void 0 : patientSensitiveData.phoneNumber) || patientProfileData.phoneNumber || null,
|
|
5025
|
-
dateOfBirth: (patientSensitiveData == null ? void 0 : patientSensitiveData.dateOfBirth) || patientProfileData.dateOfBirth ||
|
|
5113
|
+
dateOfBirth: (patientSensitiveData == null ? void 0 : patientSensitiveData.dateOfBirth) || patientProfileData.dateOfBirth || admin12.firestore.Timestamp.now(),
|
|
5026
5114
|
gender: (patientSensitiveData == null ? void 0 : patientSensitiveData.gender) || "other" /* OTHER */
|
|
5027
5115
|
};
|
|
5028
5116
|
const procedureCategory = procedure.category;
|
|
@@ -5072,9 +5160,11 @@ var BookingAdmin = class {
|
|
|
5072
5160
|
if (procedure.documentationTemplates && Array.isArray(procedure.documentationTemplates)) {
|
|
5073
5161
|
pendingUserFormsIds = procedure.documentationTemplates.filter(
|
|
5074
5162
|
(template) => template.isUserForm && template.isRequired
|
|
5075
|
-
).map(
|
|
5163
|
+
).map(
|
|
5164
|
+
(template) => template.templateId
|
|
5165
|
+
);
|
|
5076
5166
|
linkedFormIds = procedure.documentationTemplates.map(
|
|
5077
|
-
(template) => template.
|
|
5167
|
+
(template) => template.templateId
|
|
5078
5168
|
);
|
|
5079
5169
|
}
|
|
5080
5170
|
const newAppointmentId = this.db.collection(APPOINTMENTS_COLLECTION).doc().id;
|
|
@@ -5162,7 +5252,7 @@ var BookingAdmin = class {
|
|
|
5162
5252
|
let pendingUserFormTemplateIds = [];
|
|
5163
5253
|
let allLinkedFormTemplateIds = [];
|
|
5164
5254
|
if (procedure.documentationTemplates && Array.isArray(procedure.documentationTemplates) && procedure.documentationTemplates.length > 0) {
|
|
5165
|
-
const formInitResult = this.documentManagerAdmin.
|
|
5255
|
+
const formInitResult = await this.documentManagerAdmin.batchInitializeAppointmentFormsFromTechnologyTemplates(
|
|
5166
5256
|
batch,
|
|
5167
5257
|
newAppointmentId,
|
|
5168
5258
|
procedure.id,
|