예제 #1
0
    public bool AddBooking(int patientid, string title, DateTime startdatetime, 
        DateTime enddatetime, string note, int bookingtypeid)
    {
        Rehab.BookingsDataTable bookings = new Rehab.BookingsDataTable();
        Rehab.BookingsRow booking = bookings.NewBookingsRow();

        if ((startdatetime == null) || (enddatetime == null))
            throw new ApplicationException("Start-och sluttid för bokningen måste vara angivet.");

        //Do business logic validation here
        PatientsTableAdapter patientsTableAdapter = new PatientsTableAdapter();
        Rehab.PatientsDataTable patients = patientsTableAdapter.GetDataByPatientID(patientid);
        if (patients.Count == 0)
            throw new ApplicationException("Bokningen försöker göras med en patient som inte finns.");

        ValidateBookingDateTime(startdatetime, enddatetime);

        //Get other bookings this day and see if the interfere with the new booking
        Rehab.BookingsDataTable otherBookings = GetBookingsByDate(startdatetime);

        bool isBookingPossible = false;
        DateTime newStartdatetime = startdatetime;
        DateTime newEnddatetime = enddatetime;

        while ((!isBookingPossible) && (startdatetime < new DateTime(startdatetime.Year, startdatetime.Month, startdatetime.Day, 19, 0 , 0)))
        {
            isBookingPossible = CheckBlockingBookings(newStartdatetime, newEnddatetime, bookingtypeid, otherBookings);

            if (!isBookingPossible)
            {
                newStartdatetime =  newStartdatetime.AddMinutes((double)30);
                newEnddatetime = newEnddatetime.AddMinutes((double)30);
            }
        }

        if (isBookingPossible)
        {
            if (newStartdatetime != startdatetime)
                throw new Common.CollidingBookingException(startdatetime, enddatetime, newStartdatetime, newEnddatetime);
        }
        else
            throw new ApplicationException("Det finns ingen ledig tid idag från det angivna klockslaget.");

        booking.startdatetime = startdatetime;
        booking.enddatetime = enddatetime;
        booking.patientid = patientid;
        booking.title = title;
        booking.bookingtypeid = bookingtypeid;

        booking.arrived = false;
        booking.notshown = false;

        booking.cancelled = false;
        booking.SetcancellednoteNull();

        if (note == null)
            booking.SetnoteNull();
        else
            booking.note = note;

        booking.createdatetime = DateTime.Now;

        bookings.AddBookingsRow(booking);
        int affectedRows = Adapter.Update(bookings);

        return affectedRows == 1;
    }
예제 #2
0
    private void IsPatientAlreadyExisting(string personnumber, int patientid)
    {
        PatientsTableAdapter patientsTableAdapter = new PatientsTableAdapter();
        Rehab.PatientsDataTable patients = patientsTableAdapter.GetDataByPersonnumber(personnumber);

        int nrofPatients = patients.Count;
        if (nrofPatients > 0)
        {
            if (patientid == -1)
                throw new ApplicationException(string.Format("Patienten kan inte läggas till. Det finns redan en patient, {0} {1}, med personnummer {2} i patientregistret.", patients[0].surname, patients[0].firstname, personnumber));
            else if (patientid != patients[0].patientid)
                throw new ApplicationException(string.Format("Patienten kan inte uppdateras. Det finns redan en patient, {0} {1}, med personnummer {2} i patientregistret.", patients[0].surname, patients[0].firstname, personnumber));
        }
    }