@blackcode_sa/metaestetics-api 1.12.8 → 1.12.10

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.
@@ -3867,14 +3867,37 @@ var FilledFormsAggregationService = class {
3867
3867
  );
3868
3868
  return;
3869
3869
  }
3870
+ let templateData;
3871
+ const templateRef = this.db.collection("documentation-templates").doc(filledDocument.templateId);
3872
+ const templateDoc = await templateRef.get();
3873
+ if (templateDoc.exists) {
3874
+ const currentTemplateData = templateDoc.data();
3875
+ if (currentTemplateData && currentTemplateData.version === filledDocument.templateVersion) {
3876
+ templateData = currentTemplateData;
3877
+ } else {
3878
+ const versionRef = templateRef.collection("versions").doc(filledDocument.templateVersion.toString());
3879
+ const versionDoc = await versionRef.get();
3880
+ if (versionDoc.exists) {
3881
+ templateData = versionDoc.data();
3882
+ } else {
3883
+ Logger.warn(
3884
+ `[FilledFormsAggregationService] Template version ${filledDocument.templateVersion} not found for template ${filledDocument.templateId}. Falling back to the latest version.`
3885
+ );
3886
+ templateData = currentTemplateData;
3887
+ }
3888
+ }
3889
+ } else {
3890
+ Logger.error(
3891
+ `[FilledFormsAggregationService] Document template ${filledDocument.templateId} not found. Cannot retrieve title.`
3892
+ );
3893
+ }
3870
3894
  const appointment = appointmentDoc.data();
3871
3895
  const formSubcollection = filledDocument.isUserForm ? USER_FORMS_SUBCOLLECTION : DOCTOR_FORMS_SUBCOLLECTION;
3872
3896
  const linkedFormInfo = {
3873
3897
  formId: filledDocument.id,
3874
3898
  templateId: filledDocument.templateId,
3875
3899
  templateVersion: filledDocument.templateVersion,
3876
- title: filledDocument.isUserForm ? "User Form" : "Doctor Form",
3877
- // Default title if not available
3900
+ title: (templateData == null ? void 0 : templateData.title) || (filledDocument.isUserForm ? "User Form" : "Doctor Form"),
3878
3901
  isUserForm: filledDocument.isUserForm,
3879
3902
  isRequired: filledDocument.isRequired,
3880
3903
  status: filledDocument.status,
@@ -3909,7 +3932,9 @@ var FilledFormsAggregationService = class {
3909
3932
  }
3910
3933
  if (filledDocument.isUserForm && filledDocument.isRequired && (filledDocument.status === "completed" /* COMPLETED */ || filledDocument.status === "signed" /* SIGNED */)) {
3911
3934
  if (appointment.pendingUserFormsIds && appointment.pendingUserFormsIds.includes(filledDocument.id)) {
3912
- updateData.pendingUserFormsIds = admin8.firestore.FieldValue.arrayRemove(filledDocument.id);
3935
+ updateData.pendingUserFormsIds = admin8.firestore.FieldValue.arrayRemove(
3936
+ filledDocument.id
3937
+ );
3913
3938
  Logger.info(
3914
3939
  `[FilledFormsAggregationService] Removing form ${filledDocument.id} from pendingUserFormsIds`
3915
3940
  );
@@ -3957,9 +3982,7 @@ var FilledFormsAggregationService = class {
3957
3982
  }
3958
3983
  }
3959
3984
  if (appointment.linkedFormIds && appointment.linkedFormIds.includes(filledDocument.id)) {
3960
- updateData.linkedFormIds = admin8.firestore.FieldValue.arrayRemove(
3961
- filledDocument.id
3962
- );
3985
+ updateData.linkedFormIds = admin8.firestore.FieldValue.arrayRemove(filledDocument.id);
3963
3986
  }
3964
3987
  if (filledDocument.isUserForm && filledDocument.isRequired) {
3965
3988
  if (filledDocument.status !== "completed" /* COMPLETED */ && filledDocument.status !== "signed" /* SIGNED */) {
@@ -4009,9 +4032,7 @@ var FilledFormsAggregationService = class {
4009
4032
  return;
4010
4033
  }
4011
4034
  await appointmentRef.update({
4012
- pendingUserFormsIds: admin8.firestore.FieldValue.arrayUnion(
4013
- filledDocument.id
4014
- ),
4035
+ pendingUserFormsIds: admin8.firestore.FieldValue.arrayUnion(filledDocument.id),
4015
4036
  updatedAt: admin8.firestore.FieldValue.serverTimestamp()
4016
4037
  });
4017
4038
  Logger.info(
@@ -3805,14 +3805,37 @@ var FilledFormsAggregationService = class {
3805
3805
  );
3806
3806
  return;
3807
3807
  }
3808
+ let templateData;
3809
+ const templateRef = this.db.collection("documentation-templates").doc(filledDocument.templateId);
3810
+ const templateDoc = await templateRef.get();
3811
+ if (templateDoc.exists) {
3812
+ const currentTemplateData = templateDoc.data();
3813
+ if (currentTemplateData && currentTemplateData.version === filledDocument.templateVersion) {
3814
+ templateData = currentTemplateData;
3815
+ } else {
3816
+ const versionRef = templateRef.collection("versions").doc(filledDocument.templateVersion.toString());
3817
+ const versionDoc = await versionRef.get();
3818
+ if (versionDoc.exists) {
3819
+ templateData = versionDoc.data();
3820
+ } else {
3821
+ Logger.warn(
3822
+ `[FilledFormsAggregationService] Template version ${filledDocument.templateVersion} not found for template ${filledDocument.templateId}. Falling back to the latest version.`
3823
+ );
3824
+ templateData = currentTemplateData;
3825
+ }
3826
+ }
3827
+ } else {
3828
+ Logger.error(
3829
+ `[FilledFormsAggregationService] Document template ${filledDocument.templateId} not found. Cannot retrieve title.`
3830
+ );
3831
+ }
3808
3832
  const appointment = appointmentDoc.data();
3809
3833
  const formSubcollection = filledDocument.isUserForm ? USER_FORMS_SUBCOLLECTION : DOCTOR_FORMS_SUBCOLLECTION;
3810
3834
  const linkedFormInfo = {
3811
3835
  formId: filledDocument.id,
3812
3836
  templateId: filledDocument.templateId,
3813
3837
  templateVersion: filledDocument.templateVersion,
3814
- title: filledDocument.isUserForm ? "User Form" : "Doctor Form",
3815
- // Default title if not available
3838
+ title: (templateData == null ? void 0 : templateData.title) || (filledDocument.isUserForm ? "User Form" : "Doctor Form"),
3816
3839
  isUserForm: filledDocument.isUserForm,
3817
3840
  isRequired: filledDocument.isRequired,
3818
3841
  status: filledDocument.status,
@@ -3847,7 +3870,9 @@ var FilledFormsAggregationService = class {
3847
3870
  }
3848
3871
  if (filledDocument.isUserForm && filledDocument.isRequired && (filledDocument.status === "completed" /* COMPLETED */ || filledDocument.status === "signed" /* SIGNED */)) {
3849
3872
  if (appointment.pendingUserFormsIds && appointment.pendingUserFormsIds.includes(filledDocument.id)) {
3850
- updateData.pendingUserFormsIds = admin8.firestore.FieldValue.arrayRemove(filledDocument.id);
3873
+ updateData.pendingUserFormsIds = admin8.firestore.FieldValue.arrayRemove(
3874
+ filledDocument.id
3875
+ );
3851
3876
  Logger.info(
3852
3877
  `[FilledFormsAggregationService] Removing form ${filledDocument.id} from pendingUserFormsIds`
3853
3878
  );
@@ -3895,9 +3920,7 @@ var FilledFormsAggregationService = class {
3895
3920
  }
3896
3921
  }
3897
3922
  if (appointment.linkedFormIds && appointment.linkedFormIds.includes(filledDocument.id)) {
3898
- updateData.linkedFormIds = admin8.firestore.FieldValue.arrayRemove(
3899
- filledDocument.id
3900
- );
3923
+ updateData.linkedFormIds = admin8.firestore.FieldValue.arrayRemove(filledDocument.id);
3901
3924
  }
3902
3925
  if (filledDocument.isUserForm && filledDocument.isRequired) {
3903
3926
  if (filledDocument.status !== "completed" /* COMPLETED */ && filledDocument.status !== "signed" /* SIGNED */) {
@@ -3947,9 +3970,7 @@ var FilledFormsAggregationService = class {
3947
3970
  return;
3948
3971
  }
3949
3972
  await appointmentRef.update({
3950
- pendingUserFormsIds: admin8.firestore.FieldValue.arrayUnion(
3951
- filledDocument.id
3952
- ),
3973
+ pendingUserFormsIds: admin8.firestore.FieldValue.arrayUnion(filledDocument.id),
3953
3974
  updatedAt: admin8.firestore.FieldValue.serverTimestamp()
3954
3975
  });
3955
3976
  Logger.info(
package/dist/index.d.mts CHANGED
@@ -5885,7 +5885,7 @@ declare class AppointmentService extends BaseService {
5885
5885
  */
5886
5886
  updateAppointmentStatus(appointmentId: string, newStatus: AppointmentStatus, details?: {
5887
5887
  cancellationReason?: string;
5888
- canceledBy?: "patient" | "clinic" | "practitioner" | "system";
5888
+ canceledBy?: 'patient' | 'clinic' | 'practitioner' | 'system';
5889
5889
  }): Promise<Appointment>;
5890
5890
  /**
5891
5891
  * Confirms a PENDING appointment by an Admin/Clinic.
@@ -5944,7 +5944,7 @@ declare class AppointmentService extends BaseService {
5944
5944
  /**
5945
5945
  * Adds a media item to an appointment.
5946
5946
  */
5947
- addMediaToAppointment(appointmentId: string, mediaItemData: Omit<AppointmentMediaItem, "id" | "uploadedAt">): Promise<Appointment>;
5947
+ addMediaToAppointment(appointmentId: string, mediaItemData: Omit<AppointmentMediaItem, 'id' | 'uploadedAt'>): Promise<Appointment>;
5948
5948
  /**
5949
5949
  * Removes a media item from an appointment.
5950
5950
  */
@@ -5952,7 +5952,7 @@ declare class AppointmentService extends BaseService {
5952
5952
  /**
5953
5953
  * Adds or updates review information for an appointment.
5954
5954
  */
5955
- addReviewToAppointment(appointmentId: string, reviewData: Omit<PatientReviewInfo, "reviewedAt" | "reviewId">): Promise<Appointment>;
5955
+ addReviewToAppointment(appointmentId: string, reviewData: Omit<PatientReviewInfo, 'reviewedAt' | 'reviewId'>): Promise<Appointment>;
5956
5956
  /**
5957
5957
  * Updates the payment status of an appointment.
5958
5958
  */
@@ -6002,6 +6002,15 @@ declare class AppointmentService extends BaseService {
6002
6002
  appointments: Appointment[];
6003
6003
  lastDoc: DocumentSnapshot | null;
6004
6004
  }>;
6005
+ /**
6006
+ * Counts completed appointments for a patient with optional clinic filtering.
6007
+ *
6008
+ * @param patientId ID of the patient.
6009
+ * @param clinicBranchId Optional ID of the clinic branch to either include or exclude.
6010
+ * @param excludeClinic Optional boolean. If true (default), excludes the specified clinic. If false, includes only that clinic.
6011
+ * @returns The count of completed appointments.
6012
+ */
6013
+ countCompletedAppointments(patientId: string, clinicBranchId?: string, excludeClinic?: boolean): Promise<number>;
6005
6014
  }
6006
6015
 
6007
6016
  declare class UserService extends BaseService {
@@ -6066,8 +6075,6 @@ declare class UserService extends BaseService {
6066
6075
 
6067
6076
  declare class AuthService extends BaseService {
6068
6077
  private googleProvider;
6069
- private facebookProvider;
6070
- private appleProvider;
6071
6078
  private userService;
6072
6079
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, userService: UserService);
6073
6080
  /**
@@ -6105,20 +6112,6 @@ declare class AuthService extends BaseService {
6105
6112
  clinicAdmin: ClinicAdmin;
6106
6113
  clinicGroup: ClinicGroup;
6107
6114
  }>;
6108
- /**
6109
- * Prijavljuje korisnika sa Facebook-om
6110
- */
6111
- signInWithFacebook(): Promise<User>;
6112
- /**
6113
- * Prijavljuje korisnika sa Google nalogom
6114
- */
6115
- signInWithGoogle(initialRole?: UserRole, options?: {
6116
- patientInviteToken?: string;
6117
- }): Promise<User>;
6118
- /**
6119
- * Prijavljuje korisnika sa Apple-om
6120
- */
6121
- signInWithApple(): Promise<User>;
6122
6115
  /**
6123
6116
  * Prijavljuje korisnika anonimno
6124
6117
  */
@@ -6136,19 +6129,6 @@ declare class AuthService extends BaseService {
6136
6129
  */
6137
6130
  onAuthStateChange(callback: (user: User$1 | null) => void): () => void;
6138
6131
  upgradeAnonymousUser(email: string, password: string): Promise<User>;
6139
- /**
6140
- * Upgrades an anonymous user to a regular user by signing in with a Google account.
6141
- *
6142
- * @throws {AuthError} If the user is not anonymous.
6143
- * @throws {AuthError} If the user is not authenticated.
6144
- * @throws {AuthError} If the popup window is closed by the user.
6145
- * @throws {FirebaseError} If any other Firebase error occurs.
6146
- *
6147
- * @returns {Promise<User>} The upgraded user.
6148
- */
6149
- upgradeAnonymousUserWithGoogle(): Promise<User>;
6150
- upgradeAnonymousUserWithFacebook(): Promise<User>;
6151
- upgradeAnonymousUserWithApple(): Promise<User>;
6152
6132
  /**
6153
6133
  * Šalje email za resetovanje lozinke korisniku
6154
6134
  * @param email Email adresa korisnika
@@ -6203,6 +6183,22 @@ declare class AuthService extends BaseService {
6203
6183
  user: User;
6204
6184
  practitioner: Practitioner;
6205
6185
  }>;
6186
+ /**
6187
+ * Signs in a user with a Google ID token from a mobile client.
6188
+ * If the user does not exist, a new user is created.
6189
+ * @param idToken - The Google ID token obtained from the mobile app.
6190
+ * @param initialRole - The role to assign to the user if they are being created.
6191
+ * @returns The signed-in or newly created user.
6192
+ */
6193
+ signInWithGoogleIdToken(idToken: string, initialRole?: UserRole): Promise<User>;
6194
+ /**
6195
+ * Links a Google account to the currently signed-in user using an ID token.
6196
+ * This is used to upgrade an anonymous user or to allow an existing user
6197
+ * to sign in with Google in the future.
6198
+ * @param idToken - The Google ID token obtained from the mobile app.
6199
+ * @returns The updated user profile.
6200
+ */
6201
+ linkGoogleAccount(idToken: string): Promise<User>;
6206
6202
  }
6207
6203
 
6208
6204
  /**
package/dist/index.d.ts CHANGED
@@ -5885,7 +5885,7 @@ declare class AppointmentService extends BaseService {
5885
5885
  */
5886
5886
  updateAppointmentStatus(appointmentId: string, newStatus: AppointmentStatus, details?: {
5887
5887
  cancellationReason?: string;
5888
- canceledBy?: "patient" | "clinic" | "practitioner" | "system";
5888
+ canceledBy?: 'patient' | 'clinic' | 'practitioner' | 'system';
5889
5889
  }): Promise<Appointment>;
5890
5890
  /**
5891
5891
  * Confirms a PENDING appointment by an Admin/Clinic.
@@ -5944,7 +5944,7 @@ declare class AppointmentService extends BaseService {
5944
5944
  /**
5945
5945
  * Adds a media item to an appointment.
5946
5946
  */
5947
- addMediaToAppointment(appointmentId: string, mediaItemData: Omit<AppointmentMediaItem, "id" | "uploadedAt">): Promise<Appointment>;
5947
+ addMediaToAppointment(appointmentId: string, mediaItemData: Omit<AppointmentMediaItem, 'id' | 'uploadedAt'>): Promise<Appointment>;
5948
5948
  /**
5949
5949
  * Removes a media item from an appointment.
5950
5950
  */
@@ -5952,7 +5952,7 @@ declare class AppointmentService extends BaseService {
5952
5952
  /**
5953
5953
  * Adds or updates review information for an appointment.
5954
5954
  */
5955
- addReviewToAppointment(appointmentId: string, reviewData: Omit<PatientReviewInfo, "reviewedAt" | "reviewId">): Promise<Appointment>;
5955
+ addReviewToAppointment(appointmentId: string, reviewData: Omit<PatientReviewInfo, 'reviewedAt' | 'reviewId'>): Promise<Appointment>;
5956
5956
  /**
5957
5957
  * Updates the payment status of an appointment.
5958
5958
  */
@@ -6002,6 +6002,15 @@ declare class AppointmentService extends BaseService {
6002
6002
  appointments: Appointment[];
6003
6003
  lastDoc: DocumentSnapshot | null;
6004
6004
  }>;
6005
+ /**
6006
+ * Counts completed appointments for a patient with optional clinic filtering.
6007
+ *
6008
+ * @param patientId ID of the patient.
6009
+ * @param clinicBranchId Optional ID of the clinic branch to either include or exclude.
6010
+ * @param excludeClinic Optional boolean. If true (default), excludes the specified clinic. If false, includes only that clinic.
6011
+ * @returns The count of completed appointments.
6012
+ */
6013
+ countCompletedAppointments(patientId: string, clinicBranchId?: string, excludeClinic?: boolean): Promise<number>;
6005
6014
  }
6006
6015
 
6007
6016
  declare class UserService extends BaseService {
@@ -6066,8 +6075,6 @@ declare class UserService extends BaseService {
6066
6075
 
6067
6076
  declare class AuthService extends BaseService {
6068
6077
  private googleProvider;
6069
- private facebookProvider;
6070
- private appleProvider;
6071
6078
  private userService;
6072
6079
  constructor(db: Firestore, auth: Auth, app: FirebaseApp, userService: UserService);
6073
6080
  /**
@@ -6105,20 +6112,6 @@ declare class AuthService extends BaseService {
6105
6112
  clinicAdmin: ClinicAdmin;
6106
6113
  clinicGroup: ClinicGroup;
6107
6114
  }>;
6108
- /**
6109
- * Prijavljuje korisnika sa Facebook-om
6110
- */
6111
- signInWithFacebook(): Promise<User>;
6112
- /**
6113
- * Prijavljuje korisnika sa Google nalogom
6114
- */
6115
- signInWithGoogle(initialRole?: UserRole, options?: {
6116
- patientInviteToken?: string;
6117
- }): Promise<User>;
6118
- /**
6119
- * Prijavljuje korisnika sa Apple-om
6120
- */
6121
- signInWithApple(): Promise<User>;
6122
6115
  /**
6123
6116
  * Prijavljuje korisnika anonimno
6124
6117
  */
@@ -6136,19 +6129,6 @@ declare class AuthService extends BaseService {
6136
6129
  */
6137
6130
  onAuthStateChange(callback: (user: User$1 | null) => void): () => void;
6138
6131
  upgradeAnonymousUser(email: string, password: string): Promise<User>;
6139
- /**
6140
- * Upgrades an anonymous user to a regular user by signing in with a Google account.
6141
- *
6142
- * @throws {AuthError} If the user is not anonymous.
6143
- * @throws {AuthError} If the user is not authenticated.
6144
- * @throws {AuthError} If the popup window is closed by the user.
6145
- * @throws {FirebaseError} If any other Firebase error occurs.
6146
- *
6147
- * @returns {Promise<User>} The upgraded user.
6148
- */
6149
- upgradeAnonymousUserWithGoogle(): Promise<User>;
6150
- upgradeAnonymousUserWithFacebook(): Promise<User>;
6151
- upgradeAnonymousUserWithApple(): Promise<User>;
6152
6132
  /**
6153
6133
  * Šalje email za resetovanje lozinke korisniku
6154
6134
  * @param email Email adresa korisnika
@@ -6203,6 +6183,22 @@ declare class AuthService extends BaseService {
6203
6183
  user: User;
6204
6184
  practitioner: Practitioner;
6205
6185
  }>;
6186
+ /**
6187
+ * Signs in a user with a Google ID token from a mobile client.
6188
+ * If the user does not exist, a new user is created.
6189
+ * @param idToken - The Google ID token obtained from the mobile app.
6190
+ * @param initialRole - The role to assign to the user if they are being created.
6191
+ * @returns The signed-in or newly created user.
6192
+ */
6193
+ signInWithGoogleIdToken(idToken: string, initialRole?: UserRole): Promise<User>;
6194
+ /**
6195
+ * Links a Google account to the currently signed-in user using an ID token.
6196
+ * This is used to upgrade an anonymous user or to allow an existing user
6197
+ * to sign in with Google in the future.
6198
+ * @param idToken - The Google ID token obtained from the mobile app.
6199
+ * @returns The updated user profile.
6200
+ */
6201
+ linkGoogleAccount(idToken: string): Promise<User>;
6206
6202
  }
6207
6203
 
6208
6204
  /**