@blackcode_sa/metaestetics-api 1.13.11 → 1.13.13
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 +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +87 -30
- package/dist/index.mjs +87 -30
- package/package.json +1 -1
- package/src/services/clinic/clinic.service.ts +15 -10
- package/src/services/clinic/utils/clinic.utils.ts +88 -10
- package/src/services/clinic/utils/filter.utils.ts +14 -0
- package/src/services/procedure/procedure.service.ts +23 -13
package/dist/index.d.mts
CHANGED
|
@@ -6600,12 +6600,14 @@ declare class ClinicService extends BaseService {
|
|
|
6600
6600
|
activateClinic(clinicId: string, adminId: string): Promise<void>;
|
|
6601
6601
|
/**
|
|
6602
6602
|
* Dohvata kliniku po ID-u
|
|
6603
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
6603
6604
|
*/
|
|
6604
|
-
getClinic(clinicId: string): Promise<Clinic | null>;
|
|
6605
|
+
getClinic(clinicId: string, excludeDraftPractitioners?: boolean): Promise<Clinic | null>;
|
|
6605
6606
|
/**
|
|
6606
6607
|
* Dohvata sve klinike u grupi
|
|
6608
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
6607
6609
|
*/
|
|
6608
|
-
getClinicsByGroup(groupId: string): Promise<Clinic[]>;
|
|
6610
|
+
getClinicsByGroup(groupId: string, excludeDraftPractitioners?: boolean): Promise<Clinic[]>;
|
|
6609
6611
|
/**
|
|
6610
6612
|
* Pretražuje klinike u određenom radijusu
|
|
6611
6613
|
*/
|
|
@@ -6632,15 +6634,15 @@ declare class ClinicService extends BaseService {
|
|
|
6632
6634
|
* Handles both URL strings and File uploads for media fields.
|
|
6633
6635
|
*/
|
|
6634
6636
|
createClinicBranch(clinicGroupId: string, setupData: ClinicBranchSetupData, adminId: string): Promise<Clinic>;
|
|
6635
|
-
getClinicById(clinicId: string): Promise<Clinic | null>;
|
|
6636
|
-
getAllClinics(pagination?: number, lastDoc?: any): Promise<{
|
|
6637
|
+
getClinicById(clinicId: string, excludeDraftPractitioners?: boolean): Promise<Clinic | null>;
|
|
6638
|
+
getAllClinics(pagination?: number, lastDoc?: any, excludeDraftPractitioners?: boolean): Promise<{
|
|
6637
6639
|
clinics: Clinic[];
|
|
6638
6640
|
lastDoc: any;
|
|
6639
6641
|
}>;
|
|
6640
6642
|
getAllClinicsInRange(center: {
|
|
6641
6643
|
latitude: number;
|
|
6642
6644
|
longitude: number;
|
|
6643
|
-
}, rangeInKm: number, pagination?: number, lastDoc?: any): Promise<{
|
|
6645
|
+
}, rangeInKm: number, pagination?: number, lastDoc?: any, excludeDraftPractitioners?: boolean): Promise<{
|
|
6644
6646
|
clinics: (Clinic & {
|
|
6645
6647
|
distance: number;
|
|
6646
6648
|
})[];
|
package/dist/index.d.ts
CHANGED
|
@@ -6600,12 +6600,14 @@ declare class ClinicService extends BaseService {
|
|
|
6600
6600
|
activateClinic(clinicId: string, adminId: string): Promise<void>;
|
|
6601
6601
|
/**
|
|
6602
6602
|
* Dohvata kliniku po ID-u
|
|
6603
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
6603
6604
|
*/
|
|
6604
|
-
getClinic(clinicId: string): Promise<Clinic | null>;
|
|
6605
|
+
getClinic(clinicId: string, excludeDraftPractitioners?: boolean): Promise<Clinic | null>;
|
|
6605
6606
|
/**
|
|
6606
6607
|
* Dohvata sve klinike u grupi
|
|
6608
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
6607
6609
|
*/
|
|
6608
|
-
getClinicsByGroup(groupId: string): Promise<Clinic[]>;
|
|
6610
|
+
getClinicsByGroup(groupId: string, excludeDraftPractitioners?: boolean): Promise<Clinic[]>;
|
|
6609
6611
|
/**
|
|
6610
6612
|
* Pretražuje klinike u određenom radijusu
|
|
6611
6613
|
*/
|
|
@@ -6632,15 +6634,15 @@ declare class ClinicService extends BaseService {
|
|
|
6632
6634
|
* Handles both URL strings and File uploads for media fields.
|
|
6633
6635
|
*/
|
|
6634
6636
|
createClinicBranch(clinicGroupId: string, setupData: ClinicBranchSetupData, adminId: string): Promise<Clinic>;
|
|
6635
|
-
getClinicById(clinicId: string): Promise<Clinic | null>;
|
|
6636
|
-
getAllClinics(pagination?: number, lastDoc?: any): Promise<{
|
|
6637
|
+
getClinicById(clinicId: string, excludeDraftPractitioners?: boolean): Promise<Clinic | null>;
|
|
6638
|
+
getAllClinics(pagination?: number, lastDoc?: any, excludeDraftPractitioners?: boolean): Promise<{
|
|
6637
6639
|
clinics: Clinic[];
|
|
6638
6640
|
lastDoc: any;
|
|
6639
6641
|
}>;
|
|
6640
6642
|
getAllClinicsInRange(center: {
|
|
6641
6643
|
latitude: number;
|
|
6642
6644
|
longitude: number;
|
|
6643
|
-
}, rangeInKm: number, pagination?: number, lastDoc?: any): Promise<{
|
|
6645
|
+
}, rangeInKm: number, pagination?: number, lastDoc?: any, excludeDraftPractitioners?: boolean): Promise<{
|
|
6644
6646
|
clinics: (Clinic & {
|
|
6645
6647
|
distance: number;
|
|
6646
6648
|
})[];
|
package/dist/index.js
CHANGED
|
@@ -13530,22 +13530,61 @@ var import_zod21 = require("zod");
|
|
|
13530
13530
|
var import_firestore36 = require("firebase/firestore");
|
|
13531
13531
|
var import_geofire_common4 = require("geofire-common");
|
|
13532
13532
|
var import_zod20 = require("zod");
|
|
13533
|
-
|
|
13533
|
+
function filterDoctorsInfo(doctorsInfo) {
|
|
13534
|
+
if (!doctorsInfo || doctorsInfo.length === 0) {
|
|
13535
|
+
return [];
|
|
13536
|
+
}
|
|
13537
|
+
return doctorsInfo.filter((doctor) => {
|
|
13538
|
+
if (doctor.status === "draft" /* DRAFT */) {
|
|
13539
|
+
console.log(`[CLINIC_UTILS] Filtering out draft practitioner ${doctor.id} from doctorsInfo`);
|
|
13540
|
+
return false;
|
|
13541
|
+
}
|
|
13542
|
+
if (doctor.isActive === false) {
|
|
13543
|
+
console.log(`[CLINIC_UTILS] Filtering out inactive practitioner ${doctor.id} from doctorsInfo`);
|
|
13544
|
+
return false;
|
|
13545
|
+
}
|
|
13546
|
+
return true;
|
|
13547
|
+
});
|
|
13548
|
+
}
|
|
13549
|
+
function filterClinicEmbeddedArrays(clinic, excludeDraftPractitioners = false) {
|
|
13550
|
+
if (!clinic) {
|
|
13551
|
+
return clinic;
|
|
13552
|
+
}
|
|
13553
|
+
if (!excludeDraftPractitioners) {
|
|
13554
|
+
return clinic;
|
|
13555
|
+
}
|
|
13556
|
+
const filteredClinic = { ...clinic };
|
|
13557
|
+
if (filteredClinic.doctorsInfo && filteredClinic.doctorsInfo.length > 0) {
|
|
13558
|
+
const originalLength = filteredClinic.doctorsInfo.length;
|
|
13559
|
+
filteredClinic.doctorsInfo = filterDoctorsInfo(filteredClinic.doctorsInfo);
|
|
13560
|
+
if (filteredClinic.doctorsInfo.length !== originalLength) {
|
|
13561
|
+
console.log(
|
|
13562
|
+
`[CLINIC_UTILS] Filtered ${originalLength - filteredClinic.doctorsInfo.length} draft/inactive doctors from clinic ${clinic.id}`
|
|
13563
|
+
);
|
|
13564
|
+
}
|
|
13565
|
+
}
|
|
13566
|
+
return filteredClinic;
|
|
13567
|
+
}
|
|
13568
|
+
async function getClinic(db, clinicId, excludeDraftPractitioners = false) {
|
|
13534
13569
|
const docRef = (0, import_firestore36.doc)(db, CLINICS_COLLECTION, clinicId);
|
|
13535
13570
|
const docSnap = await (0, import_firestore36.getDoc)(docRef);
|
|
13536
13571
|
if (docSnap.exists()) {
|
|
13537
|
-
|
|
13572
|
+
const clinicData = docSnap.data();
|
|
13573
|
+
return filterClinicEmbeddedArrays(clinicData, excludeDraftPractitioners);
|
|
13538
13574
|
}
|
|
13539
13575
|
return null;
|
|
13540
13576
|
}
|
|
13541
|
-
async function getClinicsByGroup(db, groupId) {
|
|
13577
|
+
async function getClinicsByGroup(db, groupId, excludeDraftPractitioners = false) {
|
|
13542
13578
|
const q = (0, import_firestore36.query)(
|
|
13543
13579
|
(0, import_firestore36.collection)(db, CLINICS_COLLECTION),
|
|
13544
13580
|
(0, import_firestore36.where)("clinicGroupId", "==", groupId),
|
|
13545
13581
|
(0, import_firestore36.where)("isActive", "==", true)
|
|
13546
13582
|
);
|
|
13547
13583
|
const querySnapshot = await (0, import_firestore36.getDocs)(q);
|
|
13548
|
-
return querySnapshot.docs.map((doc47) =>
|
|
13584
|
+
return querySnapshot.docs.map((doc47) => {
|
|
13585
|
+
const clinicData = doc47.data();
|
|
13586
|
+
return filterClinicEmbeddedArrays(clinicData, excludeDraftPractitioners);
|
|
13587
|
+
});
|
|
13549
13588
|
}
|
|
13550
13589
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
13551
13590
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -13750,7 +13789,7 @@ async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGr
|
|
|
13750
13789
|
clinicGroupService
|
|
13751
13790
|
);
|
|
13752
13791
|
}
|
|
13753
|
-
async function getClinicById(db, clinicId) {
|
|
13792
|
+
async function getClinicById(db, clinicId, excludeDraftPractitioners = false) {
|
|
13754
13793
|
try {
|
|
13755
13794
|
const clinicRef = (0, import_firestore36.doc)(db, CLINICS_COLLECTION, clinicId);
|
|
13756
13795
|
const clinicSnapshot = await (0, import_firestore36.getDoc)(clinicRef);
|
|
@@ -13758,16 +13797,17 @@ async function getClinicById(db, clinicId) {
|
|
|
13758
13797
|
return null;
|
|
13759
13798
|
}
|
|
13760
13799
|
const clinicData = clinicSnapshot.data();
|
|
13761
|
-
|
|
13800
|
+
const clinicWithId = {
|
|
13762
13801
|
...clinicData,
|
|
13763
13802
|
id: clinicSnapshot.id
|
|
13764
13803
|
};
|
|
13804
|
+
return filterClinicEmbeddedArrays(clinicWithId, excludeDraftPractitioners);
|
|
13765
13805
|
} catch (error) {
|
|
13766
13806
|
console.error("[CLINIC_UTILS] Error getting clinic by ID:", error);
|
|
13767
13807
|
throw error;
|
|
13768
13808
|
}
|
|
13769
13809
|
}
|
|
13770
|
-
async function getAllClinics(db, pagination, lastDoc) {
|
|
13810
|
+
async function getAllClinics(db, pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
13771
13811
|
try {
|
|
13772
13812
|
const clinicsCollection = (0, import_firestore36.collection)(db, CLINICS_COLLECTION);
|
|
13773
13813
|
let clinicsQuery = (0, import_firestore36.query)(clinicsCollection);
|
|
@@ -13786,10 +13826,11 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
13786
13826
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
13787
13827
|
const clinics = clinicsSnapshot.docs.map((doc47) => {
|
|
13788
13828
|
const data = doc47.data();
|
|
13789
|
-
|
|
13829
|
+
const clinicWithId = {
|
|
13790
13830
|
...data,
|
|
13791
13831
|
id: doc47.id
|
|
13792
13832
|
};
|
|
13833
|
+
return filterClinicEmbeddedArrays(clinicWithId, excludeDraftPractitioners);
|
|
13793
13834
|
});
|
|
13794
13835
|
return {
|
|
13795
13836
|
clinics,
|
|
@@ -13800,7 +13841,7 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
13800
13841
|
throw error;
|
|
13801
13842
|
}
|
|
13802
13843
|
}
|
|
13803
|
-
async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc) {
|
|
13844
|
+
async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
13804
13845
|
const bounds = (0, import_geofire_common4.geohashQueryBounds)(
|
|
13805
13846
|
[center.latitude, center.longitude],
|
|
13806
13847
|
rangeInKm * 1e3
|
|
@@ -13823,8 +13864,9 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
13823
13864
|
);
|
|
13824
13865
|
const distanceInKm = distance / 1e3;
|
|
13825
13866
|
if (distanceInKm <= rangeInKm) {
|
|
13867
|
+
const filteredClinic = filterClinicEmbeddedArrays(clinic, excludeDraftPractitioners);
|
|
13826
13868
|
matchingClinics.push({
|
|
13827
|
-
...
|
|
13869
|
+
...filteredClinic,
|
|
13828
13870
|
distance: distanceInKm
|
|
13829
13871
|
});
|
|
13830
13872
|
}
|
|
@@ -14003,6 +14045,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
14003
14045
|
uniqueMap.set(c.id, c);
|
|
14004
14046
|
}
|
|
14005
14047
|
let clinics = Array.from(uniqueMap.values());
|
|
14048
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true;
|
|
14049
|
+
clinics = clinics.map((clinic) => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
14006
14050
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
14007
14051
|
const pageSize = filters.pagination || 5;
|
|
14008
14052
|
let startIndex = 0;
|
|
@@ -14056,6 +14100,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
14056
14100
|
const q = (0, import_firestore38.query)((0, import_firestore38.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
14057
14101
|
const querySnapshot = await (0, import_firestore38.getDocs)(q);
|
|
14058
14102
|
let clinics = querySnapshot.docs.map((doc47) => ({ ...doc47.data(), id: doc47.id }));
|
|
14103
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true;
|
|
14104
|
+
clinics = clinics.map((clinic) => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
14059
14105
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
14060
14106
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
14061
14107
|
console.log(`[CLINIC_SERVICE] Strategy 1 success: ${clinics.length} clinics`);
|
|
@@ -14088,6 +14134,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
14088
14134
|
const q = (0, import_firestore38.query)((0, import_firestore38.collection)(db, CLINICS_COLLECTION), ...constraints);
|
|
14089
14135
|
const querySnapshot = await (0, import_firestore38.getDocs)(q);
|
|
14090
14136
|
let clinics = querySnapshot.docs.map((doc47) => ({ ...doc47.data(), id: doc47.id }));
|
|
14137
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true;
|
|
14138
|
+
clinics = clinics.map((clinic) => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
14091
14139
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
14092
14140
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
14093
14141
|
console.log(`[CLINIC_SERVICE] Strategy 2 success: ${clinics.length} clinics`);
|
|
@@ -14569,15 +14617,17 @@ var ClinicService = class extends BaseService {
|
|
|
14569
14617
|
}
|
|
14570
14618
|
/**
|
|
14571
14619
|
* Dohvata kliniku po ID-u
|
|
14620
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
14572
14621
|
*/
|
|
14573
|
-
async getClinic(clinicId) {
|
|
14574
|
-
return getClinic(this.db, clinicId);
|
|
14622
|
+
async getClinic(clinicId, excludeDraftPractitioners = false) {
|
|
14623
|
+
return getClinic(this.db, clinicId, excludeDraftPractitioners);
|
|
14575
14624
|
}
|
|
14576
14625
|
/**
|
|
14577
14626
|
* Dohvata sve klinike u grupi
|
|
14627
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
14578
14628
|
*/
|
|
14579
|
-
async getClinicsByGroup(groupId) {
|
|
14580
|
-
return getClinicsByGroup(this.db, groupId);
|
|
14629
|
+
async getClinicsByGroup(groupId, excludeDraftPractitioners = false) {
|
|
14630
|
+
return getClinicsByGroup(this.db, groupId, excludeDraftPractitioners);
|
|
14581
14631
|
}
|
|
14582
14632
|
/**
|
|
14583
14633
|
* Pretražuje klinike u određenom radijusu
|
|
@@ -14677,19 +14727,20 @@ var ClinicService = class extends BaseService {
|
|
|
14677
14727
|
});
|
|
14678
14728
|
return clinic;
|
|
14679
14729
|
}
|
|
14680
|
-
async getClinicById(clinicId) {
|
|
14681
|
-
return getClinicById(this.db, clinicId);
|
|
14730
|
+
async getClinicById(clinicId, excludeDraftPractitioners = false) {
|
|
14731
|
+
return getClinicById(this.db, clinicId, excludeDraftPractitioners);
|
|
14682
14732
|
}
|
|
14683
|
-
async getAllClinics(pagination, lastDoc) {
|
|
14684
|
-
return getAllClinics(this.db, pagination, lastDoc);
|
|
14733
|
+
async getAllClinics(pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
14734
|
+
return getAllClinics(this.db, pagination, lastDoc, excludeDraftPractitioners);
|
|
14685
14735
|
}
|
|
14686
|
-
async getAllClinicsInRange(center, rangeInKm, pagination, lastDoc) {
|
|
14736
|
+
async getAllClinicsInRange(center, rangeInKm, pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
14687
14737
|
return getAllClinicsInRange(
|
|
14688
14738
|
this.db,
|
|
14689
14739
|
center,
|
|
14690
14740
|
rangeInKm,
|
|
14691
14741
|
pagination,
|
|
14692
|
-
lastDoc
|
|
14742
|
+
lastDoc,
|
|
14743
|
+
excludeDraftPractitioners
|
|
14693
14744
|
);
|
|
14694
14745
|
}
|
|
14695
14746
|
/**
|
|
@@ -21704,17 +21755,21 @@ var ProcedureService = class extends BaseService {
|
|
|
21704
21755
|
async getProceduresForMap() {
|
|
21705
21756
|
const proceduresRef = (0, import_firestore58.collection)(this.db, PROCEDURES_COLLECTION);
|
|
21706
21757
|
const snapshot = await (0, import_firestore58.getDocs)(proceduresRef);
|
|
21707
|
-
|
|
21758
|
+
let procedures = snapshot.docs.map((doc47) => ({
|
|
21759
|
+
id: doc47.id,
|
|
21760
|
+
...doc47.data()
|
|
21761
|
+
}));
|
|
21762
|
+
procedures = await this.filterDraftPractitionerProcedures(procedures);
|
|
21763
|
+
const proceduresForMap = procedures.map((procedure) => {
|
|
21708
21764
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21709
|
-
const data = doc47.data();
|
|
21710
21765
|
return {
|
|
21711
|
-
id:
|
|
21712
|
-
name:
|
|
21713
|
-
clinicId: (_a =
|
|
21714
|
-
clinicName: (_b =
|
|
21715
|
-
address: ((_d = (_c =
|
|
21716
|
-
latitude: (_f = (_e =
|
|
21717
|
-
longitude: (_h = (_g =
|
|
21766
|
+
id: procedure.id,
|
|
21767
|
+
name: procedure.name,
|
|
21768
|
+
clinicId: (_a = procedure.clinicInfo) == null ? void 0 : _a.id,
|
|
21769
|
+
clinicName: (_b = procedure.clinicInfo) == null ? void 0 : _b.name,
|
|
21770
|
+
address: ((_d = (_c = procedure.clinicInfo) == null ? void 0 : _c.location) == null ? void 0 : _d.address) || "",
|
|
21771
|
+
latitude: (_f = (_e = procedure.clinicInfo) == null ? void 0 : _e.location) == null ? void 0 : _f.latitude,
|
|
21772
|
+
longitude: (_h = (_g = procedure.clinicInfo) == null ? void 0 : _g.location) == null ? void 0 : _h.longitude
|
|
21718
21773
|
};
|
|
21719
21774
|
});
|
|
21720
21775
|
return proceduresForMap;
|
|
@@ -21751,10 +21806,12 @@ var ProcedureService = class extends BaseService {
|
|
|
21751
21806
|
(0, import_firestore58.orderBy)("name", "asc")
|
|
21752
21807
|
);
|
|
21753
21808
|
const querySnapshot = await (0, import_firestore58.getDocs)(proceduresQuery);
|
|
21754
|
-
|
|
21809
|
+
let procedures = querySnapshot.docs.map((doc47) => ({
|
|
21755
21810
|
id: doc47.id,
|
|
21756
21811
|
...doc47.data()
|
|
21757
21812
|
}));
|
|
21813
|
+
procedures = await this.filterDraftPractitionerProcedures(procedures);
|
|
21814
|
+
return procedures;
|
|
21758
21815
|
}
|
|
21759
21816
|
};
|
|
21760
21817
|
|
package/dist/index.mjs
CHANGED
|
@@ -13604,22 +13604,61 @@ import {
|
|
|
13604
13604
|
geohashQueryBounds
|
|
13605
13605
|
} from "geofire-common";
|
|
13606
13606
|
import { z as z20 } from "zod";
|
|
13607
|
-
|
|
13607
|
+
function filterDoctorsInfo(doctorsInfo) {
|
|
13608
|
+
if (!doctorsInfo || doctorsInfo.length === 0) {
|
|
13609
|
+
return [];
|
|
13610
|
+
}
|
|
13611
|
+
return doctorsInfo.filter((doctor) => {
|
|
13612
|
+
if (doctor.status === "draft" /* DRAFT */) {
|
|
13613
|
+
console.log(`[CLINIC_UTILS] Filtering out draft practitioner ${doctor.id} from doctorsInfo`);
|
|
13614
|
+
return false;
|
|
13615
|
+
}
|
|
13616
|
+
if (doctor.isActive === false) {
|
|
13617
|
+
console.log(`[CLINIC_UTILS] Filtering out inactive practitioner ${doctor.id} from doctorsInfo`);
|
|
13618
|
+
return false;
|
|
13619
|
+
}
|
|
13620
|
+
return true;
|
|
13621
|
+
});
|
|
13622
|
+
}
|
|
13623
|
+
function filterClinicEmbeddedArrays(clinic, excludeDraftPractitioners = false) {
|
|
13624
|
+
if (!clinic) {
|
|
13625
|
+
return clinic;
|
|
13626
|
+
}
|
|
13627
|
+
if (!excludeDraftPractitioners) {
|
|
13628
|
+
return clinic;
|
|
13629
|
+
}
|
|
13630
|
+
const filteredClinic = { ...clinic };
|
|
13631
|
+
if (filteredClinic.doctorsInfo && filteredClinic.doctorsInfo.length > 0) {
|
|
13632
|
+
const originalLength = filteredClinic.doctorsInfo.length;
|
|
13633
|
+
filteredClinic.doctorsInfo = filterDoctorsInfo(filteredClinic.doctorsInfo);
|
|
13634
|
+
if (filteredClinic.doctorsInfo.length !== originalLength) {
|
|
13635
|
+
console.log(
|
|
13636
|
+
`[CLINIC_UTILS] Filtered ${originalLength - filteredClinic.doctorsInfo.length} draft/inactive doctors from clinic ${clinic.id}`
|
|
13637
|
+
);
|
|
13638
|
+
}
|
|
13639
|
+
}
|
|
13640
|
+
return filteredClinic;
|
|
13641
|
+
}
|
|
13642
|
+
async function getClinic(db, clinicId, excludeDraftPractitioners = false) {
|
|
13608
13643
|
const docRef = doc23(db, CLINICS_COLLECTION, clinicId);
|
|
13609
13644
|
const docSnap = await getDoc25(docRef);
|
|
13610
13645
|
if (docSnap.exists()) {
|
|
13611
|
-
|
|
13646
|
+
const clinicData = docSnap.data();
|
|
13647
|
+
return filterClinicEmbeddedArrays(clinicData, excludeDraftPractitioners);
|
|
13612
13648
|
}
|
|
13613
13649
|
return null;
|
|
13614
13650
|
}
|
|
13615
|
-
async function getClinicsByGroup(db, groupId) {
|
|
13651
|
+
async function getClinicsByGroup(db, groupId, excludeDraftPractitioners = false) {
|
|
13616
13652
|
const q = query17(
|
|
13617
13653
|
collection17(db, CLINICS_COLLECTION),
|
|
13618
13654
|
where17("clinicGroupId", "==", groupId),
|
|
13619
13655
|
where17("isActive", "==", true)
|
|
13620
13656
|
);
|
|
13621
13657
|
const querySnapshot = await getDocs17(q);
|
|
13622
|
-
return querySnapshot.docs.map((doc47) =>
|
|
13658
|
+
return querySnapshot.docs.map((doc47) => {
|
|
13659
|
+
const clinicData = doc47.data();
|
|
13660
|
+
return filterClinicEmbeddedArrays(clinicData, excludeDraftPractitioners);
|
|
13661
|
+
});
|
|
13623
13662
|
}
|
|
13624
13663
|
async function updateClinic(db, clinicId, data, adminId, clinicAdminService, app) {
|
|
13625
13664
|
console.log("[CLINIC] Starting clinic update", { clinicId, adminId });
|
|
@@ -13824,7 +13863,7 @@ async function getActiveClinicsByAdmin(db, adminId, clinicAdminService, clinicGr
|
|
|
13824
13863
|
clinicGroupService
|
|
13825
13864
|
);
|
|
13826
13865
|
}
|
|
13827
|
-
async function getClinicById(db, clinicId) {
|
|
13866
|
+
async function getClinicById(db, clinicId, excludeDraftPractitioners = false) {
|
|
13828
13867
|
try {
|
|
13829
13868
|
const clinicRef = doc23(db, CLINICS_COLLECTION, clinicId);
|
|
13830
13869
|
const clinicSnapshot = await getDoc25(clinicRef);
|
|
@@ -13832,16 +13871,17 @@ async function getClinicById(db, clinicId) {
|
|
|
13832
13871
|
return null;
|
|
13833
13872
|
}
|
|
13834
13873
|
const clinicData = clinicSnapshot.data();
|
|
13835
|
-
|
|
13874
|
+
const clinicWithId = {
|
|
13836
13875
|
...clinicData,
|
|
13837
13876
|
id: clinicSnapshot.id
|
|
13838
13877
|
};
|
|
13878
|
+
return filterClinicEmbeddedArrays(clinicWithId, excludeDraftPractitioners);
|
|
13839
13879
|
} catch (error) {
|
|
13840
13880
|
console.error("[CLINIC_UTILS] Error getting clinic by ID:", error);
|
|
13841
13881
|
throw error;
|
|
13842
13882
|
}
|
|
13843
13883
|
}
|
|
13844
|
-
async function getAllClinics(db, pagination, lastDoc) {
|
|
13884
|
+
async function getAllClinics(db, pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
13845
13885
|
try {
|
|
13846
13886
|
const clinicsCollection = collection17(db, CLINICS_COLLECTION);
|
|
13847
13887
|
let clinicsQuery = query17(clinicsCollection);
|
|
@@ -13860,10 +13900,11 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
13860
13900
|
const lastVisible = clinicsSnapshot.docs[clinicsSnapshot.docs.length - 1];
|
|
13861
13901
|
const clinics = clinicsSnapshot.docs.map((doc47) => {
|
|
13862
13902
|
const data = doc47.data();
|
|
13863
|
-
|
|
13903
|
+
const clinicWithId = {
|
|
13864
13904
|
...data,
|
|
13865
13905
|
id: doc47.id
|
|
13866
13906
|
};
|
|
13907
|
+
return filterClinicEmbeddedArrays(clinicWithId, excludeDraftPractitioners);
|
|
13867
13908
|
});
|
|
13868
13909
|
return {
|
|
13869
13910
|
clinics,
|
|
@@ -13874,7 +13915,7 @@ async function getAllClinics(db, pagination, lastDoc) {
|
|
|
13874
13915
|
throw error;
|
|
13875
13916
|
}
|
|
13876
13917
|
}
|
|
13877
|
-
async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc) {
|
|
13918
|
+
async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
13878
13919
|
const bounds = geohashQueryBounds(
|
|
13879
13920
|
[center.latitude, center.longitude],
|
|
13880
13921
|
rangeInKm * 1e3
|
|
@@ -13897,8 +13938,9 @@ async function getAllClinicsInRange(db, center, rangeInKm, pagination, lastDoc)
|
|
|
13897
13938
|
);
|
|
13898
13939
|
const distanceInKm = distance / 1e3;
|
|
13899
13940
|
if (distanceInKm <= rangeInKm) {
|
|
13941
|
+
const filteredClinic = filterClinicEmbeddedArrays(clinic, excludeDraftPractitioners);
|
|
13900
13942
|
matchingClinics.push({
|
|
13901
|
-
...
|
|
13943
|
+
...filteredClinic,
|
|
13902
13944
|
distance: distanceInKm
|
|
13903
13945
|
});
|
|
13904
13946
|
}
|
|
@@ -14090,6 +14132,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
14090
14132
|
uniqueMap.set(c.id, c);
|
|
14091
14133
|
}
|
|
14092
14134
|
let clinics = Array.from(uniqueMap.values());
|
|
14135
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true;
|
|
14136
|
+
clinics = clinics.map((clinic) => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
14093
14137
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
14094
14138
|
const pageSize = filters.pagination || 5;
|
|
14095
14139
|
let startIndex = 0;
|
|
@@ -14143,6 +14187,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
14143
14187
|
const q = query19(collection19(db, CLINICS_COLLECTION), ...constraints);
|
|
14144
14188
|
const querySnapshot = await getDocs19(q);
|
|
14145
14189
|
let clinics = querySnapshot.docs.map((doc47) => ({ ...doc47.data(), id: doc47.id }));
|
|
14190
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true;
|
|
14191
|
+
clinics = clinics.map((clinic) => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
14146
14192
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
14147
14193
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
14148
14194
|
console.log(`[CLINIC_SERVICE] Strategy 1 success: ${clinics.length} clinics`);
|
|
@@ -14175,6 +14221,8 @@ async function getClinicsByFilters(db, filters) {
|
|
|
14175
14221
|
const q = query19(collection19(db, CLINICS_COLLECTION), ...constraints);
|
|
14176
14222
|
const querySnapshot = await getDocs19(q);
|
|
14177
14223
|
let clinics = querySnapshot.docs.map((doc47) => ({ ...doc47.data(), id: doc47.id }));
|
|
14224
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true;
|
|
14225
|
+
clinics = clinics.map((clinic) => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
14178
14226
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
14179
14227
|
const lastDoc = querySnapshot.docs.length > 0 ? querySnapshot.docs[querySnapshot.docs.length - 1] : null;
|
|
14180
14228
|
console.log(`[CLINIC_SERVICE] Strategy 2 success: ${clinics.length} clinics`);
|
|
@@ -14656,15 +14704,17 @@ var ClinicService = class extends BaseService {
|
|
|
14656
14704
|
}
|
|
14657
14705
|
/**
|
|
14658
14706
|
* Dohvata kliniku po ID-u
|
|
14707
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
14659
14708
|
*/
|
|
14660
|
-
async getClinic(clinicId) {
|
|
14661
|
-
return getClinic(this.db, clinicId);
|
|
14709
|
+
async getClinic(clinicId, excludeDraftPractitioners = false) {
|
|
14710
|
+
return getClinic(this.db, clinicId, excludeDraftPractitioners);
|
|
14662
14711
|
}
|
|
14663
14712
|
/**
|
|
14664
14713
|
* Dohvata sve klinike u grupi
|
|
14714
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
14665
14715
|
*/
|
|
14666
|
-
async getClinicsByGroup(groupId) {
|
|
14667
|
-
return getClinicsByGroup(this.db, groupId);
|
|
14716
|
+
async getClinicsByGroup(groupId, excludeDraftPractitioners = false) {
|
|
14717
|
+
return getClinicsByGroup(this.db, groupId, excludeDraftPractitioners);
|
|
14668
14718
|
}
|
|
14669
14719
|
/**
|
|
14670
14720
|
* Pretražuje klinike u određenom radijusu
|
|
@@ -14764,19 +14814,20 @@ var ClinicService = class extends BaseService {
|
|
|
14764
14814
|
});
|
|
14765
14815
|
return clinic;
|
|
14766
14816
|
}
|
|
14767
|
-
async getClinicById(clinicId) {
|
|
14768
|
-
return getClinicById(this.db, clinicId);
|
|
14817
|
+
async getClinicById(clinicId, excludeDraftPractitioners = false) {
|
|
14818
|
+
return getClinicById(this.db, clinicId, excludeDraftPractitioners);
|
|
14769
14819
|
}
|
|
14770
|
-
async getAllClinics(pagination, lastDoc) {
|
|
14771
|
-
return getAllClinics(this.db, pagination, lastDoc);
|
|
14820
|
+
async getAllClinics(pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
14821
|
+
return getAllClinics(this.db, pagination, lastDoc, excludeDraftPractitioners);
|
|
14772
14822
|
}
|
|
14773
|
-
async getAllClinicsInRange(center, rangeInKm, pagination, lastDoc) {
|
|
14823
|
+
async getAllClinicsInRange(center, rangeInKm, pagination, lastDoc, excludeDraftPractitioners = false) {
|
|
14774
14824
|
return getAllClinicsInRange(
|
|
14775
14825
|
this.db,
|
|
14776
14826
|
center,
|
|
14777
14827
|
rangeInKm,
|
|
14778
14828
|
pagination,
|
|
14779
|
-
lastDoc
|
|
14829
|
+
lastDoc,
|
|
14830
|
+
excludeDraftPractitioners
|
|
14780
14831
|
);
|
|
14781
14832
|
}
|
|
14782
14833
|
/**
|
|
@@ -21940,17 +21991,21 @@ var ProcedureService = class extends BaseService {
|
|
|
21940
21991
|
async getProceduresForMap() {
|
|
21941
21992
|
const proceduresRef = collection33(this.db, PROCEDURES_COLLECTION);
|
|
21942
21993
|
const snapshot = await getDocs33(proceduresRef);
|
|
21943
|
-
|
|
21994
|
+
let procedures = snapshot.docs.map((doc47) => ({
|
|
21995
|
+
id: doc47.id,
|
|
21996
|
+
...doc47.data()
|
|
21997
|
+
}));
|
|
21998
|
+
procedures = await this.filterDraftPractitionerProcedures(procedures);
|
|
21999
|
+
const proceduresForMap = procedures.map((procedure) => {
|
|
21944
22000
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21945
|
-
const data = doc47.data();
|
|
21946
22001
|
return {
|
|
21947
|
-
id:
|
|
21948
|
-
name:
|
|
21949
|
-
clinicId: (_a =
|
|
21950
|
-
clinicName: (_b =
|
|
21951
|
-
address: ((_d = (_c =
|
|
21952
|
-
latitude: (_f = (_e =
|
|
21953
|
-
longitude: (_h = (_g =
|
|
22002
|
+
id: procedure.id,
|
|
22003
|
+
name: procedure.name,
|
|
22004
|
+
clinicId: (_a = procedure.clinicInfo) == null ? void 0 : _a.id,
|
|
22005
|
+
clinicName: (_b = procedure.clinicInfo) == null ? void 0 : _b.name,
|
|
22006
|
+
address: ((_d = (_c = procedure.clinicInfo) == null ? void 0 : _c.location) == null ? void 0 : _d.address) || "",
|
|
22007
|
+
latitude: (_f = (_e = procedure.clinicInfo) == null ? void 0 : _e.location) == null ? void 0 : _f.latitude,
|
|
22008
|
+
longitude: (_h = (_g = procedure.clinicInfo) == null ? void 0 : _g.location) == null ? void 0 : _h.longitude
|
|
21954
22009
|
};
|
|
21955
22010
|
});
|
|
21956
22011
|
return proceduresForMap;
|
|
@@ -21987,10 +22042,12 @@ var ProcedureService = class extends BaseService {
|
|
|
21987
22042
|
orderBy18("name", "asc")
|
|
21988
22043
|
);
|
|
21989
22044
|
const querySnapshot = await getDocs33(proceduresQuery);
|
|
21990
|
-
|
|
22045
|
+
let procedures = querySnapshot.docs.map((doc47) => ({
|
|
21991
22046
|
id: doc47.id,
|
|
21992
22047
|
...doc47.data()
|
|
21993
22048
|
}));
|
|
22049
|
+
procedures = await this.filterDraftPractitionerProcedures(procedures);
|
|
22050
|
+
return procedures;
|
|
21994
22051
|
}
|
|
21995
22052
|
};
|
|
21996
22053
|
|
package/package.json
CHANGED
|
@@ -468,16 +468,18 @@ export class ClinicService extends BaseService {
|
|
|
468
468
|
|
|
469
469
|
/**
|
|
470
470
|
* Dohvata kliniku po ID-u
|
|
471
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
471
472
|
*/
|
|
472
|
-
async getClinic(clinicId: string): Promise<Clinic | null> {
|
|
473
|
-
return ClinicUtils.getClinic(this.db, clinicId);
|
|
473
|
+
async getClinic(clinicId: string, excludeDraftPractitioners: boolean = false): Promise<Clinic | null> {
|
|
474
|
+
return ClinicUtils.getClinic(this.db, clinicId, excludeDraftPractitioners);
|
|
474
475
|
}
|
|
475
476
|
|
|
476
477
|
/**
|
|
477
478
|
* Dohvata sve klinike u grupi
|
|
479
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
478
480
|
*/
|
|
479
|
-
async getClinicsByGroup(groupId: string): Promise<Clinic[]> {
|
|
480
|
-
return ClinicUtils.getClinicsByGroup(this.db, groupId);
|
|
481
|
+
async getClinicsByGroup(groupId: string, excludeDraftPractitioners: boolean = false): Promise<Clinic[]> {
|
|
482
|
+
return ClinicUtils.getClinicsByGroup(this.db, groupId, excludeDraftPractitioners);
|
|
481
483
|
}
|
|
482
484
|
|
|
483
485
|
/**
|
|
@@ -624,29 +626,32 @@ export class ClinicService extends BaseService {
|
|
|
624
626
|
return clinic;
|
|
625
627
|
}
|
|
626
628
|
|
|
627
|
-
async getClinicById(clinicId: string): Promise<Clinic | null> {
|
|
628
|
-
return ClinicUtils.getClinicById(this.db, clinicId);
|
|
629
|
+
async getClinicById(clinicId: string, excludeDraftPractitioners: boolean = false): Promise<Clinic | null> {
|
|
630
|
+
return ClinicUtils.getClinicById(this.db, clinicId, excludeDraftPractitioners);
|
|
629
631
|
}
|
|
630
632
|
|
|
631
633
|
async getAllClinics(
|
|
632
634
|
pagination?: number,
|
|
633
|
-
lastDoc?: any
|
|
635
|
+
lastDoc?: any,
|
|
636
|
+
excludeDraftPractitioners: boolean = false
|
|
634
637
|
): Promise<{ clinics: Clinic[]; lastDoc: any }> {
|
|
635
|
-
return ClinicUtils.getAllClinics(this.db, pagination, lastDoc);
|
|
638
|
+
return ClinicUtils.getAllClinics(this.db, pagination, lastDoc, excludeDraftPractitioners);
|
|
636
639
|
}
|
|
637
640
|
|
|
638
641
|
async getAllClinicsInRange(
|
|
639
642
|
center: { latitude: number; longitude: number },
|
|
640
643
|
rangeInKm: number,
|
|
641
644
|
pagination?: number,
|
|
642
|
-
lastDoc?: any
|
|
645
|
+
lastDoc?: any,
|
|
646
|
+
excludeDraftPractitioners: boolean = false
|
|
643
647
|
): Promise<{ clinics: (Clinic & { distance: number })[]; lastDoc: any }> {
|
|
644
648
|
return ClinicUtils.getAllClinicsInRange(
|
|
645
649
|
this.db,
|
|
646
650
|
center,
|
|
647
651
|
rangeInKm,
|
|
648
652
|
pagination,
|
|
649
|
-
lastDoc
|
|
653
|
+
lastDoc,
|
|
654
|
+
excludeDraftPractitioners
|
|
650
655
|
);
|
|
651
656
|
}
|
|
652
657
|
|
|
@@ -24,7 +24,9 @@ import {
|
|
|
24
24
|
ClinicGroup,
|
|
25
25
|
ClinicBranchSetupData,
|
|
26
26
|
ClinicLocation,
|
|
27
|
+
DoctorInfo,
|
|
27
28
|
} from "../../../types/clinic";
|
|
29
|
+
import { PractitionerStatus } from "../../../types/practitioner";
|
|
28
30
|
import {
|
|
29
31
|
geohashForLocation,
|
|
30
32
|
distanceBetween,
|
|
@@ -384,15 +386,81 @@ export async function createClinic(
|
|
|
384
386
|
* @param clinicId - ID of the clinic to get
|
|
385
387
|
* @returns The clinic or null if not found
|
|
386
388
|
*/
|
|
389
|
+
/**
|
|
390
|
+
* Filters out draft/inactive practitioners from doctorsInfo array
|
|
391
|
+
* @param doctorsInfo Array of doctor info objects
|
|
392
|
+
* @returns Filtered array excluding draft or inactive practitioners
|
|
393
|
+
*/
|
|
394
|
+
function filterDoctorsInfo(doctorsInfo: DoctorInfo[]): DoctorInfo[] {
|
|
395
|
+
if (!doctorsInfo || doctorsInfo.length === 0) {
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return doctorsInfo.filter((doctor) => {
|
|
400
|
+
// Filter out if status is DRAFT
|
|
401
|
+
if (doctor.status === PractitionerStatus.DRAFT) {
|
|
402
|
+
console.log(`[CLINIC_UTILS] Filtering out draft practitioner ${doctor.id} from doctorsInfo`);
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Filter out if isActive is explicitly false
|
|
407
|
+
if (doctor.isActive === false) {
|
|
408
|
+
console.log(`[CLINIC_UTILS] Filtering out inactive practitioner ${doctor.id} from doctorsInfo`);
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Include if status is ACTIVE or undefined (backward compatibility) and isActive is true or undefined
|
|
413
|
+
return true;
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Filters embedded arrays in a Clinic object to exclude draft/inactive practitioners
|
|
419
|
+
* @param clinic Clinic object to filter
|
|
420
|
+
* @param excludeDraftPractitioners If true, filters out draft/inactive practitioners. If false (default), returns all practitioners (for admin views)
|
|
421
|
+
* @returns Clinic object with filtered embedded arrays
|
|
422
|
+
*/
|
|
423
|
+
export function filterClinicEmbeddedArrays(clinic: Clinic, excludeDraftPractitioners: boolean = false): Clinic {
|
|
424
|
+
if (!clinic) {
|
|
425
|
+
return clinic;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// If excluding drafts is disabled (default), return clinic as-is (for admin views)
|
|
429
|
+
if (!excludeDraftPractitioners) {
|
|
430
|
+
return clinic;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const filteredClinic = { ...clinic };
|
|
434
|
+
|
|
435
|
+
// Filter doctorsInfo array
|
|
436
|
+
if (filteredClinic.doctorsInfo && filteredClinic.doctorsInfo.length > 0) {
|
|
437
|
+
const originalLength = filteredClinic.doctorsInfo.length;
|
|
438
|
+
filteredClinic.doctorsInfo = filterDoctorsInfo(filteredClinic.doctorsInfo);
|
|
439
|
+
if (filteredClinic.doctorsInfo.length !== originalLength) {
|
|
440
|
+
console.log(
|
|
441
|
+
`[CLINIC_UTILS] Filtered ${originalLength - filteredClinic.doctorsInfo.length} draft/inactive doctors from clinic ${clinic.id}`
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// Note: proceduresInfo doesn't have embedded status/isActive, so we rely on
|
|
447
|
+
// Cloud Functions to not include procedures from draft/inactive practitioners.
|
|
448
|
+
// If needed, we could add additional filtering here by checking practitioner status.
|
|
449
|
+
|
|
450
|
+
return filteredClinic;
|
|
451
|
+
}
|
|
452
|
+
|
|
387
453
|
export async function getClinic(
|
|
388
454
|
db: Firestore,
|
|
389
|
-
clinicId: string
|
|
455
|
+
clinicId: string,
|
|
456
|
+
excludeDraftPractitioners: boolean = false
|
|
390
457
|
): Promise<Clinic | null> {
|
|
391
458
|
const docRef = doc(db, CLINICS_COLLECTION, clinicId);
|
|
392
459
|
const docSnap = await getDoc(docRef);
|
|
393
460
|
|
|
394
461
|
if (docSnap.exists()) {
|
|
395
|
-
|
|
462
|
+
const clinicData = docSnap.data() as Clinic;
|
|
463
|
+
return filterClinicEmbeddedArrays(clinicData, excludeDraftPractitioners);
|
|
396
464
|
}
|
|
397
465
|
|
|
398
466
|
return null;
|
|
@@ -406,7 +474,8 @@ export async function getClinic(
|
|
|
406
474
|
*/
|
|
407
475
|
export async function getClinicsByGroup(
|
|
408
476
|
db: Firestore,
|
|
409
|
-
groupId: string
|
|
477
|
+
groupId: string,
|
|
478
|
+
excludeDraftPractitioners: boolean = false
|
|
410
479
|
): Promise<Clinic[]> {
|
|
411
480
|
const q = query(
|
|
412
481
|
collection(db, CLINICS_COLLECTION),
|
|
@@ -415,7 +484,10 @@ export async function getClinicsByGroup(
|
|
|
415
484
|
);
|
|
416
485
|
|
|
417
486
|
const querySnapshot = await getDocs(q);
|
|
418
|
-
return querySnapshot.docs.map((doc) =>
|
|
487
|
+
return querySnapshot.docs.map((doc) => {
|
|
488
|
+
const clinicData = doc.data() as Clinic;
|
|
489
|
+
return filterClinicEmbeddedArrays(clinicData, excludeDraftPractitioners);
|
|
490
|
+
});
|
|
419
491
|
}
|
|
420
492
|
|
|
421
493
|
/**
|
|
@@ -789,7 +861,8 @@ export async function getActiveClinicsByAdmin(
|
|
|
789
861
|
*/
|
|
790
862
|
export async function getClinicById(
|
|
791
863
|
db: Firestore,
|
|
792
|
-
clinicId: string
|
|
864
|
+
clinicId: string,
|
|
865
|
+
excludeDraftPractitioners: boolean = false
|
|
793
866
|
): Promise<Clinic | null> {
|
|
794
867
|
try {
|
|
795
868
|
const clinicRef = doc(db, CLINICS_COLLECTION, clinicId);
|
|
@@ -800,10 +873,11 @@ export async function getClinicById(
|
|
|
800
873
|
}
|
|
801
874
|
|
|
802
875
|
const clinicData = clinicSnapshot.data() as Clinic;
|
|
803
|
-
|
|
876
|
+
const clinicWithId = {
|
|
804
877
|
...clinicData,
|
|
805
878
|
id: clinicSnapshot.id,
|
|
806
879
|
};
|
|
880
|
+
return filterClinicEmbeddedArrays(clinicWithId, excludeDraftPractitioners);
|
|
807
881
|
} catch (error) {
|
|
808
882
|
console.error("[CLINIC_UTILS] Error getting clinic by ID:", error);
|
|
809
883
|
throw error;
|
|
@@ -821,7 +895,8 @@ export async function getClinicById(
|
|
|
821
895
|
export async function getAllClinics(
|
|
822
896
|
db: Firestore,
|
|
823
897
|
pagination?: number,
|
|
824
|
-
lastDoc?: any
|
|
898
|
+
lastDoc?: any,
|
|
899
|
+
excludeDraftPractitioners: boolean = false
|
|
825
900
|
): Promise<{ clinics: Clinic[]; lastDoc: any }> {
|
|
826
901
|
try {
|
|
827
902
|
const clinicsCollection = collection(db, CLINICS_COLLECTION);
|
|
@@ -845,10 +920,11 @@ export async function getAllClinics(
|
|
|
845
920
|
|
|
846
921
|
const clinics = clinicsSnapshot.docs.map((doc) => {
|
|
847
922
|
const data = doc.data() as Clinic;
|
|
848
|
-
|
|
923
|
+
const clinicWithId = {
|
|
849
924
|
...data,
|
|
850
925
|
id: doc.id,
|
|
851
926
|
};
|
|
927
|
+
return filterClinicEmbeddedArrays(clinicWithId, excludeDraftPractitioners);
|
|
852
928
|
});
|
|
853
929
|
|
|
854
930
|
return {
|
|
@@ -876,7 +952,8 @@ export async function getAllClinicsInRange(
|
|
|
876
952
|
center: { latitude: number; longitude: number },
|
|
877
953
|
rangeInKm: number,
|
|
878
954
|
pagination?: number,
|
|
879
|
-
lastDoc?: any
|
|
955
|
+
lastDoc?: any,
|
|
956
|
+
excludeDraftPractitioners: boolean = false
|
|
880
957
|
): Promise<{ clinics: (Clinic & { distance: number })[]; lastDoc: any }> {
|
|
881
958
|
const bounds = geohashQueryBounds(
|
|
882
959
|
[center.latitude, center.longitude],
|
|
@@ -907,8 +984,9 @@ export async function getAllClinicsInRange(
|
|
|
907
984
|
const distanceInKm = distance / 1000;
|
|
908
985
|
|
|
909
986
|
if (distanceInKm <= rangeInKm) {
|
|
987
|
+
const filteredClinic = filterClinicEmbeddedArrays(clinic, excludeDraftPractitioners);
|
|
910
988
|
matchingClinics.push({
|
|
911
|
-
...
|
|
989
|
+
...filteredClinic,
|
|
912
990
|
distance: distanceInKm,
|
|
913
991
|
});
|
|
914
992
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from 'firebase/firestore';
|
|
13
13
|
import { Clinic, ClinicTag, CLINICS_COLLECTION } from '../../../types/clinic';
|
|
14
14
|
import { geohashQueryBounds, distanceBetween } from 'geofire-common';
|
|
15
|
+
import { filterClinicEmbeddedArrays } from './clinic.utils';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Get clinics based on multiple filtering criteria with fallback strategies
|
|
@@ -36,6 +37,7 @@ export async function getClinicsByFilters(
|
|
|
36
37
|
pagination?: number;
|
|
37
38
|
lastDoc?: any;
|
|
38
39
|
isActive?: boolean;
|
|
40
|
+
excludeDraftPractitioners?: boolean; // If true, filters out draft/inactive practitioners. If false (default), returns all
|
|
39
41
|
},
|
|
40
42
|
): Promise<{
|
|
41
43
|
clinics: (Clinic & { distance?: number })[];
|
|
@@ -94,6 +96,10 @@ export async function getClinicsByFilters(
|
|
|
94
96
|
}
|
|
95
97
|
let clinics = Array.from(uniqueMap.values());
|
|
96
98
|
|
|
99
|
+
// Filter embedded arrays (draft/inactive practitioners) only if explicitly requested
|
|
100
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true; // Default to false (show all)
|
|
101
|
+
clinics = clinics.map(clinic => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
102
|
+
|
|
97
103
|
// Apply all remaining filters and compute exact distance + sorting
|
|
98
104
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
99
105
|
|
|
@@ -162,6 +168,10 @@ export async function getClinicsByFilters(
|
|
|
162
168
|
const querySnapshot = await getDocs(q);
|
|
163
169
|
let clinics = querySnapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id } as Clinic));
|
|
164
170
|
|
|
171
|
+
// Filter embedded arrays (draft/inactive practitioners) only if explicitly requested
|
|
172
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true; // Default to false (show all)
|
|
173
|
+
clinics = clinics.map(clinic => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
174
|
+
|
|
165
175
|
// Apply in-memory filters
|
|
166
176
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
167
177
|
|
|
@@ -205,6 +215,10 @@ export async function getClinicsByFilters(
|
|
|
205
215
|
const querySnapshot = await getDocs(q);
|
|
206
216
|
let clinics = querySnapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id } as Clinic));
|
|
207
217
|
|
|
218
|
+
// Filter embedded arrays (draft/inactive practitioners) only if explicitly requested
|
|
219
|
+
const excludeDrafts = filters.excludeDraftPractitioners === true; // Default to false (show all)
|
|
220
|
+
clinics = clinics.map(clinic => filterClinicEmbeddedArrays(clinic, excludeDrafts));
|
|
221
|
+
|
|
208
222
|
// Apply in-memory filters
|
|
209
223
|
clinics = applyInMemoryFilters(clinics, filters);
|
|
210
224
|
|
|
@@ -2300,18 +2300,23 @@ export class ProcedureService extends BaseService {
|
|
|
2300
2300
|
> {
|
|
2301
2301
|
const proceduresRef = collection(this.db, PROCEDURES_COLLECTION);
|
|
2302
2302
|
const snapshot = await getDocs(proceduresRef);
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2303
|
+
let procedures = snapshot.docs.map(doc => ({
|
|
2304
|
+
id: doc.id,
|
|
2305
|
+
...doc.data(),
|
|
2306
|
+
} as Procedure));
|
|
2307
|
+
|
|
2308
|
+
// Filter out procedures with draft/inactive practitioners
|
|
2309
|
+
procedures = await this.filterDraftPractitionerProcedures(procedures);
|
|
2310
|
+
|
|
2311
|
+
const proceduresForMap = procedures.map(procedure => ({
|
|
2312
|
+
id: procedure.id,
|
|
2313
|
+
name: procedure.name,
|
|
2314
|
+
clinicId: procedure.clinicInfo?.id,
|
|
2315
|
+
clinicName: procedure.clinicInfo?.name,
|
|
2316
|
+
address: procedure.clinicInfo?.location?.address || '',
|
|
2317
|
+
latitude: procedure.clinicInfo?.location?.latitude,
|
|
2318
|
+
longitude: procedure.clinicInfo?.location?.longitude,
|
|
2319
|
+
}));
|
|
2315
2320
|
return proceduresForMap;
|
|
2316
2321
|
}
|
|
2317
2322
|
|
|
@@ -2363,9 +2368,14 @@ export class ProcedureService extends BaseService {
|
|
|
2363
2368
|
|
|
2364
2369
|
const querySnapshot = await getDocs(proceduresQuery);
|
|
2365
2370
|
|
|
2366
|
-
|
|
2371
|
+
let procedures = querySnapshot.docs.map(doc => ({
|
|
2367
2372
|
id: doc.id,
|
|
2368
2373
|
...doc.data(),
|
|
2369
2374
|
} as Procedure));
|
|
2375
|
+
|
|
2376
|
+
// Filter out procedures with draft/inactive practitioners
|
|
2377
|
+
procedures = await this.filterDraftPractitionerProcedures(procedures);
|
|
2378
|
+
|
|
2379
|
+
return procedures;
|
|
2370
2380
|
}
|
|
2371
2381
|
}
|