Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/DCheckIn.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/DCheckIn.cs	(revision 1062)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/DCheckIn.cs	(revision 1111)
@@ -7,4 +7,6 @@
 using System.Diagnostics;
 using IndianHealthService.BMXNet;
+using System.Collections.Generic;
+using System.Linq;
 
 namespace IndianHealthService.ClinicalScheduling
@@ -23,8 +25,4 @@
             //
             InitializeComponent();
-
-            //
-            // TODO: Add any constructor code after InitializeComponent call
-            //
         }
 
@@ -59,6 +57,6 @@
         private DataView m_dvClinic;
         private DataView m_dvForm;
-        private bool m_bInit;
         public bool m_bPrintRouteSlip;
+        private List<Provider> _providers;
         private ToolTip toolTip1;
         
@@ -68,11 +66,12 @@
 
         /// <summary>
-        /// Returns string representation of internal entry number of Provider in PROVIDER File
-        /// </summary>
-        public string ProviderIEN
+        /// Returns Provider chosen for Check-In
+        /// </summary>
+        public Provider Provider
         {
             get
             {
-                return this.m_sProviderIEN;
+                if (cboProvider.SelectedIndex < 1) return null; // because first item is empty placeholder
+                else return this._providers[cboProvider.SelectedIndex];
             }
         }
@@ -113,42 +112,76 @@
         /// <param name="a">Appointment</param>
         /// <param name="docManager">Document Manager</param>
-        /// <param name="sDefaultProvider">Default provider</param>
-        public void InitializePage(CGAppointment a, CGDocumentManager docManager,
-            string sDefaultProvider, int nHospLoc)
-        {
-            m_bInit = true;
-            m_DocManager = docManager;
+        public void InitializePage(CGAppointment a)
+        {
+            m_DocManager = CGDocumentManager.Current;
             m_dsGlobal = m_DocManager.GlobalDataSet;
-            int nFind = 0;
+
+            Int32? nHospLoc = (from resource in m_dsGlobal.Tables["Resources"].AsEnumerable()
+                           where resource.Field<string>("RESOURCE_NAME") == a.Resource
+                           select resource.Field<Int32?>("HOSPITAL_LOCATION_ID"))
+                           .SingleOrDefault();
+
+            //smh - following logic replaced with above...
+            /*
+            DataView rv = new DataView(this.m_DocManager.GlobalDataSet.Tables["Resources"]);
+            rv.Sort = "RESOURCE_NAME ASC";
+            int nFind = rv.Find((string)a.Resource);
+            DataRowView drv = rv[nFind];
+
+            string sHospLoc = drv["HOSPITAL_LOCATION_ID"].ToString();
+            sHospLoc = (sHospLoc == "") ? "0" : sHospLoc;
+            int nHospLoc = 0;
+            try
+            {
+                nHospLoc = Convert.ToInt32(sHospLoc);
+            }
+            catch (Exception ex)
+            {
+                Debug.Write("CGView.AppointmentCheckIn Error: " + ex.Message);
+            }
+            */
 
             //smh new code
             //if the resource is linked to a valid hospital location, grab this locations providers
             //from the provider multiple and put them in the combo box.
-            if (nHospLoc != 0)
+            if (nHospLoc != null)
             {
                 //RPC BSDX HOSP LOC PROVIDERS returns Table w/ Columns: 
                 //HOSPITAL_LOCATION_ID^BMXIEN (ie Prov IEN)^NAME^DEFALUT
                 string sCommandText = "BSDX HOSP LOC PROVIDERS^" + nHospLoc;
-                m_dtProvider = docManager.RPMSDataTable(sCommandText, "ClinicProviders");
-                m_dtProvider.DefaultView.Sort = "NAME ASC";
-
-                cboProvider.DataSource = m_dtProvider;
-                cboProvider.DisplayMember = "NAME";
-                cboProvider.ValueMember = "BMXIEN";
-
-                //Add None to the top of the list
-                DataRow drProv = m_dtProvider.NewRow();
-                drProv.BeginEdit();
-                drProv["HOSPITAL_LOCATION_ID"] = 0;
-                drProv["NAME"] = "<None>";
-                drProv["BMXIEN"] = 0;
-                drProv.EndEdit();
-                m_dtProvider.Rows.InsertAt(drProv, 0);
-                cboProvider.SelectedIndex = 0;
+                m_dtProvider = m_DocManager.RPMSDataTable(sCommandText, "ClinicProviders");
+                
+                _providers = (from providerRow in m_dtProvider.AsEnumerable()
+                              orderby providerRow.Field<string>("NAME")
+                             select new Provider
+                             {
+                                 IEN = providerRow.Field<int>("BMXIEN"),
+                                 Name = providerRow.Field<string>("NAME"),
+                                 Default = providerRow.Field<string>("DEFAULT") == "YES" ? true : false
+                             }).ToList();
+
+
+
+                //cboProvider.DisplayMember = "NAME";
+                //cboProvider.ValueMember = "BMXIEN";
+                _providers.Insert(0, new Provider { Name = "<None>", IEN = -1 });
+                cboProvider.DataSource = _providers;
+                cboProvider.SelectedIndex = _providers.FindIndex(prov => prov.Default);
+                // if no provider is default, set default to be <none> item.
+                if (cboProvider.SelectedIndex == -1) cboProvider.SelectedIndex = 0;
+                ////Add None to the top of the list
+                //DataRow drProv = m_dtProvider.NewRow();
+                //drProv.BeginEdit();
+                //drProv["HOSPITAL_LOCATION_ID"] = 0;
+                //drProv["NAME"] = "<None>";
+                //drProv["BMXIEN"] = 0;
+                //drProv.EndEdit();
+                //m_dtProvider.Rows.InsertAt(drProv, 0);
+                ////cboProvider.SelectedIndex = 0;
 
                 //Find default provider--search for Yes in Field DEFAULT            
-                DataRow[] nRow = m_dtProvider.Select("DEFAULT='YES'", "NAME ASC");
-                if (nRow.Length > 0) nFind = m_dtProvider.Rows.IndexOf(nRow[0]);
-                cboProvider.SelectedIndex = nFind;
+                //DataRow[] nRow = m_dtProvider.Select("DEFAULT='YES'", "NAME ASC");
+                //if (nRow.Length > 0) nFind = m_dtProvider.Rows.IndexOf(nRow[0]);
+                
 
             }
@@ -156,21 +189,34 @@
             else
             {
-                m_dtProvider = m_dsGlobal.Tables["Provider"];
-                m_dtProvider.DefaultView.Sort = "NAME ASC";
-
-                cboProvider.DataSource = m_dtProvider;
-                cboProvider.DisplayMember = "NAME";
-                cboProvider.ValueMember = "BMXIEN";
+
+                _providers = (from providerRow in m_dsGlobal.Tables["Provider"].AsEnumerable()
+                              orderby providerRow.Field<string>("NAME")
+                              select new Provider
+                              {
+                                  IEN = providerRow.Field<int>("BMXIEN"),
+                                  Name = providerRow.Field<string>("NAME"),
+                                  Default = false
+                              }).ToList();
+
+                
+                /*m_dtProvider = m_dsGlobal.Tables["Provider"];
+                m_dtProvider.DefaultView.Sort = "NAME ASC";*/
+                _providers.Insert(0, new Provider { Name = "<None>", IEN = -1 });
+                cboProvider.DataSource = _providers;
+                cboProvider.SelectedIndex = 0;
+                //cboProvider.DisplayMember = "NAME";
+                //cboProvider.ValueMember = "BMXIEN";
 
                 //Add None to the top of the list
-                DataRow drProv = m_dtProvider.NewRow();
-                drProv.BeginEdit();
-                drProv["NAME"] = "<None>";
-                drProv["BMXIEN"] = 0;
-                drProv.EndEdit();
-                m_dtProvider.Rows.InsertAt(drProv, 0);
-                cboProvider.SelectedIndex = 0;
-            }
-
+                //DataRow drProv = m_dtProvider.NewRow();
+                //drProv.BeginEdit();
+                //drProv["NAME"] = "<None>";
+                //drProv["BMXIEN"] = 0;
+                //drProv.EndEdit();
+                //m_dtProvider.Rows.InsertAt(drProv, 0);
+                //cboProvider.SelectedIndex = 0;
+            }
+
+                            
 
             m_sPatientName = a.PatientName;
@@ -187,6 +233,8 @@
             }
 
+            //Print Routing Slip based on user preferences.
+            chkRoutingSlip.Checked = CGDocumentManager.Current.UserPreferences.PrintRoutingSlipAutomatically;
+
             UpdateDialogData(true);
-            m_bInit = false;
         }
 
@@ -363,4 +411,5 @@
             // cboProvider
             // 
+            this.cboProvider.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
             this.cboProvider.Location = new System.Drawing.Point(96, 88);
             this.cboProvider.Name = "cboProvider";
@@ -384,4 +433,5 @@
             this.chkRoutingSlip.Text = "Print Routing Slip";
             this.toolTip1.SetToolTip(this.chkRoutingSlip, "Prints routing slip to the Windows Default Printer");
+            this.chkRoutingSlip.CheckedChanged += new System.EventHandler(this.chkRoutingSlip_CheckedChanged);
             // 
             // DCheckIn
@@ -418,5 +468,16 @@
         }
 
+        /// <summary>
+        /// Save this in User Preferences Object.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void chkRoutingSlip_CheckedChanged(object sender, EventArgs e)
+        {
+            CGDocumentManager.Current.UserPreferences.PrintRoutingSlipAutomatically = chkRoutingSlip.Checked;
+        }
+
         #endregion Events
+
     }
 }
