protected void EditFullDayBookings() { DateTime? old_date = UrlEditFullDay_OldDate; DateTime? new_date = UrlEditFullDay_NewDate; Organisation old_org = UrlEditFullDay_OldOrg; Organisation new_org = UrlEditFullDay_NewOrg; Staff old_prov = UrlEditFullDay_OldProvider; Staff new_prov = UrlEditFullDay_NewProvider; if (old_date == null) { throw new Exception("Invalid url field editfullday_old_date"); } if (new_date == null) { throw new Exception("Invalid url field editfullday_new_date"); } if (old_org == null) { throw new Exception("Invalid url field editfullday_old_org"); } if (new_org == null) { throw new Exception("Invalid url field editfullday_new_org"); } if (old_prov == null) { throw new Exception("Invalid url field editfullday_old_provider"); } if (new_prov == null) { throw new Exception("Invalid url field editfullday_new_provider"); } // get all bookings from that day/staff/org // check each for clash bool hasClash = false; System.Collections.ArrayList clashes = new System.Collections.ArrayList(); Booking[] daysBookingList = BookingDB.GetBetween(old_date.Value, old_date.Value.AddDays(1), new Staff[] { old_prov }, new Organisation[] { old_org }, null, null, false, "0", false); // remove any 34 types not for this org System.Collections.ArrayList tmp = new System.Collections.ArrayList(); foreach (Booking booking in daysBookingList) { if (booking.BookingTypeID != 34 || (booking.Organisation.OrganisationID == old_org.OrganisationID && booking.Provider.StaffID == old_prov.StaffID)) { tmp.Add(booking); } } daysBookingList = (Booking[])tmp.ToArray(typeof(Booking)); foreach (Booking booking in daysBookingList) { DateTime newDateStart = new_date.Value.AddHours(booking.DateStart.Hour).AddMinutes(booking.DateStart.Minute).AddSeconds(booking.DateStart.Second); DateTime newDateEnd = new_date.Value.AddHours(booking.DateEnd.Hour).AddMinutes(booking.DateEnd.Minute).AddSeconds(booking.DateEnd.Second); Booking[] bookings = BookingDB.GetToCheckOverlap_OneTime(newDateStart, newDateEnd, new_prov, null, true, true, true, new Booking[] { booking }); // remove any non 34 types (unavailabilities) for other orgs tmp = new System.Collections.ArrayList(); foreach (Booking bk in bookings) { if (bk.Organisation.OrganisationID == old_org.OrganisationID || bk.BookingTypeID == 34) { tmp.Add(bk); } } bookings = (Booking[])tmp.ToArray(typeof(Booking)); if (Booking.HasOverlap(bookings, newDateStart, newDateEnd, booking)) { hasClash = true; clashes.Add(booking.DateStart.ToString("yyyy-MM-dd HH:mm") + (booking.Patient == null ? "" : " " + booking.Patient.Person.FullnameWithoutMiddlename)); //break; } } if (hasClash) { string clashesString = string.Empty; foreach (string s in clashes) { clashesString += (clashesString.Length == 0 ? "" : "\r\n") + s; } throw new CustomMessageException("There are clashes that need to be moved first:\r\n\r\nThese are unable to be moved:\r\n" + clashesString); } foreach (Booking booking in daysBookingList) { if (booking.BookingTypeID != 34) { continue; } DateTime newDateStart = new_date.Value.AddHours(booking.DateStart.Hour).AddMinutes(booking.DateStart.Minute).AddSeconds(booking.DateStart.Second); DateTime newDateEnd = new_date.Value.AddHours(booking.DateEnd.Hour).AddMinutes(booking.DateEnd.Minute).AddSeconds(booking.DateEnd.Second); int bookingChangeHistoryReason = 276; // 276 = Admininstration reschedule needs BookingChangeHistoryDB.Insert(booking.BookingID, GetStaffID(), bookingChangeHistoryReason, booking.DateStart); BookingDB.Update(booking.BookingID, newDateStart, newDateEnd, new_org.OrganisationID, new_prov.StaffID, booking.Patient == null ? -1 : booking.Patient.PatientID, booking.Offering == null ? -1 : booking.Offering.OfferingID, booking.BookingTypeID, booking.BookingStatus.ID, -1, booking.AddedBy.StaffID, booking.BookingConfirmedByType == null ? -1 : booking.BookingConfirmedByType.ID, booking.ConfirmedBy == null ? -1 : booking.ConfirmedBy.StaffID, booking.DateConfirmed, booking.DeletedBy == null ? -1 : booking.DeletedBy.StaffID, booking.DateDeleted, booking.CancelledBy == null ? -1 : booking.CancelledBy.StaffID, booking.DateCancelled, booking.IsPatientMissedAppt, booking.IsProviderMissedAppt, booking.IsEmergency, booking.IsRecurring, booking.RecurringDayOfWeek, booking.RecurringStartTime, booking.RecurringEndTime); } }
protected void FillGrid() { Booking booking = GetFormBooking(); if (booking == null) { SetErrorMessage("Invalid booking id"); return; } lblHeadingDetail.Text = @"<table> <tr> <td>Date/Time</td> <td style=""min-width:10px;""></td> <td>" + booking.DateStart.ToString(@"dd MMM yyyy H:mm") + (booking.DateStart.Hour < 12 ? "am" : "pm") + " - " + booking.DateEnd.ToString(@"H:mm") + (booking.DateEnd.Hour < 12 ? "am" : "pm") + @"</td> <tr> <tr> <td>Location</td> <td></td> <td>" + booking.Organisation.Name + @"</td> <tr> " + (booking.Patient == null ? "" : @"<tr> <td>Patient</td> <td></td> <td>" + booking.Patient.Person.FullnameWithoutMiddlename + @"</td> <tr> ") + (booking.Offering == null ? "" : @"<tr> <td>Service</td> <td></td> <td>" + booking.Offering.Name + @"</td> <tr> ") + "</table>"; DataTable dt = BookingChangeHistoryDB.GetDataTable_ByBookingID(booking.BookingID); Session["bookingedithistory_data"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["bookingedithistory_sortexpression"] != null && Session["bookingedithistory_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["bookingedithistory_sortexpression"].ToString(); GrdPatient.DataSource = dataView; } else { GrdPatient.DataSource = dt; } try { GrdPatient.DataBind(); GrdPatient.PagerSettings.FirstPageText = "1"; GrdPatient.PagerSettings.LastPageText = GrdPatient.PageCount.ToString(); GrdPatient.DataBind(); } catch (Exception ex) { SetErrorMessage(ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdPatient.DataSource = dt; GrdPatient.DataBind(); int TotalColumns = GrdPatient.Rows[0].Cells.Count; GrdPatient.Rows[0].Cells.Clear(); GrdPatient.Rows[0].Cells.Add(new TableCell()); GrdPatient.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdPatient.Rows[0].Cells[0].Text = "No Changes Made"; } }
protected void EditBooking() { //UrlReturnPage returnPage = GetUrlReturnPage(); bool?checkClashAllOrgs = UrlCheckClashAllOrgs; Booking booking = UrlBooking; DateTime? startDateTime = UrlStartDateTime; DateTime? endDateTime = UrlEndDateTime; Patient patient = UrlPatient; Organisation org = UrlOrg; Staff staff = UrlStaff; Offering offering = UrlOffering; bool? confirmed = UrlIsConfirmed; int? editReason = UrlEditReasonID; if (booking == null) { throw new Exception("Invalid url field booking_id"); } if (startDateTime == null) { throw new Exception("Invalid url field start_datetime"); } if (endDateTime == null) { throw new Exception("Invalid url field end_datetime"); } if (org == null) { throw new Exception("Invalid url field org_id"); } if (staff == null) { throw new Exception("Invalid url field staff_id"); } if (confirmed == null) { throw new Exception("Invalid url field is_confirmed"); } if (editReason == null) { throw new Exception("Invalid url field edit_reason_id"); } if (booking.AddedBy == null) { throw new CustomMessageException("Error - please contact system administrator.\r\n\r\nError Details:\r\nBooking 'Added By' is not set and must be set. BK ID: " + booking.BookingID); } // check booking is valid ie no overlapping with current bookings Booking[] bookings = BookingDB.GetToCheckOverlap_OneTime(startDateTime.Value, endDateTime.Value, staff, checkClashAllOrgs.Value ? null : org, booking.BookingTypeID == 342, true, false); if (Booking.HasOverlap(bookings, startDateTime.Value, endDateTime.Value, booking)) { string fromTime = startDateTime.Value.Hour.ToString().PadLeft(2, '0') + ":" + startDateTime.Value.Minute.ToString().PadLeft(2, '0'); string toTime = endDateTime.Value.Hour.ToString().PadLeft(2, '0') + ":" + endDateTime.Value.Minute.ToString().PadLeft(2, '0'); throw new CustomMessageException("Can not book " + startDateTime.Value.ToString(@"ddd MMM d") + " " + fromTime + "-" + toTime + " due to overlap with existing booking"); } int booking_confirmed_by_type_id = !confirmed.Value ? -1 : 1; int confirmedBy = !confirmed.Value ? -1 : (booking.ConfirmedBy == null ? GetStaffID() : booking.ConfirmedBy.StaffID); DateTime dateConfirmed = !confirmed.Value ? DateTime.MinValue : (booking.ConfirmedBy == null ? DateTime.Now : booking.DateConfirmed); if (patient != null && !RegisterPatientDB.IsPatientRegisteredToOrg(patient.PatientID, org.OrganisationID)) { RegisterPatientDB.Insert(org.OrganisationID, patient.PatientID); } BookingChangeHistoryDB.Insert(booking.BookingID, GetStaffID(), Convert.ToInt32(editReason.Value), booking.DateStart); BookingDB.Update(booking.BookingID, startDateTime.Value, endDateTime.Value, org.OrganisationID, staff.StaffID, patient == null ? -1 : patient.PatientID, offering == null ? -1 : offering.OfferingID, booking.BookingTypeID, booking.BookingStatus.ID, -1, booking.AddedBy.StaffID, booking_confirmed_by_type_id, confirmedBy, dateConfirmed, booking.DeletedBy == null ? -1 : booking.DeletedBy.StaffID, booking.DateDeleted, booking.CancelledBy == null ? -1 : booking.CancelledBy.StaffID, booking.DateCancelled, booking.IsPatientMissedAppt, booking.IsProviderMissedAppt, booking.IsEmergency, booking.IsRecurring, booking.RecurringDayOfWeek, booking.RecurringStartTime, booking.RecurringEndTime); if (booking.BookingTypeID == 34) { Booking newBooking = BookingDB.GetByID(booking.BookingID); newBooking.SendReminderEmail(booking); } if (booking.ArrivalTime != DateTime.MinValue && booking.DateStart != startDateTime) { BookingDB.RemoveArrivalTime(booking.BookingID); } }