Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1117)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1118)
@@ -100,4 +100,8 @@
         private MenuItem menuItem10;
         private MenuItem ctxCalGridReprintApptSlip;
+        private MenuItem ctxCalGridUndoCheckin;
+        private MenuItem ctxPrintScheduleT0;
+        private MenuItem ctxPrintScheduleT1;
+        private MenuItem ctxPrintScheduleT3;
         private IContainer components;
 
@@ -222,4 +226,6 @@
             this.ctxProperties = new System.Windows.Forms.MenuItem();
             this.ctxFindAppt = new System.Windows.Forms.MenuItem();
+            this.ctxPrintScheduleT0 = new System.Windows.Forms.MenuItem();
+            this.ctxPrintScheduleT1 = new System.Windows.Forms.MenuItem();
             this.panelRight = new System.Windows.Forms.Panel();
             this.panelClip = new System.Windows.Forms.Panel();
@@ -239,4 +245,5 @@
             this.ctxCalGridDelete = new System.Windows.Forms.MenuItem();
             this.ctxCalGridCheckIn = new System.Windows.Forms.MenuItem();
+            this.ctxCalGridUndoCheckin = new System.Windows.Forms.MenuItem();
             this.menuItem2 = new System.Windows.Forms.MenuItem();
             this.ctxCalGridNoShow = new System.Windows.Forms.MenuItem();
@@ -250,4 +257,5 @@
             this.splitter1 = new System.Windows.Forms.Splitter();
             this.splitter2 = new System.Windows.Forms.Splitter();
+            this.ctxPrintScheduleT3 = new System.Windows.Forms.MenuItem();
             this.panelRight.SuspendLayout();
             this.panelClip.SuspendLayout();
@@ -616,5 +624,5 @@
             this.tvSchedules.Location = new System.Drawing.Point(0, 0);
             this.tvSchedules.Name = "tvSchedules";
-            this.tvSchedules.Size = new System.Drawing.Size(128, 393);
+            this.tvSchedules.Size = new System.Drawing.Size(128, 351);
             this.tvSchedules.Sorted = true;
             this.tvSchedules.TabIndex = 1;
@@ -630,5 +638,8 @@
             this.ctxEditAvailability,
             this.ctxProperties,
-            this.ctxFindAppt});
+            this.ctxFindAppt,
+            this.ctxPrintScheduleT0,
+            this.ctxPrintScheduleT1,
+            this.ctxPrintScheduleT3});
             this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
             // 
@@ -649,5 +660,5 @@
             // 
             this.ctxProperties.Index = 2;
-            this.ctxProperties.Text = "&Properties";
+            this.ctxProperties.Text = "P&roperties";
             this.ctxProperties.Click += new System.EventHandler(this.ctxProperties_Click);
             // 
@@ -655,6 +666,18 @@
             // 
             this.ctxFindAppt.Index = 3;
-            this.ctxFindAppt.Text = "Find Available Appointment";
+            this.ctxFindAppt.Text = "&Find Available Appointment";
             this.ctxFindAppt.Click += new System.EventHandler(this.ctxFindAppt_Click);
+            // 
+            // ctxPrintScheduleT0
+            // 
+            this.ctxPrintScheduleT0.Index = 4;
+            this.ctxPrintScheduleT0.Text = "Print Clinic Schedule(s) (T+&0)";
+            this.ctxPrintScheduleT0.Click += new System.EventHandler(this.ctxPrintScheduleT0_Click);
+            // 
+            // ctxPrintScheduleT1
+            // 
+            this.ctxPrintScheduleT1.Index = 5;
+            this.ctxPrintScheduleT1.Text = "Print Clinic Schedule(s) (T+&1)";
+            this.ctxPrintScheduleT1.Click += new System.EventHandler(this.ctxPrintScheduleT1_Click);
             // 
             // panelRight
@@ -664,5 +687,5 @@
             this.panelRight.Location = new System.Drawing.Point(996, 0);
             this.panelRight.Name = "panelRight";
-            this.panelRight.Size = new System.Drawing.Size(128, 393);
+            this.panelRight.Size = new System.Drawing.Size(128, 351);
             this.panelRight.TabIndex = 3;
             this.panelRight.Visible = false;
@@ -760,5 +783,5 @@
             this.panelCenter.Location = new System.Drawing.Point(136, 24);
             this.panelCenter.Name = "panelCenter";
-            this.panelCenter.Size = new System.Drawing.Size(857, 345);
+            this.panelCenter.Size = new System.Drawing.Size(857, 303);
             this.panelCenter.TabIndex = 7;
             // 
@@ -782,5 +805,5 @@
             this.calendarGrid1.Resources = ((System.Collections.ArrayList)(resources.GetObject("calendarGrid1.Resources")));
             this.calendarGrid1.SelectedAppointment = 0;
-            this.calendarGrid1.Size = new System.Drawing.Size(857, 345);
+            this.calendarGrid1.Size = new System.Drawing.Size(857, 303);
             this.calendarGrid1.StartDate = new System.DateTime(2003, 1, 27, 0, 0, 0, 0);
             this.calendarGrid1.TabIndex = 0;
@@ -799,4 +822,5 @@
             this.ctxCalGridDelete,
             this.ctxCalGridCheckIn,
+            this.ctxCalGridUndoCheckin,
             this.menuItem2,
             this.ctxCalGridNoShow,
@@ -832,12 +856,18 @@
             this.ctxCalGridCheckIn.Click += new System.EventHandler(this.ctxCalGridCheckIn_Click);
             // 
+            // ctxCalGridUndoCheckin
+            // 
+            this.ctxCalGridUndoCheckin.Index = 4;
+            this.ctxCalGridUndoCheckin.Text = "&Undo Check In";
+            this.ctxCalGridUndoCheckin.Click += new System.EventHandler(this.ctxCalGridUndoCheckin_Click);
+            // 
             // menuItem2
             // 
-            this.menuItem2.Index = 4;
+            this.menuItem2.Index = 5;
             this.menuItem2.Text = "-";
             // 
             // ctxCalGridNoShow
             // 
-            this.ctxCalGridNoShow.Index = 5;
+            this.ctxCalGridNoShow.Index = 6;
             this.ctxCalGridNoShow.Text = "Mark as No Show";
             this.ctxCalGridNoShow.Click += new System.EventHandler(this.ctxCalGridNoShow_Click);
@@ -845,5 +875,5 @@
             // ctxCalGridNoShowUndo
             // 
-            this.ctxCalGridNoShowUndo.Index = 6;
+            this.ctxCalGridNoShowUndo.Index = 7;
             this.ctxCalGridNoShowUndo.Text = "Undo NoShow";
             this.ctxCalGridNoShowUndo.Click += new System.EventHandler(this.ctxCalGridNoShowUndo_Click);
@@ -851,10 +881,10 @@
             // menuItem9
             // 
-            this.menuItem9.Index = 7;
+            this.menuItem9.Index = 8;
             this.menuItem9.Text = "-";
             // 
             // ctxCalGridWalkin
             // 
-            this.ctxCalGridWalkin.Index = 8;
+            this.ctxCalGridWalkin.Index = 9;
             this.ctxCalGridWalkin.Text = "Create Wal&k-In Appointment";
             this.ctxCalGridWalkin.Click += new System.EventHandler(this.ctxCalGridWalkin_Click);
@@ -862,10 +892,10 @@
             // menuItem10
             // 
-            this.menuItem10.Index = 9;
+            this.menuItem10.Index = 10;
             this.menuItem10.Text = "-";
             // 
             // ctxCalGridReprintApptSlip
             // 
-            this.ctxCalGridReprintApptSlip.Index = 10;
+            this.ctxCalGridReprintApptSlip.Index = 11;
             this.ctxCalGridReprintApptSlip.Text = "&Reprint Appointment Slip";
             this.ctxCalGridReprintApptSlip.Click += new System.EventHandler(this.ctxCalGridReprintApptSlip_Click);
@@ -875,5 +905,5 @@
             this.panelBottom.Controls.Add(this.statusBar1);
             this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panelBottom.Location = new System.Drawing.Point(136, 369);
+            this.panelBottom.Location = new System.Drawing.Point(136, 327);
             this.panelBottom.Name = "panelBottom";
             this.panelBottom.Size = new System.Drawing.Size(857, 24);
@@ -893,5 +923,5 @@
             this.splitter1.Location = new System.Drawing.Point(128, 24);
             this.splitter1.Name = "splitter1";
-            this.splitter1.Size = new System.Drawing.Size(8, 369);
+            this.splitter1.Size = new System.Drawing.Size(8, 327);
             this.splitter1.TabIndex = 9;
             this.splitter1.TabStop = false;
@@ -902,12 +932,18 @@
             this.splitter2.Location = new System.Drawing.Point(993, 24);
             this.splitter2.Name = "splitter2";
-            this.splitter2.Size = new System.Drawing.Size(3, 369);
+            this.splitter2.Size = new System.Drawing.Size(3, 327);
             this.splitter2.TabIndex = 10;
             this.splitter2.TabStop = false;
             // 
+            // ctxPrintScheduleT3
+            // 
+            this.ctxPrintScheduleT3.Index = 6;
+            this.ctxPrintScheduleT3.Text = "Print Clinic Schedule(s) (T+&3)";
+            this.ctxPrintScheduleT3.Click += new System.EventHandler(this.ctxPrintScheduleT3_Click);
+            // 
             // CGView
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-            this.ClientSize = new System.Drawing.Size(1124, 393);
+            this.ClientSize = new System.Drawing.Size(1124, 351);
             this.Controls.Add(this.panelCenter);
             this.Controls.Add(this.panelBottom);
@@ -1097,4 +1133,9 @@
 		}
 
+        private void ctxCalGridUndoCheckin_Click(object sender, EventArgs e)
+        {
+            AppointmentUndoCheckin();
+        }
+
 		#endregion AppointmentMenu Handlers
 
@@ -1107,4 +1148,7 @@
 			this.ctxOpenSchedule.Enabled = bEnabled;
 			this.ctxFindAppt.Enabled = bEnabled;
+            this.ctxPrintScheduleT0.Enabled = bEnabled;
+            this.ctxPrintScheduleT1.Enabled = bEnabled;
+            this.ctxPrintScheduleT3.Enabled = bEnabled;
 
 			//properties not supported now
@@ -1162,4 +1206,19 @@
 		}
 
+        private void ctxPrintScheduleT0_Click(object sender, EventArgs e)
+        {
+            PrintClinicSchedule(DateTime.Today, DateTime.Today);
+        }
+
+        private void ctxPrintScheduleT1_Click(object sender, EventArgs e)
+        {
+            PrintClinicSchedule(DateTime.Today.AddDays(1), DateTime.Today.AddDays(1));
+        }
+
+        private void ctxPrintScheduleT3_Click(object sender, EventArgs e)
+        {
+            PrintClinicSchedule(DateTime.Today.AddDays(3), DateTime.Today.AddDays(3));
+        }
+
 		private void ctxProperties_Click(object sender, System.EventArgs e)
 		{
@@ -1214,10 +1273,11 @@
 			ctxCalGridEdit.Enabled = bEditAppointments;
 			ctxCalGridCheckIn.Enabled = bEditAppointments;
-			ctxCalGridNoShow.Enabled = bEditAppointments;
-			ctxCalGridNoShowUndo.Enabled = bEditAppointments;
+			ctxCalGridNoShow.Enabled = NoShowEnabled();
+            ctxCalGridNoShowUndo.Enabled = !NoShowEnabled() && calendarGrid1.SelectedAppointment > 0;
 			ctxCalGridWalkin.Enabled = ctxCalGridAdd.Enabled;
             //smh new code
-            ctxCalGridReprintApptSlip.Enabled = ctxCalGridEdit.Enabled;
-		    //end new code
+            ctxCalGridReprintApptSlip.Enabled = bEditAppointments;
+            ctxCalGridUndoCheckin.Enabled = UndoCheckinEnabled();
+            //end new code
         }
 
@@ -1342,4 +1402,19 @@
                 return ((bSlotsAvailable) || (bModSchedule) || (bOverbook));
             }
+        }
+
+        private bool NoShowEnabled()
+        {
+            if (calendarGrid1.SelectedAppointment < 1)
+                return false;
+            CGAppointment appt = (CGAppointment)this.Appointments.AppointmentTable[calendarGrid1.SelectedAppointment];
+            return !appt.NoShow;
+        }
+
+        private bool UndoCheckinEnabled()
+        {
+            if (calendarGrid1.SelectedAppointment < 1) return false;
+            CGAppointment appt = (CGAppointment)this.Appointments.AppointmentTable[calendarGrid1.SelectedAppointment];
+            return appt.CheckInTime.Ticks > 0;
         }
 
@@ -1686,8 +1761,7 @@
 
 		/// <summary>
-		/// Marks all selected appointments as No Show
+        /// Marks all selected appointments as No Show from this.calendarGrid1.SelectedAppointments
 		/// </summary>
-		/// <param name="nApptID"></param>
-		/// <returns></returns>		
+		/// <param name="bNoShow">True - Mark as noshow; False - undo noshow</param>
 		private void AppointmentNoShow(bool bNoShow)
 		{
@@ -1696,7 +1770,9 @@
 			bool			bMarked = false;	//Indicates at least one attempt to mark as noshow succeeded
 			bool			bRebook = false;	//Stores user's response to auto-rebook dialog question
-			CGAppointments	alRebookList = new CGAppointments();
-			DNoShow dlg = new DNoShow();;
-			if (bNoShow == true)
+			CGAppointments	alRebookList = new CGAppointments();  // list of appointments to rebook
+
+		    DNoShow dlg = new DNoShow(); // no show dialog
+
+			if (bNoShow == true)  // if noshowing, show the dialog to ask the user
 			{
 				if (dlg.ShowDialog(this) == DialogResult.Cancel)
@@ -1714,5 +1790,5 @@
 				try
 				{
-					if ((bNoShow == true)
+					if ((bNoShow == true)  // if no-showing
 						&&
 						(a.StartTime.Date > DateTime.Today.Date)
@@ -1721,7 +1797,7 @@
 					{
 					}
-					else
+					else  // otherwise, make or undo show
 					{
-						string sError = Document.AppointmentNoShow(nApptID, bNoShow);
+						string sError = Document.AppointmentNoShow(a, bNoShow);
 						if (sError != "1")
 							throw new Exception(sError);
@@ -1734,4 +1810,5 @@
 					MessageBox.Show("Unable to mark appointment No Show: " +  ex.Message, "Clinical Scheduling");
 				}
+
 				if (bRebook == true)
 				{
@@ -1773,24 +1850,27 @@
 					}
 				}
-			}
-			
-			if (bMarked == true)
-			{
-				//Notify other scheduling users that this schedule has changed
-				try
-				{
-					this.Document.RefreshDocument();
-					RaiseRPMSEvent("BSDX SCHEDULE" , m_Document.DocName);
-				}
-				catch (Exception ex)
-				{
-					Debug.Write(ex.Message);
-				}
-				this.calendarGrid1.Invalidate();
-				
-				AutoRebookFromList(alRebookList);
-			}			
+
+                if (bMarked == true)
+                {
+                    //Notify other scheduling users that this schedule has changed
+                    try
+                    {
+                        //this.Document.RefreshDocument(); no need for this; event raised back and prompts refresh itself.
+                        RaiseRPMSEvent("BSDX SCHEDULE", a.Resource);
+                    }
+                    catch (Exception ex)
+                    {
+                        Debug.Write(ex.Message);
+                    }
+                    this.calendarGrid1.Invalidate();
+                }						
+            }
+            AutoRebookFromList(alRebookList);
 		}
 		
+        /// <summary>
+        /// Prints Auto Rebook Letters; does nothing else to DB!!!
+        /// </summary>
+        /// <param name="alRebookList">List of appointments</param>
 		private void AutoRebookFromList(CGAppointments alRebookList)
 		{
@@ -1836,90 +1916,86 @@
 		/// Delete all selected appointments
 		/// </summary>
-		private void AppointmentDelete() 
-		{
-			calendarGrid1.CGToolTip.Active = false;
-			CGAppointments alRebookList = new CGAppointments();
-
-			DCancelAppt dCancel = new DCancelAppt();
-			dCancel.InitializePage(this.m_DocManager);
-			if (dCancel.ShowDialog(this) != DialogResult.OK)
-			{
-				calendarGrid1.CGToolTip.Active = true;
-				return;
-			}
-
-			bool bClinic = dCancel.ClinicCancelled;
-			int nReason = dCancel.CancelReason;
-			string sRemarks = dCancel.CancelRemarks;
-			bool bRebook = dCancel.AutoRebook;
-			int nRebookStart = dCancel.RebookStartDays;
-			int nRebookMax = dCancel.RebookMaxDays;
-			int nRebookAccessType = dCancel.RebookAccessType;
-
-			calendarGrid1.CGToolTip.Active = true;
-
-			bool bDeleted = false;
-			foreach (CGAppointment a in this.calendarGrid1.SelectedAppointments.AppointmentTable.Values)
-			{
-				int nApptID = a.AppointmentKey;
-				Debug.Assert(nApptID != 0);
-				try
-				{
-					string sError = Document.DeleteAppointment(nApptID,bClinic, nReason, sRemarks);
-					if (sError != "")
-						throw new Exception(sError);
-
-					bDeleted = true;
-					if (bRebook == true)
-					{
-						try
-						{
-							//TODO: Parameterize  or dialogize the minum and maximum rebook days
-							CGAppointment aRebook;
-							int nMinimumdays = nRebookStart;
-							int nMaximumdays = nRebookMax;
-							string sResult = Document.AutoRebook(a, nRebookAccessType, nMinimumdays, nMaximumdays, out aRebook);
-							if (sResult == "1")
-							{
-								//Add appointment to list of rebooked appointments
-								alRebookList.AddAppointment(a);
-							}
-
-						}
-						catch (Exception ex)
-						{
-							MessageBox.Show("Unable to rebook: " + ex.Message);
-						}
-					}
-				}
-				catch (Exception ex)
-				{
-					MessageBox.Show("Unable to delete appointment.  " +  ex.Message, "Clinical Scheduling");
-				}
-
-			}
-			if (bDeleted == true)
-			{
-				try
-				{
-                    this.UpdateArrays();
-					RaiseRPMSEvent("BSDX SCHEDULE" , m_Document.DocName);
-
-                    //Get the appointments and availabilities, async, from Server. Callback updates this thread's controls.
-                    OnUpdateScheduleDelegate ousd = new OnUpdateScheduleDelegate(OnUpdateSchedule);
-                    ousd.BeginInvoke(OnUpdateScheduleCallback, null);
-				}
-				catch (Exception ex)
-				{
-					Debug.Write(ex.Message);
-				}
-				this.calendarGrid1.Invalidate();
-				if (bRebook == true)
-				{
-					AutoRebookFromList(alRebookList);
-				}
-			}
-
-		}
+        private void AppointmentDelete()
+        {
+            calendarGrid1.CGToolTip.Active = false;
+            CGAppointments alRebookList = new CGAppointments();
+
+            // check to see if any appointment is checked in first
+            foreach (CGAppointment a in this.calendarGrid1.SelectedAppointments.AppointmentTable.Values)
+            {
+                if (a.CheckInTime.Ticks > 0)
+                {
+                    MessageBox.Show("You must Un-checkin the appointment first before removing it.");
+                    return;
+                }
+            }
+
+            DCancelAppt dCancel = new DCancelAppt();
+            dCancel.InitializePage(this.m_DocManager);
+            if (dCancel.ShowDialog(this) != DialogResult.OK)
+            {
+                calendarGrid1.CGToolTip.Active = true;
+                return;
+            }
+
+            bool bClinic = dCancel.ClinicCancelled;
+            int nReason = dCancel.CancelReason;
+            string sRemarks = dCancel.CancelRemarks;
+            bool bRebook = dCancel.AutoRebook;
+            int nRebookStart = dCancel.RebookStartDays;
+            int nRebookMax = dCancel.RebookMaxDays;
+            int nRebookAccessType = dCancel.RebookAccessType;
+
+            calendarGrid1.CGToolTip.Active = true;
+
+            foreach (CGAppointment a in this.calendarGrid1.SelectedAppointments.AppointmentTable.Values)
+            {
+                
+                int nApptID = a.AppointmentKey;
+                Debug.Assert(nApptID != 0);
+                try
+                {
+                    string sError = Document.DeleteAppointment(nApptID, bClinic, nReason, sRemarks);
+                    if (sError != "")
+                        throw new Exception(sError);
+
+                    this.UpdateArrays(); //Redraw this calendar grid
+
+                    if (bRebook == true)
+                    {
+                        try
+                        {
+                            //TODO: Parameterize  or dialogize the minum and maximum rebook days
+                            CGAppointment aRebook;
+                            int nMinimumdays = nRebookStart;
+                            int nMaximumdays = nRebookMax;
+                            string sResult = Document.AutoRebook(a, nRebookAccessType, nMinimumdays, nMaximumdays, out aRebook);
+                            if (sResult == "1")
+                            {
+                                //Add appointment to list of rebooked appointments
+                                alRebookList.AddAppointment(a);
+                            }
+
+                        }
+                        catch (Exception ex)
+                        {
+                            MessageBox.Show("Unable to rebook: " + ex.Message);
+                        }
+                    }
+
+                    RaiseRPMSEvent("BSDX SCHEDULE", a.Resource);
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show("Unable to delete appointment.  " + ex.Message, "Clinical Scheduling");
+                }
+
+
+                if (alRebookList.AppointmentCount > 0)
+                {
+                    AutoRebookFromList(alRebookList);
+                }
+            }
+        }
 
 		private void AppointmentCheckIn()
@@ -1983,4 +2059,25 @@
 
 		}
+
+        private void AppointmentUndoCheckin()
+        {
+            Debug.Assert(calendarGrid1.SelectedAppointment > 0);
+
+            foreach (CGAppointment a in this.calendarGrid1.SelectedAppointments.AppointmentTable.Values)
+            {
+                string msg; //out var
+                bool didweSucceed = Document.AppointmentUndoCheckin(a, out msg);
+
+                if (!didweSucceed)
+                {
+                    MessageBox.Show("Error: " + msg);
+                    continue;
+                }
+
+                RaiseRPMSEvent("BSDX SCHEDULE", a.Resource);
+            }
+            
+            this.UpdateArrays();
+        }
 
 		private void AppointmentAddWalkin()
@@ -2070,9 +2167,5 @@
                 this.UpdateArrays();
 
-                //Get the appointments and availabilities, async, from Server. Callback updates this thread's controls.
-                OnUpdateScheduleDelegate ousd = new OnUpdateScheduleDelegate(OnUpdateSchedule);
-                ousd.BeginInvoke(OnUpdateScheduleCallback, null);
-
-
+                RaiseRPMSEvent("BSDX SCHEDULE", appt.Resource);
 			}
 			catch (Exception ex)
@@ -2087,15 +2180,4 @@
                 return;
 			}
-
-            try
-            {
-                RaiseRPMSEvent("BSDX SCHEDULE", m_Document.DocName);
-            }
-            catch (Exception ex)
-            {
-                Debug.Write(ex.Message);
-            }
-			
-
 		}
 
@@ -2195,8 +2277,6 @@
                 //Show the new set of appointments by calling UpdateArrays. Fetches Document's CGAppointments
                 this.UpdateArrays();
-                
-                //Get the appointments and availabilities, async, from Server. Callback updates this thread's controls.
-                OnUpdateScheduleDelegate ousd = new OnUpdateScheduleDelegate(OnUpdateSchedule);
-                ousd.BeginInvoke(OnUpdateScheduleCallback, null);
+
+                RaiseRPMSEvent("BSDX SCHEDULE", appt.Resource);
 			}
 			catch (Exception ex)
@@ -2210,14 +2290,4 @@
 				MessageBox.Show("VISTA says: \r\n" + msg, "Unable to Make Appointment");
 				return;
-			}
-
-			try
-			{
-				RaiseRPMSEvent("BSDX SCHEDULE" , m_Document.DocName);
-				this.calendarGrid1.Invalidate();
-			}
-			catch (Exception ex)
-			{
-				Debug.Write(ex.Message);
 			}
 		}
@@ -2332,5 +2402,5 @@
             {
                 //Signal RPMS to raise an event
-                m_ConnectInfo.RaiseEvent(sEvent, sParams, true);
+                m_ConnectInfo.RaiseEvent(sEvent, sParams, false);
             }
             catch (Exception ex)
@@ -3367,8 +3437,18 @@
 
 
-
-
-
-        
+        private void PrintClinicSchedule(DateTime dStart, DateTime dEnd)
+        {
+            DPatientLetter dpl = new DPatientLetter();
+
+            int[] resourceIENs = (from resource in CGDocumentManager.Current.GlobalDataSet.Tables["Resources"].AsEnumerable()
+                                  join resource_name in m_alSelectedTreeResourceArray.Cast<string>() on resource.Field<string>("RESOURCE_NAME") equals resource_name
+                                  select resource.Field<int>("RESOURCEID")
+                               ).ToArray<int>();
+
+            // + | is an oddity in the Mumps code which I haven't investigated yet.
+            dpl.InitializeFormClinicSchedule(this.DocManager, string.Join("|", resourceIENs) + "|", dStart, dEnd);
+            dpl.ShowDialog(this);
+        }
+
 
 
