source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/Model/WinSession.cs@ 1172

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

Initial Import of BMX4

File size: 9.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Runtime.InteropServices;
5using IndianHealthService.BMXNet.Model;
6using System.Data;
7using IndianHealthService.BMXNet.Services;
8using IndianHealthService.BMXNet.WinForm.Services;
9using IndianHealthService.BMXNet.WinForm.Forms;
10using System.Windows.Forms;
11
12
13namespace IndianHealthService.BMXNet.WinForm.Model
14{
15 internal class WinSession : WinObject, LocalSession, LocalEventService
16 {
17 public User NewUser(String aName, String anIen, Division aDivision)
18 {
19 WinUser user = new WinUser();
20 user.Ien = anIen;
21 user.Name = aName;
22 user.Division = aDivision;
23 return user;
24 }
25
26
27
28
29 private WinFramework _framework= null;
30
31 public WinFramework Framework
32 {
33 get { return _framework; }
34 set
35 {
36 _framework = value;
37 this.RemoteSession = this._framework.PrimaryRemoteSession;
38 }
39 }
40
41 public void Open(WinFramework aFramework,WinContext aContext)
42 {
43 this.Framework = aFramework;
44 this.DesktopContext = aContext;
45 }
46
47
48 public virtual Patient FindPatientFromChart(String aChart, bool updateSelf)
49 {
50 String rawData = null;
51
52 try {
53
54 if (aChart.Length == 2 && (Char.IsLetter(aChart[0])))
55 {
56 rawData = this.RemoteSession.TransmitRPC("VEN CF GET DEMO PT DFN", aChart, "VEN RPC");
57 }
58 else
59 {
60 rawData = this.RemoteSession.TransmitRPC("VEN GET PATIENT IDENTIFIERS", aChart, "VEN RPC");
61 }
62
63 rawData=rawData.Trim();
64
65 if (rawData.Length==0) {
66 return null;
67 }
68
69 WinPatient patient = new WinPatient();
70
71 String[] peices = rawData.Split(new char[] { '|' });
72 patient.Ien = peices[0].Trim();
73 patient.PatientName = peices[1].Trim();
74 patient.PatientName = patient.PatientName;
75 patient.Age = int.Parse(peices[2].Trim());
76 patient.Dob = DateTime.Parse(peices[3].Trim());
77 patient.PrimaryProvider = peices[4];
78 patient.Sex = (peices[5].Equals("M") ? "MALE" : "FEMALE");
79 patient.HealthRecordNumber = aChart;
80
81 return patient;
82 }
83 catch
84 {
85 return null;
86 }
87 }
88
89 public List<Visit> Visits
90 {
91 get { return this.Framework.Visits(this.Context.Patient,50); }
92 }
93
94 private WinContext _desktopContext = null;
95
96 public WinContext DesktopContext
97 {
98 get { return this._desktopContext; }
99 set { this._desktopContext = value; }
100 }
101
102 public Context Context
103 {
104 get
105 {
106 return (Context)this.DesktopContext;
107 }
108 }
109
110 public User User
111 {
112 get { return this.Framework.User; }
113 }
114
115
116 #region Session Members
117
118 protected EventRegistry EventRegistry
119 {
120 get
121 {
122 return this.Framework.EventRegistry;
123 }
124 }
125
126 public event EventHandler<LocalEventArgs> ApplicationEvent;
127
128 public void TriggerEvent(string anEvent, string aStub)
129 {
130 this.EventRegistry.TriggerEvent(anEvent, aStub);
131 }
132
133 public void IncomingEventCallback(String anEventType, String aStub)
134 {
135 //Cascade "well-known" events here
136 if ("REFRESH".Equals(anEventType))
137 {
138 this.FireRefreshRequestedEvent();
139 }
140 else
141 {
142 this.FireApplicationEvent(anEventType, aStub);
143 }
144 }
145
146 private void FireRefreshRequestedEvent()
147 {
148 if (this.refreshRequested != null)
149 {
150 this.refreshRequested.Invoke(this, new EventArgs());
151 }
152 }
153
154 private void FireApplicationEvent(String anEventType, String someDetails)
155 {
156 LocalEventArgs args = new LocalEventArgs();
157 args.EventType = anEventType;
158 args.Details = someDetails;
159
160 if (this.ApplicationEvent != null)
161 {
162 try
163 {
164 this.ApplicationEvent.Invoke(this, args);
165 }
166 catch
167 {
168 //TODO: Decide what to do in case of error. For now, do not
169 //disrupt work.
170 }
171 }
172 }
173
174
175 public void Subscribe(string anEventName)
176 {
177 this.EventRegistry.Subscribe(anEventName, this);
178 }
179
180
181 public bool HasSubscribers(string anEventName)
182 {
183 return this.EventRegistry.HasSubscribers(anEventName);
184 }
185
186
187 public void Unsubscribe(string anEventName)
188 {
189 this.EventRegistry.Unsubscribe(anEventName, this);
190 }
191
192 private Log _logger = new NullLog();
193
194 public Log Logger
195 {
196 get { return _logger; }
197 set { _logger = value; }
198 }
199
200 EventHandler refreshRequested;
201
202 public event EventHandler RefreshRequested
203 {
204 add
205 {
206 refreshRequested = (EventHandler)Delegate.Combine(refreshRequested, value);
207 if (!this.HasSubscribers("REFRESH"))
208 {
209 this.Subscribe("REFRESH");
210 }
211 }
212 remove
213 {
214 refreshRequested = (EventHandler)Delegate.Remove(refreshRequested, value);
215 if (this.HasSubscribers("REFRESH"))
216 {
217 this.Unsubscribe("REFRESH");
218 }
219 }
220 }
221
222 #endregion
223
224 public void Log(string aClass, string aCategory, params string[] lines)
225 {
226 if (this.Logger.IsLogging)
227 {
228 this.LogLines(aClass, aCategory, lines);
229 }
230 }
231
232 public void Log(string aClass, string aCategory, Exception anException, params string[] lines)
233 {
234 if (this.Logger.IsLogging)
235 {
236 this.LogLines(aClass, aCategory, lines);
237 this.LogException(aClass, aCategory, anException);
238 }
239 }
240
241 protected void LogLines(string aClass, string aCategory, params string[] someLines)
242 {
243 foreach (string each in someLines)
244 {
245 String message = null;
246
247 if (each.StartsWith("***"))
248 {
249 String header = each.Substring(0, each.IndexOf("***", 4) + 3 ).Trim();
250 message = each.Substring(3 + 3 + header.Length - 1).Trim();
251
252 if (header.Length > 0)
253 {
254 this.Logger.Log(aClass,aCategory,header);
255 }
256 }
257 else
258 {
259 message = each;
260 }
261
262 if (message.Length > 0)
263 {
264 this.Logger.Log(aClass,aCategory,message);
265 }
266 }
267 }
268
269 protected void LogException(string aClass, string aCategory, Exception anException)
270 {
271 this.Logger.Log(aClass, aCategory, "Exception" + ((anException.InnerException != null) ? " (w/Inner)" : ""));
272 this.Logger.Log(aClass, aCategory, anException.Message);
273 this.Logger.Log(aClass, aCategory, anException.StackTrace);
274
275 if (anException.InnerException != null)
276 {
277 this.Logger.Log(aClass, aCategory, "Inner Exception");
278 this.Logger.Log(aClass, aCategory, anException.InnerException.Message);
279 this.Logger.Log(aClass, aCategory, anException.InnerException.StackTrace);
280 }
281 }
282
283
284
285 #region Session Members
286
287
288 public bool IsLogging
289 {
290 get { return this.Logger.IsLogging; }
291 set { this.Logger.IsLogging = value; }
292 }
293
294
295 #endregion
296
297 #region Session Members
298
299
300 public void Close()
301 {
302 this.Framework.Close(this);
303 }
304
305 #endregion
306
307
308 public LocalEventService EventServices
309 {
310 get { return this; }
311 }
312
313
314
315 #region LocalSession Members
316
317
318 public void Notify(String aTitle, Exception anException)
319 {
320 ExceptionMessageDialog.SafeShow(aTitle, anException);
321 }
322
323 public void Notify(String aTitle, String aMessage)
324 {
325 MessageBox.Show(aMessage, aTitle);
326 }
327
328 #endregion
329 }
330}
Note: See TracBrowser for help on using the repository browser.