@blackcode_sa/metaestetics-api 1.14.26 → 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.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +200 -143
- package/dist/index.mjs +179 -122
- package/package.json +1 -1
- package/src/services/auth/auth.service.ts +16 -5
- package/src/services/patient/patient.service.ts +6 -4
- package/src/services/patient/utils/clinic.utils.ts +78 -1
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
|
|
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
|
|
8019
|
-
query as
|
|
8020
|
-
where as
|
|
8021
|
-
getDocs as
|
|
8022
|
-
limit as
|
|
8023
|
-
startAfter as
|
|
8024
|
-
doc as
|
|
8025
|
-
getDoc as
|
|
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 =
|
|
7992
|
+
const patientsCollection = collection7(db, PATIENTS_COLLECTION);
|
|
8034
7993
|
const constraints = [
|
|
8035
|
-
|
|
7994
|
+
where7("doctorIds", "array-contains", practitionerId)
|
|
8036
7995
|
];
|
|
8037
|
-
let q =
|
|
7996
|
+
let q = query7(patientsCollection, ...constraints);
|
|
8038
7997
|
if (options == null ? void 0 : options.limit) {
|
|
8039
|
-
q =
|
|
7998
|
+
q = query7(q, limit4(options.limit));
|
|
8040
7999
|
}
|
|
8041
8000
|
if (options == null ? void 0 : options.startAfter) {
|
|
8042
|
-
const startAfterDoc = await
|
|
8043
|
-
|
|
8001
|
+
const startAfterDoc = await getDoc10(
|
|
8002
|
+
doc11(db, PATIENTS_COLLECTION, options.startAfter)
|
|
8044
8003
|
);
|
|
8045
8004
|
if (startAfterDoc.exists()) {
|
|
8046
|
-
q =
|
|
8005
|
+
q = query7(q, startAfter3(startAfterDoc));
|
|
8047
8006
|
}
|
|
8048
8007
|
}
|
|
8049
|
-
const patientsSnapshot = await
|
|
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
|
|
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 =
|
|
8119
|
-
const q =
|
|
8077
|
+
const practitionersCollection = collection7(db, PRACTITIONERS_COLLECTION);
|
|
8078
|
+
const q = query7(
|
|
8120
8079
|
practitionersCollection,
|
|
8121
|
-
|
|
8122
|
-
|
|
8080
|
+
where7("userRef", "==", userRef),
|
|
8081
|
+
limit4(1)
|
|
8123
8082
|
);
|
|
8124
|
-
const querySnapshot = await
|
|
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
|
|
8151
|
-
doc as
|
|
8152
|
-
getDoc as
|
|
8153
|
-
getDocs as
|
|
8154
|
-
query as
|
|
8155
|
-
where as
|
|
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:
|
|
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(
|
|
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 =
|
|
8857
|
-
const docSnap = await
|
|
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 =
|
|
8865
|
-
|
|
8866
|
-
|
|
8823
|
+
const q = query8(
|
|
8824
|
+
collection8(db, CLINIC_ADMINS_COLLECTION),
|
|
8825
|
+
where8("userRef", "==", userRef)
|
|
8867
8826
|
);
|
|
8868
|
-
const querySnapshot = await
|
|
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 =
|
|
8876
|
-
|
|
8877
|
-
|
|
8834
|
+
const q = query8(
|
|
8835
|
+
collection8(db, CLINIC_ADMINS_COLLECTION),
|
|
8836
|
+
where8("clinicGroupId", "==", clinicGroupId)
|
|
8878
8837
|
);
|
|
8879
|
-
const querySnapshot = await
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
9132
|
+
return doc13(db, PATIENTS_COLLECTION, patientId);
|
|
9174
9133
|
};
|
|
9175
9134
|
var getPatientDocRefByUserRef = async (db, userRef) => {
|
|
9176
|
-
const patientsRef =
|
|
9177
|
-
const q =
|
|
9178
|
-
const querySnapshot = await
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
15928
|
-
|
|
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
|
/**
|
package/package.json
CHANGED
|
@@ -45,7 +45,6 @@ import { FirebaseErrorCode } from '../../errors/firebase.errors';
|
|
|
45
45
|
import { FirebaseError } from '../../errors/firebase.errors';
|
|
46
46
|
import { BaseService } from '../base.service';
|
|
47
47
|
import { UserService } from '../user/user.service';
|
|
48
|
-
import { throws } from 'assert';
|
|
49
48
|
import {
|
|
50
49
|
ClinicGroup,
|
|
51
50
|
AdminToken,
|
|
@@ -639,11 +638,23 @@ export class AuthService extends BaseService {
|
|
|
639
638
|
}
|
|
640
639
|
|
|
641
640
|
const firebaseError = error as FirebaseError;
|
|
642
|
-
|
|
643
|
-
|
|
641
|
+
|
|
642
|
+
// Handle specific Firebase errors
|
|
643
|
+
switch (firebaseError.code) {
|
|
644
|
+
case FirebaseErrorCode.USER_NOT_FOUND:
|
|
645
|
+
throw AUTH_ERRORS.USER_NOT_FOUND;
|
|
646
|
+
case FirebaseErrorCode.INVALID_EMAIL:
|
|
647
|
+
throw AUTH_ERRORS.INVALID_EMAIL;
|
|
648
|
+
case FirebaseErrorCode.TOO_MANY_REQUESTS:
|
|
649
|
+
throw AUTH_ERRORS.TOO_MANY_REQUESTS;
|
|
650
|
+
case FirebaseErrorCode.NETWORK_ERROR:
|
|
651
|
+
throw AUTH_ERRORS.NETWORK_ERROR;
|
|
652
|
+
case FirebaseErrorCode.OPERATION_NOT_ALLOWED:
|
|
653
|
+
throw AUTH_ERRORS.OPERATION_NOT_ALLOWED;
|
|
654
|
+
default:
|
|
655
|
+
// Re-throw unknown errors as-is
|
|
656
|
+
throw error;
|
|
644
657
|
}
|
|
645
|
-
|
|
646
|
-
throw error;
|
|
647
658
|
}
|
|
648
659
|
}
|
|
649
660
|
|
|
@@ -86,6 +86,7 @@ import {
|
|
|
86
86
|
getPatientsByPractitionerUtil,
|
|
87
87
|
getPatientsByPractitionerWithDetailsUtil,
|
|
88
88
|
getPatientsByClinicUtil,
|
|
89
|
+
getPatientsByClinicWithDetailsUtil,
|
|
89
90
|
createPatientTokenUtil,
|
|
90
91
|
validatePatientTokenUtil,
|
|
91
92
|
markPatientTokenAsUsedUtil,
|
|
@@ -763,13 +764,14 @@ export class PatientService extends BaseService {
|
|
|
763
764
|
}
|
|
764
765
|
|
|
765
766
|
/**
|
|
766
|
-
* Gets all patients associated with a specific clinic.
|
|
767
|
+
* Gets all patients associated with a specific clinic, including sensitive info.
|
|
768
|
+
* This merges data from PatientProfile and PatientSensitiveInfo subcollection.
|
|
767
769
|
*
|
|
768
770
|
* @param {string} clinicId - ID of the clinic whose patients to retrieve
|
|
769
771
|
* @param {Object} options - Optional parameters for pagination
|
|
770
772
|
* @param {number} options.limit - Maximum number of profiles to return
|
|
771
773
|
* @param {string} options.startAfter - The ID of the document to start after (for pagination)
|
|
772
|
-
* @returns {Promise<PatientProfile[]>} A promise resolving to an array of patient profiles
|
|
774
|
+
* @returns {Promise<PatientProfile[]>} A promise resolving to an array of patient profiles with merged sensitive info
|
|
773
775
|
*/
|
|
774
776
|
async getPatientsByClinic(
|
|
775
777
|
clinicId: string,
|
|
@@ -778,8 +780,8 @@ export class PatientService extends BaseService {
|
|
|
778
780
|
startAfter?: string;
|
|
779
781
|
},
|
|
780
782
|
): Promise<PatientProfile[]> {
|
|
781
|
-
console.log(`[PatientService.getPatientsByClinic] Fetching patients for clinic: ${clinicId}`);
|
|
782
|
-
return
|
|
783
|
+
console.log(`[PatientService.getPatientsByClinic] Fetching patients with details for clinic: ${clinicId}`);
|
|
784
|
+
return getPatientsByClinicWithDetailsUtil(this.db, clinicId, options);
|
|
783
785
|
}
|
|
784
786
|
|
|
785
787
|
/**
|