source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.WinForm/DesktopSession.cs@ 1204

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

Initial Import of BMX4

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