source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.EHR/Model/CiaSession.cs@ 1240

Last change on this file since 1240 was 1146, checked in by Sam Habiel, 14 years ago

Initial Import of BMX4

File size: 13.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Runtime.InteropServices;
5using CIA_CSS;
6using IndianHealthService.BMXNet.Model;
7using System.Windows.Forms;
8using IndianHealthService.BMXNet.Services;
9
10namespace IndianHealthService.BMXNet.EHR.Model
11{
12 internal class CiaSession : CiaObject, LocalSession, LocalEventService
13 {
14
15 private CIA_CSS.ICSS_SessionEvents _comComponent = null;
16
17 public CIA_CSS.ICSS_SessionEvents ComComponent
18 {
19 get { return _comComponent; }
20 set { _comComponent = value; }
21 }
22
23 public void Teardown()
24 {
25
26 if (this.CssSession != null)
27 {
28 this.ReleaseComObject(this.CssSession);
29 this.CssSession = null;
30 }
31 if (this.CssEncounter != null)
32 {
33 this.ReleaseComObject(this.CssEncounter);
34 this.CssEncounter = null;
35 }
36
37 if (this.CssPatient != null)
38 {
39 this.ReleaseComObject(this.CssPatient);
40 this.CssPatient = null;
41 }
42
43 if (this.CssUser != null)
44 {
45 this.ReleaseComObject(this.CssUser);
46 this.CssUser = null;
47 }
48
49 this.PatientContext = null;
50 }
51
52
53 protected void ReleaseComObject(object o)
54 {
55 int countLeft=Marshal.ReleaseComObject(o);
56 }
57
58 private CSS_User.ICSS_User _cssUser;
59
60 public CSS_User.ICSS_User CssUser
61 {
62 get { return _cssUser; }
63 set { _cssUser = value; }
64 }
65
66 private CSS_Patient.ICSS_Patient _cssPatient;
67
68 public CSS_Patient.ICSS_Patient CssPatient
69 {
70 get { return _cssPatient; }
71 set
72 {
73 _cssPatient = value;
74
75 }
76 }
77
78 private CSS_Encounter.ICSS_Encounter _cssEncounter;
79
80 public CSS_Encounter.ICSS_Encounter CssEncounter
81 {
82
83 get { return _cssEncounter; }
84 set
85 {
86 _cssEncounter = value;
87 }
88 }
89
90 private CSS_Site.ICSS_Site _cssSite;
91
92 public CSS_Site.ICSS_Site CssSite
93 {
94 get { return _cssSite; }
95 set { _cssSite = value; }
96 }
97
98 public CiaSession(ICSS_Session aCssSession, IEhrEvents eventSource)
99 {
100 this.CssSession = aCssSession;
101 this.CssPatient = this.CssSession.FindServiceByProgID("CSS_Patient.Patient") as CSS_Patient.ICSS_Patient;
102 this.CssEncounter = this.CssSession.FindServiceByProgID("CSS_Encounter.Encounter") as CSS_Encounter.ICSS_Encounter;
103 this.CssUser = this.CssSession.FindServiceByProgID("CSS_User.User") as CSS_User.ICSS_User;
104 this.CssSite = this.CssSession.FindServiceByProgID("CSS_Site.Site") as CSS_Site.ICSS_Site;
105
106 this._patientContext = CiaContext.CreateFrom(this, eventSource);
107 }
108
109 private ICSS_Session _cssSession;
110
111 public ICSS_Session CssSession
112 {
113 get { return _cssSession; }
114 set { _cssSession = value; }
115 }
116
117 private CiaContext _patientContext = null;
118
119 internal CiaContext PatientContext
120 {
121 get { return _patientContext; }
122 set { _patientContext = value; }
123 }
124
125 public Context Context
126 {
127 get
128 {
129 return (Context)this.PatientContext;
130 }
131 }
132
133 public User NewUser(String aName, String anIen, Division aDivision)
134 {
135 CiaUser user = new CiaUser();
136 user.Ien = anIen;
137 user.Name = aName;
138 user.FriendDivision = aDivision;
139 return user;
140 }
141
142 private User _user = null;
143
144 public User User
145 {
146 get
147 {
148 if ((_user == null) && (this.CssPatient != null))
149 {
150 CiaUser user = new CiaUser();
151 user.Ien = this.CssUser.Handle.ToString();
152 user.Name = this.CssUser.Name;
153 user.RemoteSession = this.RemoteSession;
154
155 CiaDivision division = new CiaDivision();
156
157 if (this.CssSite != null)
158 {
159 division.Name = this.CssSite.LongName;
160 division.Ien = this.CssSite.Handle.ToString();
161 }
162 else
163 {
164 division.Name = "Unable to access division";
165 division.Ien = "";
166 }
167
168 user.FriendDivision = (Division)division;
169
170 if (user.Name==null || user.Name.Length == 0)
171 {
172 return (User)user;
173 }
174 else
175 {
176 this._user = (User)user;
177 }
178
179 /*
180 answer.Ien = aSession.CssPatient.Handle.ToString();
181 answer.PatientName = aSession.CssPatient.Name;
182 answer.Sex = aSession.CssPatient.Sex;
183 answer.Dob = aSession.CssPatient.DOB;
184 answer.AdminDate = aSession.CssPatient.AdmitDate;
185 answer.Age = aSession.CssPatient.Age;
186 answer.Ssn = aSession.CssPatient.SSN;
187 */
188 }
189
190 return _user;
191 }
192 }
193
194 private int _traceHandle = 0;
195
196 protected int TraceHandle
197 {
198 get { return _traceHandle; }
199 set { _traceHandle = value; }
200 }
201
202 public void TraceAll(String someContent, String aHeader)
203 {
204
205 }
206
207 public void TraceAll(String someContent)
208 {
209
210 }
211
212 public void TraceBegin(String traceClass, String traceType)
213 {
214
215 }
216
217 public void TraceHeader(String aString)
218 {
219
220 }
221
222 public void Trace(String aString)
223 {
224
225 }
226
227 #region Session Members
228
229 public event EventHandler<LocalEventArgs> ApplicationEvent;
230
231 public void FireLocalEvent(string anEventName, string someDetails)
232 {
233 try
234 {
235 this.CssSession.EventFireLocal(anEventName, someDetails);
236 }
237 catch (Exception aProblem)
238 {
239 throw new Exception("Unable to raise local event.", aProblem);
240 }
241 }
242
243 public void FireRemoteEvent(string anEventName, string someDetails)
244 {
245 }
246
247 public bool HasSubscribers(string anEventName)
248 {
249 try
250 {
251 return this.CssSession.EventHasSubscribers(anEventName);
252 }
253 catch (Exception aProblem)
254 {
255 throw new Exception("Unable to subscribe to event.", aProblem);
256 }
257 }
258
259 public void Subscribe(string anEventName)
260 {
261 try
262 {
263 this.CssSession.EventSubscribe(anEventName,(ICSS_SessionEvents)this.ComComponent);
264 }
265 catch (Exception aProblem)
266 {
267 throw new Exception("Unable to subscribe to event.",aProblem);
268 }
269 }
270
271
272 public void Unsubscribe(string anEventName)
273 {
274 try
275 {
276 this.CssSession.EventUnsubscribe(anEventName, (ICSS_SessionEvents)this.ComComponent);
277 }
278 catch (Exception aProblem)
279 {
280 throw new Exception("Unable to unsubscribe to event.", aProblem);
281 }
282 }
283
284
285 EventHandler refreshRequested;
286
287 public event EventHandler RefreshRequested
288 {
289 add
290 {
291 if (refreshRequested == null)
292 {
293 this.Subscribe("REFRESH");
294 }
295
296 refreshRequested = (EventHandler)Delegate.Combine(refreshRequested, value);
297
298
299 }
300 remove
301 {
302 refreshRequested = (EventHandler)Delegate.Remove(refreshRequested, value);
303 if (refreshRequested.GetInvocationList().Length == 0)
304 {
305 this.Unsubscribe("REFRESH");
306 }
307 }
308 }
309
310
311 #endregion
312
313 public void IncomingEventCallback(String anEventType, String aStub)
314 {
315 //Cascade "well-known" events here
316 if ("REFRESH".Equals(anEventType))
317 {
318 this.FireRefreshRequestedEvent();
319 }
320 else
321 {
322 this.FireApplicationEvent(anEventType, aStub);
323 }
324 }
325
326 private void FireRefreshRequestedEvent()
327 {
328 if (this.refreshRequested != null)
329 {
330 this.refreshRequested.Invoke(this, new EventArgs());
331 }
332 }
333
334
335 private void FireApplicationEvent(String anEventType, String someDetails)
336 {
337 LocalEventArgs args = new LocalEventArgs();
338 args.EventType = anEventType;
339 args.Details = someDetails;
340
341 if (this.ApplicationEvent != null)
342 {
343 try
344 {
345 this.ApplicationEvent.Invoke(this, args);
346 }
347 catch
348 {
349 //TODO: Decide what to do in case of error. For now, do not
350 //disrupt work.
351 }
352 }
353 }
354
355 #region Session Members
356
357 public bool IsLogging
358 {
359 get { return this.CssSession.TraceMode; }
360 set { this.CssSession.TraceMode = value; }
361 }
362
363
364 public void Log(string aClass, string aCategory, params string[] lines)
365 {
366 if (this.CssSession.TraceMode)
367 {
368 int handle = this.CssSession.TraceBegin(aClass, aCategory);
369 this.LogLines(handle, lines);
370 this.CssSession.TraceEnd(handle);
371 }
372 }
373
374
375 public void Log(string aClass, string aCategory, Exception anException, params string[] lines)
376 {
377 if (this.CssSession.TraceMode)
378 {
379 int handle = this.CssSession.TraceBegin(aClass, aCategory);
380
381 this.LogLines(handle, lines);
382 this.LogException(handle, anException);
383
384 this.CssSession.TraceEnd(handle);
385 }
386 }
387
388 protected void LogLines(int aHandle, params string[] someLines)
389 {
390 foreach (string each in someLines)
391 {
392 String message = null;
393
394 if (each.StartsWith("***"))
395 {
396 String header = each.Substring(3, each.IndexOf("***", 4) - 3).Trim();
397 message = each.Substring(3 + 3 + header.Length - 1).Trim();
398
399 if (header.Length > 0)
400 {
401 this.CssSession.TraceAdd(aHandle, header, true);
402 }
403 }
404 else
405 {
406 message = each;
407 }
408
409 if (message.Length > 0)
410 {
411 this.CssSession.TraceAdd(aHandle, message, false);
412 }
413 }
414 }
415
416 protected void LogException(int aHandle, Exception anException)
417 {
418 this.CssSession.TraceAdd(aHandle, "Exception" + ((anException.InnerException != null) ? " (w/Inner)" : ""), true);
419 this.CssSession.TraceAdd(aHandle, anException.Message, false);
420 this.CssSession.TraceAdd(aHandle, anException.StackTrace, false);
421 if (anException.InnerException != null)
422 {
423 this.CssSession.TraceAdd(aHandle, "Inner Exception", true);
424 this.CssSession.TraceAdd(aHandle, anException.InnerException.Message, false);
425 this.CssSession.TraceAdd(aHandle, anException.InnerException.StackTrace, false);
426 }
427
428 }
429 #endregion
430
431 #region Session Members
432
433
434 /// <summary>
435 /// Component is responsible for VueCentric/CSS cleanup
436 /// </summary>
437 public void Close()
438 {
439
440 }
441
442 #endregion
443
444
445 public LocalEventService EventServices
446 {
447 get { return this; }
448 }
449
450
451
452 #region LocalSession Members
453
454
455 public void Notify(String aTitle, Exception anException)
456 {
457 MessageBox.Show(anException.Message, aTitle);
458
459 }
460
461 public void Notify(String aTitle, String aMessage)
462 {
463 MessageBox.Show(aMessage, aTitle);
464 }
465
466 #endregion
467
468 #region LocalEventService Members
469
470
471 public void TriggerEvent(string anEventName, string someDetails)
472 {
473 this.FireLocalEvent(anEventName, someDetails);
474 }
475
476 #endregion
477 }
478}
Note: See TracBrowser for help on using the repository browser.