public static DataRow CalcWalkInTimeslot() { DataTable workingDoctors = StaffDBConverter.GetWorkingDoctors(DateTime.Today.Date, "None", "None"); // Doctor shift start & end times stored to be used to calculate appointment possibilities List <int> staffID = new List <int>(); List <int> shiftStarts = new List <int>(); List <int> shiftEnds = new List <int>(); foreach (DataRow row in workingDoctors.Rows) { staffID.Add(int.Parse(row["Id"].ToString())); shiftStarts.Add(int.Parse(row["Shift_Start"].ToString())); shiftEnds.Add(int.Parse(row["Shift_End"].ToString())); } DataTable dt = CalcTimeslots(staffID, shiftStarts, shiftEnds, PatientDBConverter.GetBookedTimeslots(DateTime.Today.Date, staffID), false); foreach (DataRow dataRow in dt.Rows) { string rowValue = dataRow["Avaliable_Reservations"].ToString(); DateTime selectedTime = DateTime.Parse(rowValue); // Returns earliest timeslot after the current time if (DateTime.Now.TimeOfDay < selectedTime.TimeOfDay) { return(dataRow); } } return(null); }
internal static DataTable GetAwaitingCheckIn(DateTime dob, string firstname, string doorNo, string postcode) { DataTable dt = new DataTable(); dt.Columns.Add("AppointmentID"); dt.Columns.Add("AppointmentTime"); dt.Columns.Add("DoctorName"); dt.Columns.Add("PatientID"); // The command begins by retrieving primary key Appointment number, Appointment time, doctor ID and patient Name which is then placed in the above datatable // within the specified columns - ID is temporarily placed in the DoctorName column. Only patients who have not been marked as Checked-in are retrieved. string cmdString = "SELECT DISTINCT BookedAppointments.AppointmentID, BookedAppointments.Appointment_Time, BookedAppointments.Assigned_DoctorID AS DoctorID, " + "BookedAppointments.PatientID FROM BookedAppointments, PatientData " + "WHERE BookedAppointments.Date = @date AND BookedAppointments.Checked_In = \"NO\" " + "AND BookedAppointments.PatientID = " + "(SELECT PatientData.PatientID FROM PatientData WHERE PatientData.Firstname = @firstname AND PatientData.ST_Number = @drNum " + "AND PatientData.Postcode = @postcode AND PatientData.DOB = @dob)"; SQLiteConnection conn = OpenConnection(); SQLiteCommand cmd = new SQLiteCommand(cmdString, conn); cmd.Parameters.Add("@date", DbType.String).Value = DateTime.Today.ToShortDateString(); cmd.Parameters.Add("@firstname", DbType.String).Value = firstname.ToLower(new System.Globalization.CultureInfo("en-UK", false)); cmd.Parameters.Add("@drNum", DbType.Int32).Value = doorNo; cmd.Parameters.Add("@postcode", DbType.String).Value = postcode.ToUpper().Replace(" ", ""); cmd.Parameters.Add("@dob", DbType.String).Value = dob.ToShortDateString(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DataRow dr = dt.NewRow(); dr[0] = reader.GetInt32(0); dr[1] = reader.GetString(1); dr[2] = reader.GetInt32(2); dr[3] = reader.GetInt32(3); dt.Rows.Add(dr); } reader.Close(); conn.Close(); // Using the obtained DoctorID, the DataTable is updated with the doctor Name using GetEmployeeNameByID - taking the previously obtained ID's as arguements foreach (DataRow dr in dt.Rows) { int id = int.Parse(dr[2].ToString()); dr[2] = StaffDBConverter.GetEmployeeNameByID(id); } return(dt); }