Skip to content

Commit

Permalink
added missed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulrhman500 committed Oct 14, 2023
1 parent 8c4b73a commit 3badfdd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
35 changes: 35 additions & 0 deletions server/src/services/appointment.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import AppointmentModel from '../models/appointment.model';
import { StatusCodes } from 'http-status-codes';
import mongoose from 'mongoose';
import { HttpError } from '../utils';
const getUpcomingPatients = async (doctorID: string) => {
//get patients that have appointments with this doctor
const patients = await AppointmentModel.find({ doctorID: doctorID }).distinct('patientID').populate('patientID');
Expand Down Expand Up @@ -28,3 +30,36 @@ const getPatients = async (doctorID: string) => {
result: patients
};
};
const filterAppointment = async (
doctorID?: string,
patientID?: string,
status?: string,
startDate?: Date,
endDate?: Date
) => {
try {
let filter = {};
if (doctorID) filter = { ...filter, doctorID: new mongoose.Types.ObjectId(doctorID) };
if (patientID) filter = { ...filter, patientID: new mongoose.Types.ObjectId(patientID) };
if (status) filter = { ...filter, status: status };
if (startDate && endDate) {
filter = {
...filter,
startTime: { $gte: startDate, $lte: endDate },
endTime: { $gte: startDate, $lte: endDate }
};
} else if (startDate) {
filter = { ...filter, startTime: { $lte: startDate }, endTime: { $gte: startDate } };
} else {
filter = { ...filter, startTime: { $lte: { endDate } }, endTime: { $gte: endDate } };
}
const result = await AppointmentModel.find(filter);
return {
result: result,
status: StatusCodes.OK,
message: 'Successfully retrieved appointments'
};
} catch (e) {
throw new HttpError(StatusCodes.INTERNAL_SERVER_ERROR, `Error happened while retrieving appointments${e}`);
}
};
15 changes: 14 additions & 1 deletion server/src/services/patient.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,25 @@ const selectPrescription = async (prescriptionID: string) => {
};
}
};
const getPatientHealthRecord = async (patientID: string) => {
try {
const result = await UserModel.findOne({ _id: new mongoose.Types.ObjectId(patientID) }).select('medicalHistory');
return {
result: result,
status: StatusCodes.OK,
message: 'Successfully retrieved health record'
};
} catch (e) {
throw new HttpError(StatusCodes.INTERNAL_SERVER_ERROR, `Error happened while retrieving health record${e}`);
}
};
export {
viewAllDoctorsForPatient,
calculateFinalSessionPrice,
getAllPrescription,
filterPrescriptions,
selectPrescription,
getFamily,
hasActivePackage
hasActivePackage,
getPatientHealthRecord
};

0 comments on commit 3badfdd

Please sign in to comment.