source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.EHR/EhrFramework.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: 12.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Diagnostics;
5using System.Text;
6using CIA_CSS;
7using IndianHealthService.BMXNet.EHR.Model;
8
9namespace IndianHealthService.BMXNet.EHR
10{
11 /// <summary>
12 /// The EhrFramework integrates the COM-based EHR/VueCentric framework with BMXNET.
13 /// A component that uses BMXNET for communications, events, and context can be implemented to
14 /// be hosted within the EHR/VueCentric framework by creating a subclass of UserControl and including
15 /// the a EHR integration partial class similar to the following:
16 /// <code>
17 ///
18 ///partial class YourEHRComponent : CSS_Patient.ICSS_PatientEvents, CSS_Encounter.ICSS_EncounterEvents, CIA_CSS.ICSS_SessionEvents, IEhrEvents, IEhrComponent
19 ///{
20 ///
21 /// #region Copy Region into partial EHR file plus include interfaces noted above
22 ///
23 /// protected override void Dispose(bool disposing)
24 /// {
25 /// this.TeardownFramework();
26 ///
27 /// if (disposing &amp;&amp; (components != null))
28 /// {
29 /// components.Dispose();
30 /// }
31 /// base.Dispose(disposing);
32 /// }
33 ///
34 /// public LocalSession LocalSession
35 /// {
36 /// get { return this.Framework.LocalSession; }
37 /// }
38 ///
39 /// public Context Context
40 /// {
41 /// get { return this.LocalSession.Context; }
42 /// }
43 ///
44 /// public RemoteSession RemoteSession
45 /// {
46 /// get { return this.Framework.RemoteSession; }
47 /// }
48 ///
49 /// private String _helpString = "";
50 ///
51 /// [ComVisible(true)]
52 /// public String HelpString
53 /// {
54 /// get { return _helpString; }
55 /// set { _helpString = value; }
56 /// }
57 ///
58 /// private String _helpContext = "";
59 ///
60 /// [ComVisible(true)]
61 /// public String HelpContext
62 /// {
63 /// get { return _helpContext; }
64 /// set { _helpContext = value; }
65 /// }
66
67 /// private String _helpFile = "";
68
69 /// [ComVisible(true)]
70 /// public String HelpFile
71 /// {
72 /// get { return _helpFile; }
73 /// set { _helpFile = value; }
74 /// }
75 ///
76 /// public virtual void AttachToEhr(object aConsumer)
77 /// {
78 /// this.SetupFramework();
79 /// this.Framework.AttachTo(aConsumer);
80 ///
81 /// if (this.HelpFile.Length == 0)
82 /// {
83 /// this.HelpFileAssemblyName(aConsumer.GetType());
84 /// }
85 /// }
86 ///
87 /// private EhrFramework _framework = null;
88 ///
89 /// public EhrFramework Framework
90 /// {
91 /// get { return _framework; }
92 /// set { _framework = value; }
93 /// }
94 ///
95 /// protected void SetupFramework()
96 /// {
97 /// this.Framework = EhrFramework.On(new CIA_CSS.CSS_ServerClass().Session, (IEhrEvents)this, (CIA_CSS.ICSS_SessionEvents)this);
98 /// }
99 ///
100 ///protected void TeardownFramework()
101 ///{
102 /// if (this.Framework != null)
103 /// {
104 /// this.Framework.Close();
105 /// }
106 ///}
107 ///
108 ///public event EventHandler&lt;ContextChangedArgs&gt; ContextChanged;
109 ///public event EventHandler&lt;ContextChangingArgs&gt; ContextChanging;
110 ///
111 /// void CSS_Encounter.ICSS_EncounterEvents.Canceled()
112 /// {
113 /// }
114 ///
115 /// void CSS_Encounter.ICSS_EncounterEvents.Committed()
116 /// {
117 /// try
118 /// {
119 /// if (this.ContextChanged != null)
120 /// {
121 /// ContextChangedArgs args = new ContextChangedArgs();
122 /// args.IsVisitChange = true;
123 /// args.AfterContext = this.Context;
124 /// this.ContextChanged.Invoke(this, args);
125 /// }
126 /// }
127 /// catch
128 /// {
129 /// }
130 /// }
131 ///
132 /// string CSS_Encounter.ICSS_EncounterEvents.Pending(bool Silent)
133 /// {
134 /// try
135 /// {
136 /// if (this.ContextChanging == null)
137 /// {
138 /// return "";
139 /// }
140 /// else
141 /// {
142 /// ContextChangingArgs args = new ContextChangingArgs();
143 /// args.BeforeContext = this.Context;
144 /// args.IsVisitChange = true;
145 /// args.Cancel = false;
146 /// this.ContextChanging.Invoke(this, args);
147 ///
148 /// return args.Cancel ? "Cancel" : "";
149 /// }
150 /// }
151 /// catch
152 /// {
153 /// return "";
154 /// }
155 /// }
156 ///
157 ///void CSS_Patient.ICSS_PatientEvents.Canceled()
158 ///{
159 ///}
160 ///
161 ///void CSS_Patient.ICSS_PatientEvents.Committed()
162 ///{
163 ///try
164 ///{
165 ///if (this.ContextChanged != null)
166 ///{
167 ///ContextChangedArgs args = new ContextChangedArgs();
168 ///args.IsPatientChange = true;
169 ///args.AfterContext = this.Context;
170 ///this.ContextChanged.Invoke(this, args);
171 ///}
172 ///}
173 ///catch
174 ///{
175 ///}
176 ///}
177 ///
178 /// string CSS_Patient.ICSS_PatientEvents.Pending(bool Silent)
179 /// {
180 /// try
181 /// {
182 /// if (this.ContextChanging == null)
183 /// {
184 /// return "";
185 /// }
186 /// else
187 /// {
188 /// ContextChangingArgs args = new ContextChangingArgs();
189 /// args.BeforeContext = this.Context;
190 /// args.IsPatientChange = true;
191 /// args.Cancel = false;
192 /// this.ContextChanging.Invoke(this, args);
193 ///
194 /// return args.Cancel ? "Cancel" : "";
195 /// }
196 /// }
197 /// catch
198 /// {
199 /// return "";
200 /// }
201 ///}
202 ///
203 /// protected virtual void UnhandledException(Exception aProblem)
204 /// {
205 /// MessageBox.Show(aProblem.Message + " \n\n\n" + aProblem.StackTrace, "Exception");
206 /// }
207 ///
208 /// protected void HelpFileAssemblyName(Type aType)
209 /// {
210 /// this.HelpFile = aType.Assembly.GetName().Name + ".chm";
211 /// }
212 ///
213 /// public void EventCallback(string anEvent, string aStub)
214 /// {
215 /// this.Framework.IncomingEventCallback(anEvent, aStub);
216 /// }
217 ///
218 /// public void RPCCallback(int Handle, string Data)
219 /// {
220 /// }
221 ///
222 /// public void RPCCallbackError(int Handle, int ErrorCode, string ErrorText)
223 /// {
224 /// }
225 ///
226 /// #endregion
227 ///
228 /// }
229 ///
230 ///
231 /// //Copy this interface too
232 /// public interface IEhrComponent : IDisposable
233 /// {
234 /// String HelpFile { get; }
235 /// String HelpContext { get; }
236 /// String HelpString { get; }
237 /// }
238 /// }
239 ///
240 /// </code>
241 /// <para>
242 /// See the BMXNET SDK IndianHealthService.BMXNet.Example.CrossComponent.EHR Project as an example.
243 /// </para>
244 /// </summary>
245 public class EhrFramework
246 {
247
248 /// <summary>
249 /// Used to create the single EhrFramework instance used for each EHR/VueCentric-based component
250 /// </summary>
251 /// <remarks>
252 /// Use the provided partial class to construct a UserControl-based component to host in the EHR/VueCentric framework
253 /// </remarks>
254 /// <param name="aCssSession">A COM instance of CSS_Session. The EhrFramework will Release() it</param>
255 /// <param name="anEventSource">The event source bridge to pass events from your COM-Visible control to the EhrFramework</param>
256 /// <param name="sessionEvents">A COM instance of ICSS_SessionEvents. The EhrFramework will Release() it</param>
257 /// <returns></returns>
258 public static EhrFramework On(CIA_CSS.CSS_Session aCssSession, IEhrEvents anEventSource, CIA_CSS.ICSS_SessionEvents sessionEvents)
259 {
260 EhrFramework answer = new EhrFramework();
261 answer.Setup(aCssSession, anEventSource, sessionEvents);
262 return answer;
263 }
264
265 private CSS_Session _cssSession = null;
266
267 protected CSS_Session CssSession
268 {
269 get { return _cssSession; }
270 set { _cssSession = value; }
271 }
272
273 private LocalSession _localSession = null;
274
275 /// <summary>
276 /// Access the LocalSession.
277 /// <remarks>
278 /// This is used by the partial class to prime your LocalSessionConsumer implementing control
279 /// </remarks>
280 /// </summary>
281 public LocalSession LocalSession
282 {
283 get { return _localSession; }
284 set { _localSession = value; }
285 }
286
287 private RemoteSession _remoteSession = null;
288
289 /// <summary>
290 /// Access the primary RemoteSession.
291 /// <remarks>
292 /// This is used by the partial class to prime your RemoteSessionConsumer implementing control
293 /// </remarks>
294 /// </summary>
295 public RemoteSession RemoteSession
296 {
297 get { return _remoteSession; }
298 set { _remoteSession = value; }
299 }
300 private BMXNetBroker _broker = null;
301
302 internal BMXNetBroker Broker
303 {
304 get { return _broker; }
305 set { _broker = value; }
306 }
307
308
309 protected void Setup(CIA_CSS.CSS_Session aCssSession, IEhrEvents anEventSource, CIA_CSS.ICSS_SessionEvents sessionEvents)
310 {
311
312 this.CssSession = aCssSession;
313
314 CiaSession ciaSession = new CiaSession(aCssSession, anEventSource);
315 ciaSession.ComComponent = sessionEvents;
316
317 this.LocalSession = ciaSession;
318
319 this.Broker = BMXNetEhrBroker.Open(ciaSession.CssSession, ciaSession.CssUser, ciaSession.User);
320 this.RemoteSession = this.Broker.PrimaryRemoteSession;
321 ciaSession.RemoteSession = this.Broker.PrimaryRemoteSession;
322
323 }
324
325 /// <summary>
326 /// Close the EhrFramework
327 /// <remarks>
328 /// Releases all COM objects
329 /// </remarks>
330 /// </summary>
331 public void Close()
332 {
333 if (this.LocalSession != null)
334 {
335 ((CiaSession)this.LocalSession).Teardown();
336 this.LocalSession = null;
337 }
338 }
339
340 /// <summary>
341 /// Forward an incoming event from the COM object to the EhrFramework
342 /// </summary>
343 /// <param name="anEventType">This string corresponds to well-known/shared EventTypes used to identify
344 /// different events published and subscribed within a local desktop application (WinFramework)
345 /// or in the EHR.</param>
346 /// <param name="someDetails">This is an optional peice of data with some event-specific details.</param>
347 public void IncomingEventCallback(string anEventType, string someDetails)
348 {
349 ((CiaSession)this.LocalSession).IncomingEventCallback(anEventType, someDetails);
350 }
351
352
353 /// <summary>
354 /// Attach the services to the aConsumer. This is basically a push of services versus a service lookup.
355 /// aConsumer will be offered to cosume:
356 /// <list>
357 /// LocalSession via LocalConsumer
358 /// RemoteSession via RemoteSessionConsumer
359 /// RemoteSessionPool via RemoteSessionPoolConsumer
360 /// </list>
361 /// </summary>
362 /// <param name="aConsumer">An object optionally implementing LocalConsumer, RemoteSessionConsumer, and/or RemoteSessionPoolConsumer</param>
363 public void AttachTo(object aConsumer)
364 {
365 LocalConsumer localConsumer = aConsumer as LocalConsumer;
366 if (localConsumer != null)
367 {
368 localConsumer.LocalSession = this.LocalSession;
369 }
370
371 RemoteSessionConsumer remoteConsumer = aConsumer as RemoteSessionConsumer;
372 if (remoteConsumer != null)
373 {
374 remoteConsumer.RemoteSession = this.RemoteSession;
375 }
376
377 RemoteSessionPoolConsumer remotePoolConsumer = aConsumer as RemoteSessionPoolConsumer;
378 if (remotePoolConsumer != null)
379 {
380 remotePoolConsumer.RemoteSessionPool = this.Broker.RemoteSessionPool;
381 }
382
383 if (this.LocalSession == null)
384 throw new Exception("BMX: Unable to establish application model");
385
386 if (this.LocalSession.Context == null)
387 throw new Exception("BMX: Unable to establish context");
388 }
389 }
390}
Note: See TracBrowser for help on using the repository browser.