Index: Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode/CGView.cs
===================================================================
--- Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1134)
+++ Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1140)
@@ -1,4 +1,5 @@
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.ComponentModel;
 using System.Windows.Forms;
@@ -106,4 +107,6 @@
         private MenuItem menuItem12;
         private MenuItem mnuRefresh;
+        private MenuItem ctxCalGridMkRadAppt;
+        private MenuItem ctxCalGridCancelRadAppt;
         private IContainer components;
 
@@ -246,6 +249,8 @@
             this.ctxCalendarGrid = new System.Windows.Forms.ContextMenu();
             this.ctxCalGridAdd = new System.Windows.Forms.MenuItem();
+            this.ctxCalGridMkRadAppt = new System.Windows.Forms.MenuItem();
             this.ctxCalGridEdit = new System.Windows.Forms.MenuItem();
             this.ctxCalGridDelete = new System.Windows.Forms.MenuItem();
+            this.ctxCalGridCancelRadAppt = new System.Windows.Forms.MenuItem();
             this.ctxCalGridCheckIn = new System.Windows.Forms.MenuItem();
             this.ctxCalGridUndoCheckin = new System.Windows.Forms.MenuItem();
@@ -647,5 +652,5 @@
             this.tvSchedules.Location = new System.Drawing.Point(0, 0);
             this.tvSchedules.Name = "tvSchedules";
-            this.tvSchedules.Size = new System.Drawing.Size(128, 359);
+            this.tvSchedules.Size = new System.Drawing.Size(128, 254);
             this.tvSchedules.Sorted = true;
             this.tvSchedules.TabIndex = 1;
@@ -716,5 +721,5 @@
             this.panelRight.Location = new System.Drawing.Point(996, 0);
             this.panelRight.Name = "panelRight";
-            this.panelRight.Size = new System.Drawing.Size(128, 359);
+            this.panelRight.Size = new System.Drawing.Size(128, 254);
             this.panelRight.TabIndex = 3;
             this.panelRight.Visible = false;
@@ -812,5 +817,5 @@
             this.panelCenter.Location = new System.Drawing.Point(136, 24);
             this.panelCenter.Name = "panelCenter";
-            this.panelCenter.Size = new System.Drawing.Size(857, 311);
+            this.panelCenter.Size = new System.Drawing.Size(857, 206);
             this.panelCenter.TabIndex = 7;
             // 
@@ -819,6 +824,8 @@
             this.ctxCalendarGrid.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
             this.ctxCalGridAdd,
+            this.ctxCalGridMkRadAppt,
             this.ctxCalGridEdit,
             this.ctxCalGridDelete,
+            this.ctxCalGridCancelRadAppt,
             this.ctxCalGridCheckIn,
             this.ctxCalGridUndoCheckin,
@@ -838,7 +845,13 @@
             this.ctxCalGridAdd.Click += new System.EventHandler(this.ctxCalGridAdd_Click);
             // 
+            // ctxCalGridMkRadAppt
+            // 
+            this.ctxCalGridMkRadAppt.Index = 1;
+            this.ctxCalGridMkRadAppt.Text = "Make Radiology Appointment";
+            this.ctxCalGridMkRadAppt.Click += new System.EventHandler(this.ctxCalGridMkRadAppt_Click);
+            // 
             // ctxCalGridEdit
             // 
-            this.ctxCalGridEdit.Index = 1;
+            this.ctxCalGridEdit.Index = 2;
             this.ctxCalGridEdit.Text = "Edit Appointment";
             this.ctxCalGridEdit.Click += new System.EventHandler(this.ctxCalGridEdit_Click);
@@ -846,11 +859,16 @@
             // ctxCalGridDelete
             // 
-            this.ctxCalGridDelete.Index = 2;
+            this.ctxCalGridDelete.Index = 3;
             this.ctxCalGridDelete.Text = "Cancel Appointment";
             this.ctxCalGridDelete.Click += new System.EventHandler(this.ctxCalGridDelete_Click);
             // 
+            // ctxCalGridCancelRadAppt
+            // 
+            this.ctxCalGridCancelRadAppt.Index = 4;
+            this.ctxCalGridCancelRadAppt.Text = "Cancel Radiology Appointment";
+            // 
             // ctxCalGridCheckIn
             // 
-            this.ctxCalGridCheckIn.Index = 3;
+            this.ctxCalGridCheckIn.Index = 5;
             this.ctxCalGridCheckIn.Text = "Check In Patient";
             this.ctxCalGridCheckIn.Click += new System.EventHandler(this.ctxCalGridCheckIn_Click);
@@ -858,5 +876,5 @@
             // ctxCalGridUndoCheckin
             // 
-            this.ctxCalGridUndoCheckin.Index = 4;
+            this.ctxCalGridUndoCheckin.Index = 6;
             this.ctxCalGridUndoCheckin.Text = "&Undo Check In";
             this.ctxCalGridUndoCheckin.Click += new System.EventHandler(this.ctxCalGridUndoCheckin_Click);
@@ -864,10 +882,10 @@
             // menuItem2
             // 
-            this.menuItem2.Index = 5;
+            this.menuItem2.Index = 7;
             this.menuItem2.Text = "-";
             // 
             // ctxCalGridNoShow
             // 
-            this.ctxCalGridNoShow.Index = 6;
+            this.ctxCalGridNoShow.Index = 8;
             this.ctxCalGridNoShow.Text = "Mark as No Show";
             this.ctxCalGridNoShow.Click += new System.EventHandler(this.ctxCalGridNoShow_Click);
@@ -875,5 +893,5 @@
             // ctxCalGridNoShowUndo
             // 
-            this.ctxCalGridNoShowUndo.Index = 7;
+            this.ctxCalGridNoShowUndo.Index = 9;
             this.ctxCalGridNoShowUndo.Text = "Undo NoShow";
             this.ctxCalGridNoShowUndo.Click += new System.EventHandler(this.ctxCalGridNoShowUndo_Click);
@@ -881,10 +899,10 @@
             // menuItem9
             // 
-            this.menuItem9.Index = 8;
+            this.menuItem9.Index = 10;
             this.menuItem9.Text = "-";
             // 
             // ctxCalGridWalkin
             // 
-            this.ctxCalGridWalkin.Index = 9;
+            this.ctxCalGridWalkin.Index = 11;
             this.ctxCalGridWalkin.Text = "Create Wal&k-In Appointment";
             this.ctxCalGridWalkin.Click += new System.EventHandler(this.ctxCalGridWalkin_Click);
@@ -892,10 +910,10 @@
             // menuItem10
             // 
-            this.menuItem10.Index = 10;
+            this.menuItem10.Index = 12;
             this.menuItem10.Text = "-";
             // 
             // ctxCalGridReprintApptSlip
             // 
-            this.ctxCalGridReprintApptSlip.Index = 11;
+            this.ctxCalGridReprintApptSlip.Index = 13;
             this.ctxCalGridReprintApptSlip.Text = "&Reprint Appointment Slip";
             this.ctxCalGridReprintApptSlip.Click += new System.EventHandler(this.ctxCalGridReprintApptSlip_Click);
@@ -905,5 +923,5 @@
             this.panelBottom.Controls.Add(this.statusBar1);
             this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panelBottom.Location = new System.Drawing.Point(136, 335);
+            this.panelBottom.Location = new System.Drawing.Point(136, 230);
             this.panelBottom.Name = "panelBottom";
             this.panelBottom.Size = new System.Drawing.Size(857, 24);
@@ -923,5 +941,5 @@
             this.splitter1.Location = new System.Drawing.Point(128, 24);
             this.splitter1.Name = "splitter1";
-            this.splitter1.Size = new System.Drawing.Size(8, 335);
+            this.splitter1.Size = new System.Drawing.Size(8, 230);
             this.splitter1.TabIndex = 9;
             this.splitter1.TabStop = false;
@@ -932,5 +950,5 @@
             this.splitter2.Location = new System.Drawing.Point(993, 24);
             this.splitter2.Name = "splitter2";
-            this.splitter2.Size = new System.Drawing.Size(3, 335);
+            this.splitter2.Size = new System.Drawing.Size(3, 230);
             this.splitter2.TabIndex = 10;
             this.splitter2.TabStop = false;
@@ -955,5 +973,5 @@
             this.calendarGrid1.Resources = ((System.Collections.ArrayList)(resources.GetObject("calendarGrid1.Resources")));
             this.calendarGrid1.SelectedAppointment = 0;
-            this.calendarGrid1.Size = new System.Drawing.Size(857, 311);
+            this.calendarGrid1.Size = new System.Drawing.Size(857, 206);
             this.calendarGrid1.StartDate = new System.DateTime(2003, 1, 27, 0, 0, 0, 0);
             this.calendarGrid1.TabIndex = 0;
@@ -968,5 +986,5 @@
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-            this.ClientSize = new System.Drawing.Size(1124, 359);
+            this.ClientSize = new System.Drawing.Size(1124, 254);
             this.Controls.Add(this.panelCenter);
             this.Controls.Add(this.panelBottom);
@@ -1289,8 +1307,42 @@
 		private void ctxCalendarGrid_Popup(object sender, System.EventArgs e)
 		{
+            bool bEditAppointments = (EditAppointmentEnabled() && (calendarGrid1.SelectedAppointment > 0)) ;
+
+            if (IsThisARadiologyResource())//this is a radiology resource
+            {
+                ctxCalGridAdd.Visible = false;
+                ctxCalGridDelete.Visible = false;
+                ctxCalGridEdit.Visible = false;
+                ctxCalGridCheckIn.Visible = false;
+                ctxCalGridNoShow.Visible = false;
+                ctxCalGridNoShowUndo.Visible = false;
+                ctxCalGridWalkin.Visible = false;
+                ctxCalGridUndoCheckin.Visible = false;
+
+                ctxCalGridMkRadAppt.Visible = true;
+                ctxCalGridCancelRadAppt.Visible = true;
+
+                
+            }
+
+            else // this is a normal resource
+            {
+                ctxCalGridAdd.Visible = true;
+                ctxCalGridDelete.Visible = true;
+                ctxCalGridEdit.Visible = true;
+                ctxCalGridCheckIn.Visible = true;
+                ctxCalGridNoShow.Visible = true;
+                ctxCalGridNoShowUndo.Visible = true;
+                ctxCalGridWalkin.Visible = true;
+                ctxCalGridUndoCheckin.Visible = true;
+
+                ctxCalGridMkRadAppt.Visible = false;
+                ctxCalGridCancelRadAppt.Visible = false;
+            }
+
 			//Toggle availability of make, edit, checkin and delete appointments
 			//based on whether appropriate element is selected.
 			ctxCalGridAdd.Enabled = AddAppointmentEnabled();
-			bool bEditAppointments = (EditAppointmentEnabled() && (calendarGrid1.SelectedAppointment > 0)) ;
+			
 			ctxCalGridDelete.Enabled = bEditAppointments;
 			ctxCalGridEdit.Enabled = bEditAppointments;
@@ -1299,8 +1351,10 @@
             ctxCalGridNoShowUndo.Enabled = !NoShowEnabled() && calendarGrid1.SelectedAppointment > 0;
 			ctxCalGridWalkin.Enabled = ctxCalGridAdd.Enabled;
-            //smh new code
             ctxCalGridReprintApptSlip.Enabled = bEditAppointments;
             ctxCalGridUndoCheckin.Enabled = UndoCheckinEnabled();
-            //end new code
+
+            //if the rad ones are visible, then these apply
+            ctxCalGridMkRadAppt.Enabled = !bEditAppointments;
+            ctxCalGridCancelRadAppt.Enabled = bEditAppointments;
         }
 
@@ -1357,4 +1411,30 @@
 		#region Methods
 
+        private bool IsThisARadiologyResource()
+        {
+            // I don't like this logic!!!
+            if (this.calendarGrid1.SelectedRange.Cells.CellCount < 1 && this.calendarGrid1.SelectedAppointment < 1)
+                return false;
+            if (this.calendarGrid1.SelectedAppointment > 0)
+                if ((this.Appointments.AppointmentTable[this.calendarGrid1.SelectedAppointment] as CGAppointment).RadiologyExamIEN > 0)
+                    return true;
+
+            DateTime dStart;
+            DateTime dEnd;
+            string sResource;
+            bool bRet = this.calendarGrid1.GetSelectedTime(out dStart, out dEnd, out sResource);
+            if (bRet == false)
+            {
+                return false;
+            }
+
+            return (from hl in CGDocumentManager.Current.GlobalDataSet.Tables["HospitalLocation"].AsEnumerable()
+                       where hl.Field<string>("IS_RADIOLOGY_LOCATION")=="1"
+                       join res in CGDocumentManager.Current.GlobalDataSet.Tables["Resources"].AsEnumerable()
+                       on hl.Field<int>("HOSPITAL_LOCATION_ID") equals res.Field<int>("HOSPITAL_LOCATION_ID")
+                       where res.Field<string>("RESOURCE_NAME") == sResource
+                       select hl).Any();
+        }
+        
         private bool EditAppointmentEnabled()
         {
@@ -3544,4 +3624,57 @@
         }
 
+        private void ctxCalGridMkRadAppt_Click(object sender, EventArgs e)
+        {
+            DateTime dStart, dEnd;
+            string sResource;
+            int nAccessTypeID = 0;
+
+            this.calendarGrid1.GetSelectedTime(out dStart, out dEnd, out sResource);
+            this.calendarGrid1.GetSelectedType(out nAccessTypeID);
+            //Display a dialog to collect Patient Name
+            DPatientLookup dPat = new DPatientLookup();
+            dPat.DocManager = m_DocManager;
+
+            if (dPat.ShowDialog(this) == DialogResult.Cancel)
+            {
+                return;
+            }
+
+            int DFN = Int32.Parse(dPat.PatientIEN);
+            int hlIEN = (from resource in CGDocumentManager.Current.GlobalDataSet.Tables["Resources"].AsEnumerable()
+                        where resource.Field<string>("RESOURCE_NAME") == sResource
+                        select resource.Field<int>("HOSPITAL_LOCATION_ID")).FirstOrDefault();
+
+            List<RadiologyExam> _radExams = CGDocumentManager.Current.DAL.GetRadiologyExamsForPatientinHL(DFN, hlIEN);
+
+            if (!_radExams.Any())
+            {
+                MessageBox.Show("Patient does not have any radiology exams to register.");
+                return;
+            }
+
+            DRadExamsSelect _radform = new DRadExamsSelect(_radExams);
+
+            if (_radform.ShowDialog() == DialogResult.Cancel) return;
+
+            int _examien = _radform.ExamIEN;
+            string _procedurename = _radform.ProcedureName;
+
+            CGDocumentManager.Current.DAL.ScheduleRadiologyExam(DFN, _examien);
+
+            //Now create and save the appointment
+            CGAppointment appt = new CGAppointment();
+            string _sNote = "Radiology Exam (" + _examien + "): " + _procedurename;
+            appt.CreateAppointment(dStart, dEnd, _sNote, 0, sResource);
+            appt.PatientID = Int32.Parse(dPat.PatientIEN);
+            appt.PatientName = dPat.PatientName;
+            appt.AccessTypeID = nAccessTypeID;
+            appt.RadiologyExamIEN = _examien;
+            this.Document.CreateAppointment(appt);
+
+            //Now redraw the grid to display the new appointments
+            this.UpdateArrays();
+        }
+
 
 
