Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/DPatientLetter.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/DPatientLetter.cs	(revision 788)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/DPatientLetter.cs	(revision 789)
@@ -31,4 +31,5 @@
         dsPatientApptDisplay2 _dsApptDisplay;
         private PrintDocument printCancelLetters;
+        private PrintDocument printRebookLetters;
         dsRebookAppts _dsRebookAppts;
 		#endregion Fields
@@ -73,5 +74,12 @@
 		}
 
-		public void InitializeFormRebookLetters(CGDocumentManager docManager,
+        /// <summary>
+        /// Print Rebook Letters by Date
+        /// </summary>
+        /// <param name="docManager">This docManger</param>
+        /// <param name="sClinicList">Clinics for which to print</param>
+        /// <param name="dtBegin">Beginning Date</param>
+        /// <param name="dtEnd">End Date</param>
+        public void InitializeFormRebookLetters(CGDocumentManager docManager,
 			string sClinicList,
 		    DateTime dtBegin,
@@ -89,9 +97,11 @@
 
                 //Call RPC to get list of appt ids that have been rebooked for these clinics on these dates
-                string sSql1 = "BSDX REBOOK CLINIC LIST^" + sClinicList + "^" + sBegin + "^" + sEnd;
-                DataTable dtLetters = docManager.RPMSDataTable(sSql1, "PatientAppts");
-				
+                string sSql1 = "BSDX REBOOK CLINIC LIST^" + sClinicList + "^" + sBegin + "^" + sEnd;				
 				string sSql2 = "BSDX RESOURCE LETTERS^" + sClinicList;
-				DataTable dt = docManager.RPMSDataTable(sSql2, "Resources");				
+
+                _dsRebookAppts = new dsRebookAppts();
+                _dsRebookAppts.PatientAppts.Merge(docManager.RPMSDataTable(sSql1, "PatientAppts"));
+                _dsRebookAppts.BSDXResource.Merge(docManager.RPMSDataTable(sSql2, "Resources"));
+
             }
 			catch (Exception ex)
@@ -99,5 +109,15 @@
 				throw ex;
 			}
-		}
+
+            PrintPreviewControl.Document = printRebookLetters;
+
+		}
+
+        /// <summary>
+        /// Print Rebook Letters by Date
+        /// </summary>
+        /// <param name="docManager">This docManger</param>
+        /// <param name="sClinicList">Clinics for which to print</param>
+        /// <param name="sApptIDList">List of appointments IENs in ^BSDXAPPT, delimited by |</param>
         public void InitializeFormRebookLetters(CGDocumentManager docManager,
             string sClinicList,
@@ -111,9 +131,11 @@
                 }
 
-                string sSql = "BSDX REBOOK LIST^" + sApptIDList;
-                DataTable dtLetters = docManager.RPMSDataTable(sSql, "PatientAppts");
-
+                string sSql1 = "BSDX REBOOK LIST^" + sApptIDList;
                 string sSql2 = "BSDX RESOURCE LETTERS^" + sClinicList;
-                DataTable dt = docManager.RPMSDataTable(sSql2, "Resources");
+
+                _dsRebookAppts = new dsRebookAppts();
+                _dsRebookAppts.PatientAppts.Merge(docManager.RPMSDataTable(sSql1, "PatientAppts"));
+                _dsRebookAppts.BSDXResource.Merge(docManager.RPMSDataTable(sSql2, "Resources"));
+
 
             }
@@ -122,4 +144,6 @@
                 throw ex;
             }
+
+            PrintPreviewControl.Document = printRebookLetters;
         }
 
@@ -203,5 +227,7 @@
 		}
 
-
+        /// <summary>
+        /// Ctor
+        /// </summary>
 		public DPatientLetter() : base()
 		{
@@ -241,4 +267,5 @@
             this.printReminderLetters = new System.Drawing.Printing.PrintDocument();
             this.printCancelLetters = new System.Drawing.Printing.PrintDocument();
+            this.printRebookLetters = new System.Drawing.Printing.PrintDocument();
             this.SuspendLayout();
             // 
@@ -254,4 +281,8 @@
             // 
             this.printCancelLetters.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printCancelLetters_PrintPage);
+            // 
+            // printRebookLetters
+            // 
+            this.printRebookLetters.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printRebookLetters_PrintPage);
             // 
             // DPatientLetter
@@ -332,4 +363,25 @@
 
         }
+
+        private void printRebookLetters_PrintPage(object sender, PrintPageEventArgs e)
+        {
+            // no patients
+            if (_dsRebookAppts.PatientAppts.Count == 0)
+            {
+                ClinicalScheduling.Printing.PrintMessage("No Appointments found", e);
+                return;
+            }
+            // if there are patients
+            else if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
+            {
+                dsRebookAppts.BSDXResourceRow c = (dsRebookAppts.BSDXResourceRow)
+                   _dsRebookAppts.PatientAppts[_currentApptPrinting].GetParentRow(_dsRebookAppts.Relations[0]);
+                //XXX: Rebook letter rather oddly currently stored in NO SHOW LETTER field. What gives???
+                ClinicalScheduling.Printing.PrintRebookLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.NO_SHOW_LETTER, "Rebook Letter");
+                _currentApptPrinting++;
+                if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
+                    e.HasMorePages = true;
+            }
+        }
 	}
 }
