@blackcode_sa/metaestetics-api 1.15.17-staging.4 → 1.15.17-staging.5

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.mjs CHANGED
@@ -482,11 +482,11 @@ var StaffInviteStatus = /* @__PURE__ */ ((StaffInviteStatus2) => {
482
482
  var CLINIC_GROUPS_COLLECTION = "clinic_groups";
483
483
  var CLINIC_ADMINS_COLLECTION = "clinic_admins";
484
484
  var CLINICS_COLLECTION = "clinics";
485
- var AdminTokenStatus = /* @__PURE__ */ ((AdminTokenStatus2) => {
486
- AdminTokenStatus2["ACTIVE"] = "active";
487
- AdminTokenStatus2["USED"] = "used";
488
- AdminTokenStatus2["EXPIRED"] = "expired";
489
- return AdminTokenStatus2;
485
+ var AdminTokenStatus = /* @__PURE__ */ ((AdminTokenStatus3) => {
486
+ AdminTokenStatus3["ACTIVE"] = "active";
487
+ AdminTokenStatus3["USED"] = "used";
488
+ AdminTokenStatus3["EXPIRED"] = "expired";
489
+ return AdminTokenStatus3;
490
490
  })(AdminTokenStatus || {});
491
491
  var SubscriptionModel = /* @__PURE__ */ ((SubscriptionModel2) => {
492
492
  SubscriptionModel2["NO_SUBSCRIPTION"] = "no_subscription";
@@ -2004,7 +2004,7 @@ var AnalyticsService = class extends BaseService {
2004
2004
  * @param limit - Number of top procedures to return
2005
2005
  * @returns Array of procedure popularity metrics
2006
2006
  */
2007
- async getProcedurePopularity(dateRange, limit22 = 10) {
2007
+ async getProcedurePopularity(dateRange, limit23 = 10) {
2008
2008
  const appointments = await this.fetchAppointments(void 0, dateRange);
2009
2009
  const completed = getCompletedAppointments(appointments);
2010
2010
  const procedureMap = /* @__PURE__ */ new Map();
@@ -2033,7 +2033,7 @@ var AnalyticsService = class extends BaseService {
2033
2033
  completedCount: data.count,
2034
2034
  rank: 0
2035
2035
  // Will be set after sorting
2036
- })).sort((a, b) => b.appointmentCount - a.appointmentCount).slice(0, limit22).map((item, index) => ({ ...item, rank: index + 1 }));
2036
+ })).sort((a, b) => b.appointmentCount - a.appointmentCount).slice(0, limit23).map((item, index) => ({ ...item, rank: index + 1 }));
2037
2037
  }
2038
2038
  /**
2039
2039
  * Get procedure profitability metrics
@@ -2042,7 +2042,7 @@ var AnalyticsService = class extends BaseService {
2042
2042
  * @param limit - Number of top procedures to return
2043
2043
  * @returns Array of procedure profitability metrics
2044
2044
  */
2045
- async getProcedureProfitability(dateRange, limit22 = 10) {
2045
+ async getProcedureProfitability(dateRange, limit23 = 10) {
2046
2046
  const appointments = await this.fetchAppointments(void 0, dateRange);
2047
2047
  const completed = getCompletedAppointments(appointments);
2048
2048
  const procedureMap = /* @__PURE__ */ new Map();
@@ -2076,7 +2076,7 @@ var AnalyticsService = class extends BaseService {
2076
2076
  appointmentCount: data.count,
2077
2077
  rank: 0
2078
2078
  // Will be set after sorting
2079
- })).sort((a, b) => b.totalRevenue - a.totalRevenue).slice(0, limit22).map((item, index) => ({ ...item, rank: index + 1 }));
2079
+ })).sort((a, b) => b.totalRevenue - a.totalRevenue).slice(0, limit23).map((item, index) => ({ ...item, rank: index + 1 }));
2080
2080
  }
2081
2081
  // ==========================================
2082
2082
  // Time Efficiency Analytics
@@ -5616,10 +5616,9 @@ var adminTokenSchema = z9.object({
5616
5616
  email: z9.string().email().optional().nullable(),
5617
5617
  status: z9.nativeEnum(AdminTokenStatus),
5618
5618
  usedByUserRef: z9.string().optional(),
5619
+ clinicGroupId: z9.string(),
5619
5620
  createdAt: z9.instanceof(Date).or(z9.instanceof(Timestamp7)),
5620
- // Timestamp
5621
5621
  expiresAt: z9.instanceof(Date).or(z9.instanceof(Timestamp7))
5622
- // Timestamp
5623
5622
  });
5624
5623
  var stripeTransactionDataSchema = z9.object({
5625
5624
  sessionId: z9.string().optional(),
@@ -5680,7 +5679,7 @@ var clinicGroupSchema = z9.object({
5680
5679
  clinicsInfo: z9.array(clinicInfoSchema),
5681
5680
  admins: z9.array(z9.string()),
5682
5681
  adminsInfo: z9.array(adminInfoSchema),
5683
- adminTokens: z9.array(adminTokenSchema),
5682
+ adminTokens: z9.array(adminTokenSchema).optional(),
5684
5683
  ownerId: z9.string().nullable(),
5685
5684
  createdAt: z9.instanceof(Date).or(z9.instanceof(Timestamp7)),
5686
5685
  // Timestamp
@@ -9749,9 +9748,6 @@ import {
9749
9748
  OAuthProvider
9750
9749
  } from "firebase/auth";
9751
9750
  import {
9752
- collection as collection22,
9753
- query as query22,
9754
- getDocs as getDocs22,
9755
9751
  runTransaction
9756
9752
  } from "firebase/firestore";
9757
9753
  import { z as z28 } from "zod";
@@ -15597,13 +15593,16 @@ var BillingTransactionsService = class extends BaseService {
15597
15593
  // src/services/clinic/utils/clinic-group.utils.ts
15598
15594
  import {
15599
15595
  collection as collection17,
15596
+ collectionGroup as collectionGroup2,
15600
15597
  doc as doc28,
15601
15598
  getDoc as getDoc30,
15602
15599
  getDocs as getDocs17,
15603
15600
  query as query17,
15604
15601
  where as where17,
15602
+ limit as limit9,
15605
15603
  updateDoc as updateDoc24,
15606
15604
  setDoc as setDoc17,
15605
+ deleteDoc as deleteDoc6,
15607
15606
  Timestamp as Timestamp20
15608
15607
  } from "firebase/firestore";
15609
15608
  import { geohashForLocation as geohashForLocation2 } from "geofire-common";
@@ -15759,6 +15758,7 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
15759
15758
  admins: [ownerId],
15760
15759
  adminsInfo: [],
15761
15760
  adminTokens: [],
15761
+ // @deprecated — tokens now in subcollection, kept for backward compat
15762
15762
  ownerId,
15763
15763
  createdAt: now,
15764
15764
  updatedAt: now,
@@ -15943,6 +15943,10 @@ async function deactivateClinicGroup(db, groupId, app) {
15943
15943
  app
15944
15944
  );
15945
15945
  }
15946
+ var ADMIN_TOKENS_SUBCOLLECTION = "adminTokens";
15947
+ function adminTokensRef(db, groupId) {
15948
+ return collection17(db, CLINIC_GROUPS_COLLECTION, groupId, ADMIN_TOKENS_SUBCOLLECTION);
15949
+ }
15946
15950
  async function createAdminToken(db, groupId, creatorAdminId, app, data) {
15947
15951
  const group = await getClinicGroup(db, groupId);
15948
15952
  if (!group) {
@@ -15958,68 +15962,60 @@ async function createAdminToken(db, groupId, creatorAdminId, app, data) {
15958
15962
  now.seconds + expiresInDays * 24 * 60 * 60,
15959
15963
  now.nanoseconds
15960
15964
  );
15965
+ const tokenRef = doc28(adminTokensRef(db, groupId));
15961
15966
  const token = {
15962
- id: generateId(),
15967
+ id: tokenRef.id,
15963
15968
  token: generateId(),
15964
15969
  status: "active" /* ACTIVE */,
15965
15970
  email,
15971
+ clinicGroupId: groupId,
15966
15972
  createdAt: now,
15967
15973
  expiresAt
15968
15974
  };
15969
- await updateClinicGroup(
15970
- db,
15971
- groupId,
15972
- {
15973
- adminTokens: [...group.adminTokens, token]
15974
- },
15975
- app
15976
- );
15975
+ await setDoc17(tokenRef, token);
15977
15976
  return token;
15978
15977
  }
15979
- async function verifyAndUseAdminToken(db, groupId, token, userRef, app) {
15980
- const group = await getClinicGroup(db, groupId);
15981
- if (!group) {
15982
- throw new Error("Clinic group not found");
15983
- }
15984
- const adminToken = group.adminTokens.find((t) => t.token === token);
15985
- if (!adminToken) {
15978
+ async function verifyAndUseAdminToken(db, groupId, tokenValue, userRef, app) {
15979
+ const tokensQuery = query17(
15980
+ adminTokensRef(db, groupId),
15981
+ where17("token", "==", tokenValue),
15982
+ limit9(1)
15983
+ );
15984
+ const snapshot = await getDocs17(tokensQuery);
15985
+ if (snapshot.empty) {
15986
15986
  throw new Error("Admin token not found");
15987
15987
  }
15988
+ const tokenDoc = snapshot.docs[0];
15989
+ const adminToken = tokenDoc.data();
15988
15990
  if (adminToken.status !== "active" /* ACTIVE */) {
15989
15991
  throw new Error("Admin token is not active");
15990
15992
  }
15991
15993
  const now = Timestamp20.now();
15992
15994
  if (adminToken.expiresAt.seconds < now.seconds) {
15993
- const updatedTokens2 = group.adminTokens.map(
15994
- (t) => t.id === adminToken.id ? { ...t, status: "expired" /* EXPIRED */ } : t
15995
- );
15996
- await updateClinicGroup(
15997
- db,
15998
- groupId,
15999
- {
16000
- adminTokens: updatedTokens2
16001
- },
16002
- app
16003
- );
15995
+ await updateDoc24(tokenDoc.ref, { status: "expired" /* EXPIRED */ });
16004
15996
  throw new Error("Admin token has expired");
16005
15997
  }
16006
- const updatedTokens = group.adminTokens.map(
16007
- (t) => t.id === adminToken.id ? {
16008
- ...t,
16009
- status: "used" /* USED */,
16010
- usedByUserRef: userRef
16011
- } : t
16012
- );
16013
- await updateClinicGroup(
16014
- db,
16015
- groupId,
16016
- {
16017
- adminTokens: updatedTokens
16018
- },
16019
- app
16020
- );
15998
+ await updateDoc24(tokenDoc.ref, {
15999
+ status: "used" /* USED */,
16000
+ usedByUserRef: userRef
16001
+ });
16021
16002
  return true;
16022
16003
  }
16004
+ async function findAdminTokenByValue(db, tokenValue) {
16005
+ const tokensQuery = query17(
16006
+ collectionGroup2(db, ADMIN_TOKENS_SUBCOLLECTION),
16007
+ where17("token", "==", tokenValue),
16008
+ where17("status", "==", "active" /* ACTIVE */),
16009
+ limit9(1)
16010
+ );
16011
+ const snapshot = await getDocs17(tokensQuery);
16012
+ if (snapshot.empty) return null;
16013
+ const tokenData = snapshot.docs[0].data();
16014
+ return {
16015
+ token: tokenData,
16016
+ clinicGroupId: tokenData.clinicGroupId
16017
+ };
16018
+ }
16023
16019
  async function deleteAdminToken(db, groupId, tokenId, adminId, app) {
16024
16020
  const group = await getClinicGroup(db, groupId);
16025
16021
  if (!group) {
@@ -16028,15 +16024,7 @@ async function deleteAdminToken(db, groupId, tokenId, adminId, app) {
16028
16024
  if (!group.admins.includes(adminId)) {
16029
16025
  throw new Error("Admin does not belong to this clinic group");
16030
16026
  }
16031
- const updatedTokens = group.adminTokens.filter((t) => t.id !== tokenId);
16032
- await updateClinicGroup(
16033
- db,
16034
- groupId,
16035
- {
16036
- adminTokens: updatedTokens
16037
- },
16038
- app
16039
- );
16027
+ await deleteDoc6(doc28(adminTokensRef(db, groupId), tokenId));
16040
16028
  }
16041
16029
  async function getActiveAdminTokens(db, groupId, adminId, app) {
16042
16030
  const group = await getClinicGroup(db, groupId);
@@ -16046,7 +16034,23 @@ async function getActiveAdminTokens(db, groupId, adminId, app) {
16046
16034
  if (!group.admins.includes(adminId)) {
16047
16035
  throw new Error("Admin does not belong to this clinic group");
16048
16036
  }
16049
- return group.adminTokens.filter((t) => t.status === "active" /* ACTIVE */);
16037
+ const tokensQuery = query17(
16038
+ adminTokensRef(db, groupId),
16039
+ where17("status", "==", "active" /* ACTIVE */)
16040
+ );
16041
+ const snapshot = await getDocs17(tokensQuery);
16042
+ return snapshot.docs.map((d) => d.data());
16043
+ }
16044
+ async function getAllAdminTokens(db, groupId, adminId, app) {
16045
+ const group = await getClinicGroup(db, groupId);
16046
+ if (!group) {
16047
+ throw new Error("Clinic group not found");
16048
+ }
16049
+ if (!group.admins.includes(adminId)) {
16050
+ throw new Error("Admin does not belong to this clinic group");
16051
+ }
16052
+ const snapshot = await getDocs17(adminTokensRef(db, groupId));
16053
+ return snapshot.docs.map((d) => d.data());
16050
16054
  }
16051
16055
 
16052
16056
  // src/services/clinic/clinic-group.service.ts
@@ -16176,11 +16180,19 @@ var ClinicGroupService = class extends BaseService {
16176
16180
  async getActiveAdminTokens(groupId, adminId) {
16177
16181
  return getActiveAdminTokens(this.db, groupId, adminId, this.app);
16178
16182
  }
16179
- // TODO: Add a method to get all admin tokens for a clinic group (not just active ones)
16180
- // TODO: Refactor admin token methods not to add tokens to the clinicGroup document,
16181
- // but to add them to a subcollection called adminTokens that belongs to a specific clinicGroup document
16182
- // TODO: Add granular control over admin permissions, e.g. only allow admins to manage certain clinics to tokens directly
16183
- // TODO: Generally refactor admin tokens and invites, also create cloud function to send invites and send updates when sombody uses the token
16183
+ /**
16184
+ * Gets ALL admin tokens for a clinic group (all statuses)
16185
+ */
16186
+ async getAllAdminTokens(groupId, adminId) {
16187
+ return getAllAdminTokens(this.db, groupId, adminId, this.app);
16188
+ }
16189
+ /**
16190
+ * Finds an admin token by its value across all clinic groups.
16191
+ * Uses a collection group query for O(1) lookup.
16192
+ */
16193
+ async findAdminTokenByValue(tokenValue) {
16194
+ return findAdminTokenByValue(this.db, tokenValue);
16195
+ }
16184
16196
  /**
16185
16197
  * Updates the onboarding status for a clinic group
16186
16198
  *
@@ -16278,7 +16290,7 @@ import {
16278
16290
  updateDoc as updateDoc25,
16279
16291
  setDoc as setDoc18,
16280
16292
  Timestamp as Timestamp21,
16281
- limit as limit9,
16293
+ limit as limit10,
16282
16294
  startAfter as startAfter8
16283
16295
  } from "firebase/firestore";
16284
16296
  import {
@@ -16567,10 +16579,10 @@ async function getAllClinics(db, pagination, lastDoc, excludeDraftPractitioners
16567
16579
  clinicsQuery = query18(
16568
16580
  clinicsCollection,
16569
16581
  startAfter8(lastDoc),
16570
- limit9(pagination)
16582
+ limit10(pagination)
16571
16583
  );
16572
16584
  } else {
16573
- clinicsQuery = query18(clinicsCollection, limit9(pagination));
16585
+ clinicsQuery = query18(clinicsCollection, limit10(pagination));
16574
16586
  }
16575
16587
  }
16576
16588
  const clinicsSnapshot = await getDocs18(clinicsQuery);
@@ -16763,8 +16775,8 @@ import {
16763
16775
  where as where20,
16764
16776
  getDocs as getDocs20,
16765
16777
  startAfter as startAfter9,
16766
- limit as limit10,
16767
- orderBy as orderBy6
16778
+ limit as limit11,
16779
+ orderBy as orderBy7
16768
16780
  } from "firebase/firestore";
16769
16781
  import { geohashQueryBounds as geohashQueryBounds3, distanceBetween as distanceBetween4 } from "geofire-common";
16770
16782
  async function getClinicsByFilters(db, filters) {
@@ -16851,7 +16863,7 @@ async function getClinicsByFilters(db, filters) {
16851
16863
  const constraints = getBaseConstraints();
16852
16864
  constraints.push(where20("nameLower", ">=", searchTerm));
16853
16865
  constraints.push(where20("nameLower", "<=", searchTerm + "\uF8FF"));
16854
- constraints.push(orderBy6("nameLower"));
16866
+ constraints.push(orderBy7("nameLower"));
16855
16867
  if (filters.lastDoc) {
16856
16868
  if (typeof filters.lastDoc.data === "function") {
16857
16869
  constraints.push(startAfter9(filters.lastDoc));
@@ -16861,7 +16873,7 @@ async function getClinicsByFilters(db, filters) {
16861
16873
  constraints.push(startAfter9(filters.lastDoc));
16862
16874
  }
16863
16875
  }
16864
- constraints.push(limit10(filters.pagination || 5));
16876
+ constraints.push(limit11(filters.pagination || 5));
16865
16877
  const q = query20(collection20(db, CLINICS_COLLECTION), ...constraints);
16866
16878
  const querySnapshot = await getDocs20(q);
16867
16879
  let clinics = querySnapshot.docs.map((doc54) => ({ ...doc54.data(), id: doc54.id }));
@@ -16886,7 +16898,7 @@ async function getClinicsByFilters(db, filters) {
16886
16898
  const constraints = getBaseConstraints();
16887
16899
  constraints.push(where20("name", ">=", searchTerm));
16888
16900
  constraints.push(where20("name", "<=", searchTerm + "\uF8FF"));
16889
- constraints.push(orderBy6("name"));
16901
+ constraints.push(orderBy7("name"));
16890
16902
  if (filters.lastDoc) {
16891
16903
  if (typeof filters.lastDoc.data === "function") {
16892
16904
  constraints.push(startAfter9(filters.lastDoc));
@@ -16896,7 +16908,7 @@ async function getClinicsByFilters(db, filters) {
16896
16908
  constraints.push(startAfter9(filters.lastDoc));
16897
16909
  }
16898
16910
  }
16899
- constraints.push(limit10(filters.pagination || 5));
16911
+ constraints.push(limit11(filters.pagination || 5));
16900
16912
  const q = query20(collection20(db, CLINICS_COLLECTION), ...constraints);
16901
16913
  const querySnapshot = await getDocs20(q);
16902
16914
  let clinics = querySnapshot.docs.map((doc54) => ({ ...doc54.data(), id: doc54.id }));
@@ -16919,7 +16931,7 @@ async function getClinicsByFilters(db, filters) {
16919
16931
  "[CLINIC_SERVICE] Strategy 3: Using createdAt ordering with client-side filtering"
16920
16932
  );
16921
16933
  const constraints = getBaseConstraints();
16922
- constraints.push(orderBy6("createdAt", "desc"));
16934
+ constraints.push(orderBy7("createdAt", "desc"));
16923
16935
  if (filters.lastDoc) {
16924
16936
  if (typeof filters.lastDoc.data === "function") {
16925
16937
  constraints.push(startAfter9(filters.lastDoc));
@@ -16929,7 +16941,7 @@ async function getClinicsByFilters(db, filters) {
16929
16941
  constraints.push(startAfter9(filters.lastDoc));
16930
16942
  }
16931
16943
  }
16932
- constraints.push(limit10(filters.pagination || 5));
16944
+ constraints.push(limit11(filters.pagination || 5));
16933
16945
  const q = query20(collection20(db, CLINICS_COLLECTION), ...constraints);
16934
16946
  const querySnapshot = await getDocs20(q);
16935
16947
  let clinics = querySnapshot.docs.map((doc54) => ({ ...doc54.data(), id: doc54.id }));
@@ -16947,8 +16959,8 @@ async function getClinicsByFilters(db, filters) {
16947
16959
  console.log("[CLINIC_SERVICE] Strategy 4: Minimal fallback");
16948
16960
  const constraints = [
16949
16961
  where20("isActive", "==", true),
16950
- orderBy6("createdAt", "desc"),
16951
- limit10(filters.pagination || 5)
16962
+ orderBy7("createdAt", "desc"),
16963
+ limit11(filters.pagination || 5)
16952
16964
  ];
16953
16965
  const q = query20(collection20(db, CLINICS_COLLECTION), ...constraints);
16954
16966
  const querySnapshot = await getDocs20(q);
@@ -17874,46 +17886,20 @@ var AuthService = class extends BaseService {
17874
17886
  console.log("[AUTH] Invite token provided", {
17875
17887
  token: data.inviteToken
17876
17888
  });
17877
- console.log("[AUTH] Searching for token in clinic groups");
17878
- const groupsRef = collection22(this.db, CLINIC_GROUPS_COLLECTION);
17879
- const q = query22(groupsRef);
17880
- const querySnapshot = await getDocs22(q);
17881
- let foundGroup = null;
17882
- let foundToken = null;
17883
- console.log("[AUTH] Found", querySnapshot.size, "clinic groups to check");
17884
- for (const docSnapshot of querySnapshot.docs) {
17885
- const group = docSnapshot.data();
17886
- console.log("[AUTH] Checking group", {
17887
- groupId: group.id,
17888
- groupName: group.name
17889
- });
17890
- const token = group.adminTokens.find((t) => {
17891
- const isMatch = t.token === data.inviteToken && t.status === "active" /* ACTIVE */ && new Date(t.expiresAt.toDate()) > /* @__PURE__ */ new Date();
17892
- console.log("[AUTH] Checking token", {
17893
- tokenId: t.id,
17894
- tokenMatch: t.token === data.inviteToken,
17895
- tokenStatus: t.status,
17896
- tokenActive: t.status === "active" /* ACTIVE */,
17897
- tokenExpiry: new Date(t.expiresAt.toDate()),
17898
- tokenExpired: new Date(t.expiresAt.toDate()) <= /* @__PURE__ */ new Date(),
17899
- isMatch
17900
- });
17901
- return isMatch;
17902
- });
17903
- if (token) {
17904
- foundGroup = group;
17905
- foundToken = token;
17906
- console.log("[AUTH] Found matching token in group", {
17907
- groupId: group.id,
17908
- tokenId: token.id
17909
- });
17910
- break;
17911
- }
17912
- }
17913
- if (!foundGroup || !foundToken) {
17914
- console.error("[AUTH] No valid token found in any clinic group");
17889
+ console.log("[AUTH] Searching for token via collection group query");
17890
+ const tokenResult = await clinicGroupService.findAdminTokenByValue(data.inviteToken);
17891
+ if (!tokenResult) {
17892
+ console.error("[AUTH] No valid active token found");
17915
17893
  throw new Error("Invalid or expired invite token");
17916
17894
  }
17895
+ console.log("[AUTH] Found matching token", {
17896
+ tokenId: tokenResult.token.id,
17897
+ clinicGroupId: tokenResult.clinicGroupId
17898
+ });
17899
+ const foundGroup = await clinicGroupService.getClinicGroup(tokenResult.clinicGroupId);
17900
+ if (!foundGroup) {
17901
+ throw new Error("Clinic group not found for token");
17902
+ }
17917
17903
  clinicGroup = foundGroup;
17918
17904
  console.log("[AUTH] Creating clinic admin");
17919
17905
  const createClinicAdminData = {
@@ -18743,7 +18729,7 @@ import {
18743
18729
  deleteDoc as deleteDoc10,
18744
18730
  query as query23,
18745
18731
  where as where23,
18746
- orderBy as orderBy8,
18732
+ orderBy as orderBy9,
18747
18733
  Timestamp as Timestamp24,
18748
18734
  serverTimestamp as serverTimestamp25
18749
18735
  } from "firebase/firestore";
@@ -18847,7 +18833,7 @@ import {
18847
18833
  deleteDoc as deleteDoc11,
18848
18834
  query as query24,
18849
18835
  where as where24,
18850
- orderBy as orderBy9,
18836
+ orderBy as orderBy10,
18851
18837
  Timestamp as Timestamp25,
18852
18838
  serverTimestamp as serverTimestamp26
18853
18839
  } from "firebase/firestore";
@@ -18891,7 +18877,7 @@ import {
18891
18877
  deleteDoc as deleteDoc12,
18892
18878
  query as query25,
18893
18879
  where as where25,
18894
- orderBy as orderBy10,
18880
+ orderBy as orderBy11,
18895
18881
  Timestamp as Timestamp26,
18896
18882
  serverTimestamp as serverTimestamp27
18897
18883
  } from "firebase/firestore";
@@ -18994,7 +18980,7 @@ import {
18994
18980
  deleteDoc as deleteDoc13,
18995
18981
  query as query26,
18996
18982
  where as where26,
18997
- orderBy as orderBy11,
18983
+ orderBy as orderBy12,
18998
18984
  Timestamp as Timestamp27,
18999
18985
  serverTimestamp as serverTimestamp28
19000
18986
  } from "firebase/firestore";
@@ -19121,7 +19107,7 @@ import {
19121
19107
  updateDoc as updateDoc32,
19122
19108
  deleteDoc as deleteDoc14,
19123
19109
  query as query27,
19124
- orderBy as orderBy12,
19110
+ orderBy as orderBy13,
19125
19111
  Timestamp as Timestamp28,
19126
19112
  serverTimestamp as serverTimestamp29
19127
19113
  } from "firebase/firestore";
@@ -19194,7 +19180,7 @@ async function getPractitionerSyncedCalendarsUtil(db, practitionerId) {
19194
19180
  db,
19195
19181
  `practitioners/${practitionerId}/${SYNCED_CALENDARS_COLLECTION}`
19196
19182
  );
19197
- const q = query27(calendarsRef, orderBy12("createdAt", "desc"));
19183
+ const q = query27(calendarsRef, orderBy13("createdAt", "desc"));
19198
19184
  const querySnapshot = await getDocs27(q);
19199
19185
  return querySnapshot.docs.map((doc54) => doc54.data());
19200
19186
  }
@@ -19211,7 +19197,7 @@ async function getPatientSyncedCalendarsUtil(db, patientId) {
19211
19197
  db,
19212
19198
  `patients/${patientId}/${SYNCED_CALENDARS_COLLECTION}`
19213
19199
  );
19214
- const q = query27(calendarsRef, orderBy12("createdAt", "desc"));
19200
+ const q = query27(calendarsRef, orderBy13("createdAt", "desc"));
19215
19201
  const querySnapshot = await getDocs27(q);
19216
19202
  return querySnapshot.docs.map((doc54) => doc54.data());
19217
19203
  }
@@ -19228,7 +19214,7 @@ async function getClinicSyncedCalendarsUtil(db, clinicId) {
19228
19214
  db,
19229
19215
  `clinics/${clinicId}/${SYNCED_CALENDARS_COLLECTION}`
19230
19216
  );
19231
- const q = query27(calendarsRef, orderBy12("createdAt", "desc"));
19217
+ const q = query27(calendarsRef, orderBy13("createdAt", "desc"));
19232
19218
  const querySnapshot = await getDocs27(q);
19233
19219
  return querySnapshot.docs.map((doc54) => doc54.data());
19234
19220
  }
@@ -21670,8 +21656,8 @@ import {
21670
21656
  deleteDoc as deleteDoc16,
21671
21657
  Timestamp as Timestamp32,
21672
21658
  serverTimestamp as serverTimestamp32,
21673
- orderBy as orderBy13,
21674
- limit as limit12
21659
+ orderBy as orderBy14,
21660
+ limit as limit13
21675
21661
  } from "firebase/firestore";
21676
21662
  var PractitionerInviteService = class extends BaseService {
21677
21663
  constructor(db, auth, app) {
@@ -21766,7 +21752,7 @@ var PractitionerInviteService = class extends BaseService {
21766
21752
  try {
21767
21753
  const constraints = [
21768
21754
  where29("practitionerId", "==", practitionerId),
21769
- orderBy13("createdAt", "desc")
21755
+ orderBy14("createdAt", "desc")
21770
21756
  ];
21771
21757
  if (statusFilter && statusFilter.length > 0) {
21772
21758
  constraints.push(where29("status", "in", statusFilter));
@@ -21795,7 +21781,7 @@ var PractitionerInviteService = class extends BaseService {
21795
21781
  try {
21796
21782
  const constraints = [
21797
21783
  where29("clinicId", "==", clinicId),
21798
- orderBy13("createdAt", "desc")
21784
+ orderBy14("createdAt", "desc")
21799
21785
  ];
21800
21786
  if (statusFilter && statusFilter.length > 0) {
21801
21787
  constraints.push(where29("status", "in", statusFilter));
@@ -21951,9 +21937,9 @@ var PractitionerInviteService = class extends BaseService {
21951
21937
  }
21952
21938
  const orderField = filters.orderBy || "createdAt";
21953
21939
  const orderDirection = filters.orderDirection || "desc";
21954
- constraints.push(orderBy13(orderField, orderDirection));
21940
+ constraints.push(orderBy14(orderField, orderDirection));
21955
21941
  if (filters.limit) {
21956
- constraints.push(limit12(filters.limit));
21942
+ constraints.push(limit13(filters.limit));
21957
21943
  }
21958
21944
  const q = query29(
21959
21945
  collection29(this.db, PRACTITIONER_INVITES_COLLECTION),
@@ -22044,8 +22030,8 @@ var PractitionerInviteService = class extends BaseService {
22044
22030
  collection29(this.db, PRACTITIONER_INVITES_COLLECTION),
22045
22031
  where29("practitionerId", "==", practitionerId),
22046
22032
  where29("clinicId", "==", clinicId),
22047
- orderBy13("createdAt", "desc"),
22048
- limit12(1)
22033
+ orderBy14("createdAt", "desc"),
22034
+ limit13(1)
22049
22035
  );
22050
22036
  const querySnapshot = await getDocs29(q);
22051
22037
  if (querySnapshot.empty) {
@@ -22073,8 +22059,8 @@ import {
22073
22059
  deleteDoc as deleteDoc17,
22074
22060
  query as query30,
22075
22061
  where as where30,
22076
- orderBy as orderBy14,
22077
- limit as limit13,
22062
+ orderBy as orderBy15,
22063
+ limit as limit14,
22078
22064
  startAfter as startAfter11
22079
22065
  } from "firebase/firestore";
22080
22066
  import { getCountFromServer as getCountFromServer2 } from "firebase/firestore";
@@ -22229,7 +22215,7 @@ var DocumentationTemplateService = class extends BaseService {
22229
22215
  this.db,
22230
22216
  `${DOCUMENTATION_TEMPLATES_COLLECTION}/${templateId}/versions`
22231
22217
  );
22232
- const q = query30(versionsCollectionRef, orderBy14("version", "desc"));
22218
+ const q = query30(versionsCollectionRef, orderBy15("version", "desc"));
22233
22219
  const querySnapshot = await getDocs30(q);
22234
22220
  const versions = [];
22235
22221
  querySnapshot.forEach((doc54) => {
@@ -22255,8 +22241,8 @@ var DocumentationTemplateService = class extends BaseService {
22255
22241
  let q = query30(
22256
22242
  this.collectionRef,
22257
22243
  where30("isActive", "==", true),
22258
- orderBy14("updatedAt", "desc"),
22259
- limit13(pageSize)
22244
+ orderBy15("updatedAt", "desc"),
22245
+ limit14(pageSize)
22260
22246
  );
22261
22247
  if (lastDoc) {
22262
22248
  q = query30(q, startAfter11(lastDoc));
@@ -22288,9 +22274,9 @@ var DocumentationTemplateService = class extends BaseService {
22288
22274
  } = options;
22289
22275
  const constraints = [
22290
22276
  where30("isActive", "==", true),
22291
- orderBy14("sortingOrder", "asc"),
22292
- orderBy14("title", "asc"),
22293
- limit13(pageSize)
22277
+ orderBy15("sortingOrder", "asc"),
22278
+ orderBy15("title", "asc"),
22279
+ limit14(pageSize)
22294
22280
  ];
22295
22281
  if (isUserForm !== void 0) {
22296
22282
  constraints.push(where30("isUserForm", "==", isUserForm));
@@ -22346,7 +22332,7 @@ var DocumentationTemplateService = class extends BaseService {
22346
22332
  const q = query30(
22347
22333
  this.collectionRef,
22348
22334
  where30("isActive", "==", true),
22349
- orderBy14("title", "asc")
22335
+ orderBy15("title", "asc")
22350
22336
  );
22351
22337
  const querySnapshot = await getDocs30(q);
22352
22338
  const templates = [];
@@ -22367,8 +22353,8 @@ var DocumentationTemplateService = class extends BaseService {
22367
22353
  this.collectionRef,
22368
22354
  where30("isActive", "==", true),
22369
22355
  where30("tags", "array-contains-any", tags),
22370
- orderBy14("updatedAt", "desc"),
22371
- limit13(pageSize)
22356
+ orderBy15("updatedAt", "desc"),
22357
+ limit14(pageSize)
22372
22358
  );
22373
22359
  if (lastDoc) {
22374
22360
  q = query30(q, startAfter11(lastDoc));
@@ -22396,8 +22382,8 @@ var DocumentationTemplateService = class extends BaseService {
22396
22382
  let q = query30(
22397
22383
  this.collectionRef,
22398
22384
  where30("createdBy", "==", userId),
22399
- orderBy14("updatedAt", "desc"),
22400
- limit13(pageSize)
22385
+ orderBy15("updatedAt", "desc"),
22386
+ limit14(pageSize)
22401
22387
  );
22402
22388
  if (lastDoc) {
22403
22389
  q = query30(q, startAfter11(lastDoc));
@@ -22423,7 +22409,7 @@ var DocumentationTemplateService = class extends BaseService {
22423
22409
  let q = query30(
22424
22410
  this.collectionRef,
22425
22411
  where30("isActive", "==", true),
22426
- orderBy14("updatedAt", "desc")
22412
+ orderBy15("updatedAt", "desc")
22427
22413
  );
22428
22414
  if ((options == null ? void 0 : options.isUserForm) !== void 0) {
22429
22415
  q = query30(q, where30("isUserForm", "==", options.isUserForm));
@@ -22449,8 +22435,8 @@ import {
22449
22435
  setDoc as setDoc30,
22450
22436
  updateDoc as updateDoc37,
22451
22437
  query as query31,
22452
- orderBy as orderBy15,
22453
- limit as limit14,
22438
+ orderBy as orderBy16,
22439
+ limit as limit15,
22454
22440
  startAfter as startAfter12
22455
22441
  } from "firebase/firestore";
22456
22442
  var FilledDocumentService = class extends BaseService {
@@ -22607,8 +22593,8 @@ var FilledDocumentService = class extends BaseService {
22607
22593
  );
22608
22594
  let q = query31(
22609
22595
  subcollectionRef,
22610
- orderBy15("updatedAt", "desc"),
22611
- limit14(pageSize)
22596
+ orderBy16("updatedAt", "desc"),
22597
+ limit15(pageSize)
22612
22598
  );
22613
22599
  if (lastDoc) {
22614
22600
  q = query31(q, startAfter12(lastDoc));
@@ -22631,8 +22617,8 @@ var FilledDocumentService = class extends BaseService {
22631
22617
  );
22632
22618
  let q = query31(
22633
22619
  subcollectionRef,
22634
- orderBy15("updatedAt", "desc"),
22635
- limit14(pageSize)
22620
+ orderBy16("updatedAt", "desc"),
22621
+ limit15(pageSize)
22636
22622
  );
22637
22623
  if (lastDoc) {
22638
22624
  q = query31(q, startAfter12(lastDoc));
@@ -22818,7 +22804,7 @@ import {
22818
22804
  where as where32,
22819
22805
  updateDoc as updateDoc38,
22820
22806
  deleteDoc as deleteDoc18,
22821
- orderBy as orderBy16,
22807
+ orderBy as orderBy17,
22822
22808
  Timestamp as Timestamp34,
22823
22809
  addDoc as addDoc3,
22824
22810
  writeBatch as writeBatch5
@@ -22869,7 +22855,7 @@ var NotificationService = class extends BaseService {
22869
22855
  const q = query32(
22870
22856
  collection32(this.db, NOTIFICATIONS_COLLECTION),
22871
22857
  where32("userId", "==", userId),
22872
- orderBy16("notificationTime", "desc")
22858
+ orderBy17("notificationTime", "desc")
22873
22859
  );
22874
22860
  const querySnapshot = await getDocs32(q);
22875
22861
  return querySnapshot.docs.map((doc54) => ({
@@ -22885,7 +22871,7 @@ var NotificationService = class extends BaseService {
22885
22871
  collection32(this.db, NOTIFICATIONS_COLLECTION),
22886
22872
  where32("userId", "==", userId),
22887
22873
  where32("isRead", "==", false),
22888
- orderBy16("notificationTime", "desc")
22874
+ orderBy17("notificationTime", "desc")
22889
22875
  );
22890
22876
  const querySnapshot = await getDocs32(q);
22891
22877
  return querySnapshot.docs.map((doc54) => ({
@@ -22959,7 +22945,7 @@ var NotificationService = class extends BaseService {
22959
22945
  collection32(this.db, NOTIFICATIONS_COLLECTION),
22960
22946
  where32("userId", "==", userId),
22961
22947
  where32("notificationType", "==", type),
22962
- orderBy16("notificationTime", "desc")
22948
+ orderBy17("notificationTime", "desc")
22963
22949
  );
22964
22950
  const querySnapshot = await getDocs32(q);
22965
22951
  return querySnapshot.docs.map((doc54) => ({
@@ -22974,7 +22960,7 @@ var NotificationService = class extends BaseService {
22974
22960
  const q = query32(
22975
22961
  collection32(this.db, NOTIFICATIONS_COLLECTION),
22976
22962
  where32("appointmentId", "==", appointmentId),
22977
- orderBy16("notificationTime", "desc")
22963
+ orderBy17("notificationTime", "desc")
22978
22964
  );
22979
22965
  const querySnapshot = await getDocs32(q);
22980
22966
  return querySnapshot.docs.map((doc54) => ({
@@ -22993,8 +22979,8 @@ import {
22993
22979
  doc as doc44,
22994
22980
  updateDoc as updateDoc39,
22995
22981
  Timestamp as Timestamp35,
22996
- orderBy as orderBy17,
22997
- limit as limit15,
22982
+ orderBy as orderBy18,
22983
+ limit as limit16,
22998
22984
  startAfter as startAfter13,
22999
22985
  getDoc as getDoc45
23000
22986
  } from "firebase/firestore";
@@ -23041,7 +23027,7 @@ var PatientRequirementsService = class extends BaseService {
23041
23027
  */
23042
23028
  async getAllPatientRequirementInstances(patientId, filters, pageLimit = 20, lastVisible) {
23043
23029
  const collRef = this.getPatientRequirementsCollectionRef(patientId);
23044
- let q = query33(collRef, orderBy17("createdAt", "desc"));
23030
+ let q = query33(collRef, orderBy18("createdAt", "desc"));
23045
23031
  const queryConstraints = [];
23046
23032
  if ((filters == null ? void 0 : filters.appointmentId) && filters.appointmentId !== "all") {
23047
23033
  queryConstraints.push(
@@ -23054,7 +23040,7 @@ var PatientRequirementsService = class extends BaseService {
23054
23040
  if (lastVisible) {
23055
23041
  queryConstraints.push(startAfter13(lastVisible));
23056
23042
  }
23057
- queryConstraints.push(limit15(pageLimit));
23043
+ queryConstraints.push(limit16(pageLimit));
23058
23044
  q = query33(collRef, ...queryConstraints);
23059
23045
  const snapshot = await getDocs33(q);
23060
23046
  let requirements = snapshot.docs.map((docSnap) => {
@@ -23194,8 +23180,8 @@ import {
23194
23180
  Timestamp as Timestamp36,
23195
23181
  serverTimestamp as serverTimestamp35,
23196
23182
  writeBatch as writeBatch6,
23197
- orderBy as orderBy18,
23198
- limit as limit16,
23183
+ orderBy as orderBy19,
23184
+ limit as limit17,
23199
23185
  startAfter as startAfter14,
23200
23186
  documentId as documentId2
23201
23187
  } from "firebase/firestore";
@@ -24421,20 +24407,20 @@ var ProcedureService = class extends BaseService {
24421
24407
  const proceduresCollection = collection34(this.db, PROCEDURES_COLLECTION);
24422
24408
  let proceduresQuery = query34(proceduresCollection);
24423
24409
  if (pagination && pagination > 0) {
24424
- const { limit: limit22, startAfter: startAfter20 } = await import("firebase/firestore");
24410
+ const { limit: limit23, startAfter: startAfter20 } = await import("firebase/firestore");
24425
24411
  if (lastDoc) {
24426
24412
  proceduresQuery = query34(
24427
24413
  proceduresCollection,
24428
- orderBy18("name"),
24414
+ orderBy19("name"),
24429
24415
  // Use imported orderBy
24430
24416
  startAfter20(lastDoc),
24431
- limit22(pagination)
24417
+ limit23(pagination)
24432
24418
  );
24433
24419
  } else {
24434
- proceduresQuery = query34(proceduresCollection, orderBy18("name"), limit22(pagination));
24420
+ proceduresQuery = query34(proceduresCollection, orderBy19("name"), limit23(pagination));
24435
24421
  }
24436
24422
  } else {
24437
- proceduresQuery = query34(proceduresCollection, orderBy18("name"));
24423
+ proceduresQuery = query34(proceduresCollection, orderBy19("name"));
24438
24424
  }
24439
24425
  const proceduresSnapshot = await getDocs34(proceduresQuery);
24440
24426
  let procedures = proceduresSnapshot.docs.map((doc54) => {
@@ -24617,7 +24603,7 @@ var ProcedureService = class extends BaseService {
24617
24603
  }
24618
24604
  constraints.push(where34("nameLower", ">=", searchTerm));
24619
24605
  constraints.push(where34("nameLower", "<=", searchTerm + "\uF8FF"));
24620
- constraints.push(orderBy18("nameLower"));
24606
+ constraints.push(orderBy19("nameLower"));
24621
24607
  if (filters.lastDoc) {
24622
24608
  const cursorValues = this.getCursorValuesForStartAfter(filters.lastDoc, "nameLower");
24623
24609
  if (cursorValues) {
@@ -24625,7 +24611,7 @@ var ProcedureService = class extends BaseService {
24625
24611
  console.log("[PROCEDURE_SERVICE] Strategy 1: Using cursor for pagination");
24626
24612
  }
24627
24613
  }
24628
- constraints.push(limit16(filters.pagination || 10));
24614
+ constraints.push(limit17(filters.pagination || 10));
24629
24615
  const q = query34(collection34(this.db, PROCEDURES_COLLECTION), ...constraints);
24630
24616
  const querySnapshot = await getDocs34(q);
24631
24617
  let procedures = querySnapshot.docs.map(
@@ -24659,7 +24645,7 @@ var ProcedureService = class extends BaseService {
24659
24645
  }
24660
24646
  constraints.push(where34("name", ">=", searchTerm));
24661
24647
  constraints.push(where34("name", "<=", searchTerm + "\uF8FF"));
24662
- constraints.push(orderBy18("name"));
24648
+ constraints.push(orderBy19("name"));
24663
24649
  if (filters.lastDoc) {
24664
24650
  const cursorValues = this.getCursorValuesForStartAfter(filters.lastDoc, "name");
24665
24651
  if (cursorValues) {
@@ -24667,7 +24653,7 @@ var ProcedureService = class extends BaseService {
24667
24653
  console.log("[PROCEDURE_SERVICE] Strategy 2: Using cursor for pagination");
24668
24654
  }
24669
24655
  }
24670
- constraints.push(limit16(filters.pagination || 10));
24656
+ constraints.push(limit17(filters.pagination || 10));
24671
24657
  const q = query34(collection34(this.db, PROCEDURES_COLLECTION), ...constraints);
24672
24658
  const querySnapshot = await getDocs34(q);
24673
24659
  let procedures = querySnapshot.docs.map(
@@ -24733,7 +24719,7 @@ var ProcedureService = class extends BaseService {
24733
24719
  "[PROCEDURE_SERVICE] Strategy 3 Firestore constraints (nested filters excluded):",
24734
24720
  constraints.map((c) => c.fieldPath || "unknown")
24735
24721
  );
24736
- constraints.push(orderBy18("createdAt", "desc"));
24722
+ constraints.push(orderBy19("createdAt", "desc"));
24737
24723
  if (filters.lastDoc) {
24738
24724
  const cursorValues = this.getCursorValuesForStartAfter(filters.lastDoc, "createdAt");
24739
24725
  if (cursorValues) {
@@ -24741,7 +24727,7 @@ var ProcedureService = class extends BaseService {
24741
24727
  console.log("[PROCEDURE_SERVICE] Strategy 3: Using cursor for pagination");
24742
24728
  }
24743
24729
  }
24744
- constraints.push(limit16(filters.pagination || 10));
24730
+ constraints.push(limit17(filters.pagination || 10));
24745
24731
  const q = query34(collection34(this.db, PROCEDURES_COLLECTION), ...constraints);
24746
24732
  const querySnapshot = await getDocs34(q);
24747
24733
  let procedures = querySnapshot.docs.map(
@@ -24779,7 +24765,7 @@ var ProcedureService = class extends BaseService {
24779
24765
  console.log("[PROCEDURE_SERVICE] Strategy 4: Minimal query fallback");
24780
24766
  const constraints = [
24781
24767
  where34("isActive", "==", filters.isActive !== void 0 ? filters.isActive : true),
24782
- orderBy18("createdAt", "desc")
24768
+ orderBy19("createdAt", "desc")
24783
24769
  ];
24784
24770
  if (filters.practitionerId) {
24785
24771
  constraints.push(where34("practitionerId", "==", filters.practitionerId));
@@ -24794,7 +24780,7 @@ var ProcedureService = class extends BaseService {
24794
24780
  console.log("[PROCEDURE_SERVICE] Strategy 4: Using cursor for pagination");
24795
24781
  }
24796
24782
  }
24797
- constraints.push(limit16(filters.pagination || 10));
24783
+ constraints.push(limit17(filters.pagination || 10));
24798
24784
  const q = query34(collection34(this.db, PROCEDURES_COLLECTION), ...constraints);
24799
24785
  const querySnapshot = await getDocs34(q);
24800
24786
  let procedures = querySnapshot.docs.map(
@@ -25183,7 +25169,7 @@ var ProcedureService = class extends BaseService {
25183
25169
  const proceduresQuery = query34(
25184
25170
  collection34(this.db, PROCEDURES_COLLECTION),
25185
25171
  ...constraints,
25186
- orderBy18("name", "asc")
25172
+ orderBy19("name", "asc")
25187
25173
  );
25188
25174
  const querySnapshot = await getDocs34(proceduresQuery);
25189
25175
  let procedures = querySnapshot.docs.map((doc54) => ({
@@ -25205,7 +25191,7 @@ import {
25205
25191
  deleteDoc as deleteDoc20,
25206
25192
  query as query35,
25207
25193
  where as where35,
25208
- orderBy as orderBy19,
25194
+ orderBy as orderBy20,
25209
25195
  writeBatch as writeBatch7,
25210
25196
  updateDoc as updateDoc41,
25211
25197
  serverTimestamp as serverTimestamp36,
@@ -25359,7 +25345,7 @@ var ResourceService = class extends BaseService {
25359
25345
  async getResourcesByClinic(clinicBranchId) {
25360
25346
  const q = query35(
25361
25347
  this.getResourcesRef(clinicBranchId),
25362
- orderBy19("nameLower")
25348
+ orderBy20("nameLower")
25363
25349
  );
25364
25350
  const snapshot = await getDocs35(q);
25365
25351
  return snapshot.docs.map(
@@ -25373,7 +25359,7 @@ var ResourceService = class extends BaseService {
25373
25359
  const q = query35(
25374
25360
  this.getResourcesRef(clinicBranchId),
25375
25361
  where35("status", "==", "active" /* ACTIVE */),
25376
- orderBy19("nameLower")
25362
+ orderBy20("nameLower")
25377
25363
  );
25378
25364
  const snapshot = await getDocs35(q);
25379
25365
  return snapshot.docs.map(
@@ -25491,7 +25477,7 @@ var ResourceService = class extends BaseService {
25491
25477
  async getResourceInstances(clinicBranchId, resourceId) {
25492
25478
  const q = query35(
25493
25479
  this.getInstancesRef(clinicBranchId, resourceId),
25494
- orderBy19("index")
25480
+ orderBy20("index")
25495
25481
  );
25496
25482
  const snapshot = await getDocs35(q);
25497
25483
  return snapshot.docs.map(
@@ -25505,7 +25491,7 @@ var ResourceService = class extends BaseService {
25505
25491
  const q = query35(
25506
25492
  this.getInstancesRef(clinicBranchId, resourceId),
25507
25493
  where35("status", "==", "active" /* ACTIVE */),
25508
- orderBy19("index")
25494
+ orderBy20("index")
25509
25495
  );
25510
25496
  const snapshot = await getDocs35(q);
25511
25497
  return snapshot.docs.map(
@@ -25525,7 +25511,7 @@ var ResourceService = class extends BaseService {
25525
25511
  calendarRef,
25526
25512
  where35("eventTime.start", ">=", start),
25527
25513
  where35("eventTime.start", "<=", end),
25528
- orderBy19("eventTime.start")
25514
+ orderBy20("eventTime.start")
25529
25515
  );
25530
25516
  const snapshot = await getDocs35(q);
25531
25517
  return snapshot.docs.map(
@@ -25644,7 +25630,7 @@ var ResourceService = class extends BaseService {
25644
25630
  const q = query35(
25645
25631
  calendarRef,
25646
25632
  where35("eventType", "==", "blocking" /* BLOCKING */),
25647
- orderBy19("eventTime.start")
25633
+ orderBy20("eventTime.start")
25648
25634
  );
25649
25635
  const snapshot = await getDocs35(q);
25650
25636
  return snapshot.docs.map(
@@ -26290,8 +26276,8 @@ import {
26290
26276
  query as query37,
26291
26277
  updateDoc as updateDoc42,
26292
26278
  where as where37,
26293
- limit as limit17,
26294
- orderBy as orderBy20,
26279
+ limit as limit18,
26280
+ orderBy as orderBy21,
26295
26281
  startAfter as startAfter15,
26296
26282
  getCountFromServer as getCountFromServer3
26297
26283
  } from "firebase/firestore";
@@ -26331,7 +26317,7 @@ var BrandService = class extends BaseService {
26331
26317
  async getAll(rowsPerPage, searchTerm, lastVisible) {
26332
26318
  const constraints = [
26333
26319
  where37("isActive", "==", true),
26334
- orderBy20("name_lowercase")
26320
+ orderBy21("name_lowercase")
26335
26321
  ];
26336
26322
  if (searchTerm) {
26337
26323
  const lowercasedSearchTerm = searchTerm.toLowerCase();
@@ -26343,7 +26329,7 @@ var BrandService = class extends BaseService {
26343
26329
  if (lastVisible) {
26344
26330
  constraints.push(startAfter15(lastVisible));
26345
26331
  }
26346
- constraints.push(limit17(rowsPerPage));
26332
+ constraints.push(limit18(rowsPerPage));
26347
26333
  const q = query37(this.getBrandsRef(), ...constraints);
26348
26334
  const snapshot = await getDocs37(q);
26349
26335
  const brands = snapshot.docs.map(
@@ -26379,7 +26365,7 @@ var BrandService = class extends BaseService {
26379
26365
  const q = query37(
26380
26366
  this.getBrandsRef(),
26381
26367
  where37("isActive", "==", true),
26382
- orderBy20("name")
26368
+ orderBy21("name")
26383
26369
  );
26384
26370
  const snapshot = await getDocs37(q);
26385
26371
  return snapshot.docs.map(
@@ -26449,9 +26435,9 @@ var BrandService = class extends BaseService {
26449
26435
  if (!includeInactive) {
26450
26436
  baseConstraints.push(where37("isActive", "==", true));
26451
26437
  }
26452
- baseConstraints.push(orderBy20("name_lowercase"));
26438
+ baseConstraints.push(orderBy21("name_lowercase"));
26453
26439
  while (true) {
26454
- const constraints = [...baseConstraints, limit17(PAGE_SIZE)];
26440
+ const constraints = [...baseConstraints, limit18(PAGE_SIZE)];
26455
26441
  if (cursor) constraints.push(startAfter15(cursor));
26456
26442
  const q = query37(this.getBrandsRef(), ...constraints);
26457
26443
  const snapshot = await getDocs37(q);
@@ -26500,8 +26486,8 @@ import {
26500
26486
  doc as doc49,
26501
26487
  getDoc as getDoc50,
26502
26488
  getDocs as getDocs38,
26503
- limit as limit18,
26504
- orderBy as orderBy21,
26489
+ limit as limit19,
26490
+ orderBy as orderBy22,
26505
26491
  query as query38,
26506
26492
  startAfter as startAfter16,
26507
26493
  updateDoc as updateDoc43,
@@ -26589,7 +26575,7 @@ var CategoryService = class extends BaseService {
26589
26575
  this.categoriesRef,
26590
26576
  where38("family", "==", family),
26591
26577
  where38("isActive", "==", true),
26592
- orderBy21("name")
26578
+ orderBy22("name")
26593
26579
  );
26594
26580
  const snapshot = await getDocs38(q);
26595
26581
  const categories = snapshot.docs.map(
@@ -26609,8 +26595,8 @@ var CategoryService = class extends BaseService {
26609
26595
  const { active = true, limit: queryLimit = 10, lastVisible } = options;
26610
26596
  const constraints = [
26611
26597
  where38("isActive", "==", active),
26612
- orderBy21("name"),
26613
- queryLimit ? limit18(queryLimit) : void 0,
26598
+ orderBy22("name"),
26599
+ queryLimit ? limit19(queryLimit) : void 0,
26614
26600
  lastVisible ? startAfter16(lastVisible) : void 0
26615
26601
  ].filter((c) => !!c);
26616
26602
  const q = query38(this.categoriesRef, ...constraints);
@@ -26636,8 +26622,8 @@ var CategoryService = class extends BaseService {
26636
26622
  const constraints = [
26637
26623
  where38("family", "==", family),
26638
26624
  where38("isActive", "==", active),
26639
- orderBy21("name"),
26640
- queryLimit ? limit18(queryLimit) : void 0,
26625
+ orderBy22("name"),
26626
+ queryLimit ? limit19(queryLimit) : void 0,
26641
26627
  lastVisible ? startAfter16(lastVisible) : void 0
26642
26628
  ].filter((c) => !!c);
26643
26629
  const q = query38(this.categoriesRef, ...constraints);
@@ -26758,9 +26744,9 @@ var CategoryService = class extends BaseService {
26758
26744
  if (!includeInactive) {
26759
26745
  constraints.push(where38("isActive", "==", true));
26760
26746
  }
26761
- constraints.push(orderBy21("name"));
26747
+ constraints.push(orderBy22("name"));
26762
26748
  while (true) {
26763
- const queryConstraints = [...constraints, limit18(PAGE_SIZE)];
26749
+ const queryConstraints = [...constraints, limit19(PAGE_SIZE)];
26764
26750
  if (cursor) queryConstraints.push(startAfter16(cursor));
26765
26751
  const q = query38(this.categoriesRef, ...queryConstraints);
26766
26752
  const snapshot = await getDocs38(q);
@@ -26806,13 +26792,13 @@ var CategoryService = class extends BaseService {
26806
26792
  import {
26807
26793
  addDoc as addDoc6,
26808
26794
  collection as collection39,
26809
- collectionGroup as collectionGroup2,
26795
+ collectionGroup as collectionGroup3,
26810
26796
  deleteDoc as deleteDoc22,
26811
26797
  doc as doc50,
26812
26798
  getDoc as getDoc51,
26813
26799
  getDocs as getDocs39,
26814
- limit as limit19,
26815
- orderBy as orderBy22,
26800
+ limit as limit20,
26801
+ orderBy as orderBy23,
26816
26802
  query as query39,
26817
26803
  setDoc as setDoc34,
26818
26804
  startAfter as startAfter17,
@@ -26896,8 +26882,8 @@ var SubcategoryService = class extends BaseService {
26896
26882
  const { active = true, limit: queryLimit = 10, lastVisible } = options;
26897
26883
  const constraints = [
26898
26884
  where39("isActive", "==", active),
26899
- orderBy22("name"),
26900
- queryLimit ? limit19(queryLimit) : void 0,
26885
+ orderBy23("name"),
26886
+ queryLimit ? limit20(queryLimit) : void 0,
26901
26887
  lastVisible ? startAfter17(lastVisible) : void 0
26902
26888
  ].filter((c) => !!c);
26903
26889
  const q = query39(this.getSubcategoriesRef(categoryId), ...constraints);
@@ -26924,12 +26910,12 @@ var SubcategoryService = class extends BaseService {
26924
26910
  const { active = true, limit: queryLimit = 10, lastVisible } = options;
26925
26911
  const constraints = [
26926
26912
  where39("isActive", "==", active),
26927
- orderBy22("name"),
26928
- queryLimit ? limit19(queryLimit) : void 0,
26913
+ orderBy23("name"),
26914
+ queryLimit ? limit20(queryLimit) : void 0,
26929
26915
  lastVisible ? startAfter17(lastVisible) : void 0
26930
26916
  ].filter((c) => !!c);
26931
26917
  const q = query39(
26932
- collectionGroup2(this.db, SUBCATEGORIES_COLLECTION),
26918
+ collectionGroup3(this.db, SUBCATEGORIES_COLLECTION),
26933
26919
  ...constraints
26934
26920
  );
26935
26921
  const querySnapshot = await getDocs39(q);
@@ -26968,7 +26954,7 @@ var SubcategoryService = class extends BaseService {
26968
26954
  */
26969
26955
  async getAllForFilter() {
26970
26956
  const q = query39(
26971
- collectionGroup2(this.db, SUBCATEGORIES_COLLECTION),
26957
+ collectionGroup3(this.db, SUBCATEGORIES_COLLECTION),
26972
26958
  where39("isActive", "==", true)
26973
26959
  );
26974
26960
  const querySnapshot = await getDocs39(q);
@@ -27119,12 +27105,12 @@ var SubcategoryService = class extends BaseService {
27119
27105
  if (!includeInactive) {
27120
27106
  constraints.push(where39("isActive", "==", true));
27121
27107
  }
27122
- constraints.push(orderBy22("name"));
27108
+ constraints.push(orderBy23("name"));
27123
27109
  while (true) {
27124
- const queryConstraints = [...constraints, limit19(PAGE_SIZE)];
27110
+ const queryConstraints = [...constraints, limit20(PAGE_SIZE)];
27125
27111
  if (cursor) queryConstraints.push(startAfter17(cursor));
27126
27112
  const q = query39(
27127
- collectionGroup2(this.db, SUBCATEGORIES_COLLECTION),
27113
+ collectionGroup3(this.db, SUBCATEGORIES_COLLECTION),
27128
27114
  ...queryConstraints
27129
27115
  );
27130
27116
  const snapshot = await getDocs39(q);
@@ -27173,8 +27159,8 @@ import {
27173
27159
  doc as doc51,
27174
27160
  getDoc as getDoc52,
27175
27161
  getDocs as getDocs40,
27176
- limit as limit20,
27177
- orderBy as orderBy23,
27162
+ limit as limit21,
27163
+ orderBy as orderBy24,
27178
27164
  query as query40,
27179
27165
  startAfter as startAfter18,
27180
27166
  updateDoc as updateDoc45,
@@ -27281,8 +27267,8 @@ var TechnologyService = class extends BaseService {
27281
27267
  const { active = true, limit: queryLimit = 10, lastVisible } = options;
27282
27268
  const constraints = [
27283
27269
  where40("isActive", "==", active),
27284
- orderBy23("name"),
27285
- queryLimit ? limit20(queryLimit) : void 0,
27270
+ orderBy24("name"),
27271
+ queryLimit ? limit21(queryLimit) : void 0,
27286
27272
  lastVisible ? startAfter18(lastVisible) : void 0
27287
27273
  ].filter((c) => !!c);
27288
27274
  const q = query40(this.technologiesRef, ...constraints);
@@ -27308,8 +27294,8 @@ var TechnologyService = class extends BaseService {
27308
27294
  const constraints = [
27309
27295
  where40("categoryId", "==", categoryId),
27310
27296
  where40("isActive", "==", active),
27311
- orderBy23("name"),
27312
- queryLimit ? limit20(queryLimit) : void 0,
27297
+ orderBy24("name"),
27298
+ queryLimit ? limit21(queryLimit) : void 0,
27313
27299
  lastVisible ? startAfter18(lastVisible) : void 0
27314
27300
  ].filter((c) => !!c);
27315
27301
  const q = query40(this.technologiesRef, ...constraints);
@@ -27335,8 +27321,8 @@ var TechnologyService = class extends BaseService {
27335
27321
  const constraints = [
27336
27322
  where40("subcategoryId", "==", subcategoryId),
27337
27323
  where40("isActive", "==", active),
27338
- orderBy23("name"),
27339
- queryLimit ? limit20(queryLimit) : void 0,
27324
+ orderBy24("name"),
27325
+ queryLimit ? limit21(queryLimit) : void 0,
27340
27326
  lastVisible ? startAfter18(lastVisible) : void 0
27341
27327
  ].filter((c) => !!c);
27342
27328
  const q = query40(this.technologiesRef, ...constraints);
@@ -27809,7 +27795,7 @@ var TechnologyService = class extends BaseService {
27809
27795
  collection40(this.db, TECHNOLOGIES_COLLECTION),
27810
27796
  where40("isActive", "==", true),
27811
27797
  where40("subcategoryId", "==", subcategoryId),
27812
- orderBy23("name")
27798
+ orderBy24("name")
27813
27799
  );
27814
27800
  const snapshot = await getDocs40(q);
27815
27801
  const technologies = snapshot.docs.map(
@@ -27831,7 +27817,7 @@ var TechnologyService = class extends BaseService {
27831
27817
  where40("isActive", "==", true),
27832
27818
  where40("categoryId", "==", categoryId),
27833
27819
  where40("subcategoryId", "==", subcategoryId),
27834
- orderBy23("name")
27820
+ orderBy24("name")
27835
27821
  );
27836
27822
  const snapshot = await getDocs40(q);
27837
27823
  const technologies = snapshot.docs.map(
@@ -27849,7 +27835,7 @@ var TechnologyService = class extends BaseService {
27849
27835
  const q = query40(
27850
27836
  collection40(this.db, TECHNOLOGIES_COLLECTION),
27851
27837
  where40("isActive", "==", true),
27852
- orderBy23("name")
27838
+ orderBy24("name")
27853
27839
  );
27854
27840
  const snapshot = await getDocs40(q);
27855
27841
  const technologies = snapshot.docs.map(
@@ -27902,7 +27888,7 @@ var TechnologyService = class extends BaseService {
27902
27888
  collection40(this.db, PRODUCTS_COLLECTION),
27903
27889
  where40("assignedTechnologyIds", "array-contains", technologyId),
27904
27890
  where40("isActive", "==", true),
27905
- orderBy23("name")
27891
+ orderBy24("name")
27906
27892
  );
27907
27893
  const snapshot = await getDocs40(q);
27908
27894
  return snapshot.docs.map(
@@ -27919,7 +27905,7 @@ var TechnologyService = class extends BaseService {
27919
27905
  const q = query40(
27920
27906
  collection40(this.db, PRODUCTS_COLLECTION),
27921
27907
  where40("isActive", "==", true),
27922
- orderBy23("name")
27908
+ orderBy24("name")
27923
27909
  );
27924
27910
  const snapshot = await getDocs40(q);
27925
27911
  const allProducts = snapshot.docs.map(
@@ -28017,9 +28003,9 @@ var TechnologyService = class extends BaseService {
28017
28003
  if (!includeInactive) {
28018
28004
  constraints.push(where40("isActive", "==", true));
28019
28005
  }
28020
- constraints.push(orderBy23("name"));
28006
+ constraints.push(orderBy24("name"));
28021
28007
  while (true) {
28022
- const queryConstraints = [...constraints, limit20(PAGE_SIZE)];
28008
+ const queryConstraints = [...constraints, limit21(PAGE_SIZE)];
28023
28009
  if (cursor) queryConstraints.push(startAfter18(cursor));
28024
28010
  const q = query40(this.technologiesRef, ...queryConstraints);
28025
28011
  const snapshot = await getDocs40(q);
@@ -28087,15 +28073,15 @@ var TechnologyService = class extends BaseService {
28087
28073
  import {
28088
28074
  addDoc as addDoc8,
28089
28075
  collection as collection41,
28090
- collectionGroup as collectionGroup3,
28076
+ collectionGroup as collectionGroup4,
28091
28077
  doc as doc52,
28092
28078
  getDoc as getDoc53,
28093
28079
  getDocs as getDocs41,
28094
28080
  query as query41,
28095
28081
  updateDoc as updateDoc46,
28096
28082
  where as where41,
28097
- limit as limit21,
28098
- orderBy as orderBy24,
28083
+ limit as limit22,
28084
+ orderBy as orderBy25,
28099
28085
  startAfter as startAfter19,
28100
28086
  getCountFromServer as getCountFromServer7,
28101
28087
  arrayUnion as arrayUnion10,
@@ -28140,7 +28126,7 @@ var ProductService = class extends BaseService {
28140
28126
  */
28141
28127
  async getAll(options) {
28142
28128
  const { rowsPerPage, lastVisible, categoryId, subcategoryId, technologyId } = options;
28143
- const constraints = [where41("isActive", "==", true), orderBy24("name")];
28129
+ const constraints = [where41("isActive", "==", true), orderBy25("name")];
28144
28130
  if (categoryId) {
28145
28131
  constraints.push(where41("categoryId", "==", categoryId));
28146
28132
  }
@@ -28153,8 +28139,8 @@ var ProductService = class extends BaseService {
28153
28139
  if (lastVisible) {
28154
28140
  constraints.push(startAfter19(lastVisible));
28155
28141
  }
28156
- constraints.push(limit21(rowsPerPage));
28157
- const q = query41(collectionGroup3(this.db, PRODUCTS_COLLECTION), ...constraints);
28142
+ constraints.push(limit22(rowsPerPage));
28143
+ const q = query41(collectionGroup4(this.db, PRODUCTS_COLLECTION), ...constraints);
28158
28144
  const snapshot = await getDocs41(q);
28159
28145
  const products = snapshot.docs.map(
28160
28146
  (doc54) => ({
@@ -28180,7 +28166,7 @@ var ProductService = class extends BaseService {
28180
28166
  if (technologyId) {
28181
28167
  constraints.push(where41("technologyId", "==", technologyId));
28182
28168
  }
28183
- const q = query41(collectionGroup3(this.db, PRODUCTS_COLLECTION), ...constraints);
28169
+ const q = query41(collectionGroup4(this.db, PRODUCTS_COLLECTION), ...constraints);
28184
28170
  const snapshot = await getCountFromServer7(q);
28185
28171
  return snapshot.data().count;
28186
28172
  }
@@ -28194,7 +28180,7 @@ var ProductService = class extends BaseService {
28194
28180
  bySubcategory: {},
28195
28181
  byTechnology: {}
28196
28182
  };
28197
- const q = query41(collectionGroup3(this.db, PRODUCTS_COLLECTION), where41("isActive", "==", true));
28183
+ const q = query41(collectionGroup4(this.db, PRODUCTS_COLLECTION), where41("isActive", "==", true));
28198
28184
  const snapshot = await getDocs41(q);
28199
28185
  snapshot.docs.forEach((doc54) => {
28200
28186
  const product = doc54.data();
@@ -28217,7 +28203,7 @@ var ProductService = class extends BaseService {
28217
28203
  const q = query41(
28218
28204
  this.getProductsRef(technologyId),
28219
28205
  where41("isActive", "==", true),
28220
- orderBy24("name")
28206
+ orderBy25("name")
28221
28207
  );
28222
28208
  const snapshot = await getDocs41(q);
28223
28209
  return snapshot.docs.map(
@@ -28313,7 +28299,7 @@ var ProductService = class extends BaseService {
28313
28299
  brandId: brandId || "none",
28314
28300
  category: category || "none"
28315
28301
  });
28316
- const constraints = [where41("isActive", "==", true), orderBy24("name")];
28302
+ const constraints = [where41("isActive", "==", true), orderBy25("name")];
28317
28303
  if (brandId) {
28318
28304
  console.log("[ProductService.getAllTopLevel] Adding brandId filter:", brandId);
28319
28305
  constraints.push(where41("brandId", "==", brandId));
@@ -28325,7 +28311,7 @@ var ProductService = class extends BaseService {
28325
28311
  if (lastVisible) {
28326
28312
  constraints.push(startAfter19(lastVisible));
28327
28313
  }
28328
- constraints.push(limit21(rowsPerPage));
28314
+ constraints.push(limit22(rowsPerPage));
28329
28315
  const q = query41(this.getTopLevelProductsRef(), ...constraints);
28330
28316
  const snapshot = await getDocs41(q);
28331
28317
  const products = snapshot.docs.map(
@@ -28397,7 +28383,7 @@ var ProductService = class extends BaseService {
28397
28383
  this.getTopLevelProductsRef(),
28398
28384
  where41("assignedTechnologyIds", "array-contains", technologyId),
28399
28385
  where41("isActive", "==", true),
28400
- orderBy24("name")
28386
+ orderBy25("name")
28401
28387
  );
28402
28388
  const snapshot = await getDocs41(q);
28403
28389
  return snapshot.docs.map(
@@ -28414,7 +28400,7 @@ var ProductService = class extends BaseService {
28414
28400
  const q = query41(
28415
28401
  this.getTopLevelProductsRef(),
28416
28402
  where41("isActive", "==", true),
28417
- orderBy24("name")
28403
+ orderBy25("name")
28418
28404
  );
28419
28405
  const snapshot = await getDocs41(q);
28420
28406
  const allProducts = snapshot.docs.map(
@@ -28438,7 +28424,7 @@ var ProductService = class extends BaseService {
28438
28424
  this.getTopLevelProductsRef(),
28439
28425
  where41("brandId", "==", brandId),
28440
28426
  where41("isActive", "==", true),
28441
- orderBy24("name")
28427
+ orderBy25("name")
28442
28428
  );
28443
28429
  const snapshot = await getDocs41(q);
28444
28430
  return snapshot.docs.map(
@@ -28476,9 +28462,9 @@ var ProductService = class extends BaseService {
28476
28462
  if (!includeInactive) {
28477
28463
  constraints.push(where41("isActive", "==", true));
28478
28464
  }
28479
- constraints.push(orderBy24("name"));
28465
+ constraints.push(orderBy25("name"));
28480
28466
  while (true) {
28481
- const queryConstraints = [...constraints, limit21(PAGE_SIZE)];
28467
+ const queryConstraints = [...constraints, limit22(PAGE_SIZE)];
28482
28468
  if (cursor) queryConstraints.push(startAfter19(cursor));
28483
28469
  const q = query41(this.getTopLevelProductsRef(), ...queryConstraints);
28484
28470
  const snapshot = await getDocs41(q);
@@ -28573,9 +28559,9 @@ var ConstantsService = class extends BaseService {
28573
28559
  */
28574
28560
  async getAllBenefits(options) {
28575
28561
  const allBenefits = await this.getAllBenefitsForFilter();
28576
- const { page, limit: limit22 } = options;
28577
- const startIndex = page * limit22;
28578
- const endIndex = startIndex + limit22;
28562
+ const { page, limit: limit23 } = options;
28563
+ const startIndex = page * limit23;
28564
+ const endIndex = startIndex + limit23;
28579
28565
  const paginatedBenefits = allBenefits.slice(startIndex, endIndex);
28580
28566
  return { benefits: paginatedBenefits, total: allBenefits.length };
28581
28567
  }
@@ -28672,9 +28658,9 @@ var ConstantsService = class extends BaseService {
28672
28658
  */
28673
28659
  async getAllContraindications(options) {
28674
28660
  const allContraindications = await this.getAllContraindicationsForFilter();
28675
- const { page, limit: limit22 } = options;
28676
- const startIndex = page * limit22;
28677
- const endIndex = startIndex + limit22;
28661
+ const { page, limit: limit23 } = options;
28662
+ const startIndex = page * limit23;
28663
+ const endIndex = startIndex + limit23;
28678
28664
  const paginatedContraindications = allContraindications.slice(
28679
28665
  startIndex,
28680
28666
  endIndex