source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.TestBench/ComponentTester.cs@ 1722

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

Initial Import of BMX4

File size: 9.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using IndianHealthService.BMXNet;
9using System.Reflection;
10using IndianHealthService.BMXNet.Model;
11
12using IndianHealthService.BMXNet.WinForm;
13
14namespace IndianHealthService.BMXNet.TestBench
15{
16 public partial class ComponentTester : Form
17 {
18 public ComponentTester()
19 {
20 InitializeComponent();
21 }
22
23
24 protected void Login()
25 {
26
27 this.LoginToRpms();
28 this.PostLoginToRpms();
29 }
30
31 private BMXNetConnectInfo _bmxBroker=null;
32
33public BMXNetConnectInfo BmxBroker
34{
35 get { return _bmxBroker; }
36 set { _bmxBroker = value; }
37}
38
39private String _rpmsConnectionInfo = "";
40
41public String RpmsConnectionInfo
42{
43 get { return _rpmsConnectionInfo; }
44 set { _rpmsConnectionInfo = value; }
45}
46
47private DesktopFramework _broker = new DesktopFramework();
48
49public DesktopFramework Framework
50{
51 get { return _broker; }
52 set { _broker = value; }
53}
54
55protected virtual void LoginToRpms()
56{
57 this.BmxBroker = new BMXNetConnectInfo();
58 String[] peices = this.RpmsConnectionInfo.Split(new char[] { '~' });
59 this.BmxBroker.LoadConnectInfo(peices[0],int.Parse(peices[1]),peices[2],peices[3]);
60 if (this.BmxBroker.Connected)
61 {
62 this.Framework= DesktopFramework.OpenOn(this.BmxBroker.Broker.OpenRpcSession());
63 this.NonComponentSession = this.Framework.OpenSession();
64 this.NonComponentSession.Logger = this.transcript;
65 this.NonComponentSession.Log("Bench", "Access", "Logged in");
66
67 }
68 else
69 {
70
71 MessageBox.Show("Unable to log in to RPMS");
72 }
73}
74
75
76 private Context _context;
77
78 public Context Context
79 {
80 get { return _context; }
81 set { _context = value; }
82 }
83
84 private DesktopSession _nonComponentSession = null;
85
86 public DesktopSession NonComponentSession
87 {
88 get { return _nonComponentSession; }
89 set { _nonComponentSession = value; }
90 }
91
92
93 protected void PostLoginToRpms()
94 {
95 if (this.NonComponentSession != null)
96 {
97 this.Context = this.NonComponentSession.Context;
98 this.Context.Changed += new EventHandler<ContextChangedArgs>(Context_Changed);
99
100 }
101 else
102 {
103 this.Context = null;
104 }
105 }
106
107 void Context_Changed(object sender, ContextChangedArgs e)
108 {
109 this.UpdateTitle();
110 }
111
112 private void UpdateTitle()
113 {
114 StringBuilder builder = new StringBuilder();
115 builder.Append(this.HostedControl == null ? "[No Component]" : this.ComponentClassName);
116 this.Text = builder.ToString();
117
118 builder = new StringBuilder();
119 builder.Append(this.Context.HasPatient ? this.Context.Patient.PatientName : "[No Patient]");
120 builder.Append(" :: ");
121 builder.Append(this.Context.HasVisit ? this.Context.Visit.Ien : "[No Visit]");
122 this.contextLabel.Text = builder.ToString();
123 }
124
125
126 private void ComponentTester_Load(object sender, EventArgs e)
127 {
128 this.ParseCommandLine();
129
130 this.Login();
131
132 if (this.Context == null)
133 {
134 MessageBox.Show("Unable to create context");
135 this.Close();
136 }
137 else
138 {
139 this.InitializeContext();
140 this.CreateHostedControl();
141 this.UpdateTitle();
142 }
143
144
145
146 }
147
148 private void InitializeContext()
149 {
150 if (this.InitialChart != null)
151 {
152 Patient hit = this.NonComponentSession.FindPatientFromChart(this.InitialChart, false);
153 if (hit != null)
154 {
155 this.Framework.ChangePatient(hit);
156 }
157 }
158 }
159
160 private String _componentClassName;
161
162 public String ComponentClassName
163 {
164 get { return _componentClassName; }
165 set { _componentClassName = value; }
166 }
167 private String _componentAssemblyName;
168
169 public String ComponentAssemblyName
170 {
171 get { return _componentAssemblyName; }
172 set { _componentAssemblyName = value; }
173 }
174 private String _initialChart;
175
176 public String InitialChart
177 {
178 get { return _initialChart; }
179 set { _initialChart = value; }
180 }
181 private String _initialIen;
182
183 public String InitialIen
184 {
185 get { return _initialIen; }
186 set { _initialIen = value; }
187 }
188 private String _initialVisitDate;
189
190 public String InitialVisitDate
191 {
192 get { return _initialVisitDate; }
193 set { _initialVisitDate = value; }
194 }
195
196 private void ParseCommandLine()
197 {
198
199 String[] args = Environment.GetCommandLineArgs();
200
201 foreach (String set in args)
202 {
203 String[] split = set.Split(new char[] { ':' });
204 if (split[0].Equals(@"/class"))
205 {
206 this.ComponentClassName = split[1];
207 }
208 else if (split[0].Equals(@"/assembly"))
209 {
210 this.ComponentAssemblyName = split[1];
211 }
212 else if (split[0].Equals(@"/chart"))
213 {
214 this.InitialChart = split[1];
215 }
216 else if (split[0].Equals(@"/ien"))
217 {
218 this.InitialIen = split[1];
219 }
220 else if (split[0].Equals(@"/rpms"))
221 {
222 this.RpmsConnectionInfo = split[1];
223 }
224 else if (split[0].Equals(@"/visit"))
225 {
226 this.InitialVisitDate = split[1];
227 } if (split[0].Equals(@"/property"))
228 {
229 String parameters= split[1];
230 String[] pair=parameters.Split(new char[] {'~'});
231 this.PropertyPairs.Add(pair[0],pair[1].Replace("_"," "));
232 }
233 }
234 }
235
236 private SortedDictionary<String, String> _propertyPairs = new SortedDictionary<string, string>();
237
238 public SortedDictionary<String, String> PropertyPairs
239 {
240 get { return _propertyPairs; }
241 set { _propertyPairs = value; }
242 }
243
244 private void CreateHostedControl()
245 {
246 try
247 {
248 Assembly componentAssembly = Assembly.LoadFrom(this.ComponentAssemblyName);
249
250 this.HostedControl = (UserControl)componentAssembly.CreateInstance(this.ComponentClassName);
251 DesktopSession session = this.Framework.OpenSession();
252 session.Logger = this.transcript;
253
254 (this.HostedControl as ModelConsumer).Session = session;
255 (this.HostedControl as BMXNetConsumer).Bmx= this.Framework.Bmx;
256
257 foreach (String key in this.PropertyPairs.Keys)
258 {
259 PropertyInfo property = this.HostedControl.GetType().GetProperty(key);
260 property.SetValue(this.HostedControl, this.PropertyPairs[key],null);
261 }
262
263 this.ClientSize = this.HostedControl.Size;
264 this.HostedControl.Dock = DockStyle.Fill;
265 this.componentHolder.Controls.Add(this.HostedControl);
266
267 }
268 catch
269 {
270 MessageBox.Show("Unable to create control from command line " + Environment.CommandLine);
271 }
272 }
273
274
275 private UserControl _hostedControl = null;
276
277 public UserControl HostedControl
278 {
279 get { return _hostedControl; }
280 set { _hostedControl = value; }
281 }
282
283 private void loginToolStripMenuItem_Click(object sender, EventArgs e)
284 {
285 this.Login();
286 }
287
288 private void changePatientToolStripMenuItem_Click(object sender, EventArgs e)
289 {
290 this.contextLabel_Click(null, null);
291 }
292
293
294
295 private void resetToolStripMenuItem_Click(object sender, EventArgs e)
296 {
297 this.Framework.ChangePatient(null);
298 }
299
300 private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
301 {
302
303 }
304
305 private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
306 {
307
308 }
309
310
311
312 private void contextLabel_Click(object sender, EventArgs e)
313 {
314 PatientVisitPicker dialog = new PatientVisitPicker();
315 dialog.DesktopSession = this.NonComponentSession;
316 dialog.Framework = this.Framework;
317 dialog.Context = this.Context;
318
319 if (dialog.ShowDialog() == DialogResult.OK)
320 {
321 }
322
323
324 }
325
326 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
327 {
328 AboutDialog dialog = new AboutDialog();
329 dialog.ShowDialog();
330 }
331
332 }
333}
Note: See TracBrowser for help on using the repository browser.