This is a migrated thread and some comments may be shown as answers.

ClinicScheduler with RadScheduler

8 Answers 102 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
shahab
Top achievements
Rank 1
shahab asked on 14 Mar 2013, 09:40 AM
Dear dude
I want to use RadScheuduler to design clinic scheduler with different doctors. I want to set doctors times in RadScheduler. Then Patient set specified work time in another form. doctor can work in different place. Please see the diagram. Now I have a problem in patient Appointment. I should set time slot disable/enable based on doctorAppointment And Then patient insert appointment for special doctor based on timeslot. I used entityframework but I got may error. How can I Access doctorAppointment in PatientAppointment?
I defiened resourceType for Room,Doctor,DoctorAppointment,AppointmentType but in insertForm I can not Access roomID and DoctorID which are in DoctorAppointmentTable.
RadScheduler:
<telerik:RadScheduler runat="server" ID="PatientsScheduler" GroupBy="Doctor"
                DataSourceID="PatientsAppointmentEntityDataSource" DataKeyField="Id" DataSubjectField="FirstName"
                DataStartField="Start" DataEndField="End"  ....>
InsertTemplate Which has error to find FirstName:
    <InlineInsertTemplate>                 
                            <asp:Label ID="Label4" AssociatedControlID="FirstNameTextBox" runat="server" CssClass="inline-label"/>
                            <asp:TextBox ID="FirstNameTextBox" Rows="2" Columns="20" runat="server" Text='<%# Bind("FirstName") %>'
                                Width="97%" TextMode="MultiLine"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="FirstNameRequiredFieldValidator" runat="server" ValidationGroup="Insert"
                                ControlToValidate="FirstNameTextBox" ErrorMessage="نام بیمار اجباری">*</asp:RequiredFieldValidator>
                            <br />                      
                            <asp:Label ID="Label5" AssociatedControlID="StartInput" runat="server" CssClass="inline-label"/>
                            <telerik:RadDateInput ID="StartInput" SelectedDate='<%# Bind("Start") %>' runat="server"
                                EnableSingleInputRendering="false">
                            </telerik:RadDateInput>                            
                            <br />                    
                            <asp:Label ID="Label3" AssociatedControlID="AppointmentTypeComboBox" runat="server" />
                            <telerik:RadComboBox runat="server" ID="AppointmentTypeComboBox" DataTextField="Name"
                                DataValueField="Id" Width="90%" Skin="Office2007" SelectedValue='<%# Bind("AppointmentTypeId") %>'
                                DataSourceID="AppointmentTypesEntityDataSource">
                            </telerik:RadComboBox>                                    
                </InlineInsertTemplate>
ResourceTypes are:
   <ResourceTypes>                 
                    <telerik:ResourceType KeyField="Id" Name="Doctor" TextField="Name" ForeignKeyField="DoctorId"
                        DataSourceID="DoctorsEntityDataSource"></telerik:ResourceType>
                    <telerik:ResourceType KeyField="Id" Name="Room" TextField="Name" ForeignKeyField="RoomId"
                        DataSourceID="RoomsEntityDataSource"></telerik:ResourceType>
                    <telerik:ResourceType KeyField="Id" Name="AppointmentType" TextField="Name" ForeignKeyField="AppointmentTypeId"
                        DataSourceID="AppointmentTypesEntityDataSource"></telerik:ResourceType>
                         <telerik:ResourceType KeyField="Id" Name="DoctorAppointment" TextField="Subject" ForeignKeyField="DoctorAppointmentId"
                        DataSourceID="DoctorAppointmentsEntityDataSource"></telerik:ResourceType>
                </ResourceTypes>
And EntityDataSources Are:
  <asp:EntityDataSource ID="DoctorAppointmentsEntityDataSource" runat="server" ConnectionString="name=DatabaseEntities"
            DefaultContainerName="DatabaseEntities" EntitySetName="DoctorAppointments" EnableInsert="True">
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="PatientsAppointmentEntityDataSource" runat="server" ConnectionString="name=DatabaseEntities"
            DefaultContainerName="DatabaseEntities"
            EnableInsert="True" EntitySetName="PatientAppointments">
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="RoomsEntityDataSource" runat="server" ConnectionString="name=DatabaseEntities"
            DefaultContainerName="DatabaseEntities" EntitySetName="Rooms">
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="DoctorsEntityDataSource" runat="server" ConnectionString="name=DatabaseEntities"
            DefaultContainerName="DatabaseEntities" CommandText="SELECT it.[Id] , it.[FirstName] + ' ' + it.[LastName] as Name From DatabaseEntities.Doctors as it">
        </asp:EntityDataSource>
        <asp:EntityDataSource ID="AppointmentTypesEntityDataSource" runat="server" ConnectionString="name=DatabaseEntities"
            DefaultContainerName="DatabaseEntities" EntitySetName="AppointmentTypes">
        </asp:EntityDataSource> 


Please guide me on that. If you think it's better to change my method I would be glad for your kindness

8 Answers, 1 is accepted

Sort by
0
shahab
Top achievements
Rank 1
answered on 18 Mar 2013, 05:55 AM
There is no answer after 4days!!
I Found DBSchedulerProviderBase solution. I set Doctor's Time and Location on special day in doctorAppointments_Table. Patient can select from them a subset of time. I define patientAppointment_table for that. There for in DBSchedulerProviderBase I have:
using Telerik.Web.UI;
using System.Collections.Generic;
using Models;
using System;
using System.Data.Objects;
using System.Data.Common;
using System.Data.SqlClient;
namespace Provider
{
    public class PatientSchedulerProviderBase : DbSchedulerProviderBase
    {
        public IDictionary<int, Resource> _doctorAppointments;
        public IDictionary<int, Resource> _patients;

        private IDictionary<int, Resource> DoctorAppointments
        {
            get
            {
                return _doctorAppointments;
            }
        }

        private IDictionary<int, Resource> Patients
        {
            get
            {
                return _patients;
            }
        }

        private void LoadResources()
        {
            if (_doctorAppointments == null)
            {
                _doctorAppointments = new Dictionary<int, Resource>();
            }
            _doctorAppointments.Clear();
            foreach (Resource doctorAppointment in LoadDoctorAppointments())
            {
                _doctorAppointments.Add((int)doctorAppointment.Key, doctorAppointment);
            }
            if (_patients == null)
            {
                _patients = new Dictionary<int, Resource>();
            }
            _patients.Clear();
            foreach (Resource patient in LoadPatients())
            {
                _patients.Add((int)patient.Key, patient);
            }
        }

        public override IEnumerable<Appointment> GetAppointments(RadScheduler owner)
        {
            List<Appointment> appointments = new List<Appointment>();

            DatabaseEntities databaseEntities = new DatabaseEntities();
            foreach (PatientAppointment patientAppointment in databaseEntities.PatientAppointments)
            {
                Appointment apt = new Appointment();
                apt.Owner = owner;
                apt.ID = patientAppointment.Id; ;
                apt.Subject = string.Format("{0} {1}", patientAppointment.Patient.FirstName, patientAppointment.Patient.LastName);
                apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(patientAppointment.Start), DateTimeKind.Utc);
                apt.End = DateTime.SpecifyKind(Convert.ToDateTime(patientAppointment.End), DateTimeKind.Utc);
                if (apt.RecurrenceParentID != null)
                {
                    apt.RecurrenceState = RecurrenceState.Exception;
                }
                else if (apt.RecurrenceRule != string.Empty)
                {
                    apt.RecurrenceState = RecurrenceState.Master;
                }
                LoadResources(apt);
                appointments.Add(apt);
            }
            return appointments;
        }

        public override void Insert(RadScheduler owner, Appointment appointmentToInsert)
        {
            if (!PersistChanges)
            {
                return;
            }
            using (DbConnection conn = OpenConnection())
            {
                using (DbTransaction tran = conn.BeginTransaction())
                {
                    DbCommand cmd = DbFactory.CreateCommand();
                    cmd.Connection = conn;
                    cmd.Transaction = tran;
                    PopulateAppointmentParameters(cmd, appointmentToInsert);
                    cmd.CommandText =
                         @" INSERT INTO [PatientAppointment]
                           ([Subject], [Start], [End], [PatientId],[DoctorAppointmentId])
                    VALUES (@Subject, @Start, @End, @PatientId,@DoctorAppointmentId)";
                    tran.Commit();
                }
            }
        }

        public override void Update(RadScheduler owner, Appointment appointmentToUpdate)
        {
            if (!PersistChanges)
            {
                return;
            }
            using (DbConnection conn = OpenConnection())
            {
                using (DbTransaction tran = conn.BeginTransaction())
                {
                    DbCommand cmd = DbFactory.CreateCommand();
                    cmd.Connection = conn;
                    cmd.Transaction = tran;
                    PopulateAppointmentParameters(cmd, appointmentToUpdate);
                    cmd.Parameters.Add(CreateParameter("@id", appointmentToUpdate.ID));
                    cmd.CommandText = "UPDATE [PatientAppointment] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [DoctorAppointmentID] = @DoctorAppointmentID, [PatientID] = @PatientID WHERE [Id] = @Id";
                    cmd.ExecuteNonQuery();
                    //ClearPatientAppointments(appointmentToUpdate.ID, cmd);
                    //FillPatientAppointments(appointmentToUpdate, cmd, appointmentToUpdate.ID);
                    tran.Commit();
                }
            }
        }

        public override void Delete(RadScheduler owner, Appointment appointmentToDelete)
        {
            if (!PersistChanges)
            {
                return;
            }
            using (DbConnection conn = OpenConnection())
            {
                DbCommand cmd = DbFactory.CreateCommand();
                cmd.Connection = conn;
                using (DbTransaction tran = conn.BeginTransaction())
                {
                    cmd.Transaction = tran;
                    ClearPatientAppointments(appointmentToDelete.ID, cmd);
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(CreateParameter("@Id", appointmentToDelete.ID));
                    cmd.CommandText = "DELETE FROM [PatientAppointment] WHERE [Id] = @Id";
                    cmd.ExecuteNonQuery();
                    tran.Commit();
                }
            }
        }

        public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner)
        {
            ResourceType[] resourceTypes = new ResourceType[2];            
            resourceTypes[0] = new ResourceType("Patient", false);
            resourceTypes[1] = new ResourceType("DoctorAppointment", false);
            return resourceTypes;
        }

        public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType)
        {
            LoadResources();
            switch (resourceType)
            {
                case "Patient":
                    return this.Patients.Values;
                case "DoctorAppointment":
                    return this.DoctorAppointments.Values;
                default:
                    throw new InvalidOperationException("Unknown resource type: " + resourceType);
            }
        }

        private void LoadResources(Appointment appointment)
        {
            DatabaseEntities databaseEntities = new DatabaseEntities();

            ObjectQuery<DoctorAppointment> doctorAppointments = databaseEntities.DoctorAppointments.Where("it.ID = @Id");
            doctorAppointments.Parameters.Add(new ObjectParameter("Id", appointment.ID));

            foreach (DoctorAppointment doctorAppointmentItem in doctorAppointments)
            {
                Resource doctorAppointment = DoctorAppointments[doctorAppointmentItem.Id];
                appointment.Resources.Add(doctorAppointment);
            }

            ObjectQuery<PatientAppointment> patientAppointments = databaseEntities.PatientAppointments.Where("it.ID = @Id");
            patientAppointments.Parameters.Add(new ObjectParameter("Id", appointment.ID));

            foreach (PatientAppointment patientAppointment in patientAppointments)
            {
                Resource patient = Patients[patientAppointment.PatientId];
                appointment.Resources.Add(patient);
            }
        }

        private IEnumerable<Resource> LoadDoctorAppointments()
        {
            List<Resource> resources = new List<Resource>();
            DatabaseEntities databaseEntities = new DatabaseEntities();
            foreach (DoctorAppointment doctorAppointment in databaseEntities.DoctorAppointments)
            {
                Resource res = new Resource();
                res.Type = "DoctorAppointment";
                res.Key = doctorAppointment.Id;
                res.Text = string.Format("{0} {1}: {2}-{3}", doctorAppointment.Doctor.FirstName, doctorAppointment.Doctor.LastName, doctorAppointment.Room.Name, doctorAppointment.Room.Address);
                res.Attributes["DoctorName"] = doctorAppointment.Doctor.FirstName + " " + doctorAppointment.Doctor.LastName;
                res.Attributes["RoomName"] = doctorAppointment.Room.Name + ":" + doctorAppointment.Room.Address;
                resources.Add(res);
            }
            return resources;
        }

        private IEnumerable<Resource> LoadPatients()
        {
            List<Resource> resources = new List<Resource>();
            DatabaseEntities databaseEntities = new DatabaseEntities();
            foreach (Patient patient in databaseEntities.Patients)
            {
                Resource res = new Resource();
                res.Type = "Patient";
                res.Key = patient.Id;
                res.Text = patient.FirstName + " " + patient.LastName;
                res.Attributes["FirstName"] = patient.FirstName;
                res.Attributes["LastName"] = patient.LastName;
                resources.Add(res);
            }
            return resources;
        }

        private void ClearPatientAppointments(object id, DbCommand cmd)
        {
            cmd.Parameters.Clear();
            cmd.Parameters.Add(CreateParameter("@Id", id));
            cmd.CommandText = "DELETE FROM [PatientAppointment] WHERE [Id] = @Id";
            cmd.ExecuteNonQuery();
        }

        private void PopulateAppointmentParameters(DbCommand cmd, Appointment apt)
        {
            cmd.Parameters.Add(CreateParameter("@Subject", apt.Subject));
            cmd.Parameters.Add(CreateParameter("@Start", apt.Start));
            cmd.Parameters.Add(CreateParameter("@End", apt.End));

            Resource doctorAppointment = apt.Resources.GetResourceByType("DoctorAppointment");
            object doctorAppointmentId = doctorAppointmentId = doctorAppointment.Key;
            cmd.Parameters.Add(CreateParameter("@DoctorAppointmentId", doctorAppointmentId));

            Resource patient = apt.Resources.GetResourceByType("Patient");
            object patientId = patient.Key;
            cmd.Parameters.Add(CreateParameter("@PatientId", patientId));
        }
    }
}
Update is Ok but before open insert form I've got an error:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Value of '3/17/2013 12:00:00 ق.ظ' is not valid for 'SelectedDate'. 'SelectedDate' should be between 'MinDate' and 'MaxDate'.
Parameter name: SelectedDate
How can I define InlineInsertTemplate for that?
0
Plamen
Telerik team
answered on 19 Mar 2013, 07:25 AM
Hello shahab,

 
It is not clear from the code provided what is not working properly. Would you please elaborate once again what is the scenario you choose for binding your RadScheduler and may be point the sample or help article that you followed to implement it so we could provide a working sample for you and be more helpful.

Regards,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
shahab
Top achievements
Rank 1
answered on 19 Mar 2013, 08:16 AM
I want to use RadScheduler to implement clinic scheduling. Doctors can set work time on doctorAppointment. Now patient should select visit time among doctorAppointment. Model Diagram is shown: Doctor---DoctorAppointment--PatientAppoitnemtn--Patient.
I used ur Teachers--Student Sample to implement this(DbSchedulerProviderBase).
I have two Problem on that:
1. I don not hot to set resources in InlineUpdateForm and InsertUpdateForm. I want to program custom Update and Insert Form.
2. About selectedDate Error I found the reason: Persian to Georgian DateTime Convertion
 mentioned it in
http://www.telerik.com/community/forums/aspnet-ajax/scheduler/radscheduler-problem-with-persian-calendar.aspx
0
Plamen
Telerik team
answered on 21 Mar 2013, 02:56 PM
Hi shahab,

 
RadScheduler does support putting the resources in the InlineForm and we recommend using them in the Advanced form as in this on-line demo for example.

Kind regards,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
shahab
Top achievements
Rank 1
answered on 22 Mar 2013, 06:36 AM
Resource does not work with Provider. I have tested it! How should I bind it when I used Provider in inlineInsertForm and AdvancedInsertForm? I have tested your Examples  but they did not work
0
Plamen
Telerik team
answered on 27 Mar 2013, 06:45 AM
Hi,

If you are having difficulties implement a provider for the resources you can refer to this  help topic where more information is provided.

If any of our official demos or Examples does not work please share it with us so we could inspect it and fix it.

Regards,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
shahab
Top achievements
Rank 1
answered on 28 Mar 2013, 08:30 AM
As I mentioned before I used your link. I have a problem in InlineEditForm. I want to Define Dropdownlists in inLineEditForm to bind it to Teacher and Student but I have got an error.
How can I use defined resources of provider in inlineEditForm? your example does not contains this one.
0
Plamen
Telerik team
answered on 28 Mar 2013, 02:06 PM
Hello shahab,

 
As I mentioned -unfortunately RadScheduler does not support such scenario in the inline form and when resources are used one should use the advanced form.

Hope this will explain the issue.

Greetings,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Scheduler
Asked by
shahab
Top achievements
Rank 1
Answers by
shahab
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or