@blackcode_sa/metaestetics-api 1.14.23 → 1.14.27

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
@@ -7621,69 +7621,28 @@ import { Timestamp as Timestamp15 } from "firebase/firestore";
7621
7621
 
7622
7622
  // src/services/patient/utils/clinic.utils.ts
7623
7623
  import {
7624
- collection as collection7,
7625
- query as query7,
7626
- where as where7,
7627
- getDocs as getDocs7,
7628
- limit as limit4,
7629
- startAfter as startAfter3,
7630
- doc as doc11,
7631
- getDoc as getDoc10
7632
- } from "firebase/firestore";
7633
- var getPatientsByClinicUtil = async (db, clinicId, options) => {
7634
- try {
7635
- console.log(
7636
- `[getPatientsByClinicUtil] Fetching patients for clinic ID: ${clinicId} with options:`,
7637
- options
7638
- );
7639
- const patientsCollection = collection7(db, PATIENTS_COLLECTION);
7640
- const constraints = [
7641
- where7("clinicIds", "array-contains", clinicId)
7642
- ];
7643
- let q = query7(patientsCollection, ...constraints);
7644
- if (options == null ? void 0 : options.limit) {
7645
- q = query7(q, limit4(options.limit));
7646
- }
7647
- if (options == null ? void 0 : options.startAfter) {
7648
- const startAfterDoc = await getDoc10(
7649
- doc11(db, PATIENTS_COLLECTION, options.startAfter)
7650
- );
7651
- if (startAfterDoc.exists()) {
7652
- q = query7(q, startAfter3(startAfterDoc));
7653
- }
7654
- }
7655
- const patientsSnapshot = await getDocs7(q);
7656
- const patients = [];
7657
- patientsSnapshot.forEach((doc47) => {
7658
- patients.push(doc47.data());
7659
- });
7660
- console.log(
7661
- `[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
7662
- );
7663
- return patients;
7664
- } catch (error) {
7665
- console.error(
7666
- `[getPatientsByClinicUtil] Error fetching patients for clinic:`,
7667
- error
7668
- );
7669
- throw new Error(
7670
- `Failed to retrieve patients for clinic: ${error instanceof Error ? error.message : String(error)}`
7671
- );
7672
- }
7673
- };
7674
-
7675
- // src/services/patient/utils/docs.utils.ts
7676
- import {
7677
- doc as doc14,
7678
7624
  collection as collection10,
7679
7625
  query as query10,
7680
7626
  where as where10,
7681
7627
  getDocs as getDocs10,
7628
+ limit as limit5,
7629
+ startAfter as startAfter4,
7630
+ doc as doc14,
7682
7631
  getDoc as getDoc14
7683
7632
  } from "firebase/firestore";
7684
7633
 
7634
+ // src/services/patient/utils/docs.utils.ts
7635
+ import {
7636
+ doc as doc13,
7637
+ collection as collection9,
7638
+ query as query9,
7639
+ where as where9,
7640
+ getDocs as getDocs9,
7641
+ getDoc as getDoc13
7642
+ } from "firebase/firestore";
7643
+
7685
7644
  // src/services/patient/utils/sensitive.utils.ts
7686
- import { getDoc as getDoc13, updateDoc as updateDoc8, setDoc as setDoc4, serverTimestamp as serverTimestamp9 } from "firebase/firestore";
7645
+ import { getDoc as getDoc12, updateDoc as updateDoc8, setDoc as setDoc4, serverTimestamp as serverTimestamp9 } from "firebase/firestore";
7687
7646
 
7688
7647
  // src/validations/patient.schema.ts
7689
7648
  import { z as z7 } from "zod";
@@ -8015,14 +7974,14 @@ import { z as z11 } from "zod";
8015
7974
 
8016
7975
  // src/services/patient/utils/practitioner.utils.ts
8017
7976
  import {
8018
- collection as collection8,
8019
- query as query8,
8020
- where as where8,
8021
- getDocs as getDocs8,
8022
- limit as limit5,
8023
- startAfter as startAfter4,
8024
- doc as doc12,
8025
- getDoc as getDoc11
7977
+ collection as collection7,
7978
+ query as query7,
7979
+ where as where7,
7980
+ getDocs as getDocs7,
7981
+ limit as limit4,
7982
+ startAfter as startAfter3,
7983
+ doc as doc11,
7984
+ getDoc as getDoc10
8026
7985
  } from "firebase/firestore";
8027
7986
  var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
8028
7987
  try {
@@ -8030,23 +7989,23 @@ var getPatientsByPractitionerUtil = async (db, practitionerId, options) => {
8030
7989
  `[getPatientsByPractitionerUtil] Fetching patients for practitioner ID: ${practitionerId} with options:`,
8031
7990
  options
8032
7991
  );
8033
- const patientsCollection = collection8(db, PATIENTS_COLLECTION);
7992
+ const patientsCollection = collection7(db, PATIENTS_COLLECTION);
8034
7993
  const constraints = [
8035
- where8("doctorIds", "array-contains", practitionerId)
7994
+ where7("doctorIds", "array-contains", practitionerId)
8036
7995
  ];
8037
- let q = query8(patientsCollection, ...constraints);
7996
+ let q = query7(patientsCollection, ...constraints);
8038
7997
  if (options == null ? void 0 : options.limit) {
8039
- q = query8(q, limit5(options.limit));
7998
+ q = query7(q, limit4(options.limit));
8040
7999
  }
8041
8000
  if (options == null ? void 0 : options.startAfter) {
8042
- const startAfterDoc = await getDoc11(
8043
- doc12(db, PATIENTS_COLLECTION, options.startAfter)
8001
+ const startAfterDoc = await getDoc10(
8002
+ doc11(db, PATIENTS_COLLECTION, options.startAfter)
8044
8003
  );
8045
8004
  if (startAfterDoc.exists()) {
8046
- q = query8(q, startAfter4(startAfterDoc));
8005
+ q = query7(q, startAfter3(startAfterDoc));
8047
8006
  }
8048
8007
  }
8049
- const patientsSnapshot = await getDocs8(q);
8008
+ const patientsSnapshot = await getDocs7(q);
8050
8009
  const patients = [];
8051
8010
  patientsSnapshot.forEach((doc47) => {
8052
8011
  patients.push(doc47.data());
@@ -8079,7 +8038,7 @@ var getPatientsByPractitionerWithDetailsUtil = async (db, practitionerId, option
8079
8038
  const patientProfilesWithDetails = await Promise.all(
8080
8039
  patientProfiles.map(async (profile) => {
8081
8040
  try {
8082
- const sensitiveInfoDoc = await getDoc11(
8041
+ const sensitiveInfoDoc = await getDoc10(
8083
8042
  getSensitiveInfoDocRef(db, profile.id)
8084
8043
  );
8085
8044
  const sensitiveInfo = sensitiveInfoDoc.exists() ? sensitiveInfoDoc.data() : void 0;
@@ -8115,13 +8074,13 @@ var getPractitionerProfileByUserRef = async (db, userRef) => {
8115
8074
  console.log(
8116
8075
  `[getPractitionerProfileByUserRef] Fetching practitioner with userRef: ${userRef}`
8117
8076
  );
8118
- const practitionersCollection = collection8(db, PRACTITIONERS_COLLECTION);
8119
- const q = query8(
8077
+ const practitionersCollection = collection7(db, PRACTITIONERS_COLLECTION);
8078
+ const q = query7(
8120
8079
  practitionersCollection,
8121
- where8("userRef", "==", userRef),
8122
- limit5(1)
8080
+ where7("userRef", "==", userRef),
8081
+ limit4(1)
8123
8082
  );
8124
- const querySnapshot = await getDocs8(q);
8083
+ const querySnapshot = await getDocs7(q);
8125
8084
  if (querySnapshot.empty) {
8126
8085
  console.log(
8127
8086
  `[getPractitionerProfileByUserRef] No practitioner found with userRef: ${userRef}`
@@ -8147,12 +8106,12 @@ var getPractitionerProfileByUserRef = async (db, userRef) => {
8147
8106
 
8148
8107
  // src/services/clinic/utils/admin.utils.ts
8149
8108
  import {
8150
- collection as collection9,
8151
- doc as doc13,
8152
- getDoc as getDoc12,
8153
- getDocs as getDocs9,
8154
- query as query9,
8155
- where as where9,
8109
+ collection as collection8,
8110
+ doc as doc12,
8111
+ getDoc as getDoc11,
8112
+ getDocs as getDocs8,
8113
+ query as query8,
8114
+ where as where8,
8156
8115
  updateDoc as updateDoc7,
8157
8116
  setDoc as setDoc3,
8158
8117
  deleteDoc as deleteDoc3,
@@ -8769,7 +8728,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
8769
8728
  }
8770
8729
  console.log("[CLINIC_ADMIN] Preparing admin data object");
8771
8730
  const adminData = {
8772
- id: doc13(collection9(db, CLINIC_ADMINS_COLLECTION)).id,
8731
+ id: doc12(collection8(db, CLINIC_ADMINS_COLLECTION)).id,
8773
8732
  // Generate a new ID for the admin document
8774
8733
  userRef: validatedData.userRef,
8775
8734
  clinicGroupId: clinicGroupId || "",
@@ -8804,7 +8763,7 @@ async function createClinicAdmin(db, data, clinicGroupService) {
8804
8763
  adminId: adminData.id
8805
8764
  });
8806
8765
  try {
8807
- await setDoc3(doc13(db, CLINIC_ADMINS_COLLECTION, adminData.id), adminData);
8766
+ await setDoc3(doc12(db, CLINIC_ADMINS_COLLECTION, adminData.id), adminData);
8808
8767
  console.log("[CLINIC_ADMIN] Admin saved successfully");
8809
8768
  } catch (firestoreError) {
8810
8769
  console.error(
@@ -8853,30 +8812,30 @@ async function checkClinicGroupExists(db, groupId, clinicGroupService) {
8853
8812
  return !!group;
8854
8813
  }
8855
8814
  async function getClinicAdmin(db, adminId) {
8856
- const docRef = doc13(db, CLINIC_ADMINS_COLLECTION, adminId);
8857
- const docSnap = await getDoc12(docRef);
8815
+ const docRef = doc12(db, CLINIC_ADMINS_COLLECTION, adminId);
8816
+ const docSnap = await getDoc11(docRef);
8858
8817
  if (docSnap.exists()) {
8859
8818
  return docSnap.data();
8860
8819
  }
8861
8820
  return null;
8862
8821
  }
8863
8822
  async function getClinicAdminByUserRef(db, userRef) {
8864
- const q = query9(
8865
- collection9(db, CLINIC_ADMINS_COLLECTION),
8866
- where9("userRef", "==", userRef)
8823
+ const q = query8(
8824
+ collection8(db, CLINIC_ADMINS_COLLECTION),
8825
+ where8("userRef", "==", userRef)
8867
8826
  );
8868
- const querySnapshot = await getDocs9(q);
8827
+ const querySnapshot = await getDocs8(q);
8869
8828
  if (querySnapshot.empty) {
8870
8829
  return null;
8871
8830
  }
8872
8831
  return querySnapshot.docs[0].data();
8873
8832
  }
8874
8833
  async function getClinicAdminsByGroup(db, clinicGroupId) {
8875
- const q = query9(
8876
- collection9(db, CLINIC_ADMINS_COLLECTION),
8877
- where9("clinicGroupId", "==", clinicGroupId)
8834
+ const q = query8(
8835
+ collection8(db, CLINIC_ADMINS_COLLECTION),
8836
+ where8("clinicGroupId", "==", clinicGroupId)
8878
8837
  );
8879
- const querySnapshot = await getDocs9(q);
8838
+ const querySnapshot = await getDocs8(q);
8880
8839
  return querySnapshot.docs.map((doc47) => doc47.data());
8881
8840
  }
8882
8841
  async function updateClinicAdmin(db, adminId, data) {
@@ -8888,7 +8847,7 @@ async function updateClinicAdmin(db, adminId, data) {
8888
8847
  ...data,
8889
8848
  updatedAt: serverTimestamp8()
8890
8849
  };
8891
- await updateDoc7(doc13(db, CLINIC_ADMINS_COLLECTION, adminId), updatedData);
8850
+ await updateDoc7(doc12(db, CLINIC_ADMINS_COLLECTION, adminId), updatedData);
8892
8851
  const updatedAdmin = await getClinicAdmin(db, adminId);
8893
8852
  if (!updatedAdmin) {
8894
8853
  throw new Error("Failed to retrieve updated admin");
@@ -8900,7 +8859,7 @@ async function deleteClinicAdmin(db, adminId) {
8900
8859
  if (!admin) {
8901
8860
  throw new Error("Clinic admin not found");
8902
8861
  }
8903
- await deleteDoc3(doc13(db, CLINIC_ADMINS_COLLECTION, adminId));
8862
+ await deleteDoc3(doc12(db, CLINIC_ADMINS_COLLECTION, adminId));
8904
8863
  }
8905
8864
  async function addClinicToManaged(db, adminId, clinicId, requesterId, clinicService) {
8906
8865
  const admin = await getClinicAdmin(db, adminId);
@@ -9014,7 +8973,7 @@ async function syncOwnerClinics(db, adminId, clinicService, clinicGroupService)
9014
8973
  // src/services/patient/utils/sensitive.utils.ts
9015
8974
  var checkSensitiveAccessUtil = async (db, patientId, requesterId, requesterRoles) => {
9016
8975
  var _a;
9017
- const patientDoc = await getDoc13(getPatientDocRef(db, patientId));
8976
+ const patientDoc = await getDoc12(getPatientDocRef(db, patientId));
9018
8977
  if (!patientDoc.exists()) {
9019
8978
  throw new Error("Patient profile not found");
9020
8979
  }
@@ -9073,7 +9032,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
9073
9032
  try {
9074
9033
  await checkSensitiveAccessUtil(db, data.patientId, requesterId, requesterRoles);
9075
9034
  const validatedData = createPatientSensitiveInfoSchema.parse(data);
9076
- const sensitiveDoc = await getDoc13(getSensitiveInfoDocRef(db, data.patientId));
9035
+ const sensitiveDoc = await getDoc12(getSensitiveInfoDocRef(db, data.patientId));
9077
9036
  if (sensitiveDoc.exists()) {
9078
9037
  throw new Error("Sensitive information already exists for this patient");
9079
9038
  }
@@ -9094,7 +9053,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
9094
9053
  updatedAt: serverTimestamp9()
9095
9054
  };
9096
9055
  await setDoc4(getSensitiveInfoDocRef(db, data.patientId), sensitiveInfoData);
9097
- const createdDoc = await getDoc13(getSensitiveInfoDocRef(db, data.patientId));
9056
+ const createdDoc = await getDoc12(getSensitiveInfoDocRef(db, data.patientId));
9098
9057
  if (!createdDoc.exists()) {
9099
9058
  throw new Error("Failed to create sensitive information");
9100
9059
  }
@@ -9109,7 +9068,7 @@ var createSensitiveInfoUtil = async (db, data, requesterId, requesterRoles, medi
9109
9068
  var getSensitiveInfoUtil = async (db, patientId, requesterId, requesterRoles) => {
9110
9069
  await checkSensitiveAccessUtil(db, patientId, requesterId, requesterRoles);
9111
9070
  await initSensitiveInfoDocIfNotExists(db, patientId, requesterId);
9112
- const sensitiveDoc = await getDoc13(getSensitiveInfoDocRef(db, patientId));
9071
+ const sensitiveDoc = await getDoc12(getSensitiveInfoDocRef(db, patientId));
9113
9072
  return sensitiveDoc.exists() ? sensitiveDoc.data() : null;
9114
9073
  };
9115
9074
  var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requesterRoles, mediaService) => {
@@ -9131,14 +9090,14 @@ var updateSensitiveInfoUtil = async (db, patientId, data, requesterId, requester
9131
9090
  updatedAt: serverTimestamp9()
9132
9091
  };
9133
9092
  await updateDoc8(getSensitiveInfoDocRef(db, patientId), updateData);
9134
- const updatedDoc = await getDoc13(getSensitiveInfoDocRef(db, patientId));
9093
+ const updatedDoc = await getDoc12(getSensitiveInfoDocRef(db, patientId));
9135
9094
  if (!updatedDoc.exists()) {
9136
9095
  throw new Error("Failed to retrieve updated sensitive information");
9137
9096
  }
9138
9097
  return updatedDoc.data();
9139
9098
  };
9140
9099
  var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9141
- const patientDoc = await getDoc13(getPatientDocRef(db, patientId));
9100
+ const patientDoc = await getDoc12(getPatientDocRef(db, patientId));
9142
9101
  if (!patientDoc.exists()) {
9143
9102
  throw new Error("Patient profile not found");
9144
9103
  }
@@ -9149,7 +9108,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9149
9108
  if (patientData.userRef) {
9150
9109
  throw new Error("Patient profile has already been claimed");
9151
9110
  }
9152
- const sensitiveDoc = await getDoc13(getSensitiveInfoDocRef(db, patientId));
9111
+ const sensitiveDoc = await getDoc12(getSensitiveInfoDocRef(db, patientId));
9153
9112
  if (!sensitiveDoc.exists()) {
9154
9113
  throw new Error("Patient sensitive information not found");
9155
9114
  }
@@ -9161,7 +9120,7 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9161
9120
  userRef: userId,
9162
9121
  updatedAt: serverTimestamp9()
9163
9122
  });
9164
- const updatedDoc = await getDoc13(getSensitiveInfoDocRef(db, patientId));
9123
+ const updatedDoc = await getDoc12(getSensitiveInfoDocRef(db, patientId));
9165
9124
  if (!updatedDoc.exists()) {
9166
9125
  throw new Error("Failed to retrieve updated sensitive information");
9167
9126
  }
@@ -9170,21 +9129,21 @@ var claimPatientSensitiveInfoUtil = async (db, patientId, userId) => {
9170
9129
 
9171
9130
  // src/services/patient/utils/docs.utils.ts
9172
9131
  var getPatientDocRef = (db, patientId) => {
9173
- return doc14(db, PATIENTS_COLLECTION, patientId);
9132
+ return doc13(db, PATIENTS_COLLECTION, patientId);
9174
9133
  };
9175
9134
  var getPatientDocRefByUserRef = async (db, userRef) => {
9176
- const patientsRef = collection10(db, PATIENTS_COLLECTION);
9177
- const q = query10(patientsRef, where10("userRef", "==", userRef));
9178
- const querySnapshot = await getDocs10(q);
9135
+ const patientsRef = collection9(db, PATIENTS_COLLECTION);
9136
+ const q = query9(patientsRef, where9("userRef", "==", userRef));
9137
+ const querySnapshot = await getDocs9(q);
9179
9138
  if (querySnapshot.empty) {
9180
9139
  throw new Error("Patient profile not found");
9181
9140
  }
9182
- return doc14(db, PATIENTS_COLLECTION, querySnapshot.docs[0].id);
9141
+ return doc13(db, PATIENTS_COLLECTION, querySnapshot.docs[0].id);
9183
9142
  };
9184
9143
  var getSensitiveInfoDocRef = (db, patientId) => {
9185
9144
  const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_SENSITIVE_INFO_COLLECTION}/${patientId}`;
9186
9145
  console.log(`[getSensitiveInfoDocRef] Creating reference with path: ${path}`);
9187
- return doc14(
9146
+ return doc13(
9188
9147
  db,
9189
9148
  PATIENTS_COLLECTION,
9190
9149
  patientId,
@@ -9195,7 +9154,7 @@ var getSensitiveInfoDocRef = (db, patientId) => {
9195
9154
  var getLocationInfoDocRef = (db, patientId) => {
9196
9155
  const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_LOCATION_INFO_COLLECTION}/${patientId}`;
9197
9156
  console.log(`[getLocationInfoDocRef] Creating reference with path: ${path}`);
9198
- return doc14(
9157
+ return doc13(
9199
9158
  db,
9200
9159
  PATIENTS_COLLECTION,
9201
9160
  patientId,
@@ -9206,7 +9165,7 @@ var getLocationInfoDocRef = (db, patientId) => {
9206
9165
  var getMedicalInfoDocRef = (db, patientId) => {
9207
9166
  const path = `${PATIENTS_COLLECTION}/${patientId}/${PATIENT_MEDICAL_INFO_COLLECTION}/${patientId}`;
9208
9167
  console.log(`[getMedicalInfoDocRef] Creating reference with path: ${path}`);
9209
- return doc14(
9168
+ return doc13(
9210
9169
  db,
9211
9170
  PATIENTS_COLLECTION,
9212
9171
  patientId,
@@ -9223,7 +9182,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
9223
9182
  console.log(
9224
9183
  `[initSensitiveInfoDocIfNotExists] Got document reference: ${sensitiveInfoRef.path}`
9225
9184
  );
9226
- const sensitiveDoc = await getDoc14(sensitiveInfoRef);
9185
+ const sensitiveDoc = await getDoc13(sensitiveInfoRef);
9227
9186
  console.log(
9228
9187
  `[initSensitiveInfoDocIfNotExists] Document exists: ${sensitiveDoc.exists()}`
9229
9188
  );
@@ -9247,7 +9206,7 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
9247
9206
  )
9248
9207
  );
9249
9208
  await createSensitiveInfoUtil(db, defaultSensitiveInfo, userRef);
9250
- const verifyDoc = await getDoc14(sensitiveInfoRef);
9209
+ const verifyDoc = await getDoc13(sensitiveInfoRef);
9251
9210
  console.log(
9252
9211
  `[initSensitiveInfoDocIfNotExists] Verification - document exists: ${verifyDoc.exists()}`
9253
9212
  );
@@ -9263,6 +9222,93 @@ var initSensitiveInfoDocIfNotExists = async (db, patientId, userRef) => {
9263
9222
  }
9264
9223
  };
9265
9224
 
9225
+ // src/services/patient/utils/clinic.utils.ts
9226
+ var getPatientsByClinicUtil = async (db, clinicId, options) => {
9227
+ try {
9228
+ console.log(
9229
+ `[getPatientsByClinicUtil] Fetching patients for clinic ID: ${clinicId} with options:`,
9230
+ options
9231
+ );
9232
+ const patientsCollection = collection10(db, PATIENTS_COLLECTION);
9233
+ const constraints = [
9234
+ where10("clinicIds", "array-contains", clinicId)
9235
+ ];
9236
+ let q = query10(patientsCollection, ...constraints);
9237
+ if (options == null ? void 0 : options.limit) {
9238
+ q = query10(q, limit5(options.limit));
9239
+ }
9240
+ if (options == null ? void 0 : options.startAfter) {
9241
+ const startAfterDoc = await getDoc14(
9242
+ doc14(db, PATIENTS_COLLECTION, options.startAfter)
9243
+ );
9244
+ if (startAfterDoc.exists()) {
9245
+ q = query10(q, startAfter4(startAfterDoc));
9246
+ }
9247
+ }
9248
+ const patientsSnapshot = await getDocs10(q);
9249
+ const patients = [];
9250
+ patientsSnapshot.forEach((doc47) => {
9251
+ patients.push(doc47.data());
9252
+ });
9253
+ console.log(
9254
+ `[getPatientsByClinicUtil] Found ${patients.length} patients for clinic ID: ${clinicId}`
9255
+ );
9256
+ return patients;
9257
+ } catch (error) {
9258
+ console.error(
9259
+ `[getPatientsByClinicUtil] Error fetching patients for clinic:`,
9260
+ error
9261
+ );
9262
+ throw new Error(
9263
+ `Failed to retrieve patients for clinic: ${error instanceof Error ? error.message : String(error)}`
9264
+ );
9265
+ }
9266
+ };
9267
+ var getPatientsByClinicWithDetailsUtil = async (db, clinicId, options) => {
9268
+ try {
9269
+ console.log(
9270
+ `[getPatientsByClinicWithDetailsUtil] Fetching patients with details for clinic ID: ${clinicId} with options:`,
9271
+ options
9272
+ );
9273
+ const patientProfiles = await getPatientsByClinicUtil(db, clinicId, options);
9274
+ const patientsWithDetails = await Promise.all(
9275
+ patientProfiles.map(async (profile) => {
9276
+ try {
9277
+ const sensitiveInfoDoc = await getDoc14(
9278
+ getSensitiveInfoDocRef(db, profile.id)
9279
+ );
9280
+ const sensitiveInfo = sensitiveInfoDoc.exists() ? sensitiveInfoDoc.data() : null;
9281
+ return {
9282
+ ...profile,
9283
+ // Merge phoneNumber from sensitive info if not in profile
9284
+ phoneNumber: profile.phoneNumber || (sensitiveInfo == null ? void 0 : sensitiveInfo.phoneNumber) || null,
9285
+ // Merge dateOfBirth from sensitive info if not in profile
9286
+ dateOfBirth: profile.dateOfBirth || (sensitiveInfo == null ? void 0 : sensitiveInfo.dateOfBirth) || null
9287
+ };
9288
+ } catch (error) {
9289
+ console.error(
9290
+ `[getPatientsByClinicWithDetailsUtil] Error fetching sensitive info for patient ${profile.id}:`,
9291
+ error
9292
+ );
9293
+ return profile;
9294
+ }
9295
+ })
9296
+ );
9297
+ console.log(
9298
+ `[getPatientsByClinicWithDetailsUtil] Found ${patientsWithDetails.length} patients with details for clinic ID: ${clinicId}`
9299
+ );
9300
+ return patientsWithDetails;
9301
+ } catch (error) {
9302
+ console.error(
9303
+ `[getPatientsByClinicWithDetailsUtil] Error fetching patients with details:`,
9304
+ error
9305
+ );
9306
+ throw new Error(
9307
+ `Failed to retrieve patients with details: ${error instanceof Error ? error.message : String(error)}`
9308
+ );
9309
+ }
9310
+ };
9311
+
9266
9312
  // src/services/patient/utils/location.utils.ts
9267
9313
  import {
9268
9314
  getDoc as getDoc15,
@@ -10858,17 +10904,18 @@ var PatientService = class extends BaseService {
10858
10904
  return getPatientsByPractitionerWithDetailsUtil(this.db, practitionerId, options);
10859
10905
  }
10860
10906
  /**
10861
- * Gets all patients associated with a specific clinic.
10907
+ * Gets all patients associated with a specific clinic, including sensitive info.
10908
+ * This merges data from PatientProfile and PatientSensitiveInfo subcollection.
10862
10909
  *
10863
10910
  * @param {string} clinicId - ID of the clinic whose patients to retrieve
10864
10911
  * @param {Object} options - Optional parameters for pagination
10865
10912
  * @param {number} options.limit - Maximum number of profiles to return
10866
10913
  * @param {string} options.startAfter - The ID of the document to start after (for pagination)
10867
- * @returns {Promise<PatientProfile[]>} A promise resolving to an array of patient profiles
10914
+ * @returns {Promise<PatientProfile[]>} A promise resolving to an array of patient profiles with merged sensitive info
10868
10915
  */
10869
10916
  async getPatientsByClinic(clinicId, options) {
10870
- console.log(`[PatientService.getPatientsByClinic] Fetching patients for clinic: ${clinicId}`);
10871
- return getPatientsByClinicUtil(this.db, clinicId, options);
10917
+ console.log(`[PatientService.getPatientsByClinic] Fetching patients with details for clinic: ${clinicId}`);
10918
+ return getPatientsByClinicWithDetailsUtil(this.db, clinicId, options);
10872
10919
  }
10873
10920
  /**
10874
10921
  * Creates a token for inviting a patient to claim their profile.
@@ -15924,10 +15971,20 @@ var AuthService = class extends BaseService {
15924
15971
  throw AUTH_ERRORS.VALIDATION_ERROR;
15925
15972
  }
15926
15973
  const firebaseError = error;
15927
- if (firebaseError.code === "auth/user-not-found" /* USER_NOT_FOUND */) {
15928
- throw AUTH_ERRORS.USER_NOT_FOUND;
15974
+ switch (firebaseError.code) {
15975
+ case "auth/user-not-found" /* USER_NOT_FOUND */:
15976
+ throw AUTH_ERRORS.USER_NOT_FOUND;
15977
+ case "auth/invalid-email" /* INVALID_EMAIL */:
15978
+ throw AUTH_ERRORS.INVALID_EMAIL;
15979
+ case "auth/too-many-requests" /* TOO_MANY_REQUESTS */:
15980
+ throw AUTH_ERRORS.TOO_MANY_REQUESTS;
15981
+ case "auth/network-request-failed" /* NETWORK_ERROR */:
15982
+ throw AUTH_ERRORS.NETWORK_ERROR;
15983
+ case "auth/operation-not-allowed" /* OPERATION_NOT_ALLOWED */:
15984
+ throw AUTH_ERRORS.OPERATION_NOT_ALLOWED;
15985
+ default:
15986
+ throw error;
15929
15987
  }
15930
- throw error;
15931
15988
  }
15932
15989
  }
15933
15990
  /**
@@ -23535,12 +23592,13 @@ var BrandService = class extends BaseService {
23535
23592
  return { id: docRef.id, ...newBrand };
23536
23593
  }
23537
23594
  /**
23538
- * Gets a paginated list of active brands, optionally filtered by name.
23595
+ * Gets a paginated list of active brands, optionally filtered by name and category.
23539
23596
  * @param rowsPerPage - The number of brands to fetch.
23540
23597
  * @param searchTerm - An optional string to filter brand names by (starts-with search).
23541
23598
  * @param lastVisible - An optional document snapshot to use as a cursor for pagination.
23599
+ * @param category - An optional category to filter brands by.
23542
23600
  */
23543
- async getAll(rowsPerPage, searchTerm, lastVisible) {
23601
+ async getAll(rowsPerPage, searchTerm, lastVisible, category) {
23544
23602
  const constraints = [
23545
23603
  where35("isActive", "==", true),
23546
23604
  orderBy19("name_lowercase")
@@ -23552,6 +23610,9 @@ var BrandService = class extends BaseService {
23552
23610
  where35("name_lowercase", "<=", lowercasedSearchTerm + "\uF8FF")
23553
23611
  );
23554
23612
  }
23613
+ if (category) {
23614
+ constraints.push(where35("category", "==", category));
23615
+ }
23555
23616
  if (lastVisible) {
23556
23617
  constraints.push(startAfter15(lastVisible));
23557
23618
  }
@@ -23568,10 +23629,11 @@ var BrandService = class extends BaseService {
23568
23629
  return { brands, lastVisible: newLastVisible };
23569
23630
  }
23570
23631
  /**
23571
- * Gets the total count of active brands, optionally filtered by name.
23632
+ * Gets the total count of active brands, optionally filtered by name and category.
23572
23633
  * @param searchTerm - An optional string to filter brand names by (starts-with search).
23634
+ * @param category - An optional category to filter brands by.
23573
23635
  */
23574
- async getBrandsCount(searchTerm) {
23636
+ async getBrandsCount(searchTerm, category) {
23575
23637
  const constraints = [where35("isActive", "==", true)];
23576
23638
  if (searchTerm) {
23577
23639
  const lowercasedSearchTerm = searchTerm.toLowerCase();
@@ -23580,6 +23642,9 @@ var BrandService = class extends BaseService {
23580
23642
  where35("name_lowercase", "<=", lowercasedSearchTerm + "\uF8FF")
23581
23643
  );
23582
23644
  }
23645
+ if (category) {
23646
+ constraints.push(where35("category", "==", category));
23647
+ }
23583
23648
  const q = query35(this.getBrandsRef(), ...constraints);
23584
23649
  const snapshot = await getCountFromServer3(q);
23585
23650
  return snapshot.data().count;
@@ -23649,6 +23714,7 @@ var BrandService = class extends BaseService {
23649
23714
  "id",
23650
23715
  "name",
23651
23716
  "manufacturer",
23717
+ "category",
23652
23718
  "website",
23653
23719
  "description",
23654
23720
  "isActive"
@@ -23679,14 +23745,15 @@ var BrandService = class extends BaseService {
23679
23745
  return includeBom ? "\uFEFF" + csvBody : csvBody;
23680
23746
  }
23681
23747
  brandToCsvRow(brand) {
23682
- var _a, _b, _c, _d, _e, _f;
23748
+ var _a, _b, _c, _d, _e, _f, _g;
23683
23749
  const values = [
23684
23750
  (_a = brand.id) != null ? _a : "",
23685
23751
  (_b = brand.name) != null ? _b : "",
23686
23752
  (_c = brand.manufacturer) != null ? _c : "",
23687
- (_d = brand.website) != null ? _d : "",
23688
- (_e = brand.description) != null ? _e : "",
23689
- String((_f = brand.isActive) != null ? _f : "")
23753
+ (_d = brand.category) != null ? _d : "",
23754
+ (_e = brand.website) != null ? _e : "",
23755
+ (_f = brand.description) != null ? _f : "",
23756
+ String((_g = brand.isActive) != null ? _g : "")
23690
23757
  ];
23691
23758
  return values.map((v) => this.formatCsvValue(v)).join(",");
23692
23759
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.14.23",
4
+ "version": "1.14.27",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -117,5 +117,8 @@
117
117
  "setupFilesAfterEnv": [
118
118
  "<rootDir>/jest.setup.ts"
119
119
  ]
120
+ },
121
+ "overrides": {
122
+ "node-forge": ">=1.3.2"
120
123
  }
121
124
  }