source: Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocumentManager.cs@ 739

Last change on this file since 739 was 627, checked in by Sam Habiel, 15 years ago

Removed user-interface references to RPMS.

File size: 29.7 KB
Line 
1using System;
2using System.Windows.Forms;
3using System.Collections;
4using System.Data;
5using System.Text;
6using System.Diagnostics;
7using System.Net;
8using System.Net.Sockets;
9using System.Threading;
10using System.IO;
11using IndianHealthService.BMXNet;
12using System.Configuration;
13
14namespace IndianHealthService.ClinicalScheduling
15{
16 /// <summary>
17 /// Summary description for DocumentManager.
18 /// </summary>
19 public class CGDocumentManager : System.Windows.Forms.Form
20 {
21 #region Member Variables
22
23 private static CGDocumentManager _current;
24 private Hashtable _views = new Hashtable();
25 private Hashtable m_AVViews = new Hashtable();
26 private string m_sWindowText = "Clinical Scheduling"; //Default Window Text
27 private bool m_bSchedManager;
28 private bool m_bExitOK = true;
29 public string m_sHandle = "0";
30
31 //M Connection member variables
32 private DataSet m_dsGlobal = null;
33 private System.ComponentModel.IContainer components = null;
34 private BMXNetConnectInfo m_ConnectInfo = null;
35 private BMXNetConnectInfo.BMXNetEventDelegate CDocMgrEventDelegate;
36
37 #endregion
38
39 public CGDocumentManager()
40 {
41 InitializeComponent();
42 m_ConnectInfo = new BMXNetConnectInfo();
43 //m_ConnectInfo.bmxNetLib.StartLog(); //This line turns on logging of messages
44 m_bSchedManager = false;
45 CDocMgrEventDelegate = new BMXNetConnectInfo.BMXNetEventDelegate(CDocMgrEventHandler);
46 m_ConnectInfo.BMXNetEvent += CDocMgrEventDelegate;
47 m_ConnectInfo.EventPollingEnabled = false;
48 }
49
50 #region BMXNet Event Handler
51 private void CDocMgrEventHandler(Object obj, BMXNet.BMXNetEventArgs e)
52 {
53 if (e.BMXEvent == "BSDX CALL WORKSTATIONS")
54 {
55 string sParam = "";
56 string sDelim="~";
57 sParam += this.m_ConnectInfo.UserName + sDelim;
58 sParam += this.m_sHandle + sDelim;
59 sParam += Application.ProductVersion + sDelim;
60 sParam += this._views.Count.ToString();
61 _current.m_ConnectInfo.RaiseEvent("BSDX WORKSTATION REPORT", sParam, true);
62 }
63 if (e.BMXEvent == "BSDX ADMIN MESSAGE")
64 {
65 string sMsg = e.BMXParam;
66 ShowAdminMsgDelegate samd = new ShowAdminMsgDelegate(ShowAdminMsg);
67 this.Invoke(samd, new object [] {sMsg});
68 }
69 if (e.BMXEvent == "BSDX ADMIN SHUTDOWN")
70 {
71 string sMsg = e.BMXParam;
72 CloseAllDelegate cad = new CloseAllDelegate(CloseAll);
73 this.Invoke(cad, new object [] {sMsg});
74 }
75 }
76
77 delegate void ShowAdminMsgDelegate(string sMsg);
78
79 private void ShowAdminMsg(string sMsg)
80 {
81 MessageBox.Show(sMsg, "Message from Scheduling Administrator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
82 }
83
84 #endregion BMXNet Event Handler
85
86 #region Properties
87
88 /// <summary>
89 /// Returns the document manager's BMXNetConnectInfo member
90 /// </summary>
91 public BMXNetConnectInfo ConnectInfo
92 {
93 get
94 {
95 return m_ConnectInfo;
96 }
97 }
98
99 /// <summary>
100 /// True if the current user holds the BSDXZMGR or XUPROGMODE keys in RPMS
101 /// </summary>
102 public bool ScheduleManager
103 {
104 get
105 {
106 return m_bSchedManager;
107 }
108 }
109
110 /// <summary>
111 /// Holds the user and division
112 /// </summary>
113 public string WindowText
114 {
115 get
116 {
117 return m_sWindowText;
118 }
119 }
120
121 /// <summary>
122 /// This dataset contains tables used by the entire application
123 /// </summary>
124 public DataSet GlobalDataSet
125 {
126 get
127 {
128 return m_dsGlobal;
129 }
130 set
131 {
132 m_dsGlobal = value;
133 }
134 }
135 //public BMXNetConnection ADOConnection
136 //{
137 // get
138 // {
139 // return m_ADOConnection;
140 // }
141 //}
142
143 /// <summary>
144 /// Returns the single CGDocumentManager object
145 /// </summary>
146 public static CGDocumentManager Current
147 {
148 get
149 {
150 return _current;
151 }
152 }
153
154 /// <summary>
155 /// Returns the list of currently opened documents
156 /// </summary>
157 public Hashtable Views
158 {
159 get
160 {
161 return _views;
162 }
163 }
164
165 /// <summary>
166 /// Returns the list of currently opened CGAVViews
167 /// </summary>
168 public Hashtable AvailabilityViews
169 {
170 get
171 {
172 return this.m_AVViews;
173 }
174 }
175
176
177 #endregion
178
179 #region Methods & Events
180 /// <summary>
181 /// Clean up any resources being used.
182 /// </summary>
183 protected override void Dispose( bool disposing )
184 {
185 if( disposing )
186 {
187 if (m_ConnectInfo != null)
188 {
189 m_ConnectInfo.EventPollingEnabled = false;
190 m_ConnectInfo.UnSubscribeEvent("BSDX SCHEDULE");
191 m_ConnectInfo.UnSubscribeEvent("BSDX CALL WORKSTATIONS");
192 m_ConnectInfo.CloseConnection();
193 }
194 if (components != null)
195 {
196 components.Dispose();
197 }
198 }
199 base.Dispose( disposing );
200 }
201
202
203 private void InitializeComponent()
204 {
205 //
206 // CGDocumentManager
207 //
208 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
209 this.ClientSize = new System.Drawing.Size(292, 266);
210 this.Name = "CGDocumentManager";
211
212 }
213
214
215 private DSplash m_ds;
216 public void StartSplash()
217 {
218 m_ds = new DSplash();
219 m_ds.ShowDialog();
220 }
221
222 private void InitializeApp()
223 {
224 InitializeApp(false);
225 }
226
227 private void InitializeApp(bool bReLogin)
228 {
229 try
230 {
231 //Set M connection info
232 //Show a splash screen while initializing
233 m_ds = new DSplash();
234 m_ds.Show(this);
235 m_ds.SetStatus("Loading Configuration Settings...");
236 m_ds.Refresh();
237 this.Activate();
238 System.Configuration.ConfigurationManager.GetSection("appSettings");
239 m_ds.SetStatus("Connecting to VistA Server...");
240 m_ds.Refresh();
241 bool bRetry = true;
242 do
243 {
244 try
245 {
246 if (bReLogin == true)
247 {
248 //Prompt for Access and Verify codes
249 _current.m_ConnectInfo.LoadConnectInfo("", "");
250 }
251 else
252 {
253 //Use autologin
254 _current.m_ConnectInfo.LoadConnectInfo();
255 }
256 bRetry = false;
257 }
258 catch (Exception ex)
259 {
260 m_ds.Close();
261 if (MessageBox.Show("Unable to connect to VistA. " + ex.Message , "Clinical Scheduling", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
262 {
263 bRetry = true;
264 _current.m_ConnectInfo.ChangeServerInfo();
265 }
266 else
267 {
268 bRetry = false;
269 throw ex;
270 }
271 }
272 }while (bRetry == true);
273
274 //Create global dataset
275 _current.m_dsGlobal = new DataSet("GlobalDataSet");
276
277 //Version info
278 m_ds.SetStatus("Getting Version Info...");
279 m_ds.Refresh();
280 String sCmd = "BMX VERSION INFO^BSDX^";
281 this.m_ConnectInfo.RPMSDataTable(sCmd, "VersionInfo", m_dsGlobal);
282
283 //Keep the following commented code for future use:
284 //How to extract the version numbers:
285 //DataTable dtVersion = m_dsGlobal.Tables["VersionInfo"];
286 //Debug.Assert(dtVersion.Rows.Count == 1);
287 //DataRow rVersion = dtVersion.Rows[0];
288 //string sMajor = rVersion["MAJOR_VERSION"].ToString();
289 //string sMinor = rVersion["MINOR_VERSION"].ToString();
290 //string sBuild = rVersion["BUILD"].ToString();
291 //decimal fBuild = Convert.ToDecimal(sBuild);
292
293 //Set application context
294 m_ds.SetStatus("Setting Application Context...");
295 m_ds.Refresh();
296 m_ConnectInfo.AppContext = "BSDXRPC";
297
298 //Load global recordsets
299 m_ds.SetStatus("Loading VistA data tables...");
300 m_ds.Refresh();
301 if (_current.LoadGlobalRecordsets() == false)
302 {
303 MessageBox.Show("Unable to create VistA recordsets"); //TODO Improve this message
304 m_ds.Close();
305 return;
306 }
307
308 System.IntPtr pHandle = this.Handle;
309 System.IntPtr pConnHandle = this.ConnectInfo.Handle;
310 this.m_sHandle = pHandle.ToString();
311
312 _current.m_ConnectInfo.ReceiveTimeout = 30000; //30-second timeout
313
314#if DEBUG
315 _current.m_ConnectInfo.ReceiveTimeout = 600000; //longer timeout for debugging
316#endif
317 _current.m_ConnectInfo.SubscribeEvent("BSDX SCHEDULE");
318 _current.m_ConnectInfo.SubscribeEvent("BSDX CALL WORKSTATIONS");
319 _current.m_ConnectInfo.SubscribeEvent("BSDX ADMIN MESSAGE");
320 _current.m_ConnectInfo.SubscribeEvent("BSDX ADMIN SHUTDOWN");
321
322 _current.m_ConnectInfo.EventPollingInterval = 5000; //in milliseconds
323 _current.m_ConnectInfo.EventPollingEnabled = true;
324 _current.m_ConnectInfo.AutoFire = 12; //AutoFire every 12*5 seconds
325
326 m_ds.Close();
327 }
328 catch (Exception ex)
329 {
330 m_ds.Close();
331 Debug.Write(ex.Message);
332 MessageBox.Show(ex.Message + ex.StackTrace, "Clinical Scheduling Error -- Closing Application");
333 throw ex;
334 }
335 }
336
337 [STAThread()] static void Main()
338 {
339 try
340 {
341 //Store the current manager
342 _current = new CGDocumentManager();
343
344 try
345 {
346 _current.InitializeApp();
347 }
348 catch (Exception ex)
349 {
350 Debug.Write(ex.Message);
351 return;
352 }
353
354 //Create the first empty document
355 CGDocument doc = new CGDocument();
356 doc.DocManager = _current;
357 doc.OnNewDocument();
358 Application.DoEvents();
359
360 //Run the application
361 Application.Run();
362 }
363 catch (Exception ex)
364 {
365 Debug.Write(ex.Message);
366 MessageBox.Show(ex.Message + ex.StackTrace, "CGDocumentManager.Main(): Clinical Scheduling Error -- Closing Application");
367 return;
368 }
369 }
370
371 public void LoadAccessTypesTable()
372 {
373 string sCommandText = "SELECT * FROM BSDX_ACCESS_TYPE";
374 ConnectInfo.RPMSDataTable(sCommandText, "AccessTypes", m_dsGlobal);
375 Debug.Write("LoadGlobalRecordsets -- AccessTypes loaded\n");
376 }
377
378 public void LoadAccessGroupsTable()
379 {
380 string sCommandText = "SELECT * FROM BSDX_ACCESS_GROUP";
381 ConnectInfo.RPMSDataTable(sCommandText, "AccessGroup", m_dsGlobal);
382 Debug.Write("LoadGlobalRecordsets -- AccessGroups loaded\n");
383 }
384
385 public void LoadAccessGroupTypesTable()
386 {
387 string sCommandText = "BSDX GET ACCESS GROUP TYPES";
388 ConnectInfo.RPMSDataTable(sCommandText, "AccessGroupType", m_dsGlobal);
389 Debug.Write("LoadGlobalRecordsets -- AccessGroupTypes loaded\n");
390 }
391
392 public void LoadClinicSetupTable()
393 {
394 string sCommandText = "BSDX CLINIC SETUP";
395 ConnectInfo.RPMSDataTable(sCommandText, "ClinicSetupParameters", m_dsGlobal);
396 Debug.Write("LoadGlobalRecordsets -- ClinicSetupParameters loaded\n");
397 }
398
399 public void LoadBSDXResourcesTable()
400 {
401 string sCommandText = "BSDX RESOURCES^" + m_ConnectInfo.DUZ;
402 ConnectInfo.RPMSDataTable(sCommandText, "Resources", m_dsGlobal);
403 Debug.Write("LoadGlobalRecordsets -- Resources loaded\n");
404 }
405
406 public void LoadResourceGroupTable()
407 {
408 //ResourceGroup Table (Resource Groups by User)
409 //Table "ResourceGroup" contains all resource group names
410 //to which user has access
411 //Fields are: RESOURCE_GROUPID, RESOURCE_GROUP
412 string sCommandText = "BSDX RESOURCE GROUPS BY USER^" + m_ConnectInfo.DUZ;
413 ConnectInfo.RPMSDataTable(sCommandText, "ResourceGroup", m_dsGlobal);
414 Debug.Write("LoadGlobalRecordsets -- ResourceGroup loaded\n");
415 }
416
417 public void LoadGroupResourcesTable()
418 {
419 //Table "GroupResources" contains all active GROUP/RESOURCE combinations
420 //to which user has access based on entries in BSDX RESOURCE USER file
421 //If user has BSDXZMGR or XUPROGMODE keys, then ALL Group/Resource combinstions
422 //are returned.
423 //Fields are: RESOURCE_GROUPID, RESOURCE_GROUP, RESOURCE_GROUP_ITEMID, RESOURCE_NAME, RESOURCE_ID
424 string sCommandText = "BSDX GROUP RESOURCE^" + m_ConnectInfo.DUZ;
425 ConnectInfo.RPMSDataTable(sCommandText, "GroupResources", m_dsGlobal);
426 Debug.Write("LoadGlobalRecordsets -- GroupResources loaded\n");
427 }
428
429 public void LoadScheduleUserTable()
430 {
431 //Table "ScheduleUser" contains an entry for each user in File 200 (NEW PERSON)
432 //who possesses the BSDXZMENU security key.
433 string sCommandText = "BSDX SCHEDULE USER";
434 ConnectInfo.RPMSDataTable(sCommandText, "ScheduleUser", m_dsGlobal);
435 Debug.Write("LoadGlobalRecordsets -- ScheduleUser loaded\n");
436 }
437
438 public void LoadResourceUserTable()
439 {
440 //Table "ResourceUser" duplicates the BSDX RESOURCE USER File.
441 //NOTE: Column names are RESOURCEUSER_ID, RESOURCEID,
442 // OVERBOOK, MODIFY_SCHEDULE, USERID, USERID1
443 //string sCommandText = "SELECT BMXIEN RESOURCEUSER_ID, INTERNAL[RESOURCENAME] RESOURCEID, OVERBOOK, MODIFY_SCHEDULE, USERNAME USERID, INTERNAL[USERNAME] FROM BSDX_RESOURCE_USER";
444 LoadResourceUserTable(false);
445 }
446
447 public void LoadResourceUserTable(bool bAllUsers)
448 {
449 string sCommandText = "SELECT BMXIEN RESOURCEUSER_ID, RESOURCENAME, INTERNAL[RESOURCENAME] RESOURCEID, OVERBOOK, MODIFY_SCHEDULE, MODIFY_APPOINTMENTS, USERNAME, INTERNAL[USERNAME] USERID FROM BSDX_RESOURCE_USER";
450 ConnectInfo.RPMSDataTable(sCommandText, "ResourceUser", m_dsGlobal);
451 Debug.Write("LoadGlobalRecordsets -- ResourceUser loaded\n");
452 }
453
454 private bool LoadGlobalRecordsets()
455 {
456 //Schedule User Info
457 string sCommandText = "BSDX SCHEDULING USER INFO^" + m_ConnectInfo.DUZ;
458 DataTable dtUser = ConnectInfo.RPMSDataTable(sCommandText, "SchedulingUser", m_dsGlobal);
459
460 Debug.Assert(dtUser.Rows.Count == 1);
461 DataRow rUser = dtUser.Rows[0];
462 Object oUser = rUser["MANAGER"];
463 string sUser = oUser.ToString();
464 m_bSchedManager = (sUser == "YES")?true:false;
465
466 //AccessTypes
467 LoadAccessTypesTable();
468
469 //Build Primary Key for AccessTypes table
470 DataTable dtTypes = m_dsGlobal.Tables["AccessTypes"];
471 DataColumn dcKey = dtTypes.Columns["BMXIEN"];
472 DataColumn[] dcKeys = new DataColumn[1];
473 dcKeys[0] = dcKey;
474 dtTypes.PrimaryKey = dcKeys;
475
476 //AccessGroups
477 LoadAccessGroupsTable();
478
479 //Build Primary Key for AccessGroup table
480 DataTable dtGroups = m_dsGlobal.Tables["AccessGroup"];
481 dcKey = dtGroups.Columns["ACCESS_GROUP"];
482 dcKeys = new DataColumn[1];
483 dcKeys[0] = dcKey;
484 dtGroups.PrimaryKey = dcKeys;
485
486 //AccessGroupType
487 LoadAccessGroupTypesTable();
488
489 //Build Primary Key for AccessGroupType table
490 DataTable dtAGTypes = m_dsGlobal.Tables["AccessGroupType"];
491 DataColumn dcGTKey = dtAGTypes.Columns["ACCESS_GROUP_TYPEID"];
492 DataColumn[] dcGTKeys = new DataColumn[1];
493 dcGTKeys[0] = dcGTKey;
494 dtAGTypes.PrimaryKey = dcGTKeys;
495
496 //Build Data Relationship between AccessGroupType and AccessTypes tables
497 DataRelation dr = new DataRelation("AccessGroupType", //Relation Name
498 m_dsGlobal.Tables["AccessGroup"].Columns["BMXIEN"], //Parent
499 m_dsGlobal.Tables["AccessGroupType"].Columns["ACCESS_GROUP_ID"]); //Child
500 m_dsGlobal.Relations.Add(dr);
501
502 //ResourceGroup Table (Resource Groups by User)
503 LoadResourceGroupTable();
504
505 //Resources by user
506 LoadBSDXResourcesTable();
507
508 //Build Primary Key for Resources table
509 DataColumn[] dc = new DataColumn[1];
510 dc[0] = m_dsGlobal.Tables["Resources"].Columns["RESOURCEID"];
511 m_dsGlobal.Tables["Resources"].PrimaryKey = dc;
512
513 //GroupResources table
514 LoadGroupResourcesTable();
515
516 //Build Primary Key for ResourceGroup table
517 dc = new DataColumn[1];
518 dc[0] = m_dsGlobal.Tables["ResourceGroup"].Columns["RESOURCE_GROUP"];
519 m_dsGlobal.Tables["ResourceGroup"].PrimaryKey = dc;
520
521 //Build Data Relationships between ResourceGroup and GroupResources tables
522 dr = new DataRelation("GroupResource", //Relation Name
523 m_dsGlobal.Tables["ResourceGroup"].Columns["RESOURCE_GROUP"], //Parent
524 m_dsGlobal.Tables["GroupResources"].Columns["RESOURCE_GROUP"]); //Child
525 CGSchedLib.OutputArray(m_dsGlobal.Tables["GroupResources"], "GroupResources");
526 m_dsGlobal.Relations.Add(dr);
527
528 //HospitalLocation table
529 //cmd.CommandText = "SELECT BMXIEN 'HOSPITAL_LOCATION_ID', NAME 'HOSPITAL_LOCATION', DEFAULT_PROVIDER, STOP_CODE_NUMBER, INACTIVATE_DATE, REACTIVATE_DATE FROM HOSPITAL_LOCATION";
530 sCommandText = "BSDX HOSPITAL LOCATION";
531 ConnectInfo.RPMSDataTable(sCommandText, "HospitalLocation", m_dsGlobal);
532 Debug.Write("LoadGlobalRecordsets -- HospitalLocation loaded\n");
533
534 //Build Primary Key for HospitalLocation table
535 dc = new DataColumn[1];
536 DataTable dtTemp = m_dsGlobal.Tables["HospitalLocation"];
537 dc[0] = dtTemp.Columns["HOSPITAL_LOCATION_ID"];
538 m_dsGlobal.Tables["HospitalLocation"].PrimaryKey = dc;
539
540 LoadClinicSetupTable();
541
542 //Build Primary Key for ClinicSetupParameters table
543 dc = new DataColumn[1];
544 dtTemp = m_dsGlobal.Tables["ClinicSetupParameters"];
545 dc[0] = dtTemp.Columns["HOSPITAL_LOCATION_ID"];
546 m_dsGlobal.Tables["ClinicSetupParameters"].PrimaryKey = dc;
547
548 //Build Data Relationships between ClinicSetupParameters and HospitalLocation tables
549 dr = new DataRelation("HospitalLocationClinic", //Relation Name
550 m_dsGlobal.Tables["HospitalLocation"].Columns["HOSPITAL_LOCATION_ID"], //Parent
551 m_dsGlobal.Tables["ClinicSetupParameters"].Columns["HOSPITAL_LOCATION_ID"], false); //Child
552 m_dsGlobal.Relations.Add(dr);
553
554 dtTemp.Columns.Add("PROVIDER", System.Type.GetType("System.String"), "Parent.DEFAULT_PROVIDER");
555 dtTemp.Columns.Add("CLINIC_STOP", System.Type.GetType("System.String"), "Parent.STOP_CODE_NUMBER");
556 dtTemp.Columns.Add("INACTIVATE_DATE", System.Type.GetType("System.String"), "Parent.INACTIVATE_DATE");
557 dtTemp.Columns.Add("REACTIVATE_DATE", System.Type.GetType("System.String"), "Parent.REACTIVATE_DATE");
558
559 //Build Data Relationships between Resources and HospitalLocation tables
560 dr = new DataRelation("HospitalLocationResource", //Relation Name
561 m_dsGlobal.Tables["HospitalLocation"].Columns["HOSPITAL_LOCATION_ID"], //Parent
562 m_dsGlobal.Tables["Resources"].Columns["HOSPITAL_LOCATION_ID"], false); //Child
563 m_dsGlobal.Relations.Add(dr);
564
565 //Build ScheduleUser table
566 this.LoadScheduleUserTable();
567
568 //Build Primary Key for ScheduleUser table
569 dc = new DataColumn[1];
570 dtTemp = m_dsGlobal.Tables["ScheduleUser"];
571 dc[0] = dtTemp.Columns["USERID"];
572 m_dsGlobal.Tables["ScheduleUser"].PrimaryKey = dc;
573
574 //Build ResourceUser table
575 this.LoadResourceUserTable();
576
577 //Build Primary Key for ResourceUser table
578 dc = new DataColumn[1];
579 dtTemp = m_dsGlobal.Tables["ResourceUser"];
580 dc[0] = dtTemp.Columns["RESOURCEUSER_ID"];
581 m_dsGlobal.Tables["ResourceUser"].PrimaryKey = dc;
582
583 //Create relation between BSDX Resource and BSDX Resource User tables
584 dr = new DataRelation("ResourceUser", //Relation Name
585 m_dsGlobal.Tables["Resources"].Columns["RESOURCEID"], //Parent
586 m_dsGlobal.Tables["ResourceUser"].Columns["RESOURCEID"]); //Child
587 m_dsGlobal.Relations.Add(dr);
588
589 //Build active provider table
590 sCommandText = "SELECT BMXIEN, NAME FROM NEW_PERSON WHERE INACTIVE_DATE = '' AND INTERNAL[PROVIDER_CLASS] > 0";
591 ConnectInfo.RPMSDataTable(sCommandText, "Provider", m_dsGlobal);
592 Debug.Write("LoadGlobalRecordsets -- Provider loaded\n");
593
594 //Build the CLINIC_STOP table
595 // sCommandText = "SELECT BMXIEN, CODE, NAME FROM CLINIC_STOP"; //SMH
596 sCommandText = "SELECT BMXIEN, AMIS_REPORTING_STOP_CODE, NAME FROM CLINIC_STOP";
597 ConnectInfo.RPMSDataTable(sCommandText, "ClinicStop", m_dsGlobal);
598 Debug.Write("LoadGlobalRecordsets -- ClinicStop loaded\n");
599
600 //Build the HOLIDAY table
601 sCommandText = "SELECT NAME, DATE FROM HOLIDAY WHERE DATE > '" + DateTime.Today.ToShortDateString() + "'";
602 ConnectInfo.RPMSDataTable(sCommandText, "HOLIDAY", m_dsGlobal);
603
604 //Save the xml schema
605 //m_dsGlobal.WriteXmlSchema(@"..\..\csSchema20060526.xsd");
606
607 return true;
608 }
609
610 public void RegisterDocumentView(CGDocument doc, CGView view)
611 {
612 //Store the view in the list of views
613 this.Views.Add(view, doc);
614
615 //Hook into the view's 'closed' event
616 view.Closed += new EventHandler(ViewClosed);
617
618 //Hook into the view's mnuRPMSServer.Click event
619 view.mnuRPMSServer.Click += new EventHandler(mnuRPMSServer_Click);
620
621 //Hook into the view's mnuRPMSLogin.Click event
622 view.mnuRPMSLogin.Click += new EventHandler(mnuRPMSLogin_Click);
623
624 }
625
626 public void RegisterAVDocumentView(CGAVDocument doc, CGAVView view)
627 {
628 //Store the view in the list of views
629 this.AvailabilityViews.Add(view, doc);
630
631 //Hook into the view's 'closed' event
632 view.Closed += new EventHandler(AVViewClosed);
633 }
634
635 public CGAVView GetAVViewByResource(ArrayList sResourceArray)
636 {
637 if (sResourceArray == null)
638 return null;
639
640 bool bEqual = true;
641 foreach (CGAVView v in m_AVViews.Keys)
642 {
643 CGAVDocument d = v.Document;
644
645 bEqual = false;
646 if (d.Resources.Count == sResourceArray.Count)
647 {
648 bEqual = true;
649 for (int j = 0; j < sResourceArray.Count; j++)
650 {
651 if (sResourceArray.Contains(d.Resources[j]) == false)
652 {
653 bEqual = false;
654 break;
655 }
656 if (d.Resources.Contains(sResourceArray[j]) == false)
657 {
658 bEqual = false;
659 break;
660 }
661 }
662 if (bEqual == true)
663 return v;
664 }
665 }
666 return null;
667 }
668 /// <summary>
669 /// Return the first view having a resource array matching sResourceArray
670 /// </summary>
671 /// <param name="sResourceArray"></param>
672 /// <returns></returns>
673 public CGView GetViewByResource(ArrayList sResourceArray)
674 {
675 if (sResourceArray == null)
676 return null;
677
678 bool bEqual = true;
679 foreach (CGView v in _views.Keys)
680 {
681 CGDocument d = v.Document;
682
683 bEqual = false;
684 if (d.Resources.Count == sResourceArray.Count)
685 {
686 bEqual = true;
687 for (int j = 0; j < sResourceArray.Count; j++)
688 {
689 if (sResourceArray.Contains(d.Resources[j]) == false)
690 {
691 bEqual = false;
692 break;
693 }
694 if (d.Resources.Contains(sResourceArray[j]) == false)
695 {
696 bEqual = false;
697 break;
698 }
699 }
700 if (bEqual == true)
701 return v;
702 }
703 }
704 return null;
705 }
706
707 private void ViewClosed(object sender, EventArgs e)
708 {
709 //Remove the sender from our document list
710 Views.Remove(sender);
711
712 //If no documents left, then close RPMS connection & exit the application
713 if ((Views.Count == 0)&&(this.AvailabilityViews.Count == 0)&&(m_bExitOK == true))
714 {
715 m_ConnectInfo.EventPollingEnabled = false;
716 m_ConnectInfo.UnSubscribeEvent("BSDX SCHEDULE");
717 m_ConnectInfo.CloseConnection();
718 Application.Exit();
719 }
720 }
721
722 private void AVViewClosed(object sender, EventArgs e)
723 {
724 //Remove the sender from our document list
725 this.AvailabilityViews.Remove(sender);
726
727 //If no documents left, then close RPMS connection & exit the application
728 if ((Views.Count == 0)&&(this.AvailabilityViews.Count == 0)&&(m_bExitOK == true))
729 {
730 m_ConnectInfo.bmxNetLib.CloseConnection();
731 Application.Exit();
732 }
733 }
734
735 private void KeepAlive()
736 {
737 foreach (CGView v in _views.Keys)
738 {
739 CGDocument d = v.Document;
740 DateTime dNow = DateTime.Now;
741 DateTime dLast = d.LastRefreshed;
742 TimeSpan tsDiff = dNow - dLast;
743 if (tsDiff.Seconds > 180)
744 {
745 for (int j = 0; j < d.Resources.Count; j++)
746 {
747 v.RaiseRPMSEvent("SCHEDULE-" + d.Resources[j].ToString(), "");
748 }
749
750 break;
751 }
752 }
753 }
754
755 /// <summary>
756 /// Propogate availability updates to all sRresource's doc/views
757 /// </summary>
758 public void UpdateViews(string sResource, string sOldResource)
759 {
760 if (sResource == null)
761 return;
762 foreach (CGView v in _views.Keys)
763 {
764 CGDocument d = v.Document;
765 for (int j = 0; j < d.Resources.Count; j++)
766 {
767 if ((sResource == "") || (sResource == ((string) d.Resources[j])) || (sOldResource == ((string) d.Resources[j])))
768 {
769 d.RefreshDocument();
770 break;
771 }
772 }
773 v.UpdateTree();
774 }
775 }
776
777 /// <summary>
778 /// Propogate availability updates to all doc/views
779 /// </summary>
780 public void UpdateViews()
781 {
782 UpdateViews("","");
783 foreach (CGView v in _views.Keys)
784 {
785 v.UpdateTree();
786 }
787 }
788
789 /// <summary>
790 /// Calls each view associated with document Doc and closes it.
791 /// </summary>
792 public void CloseAllViews(CGDocument doc)
793 {
794 //iterate through all views and call update.
795 Hashtable h = CGDocumentManager.Current.Views;
796
797 CGDocument d;
798 int nTempCount = h.Count;
799 do
800 {
801 nTempCount = h.Count;
802 foreach (CGView v in h.Keys)
803 {
804 d = (CGDocument) h[v];
805 if (d == doc)
806 {
807 v.Close();
808 break;
809 }
810 }
811 } while ((h.Count > 0) && (nTempCount != h.Count));
812 }
813
814 /// <summary>
815 /// Calls each view associated with Availability Doc and closes it.
816 /// </summary>
817 public void CloseAllViews(CGAVDocument doc)
818 {
819 //iterate through all views and call update.
820 Hashtable h = CGDocumentManager.Current.AvailabilityViews;
821
822 CGAVDocument d;
823 int nTempCount = h.Count;
824 do
825 {
826 nTempCount = h.Count;
827 foreach (CGAVView v in h.Keys)
828 {
829 d = (CGAVDocument) h[v];
830 if (d == doc)
831 {
832 v.Close();
833 break;
834 }
835 }
836 } while ((h.Count > 0) && (nTempCount != h.Count));
837
838
839 }
840
841 private void mnuRPMSServer_Click(object sender, EventArgs e)
842 {
843 //Warn that changing servers will close all schedules
844 if (MessageBox.Show("Are you sure you want to close all schedules and connect to a different VistA server?", "Clinical Scheduling", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
845 return;
846
847 //Reconnect to RPMS and recreate all global recordsets
848 try
849 {
850 m_bExitOK = false;
851 bool bRetry = true;
852 BMXNetConnectInfo tmpInfo;
853 do
854 {
855 tmpInfo = m_ConnectInfo;
856 try
857 {
858 tmpInfo.ChangeServerInfo();
859 bRetry = false;
860 }
861 catch (Exception ex)
862 {
863 if (ex.Message == "User cancelled.")
864 {
865 bRetry = false;
866 return;
867 }
868 if (MessageBox.Show("Unable to connect to VistA. " + ex.Message , "Clinical Scheduling", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
869 {
870 bRetry = true;
871 }
872 else
873 {
874 bRetry = false;
875 return;
876 }
877 }
878 } while (bRetry == true);
879
880 CloseAll();
881 m_bExitOK = true;
882 m_ConnectInfo = tmpInfo;
883
884 this.InitializeApp();
885
886 //Create a new document
887 CGDocument doc = new CGDocument();
888 doc.DocManager = _current;
889 doc.OnNewDocument();
890
891 }
892 catch (Exception ex)
893 {
894 throw ex;
895 }
896
897 }
898
899 private void mnuRPMSLogin_Click(object sender, EventArgs e)
900 {
901 //Warn that changing login will close all schedules
902 if (MessageBox.Show("Are you sure you want to close all schedules and login to VistA?", "Clinical Scheduling", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
903 return;
904
905 //Reconnect to RPMS and recreate all global recordsets
906 try
907 {
908 m_bExitOK = false;
909 CloseAll();
910 m_bExitOK = true;
911 _current.m_ConnectInfo = new BMXNet.BMXNetConnectInfo();
912 this.InitializeApp(true);
913 //Create a new document
914 CGDocument doc = new CGDocument();
915 doc.DocManager = _current;
916 doc.OnNewDocument();
917 }
918 catch (Exception ex)
919 {
920 throw ex;
921 }
922
923 }
924
925 delegate void CloseAllDelegate(string sMsg);
926
927 private void CloseAll(string sMsg)
928 {
929 if (sMsg == "")
930 {
931 sMsg = "Scheduling System Shutting Down Immediately for Maintenance.";
932 }
933
934 MessageBox.Show(sMsg, "Clinical Scheduling Administrator -- System Shutdown Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
935
936 CloseAll();
937 }
938
939 private void CloseAll()
940 {
941 //Close all documents, views and connections
942 Hashtable h = CGDocumentManager.Current.Views;
943 int nTempCount = h.Count;
944 do
945 {
946 nTempCount = h.Count;
947 foreach (CGView v in h.Keys)
948 {
949 v.Close();
950 break;
951 }
952 } while ((h.Count > 0) && (nTempCount != h.Count));
953
954 h = CGDocumentManager.Current.AvailabilityViews;
955 nTempCount = h.Count;
956 do
957 {
958 nTempCount = h.Count;
959 foreach (CGAVView v in h.Keys)
960 {
961 v.Close();
962 break;
963 }
964 } while ((h.Count > 0) && (nTempCount != h.Count));
965
966 }
967
968 delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName);
969
970 public DataTable RPMSDataTable(string sSQL, string sTableName)
971 {
972 //Retrieves a recordset from RPMS
973 string sErrorMessage = "";
974 try
975 {
976 System.IntPtr pHandle = this.Handle;
977 DataTable dtOut;
978 RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(ConnectInfo.RPMSDataTable);
979 dtOut = (DataTable) this.Invoke(rdtd, new object[] {sSQL, sTableName});
980 return dtOut;
981 }
982 catch (Exception ex)
983 {
984 sErrorMessage = "CGDocumentManager.RPMSDataTable error: " + ex.Message;
985 throw ex;
986 }
987 }
988
989 public void ChangeDivision(System.Windows.Forms.Form frmCaller)
990 {
991 this.ConnectInfo.ChangeDivision(frmCaller);
992 foreach (CGView v in _views.Keys)
993 {
994 v.InitializeDocView(v.Document.DocName);
995 v.Document.RefreshDocument();
996 }
997 }
998
999 public void ViewRefresh()
1000 {
1001 foreach (CGView v in _views.Keys)
1002 {
1003 try
1004 {
1005 v.Document.RefreshDocument();
1006 }
1007 catch (Exception ex)
1008 {
1009 Debug.Write("CGDocumentManager.ViewRefresh Exception: " + ex.Message + "\n");
1010 }
1011 finally
1012 {
1013 }
1014 }
1015 Debug.Write("DocManager refreshed all views.\n");
1016 }
1017
1018 #endregion Methods & Events
1019
1020 }
1021}
Note: See TracBrowser for help on using the repository browser.