1const p_id = patient_id;
2 let fetchingReports = await Reports.aggregate([
3 ...(p_id
4 ? [
5 {
6 $match: {
7 createdBy: mongoose.Types.ObjectId(id),
8 patient_id: p_id,
9 },
10 },
11 ]
12 : [
13 {
14 $match: {
15 createdBy: mongoose.Types.ObjectId(id),
16 },
17 },