-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientOrderEditDialog.xaml.cs
421 lines (366 loc) · 16.1 KB
/
ClientOrderEditDialog.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
using System.Windows.Xps.Serialization;
namespace YPIConnect
{
public partial class ClientOrderEditDialog : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private StateCollection m_StateCollection;
private EthnicityDictionary m_EthnicityDictionary;
private RaceDictionary m_RaceDictionary;
private PhysicianCollection m_PhysicianCollection;
private PhysicianClientCollection m_PhysicianClientCollection;
private AuthenticatedUser m_AthenticatedUser;
private ClientOrder m_ClientOrder;
private ClientOrder m_ClientOrderClone;
private ClientOrderDetail m_ClientOrderDetail;
private Visibility m_NextButtonVisibility;
private Visibility m_BackButtonVisibility;
private Visibility m_DoneButtonVisibility;
private OrderValidationCollection m_OrderValidationCollection;
private PhysicianClient m_SelectedPhysicianClient;
public ClientOrderEditDialog(ClientOrder clientOrder)
{
this.m_NextButtonVisibility = Visibility.Visible;
this.m_BackButtonVisibility = Visibility.Collapsed;
this.m_DoneButtonVisibility = Visibility.Collapsed;
this.m_ClientOrder = clientOrder;
this.m_ClientOrderClone = clientOrder.Clone();
if(this.m_ClientOrder.ClientOrderDetailCollection.Count == 1)
{
this.m_ClientOrderDetail = this.m_ClientOrder.ClientOrderDetailCollection[0];
}
this.m_EthnicityDictionary = new EthnicityDictionary();
this.m_RaceDictionary = new RaceDictionary();
this.m_StateCollection = StateCollection.Instance;
this.m_PhysicianCollection = PhysicianCollection.Instance;
this.m_PhysicianClientCollection = PhysicianClientCollection.Instance;
this.m_AthenticatedUser = AuthenticatedUser.Instance;
InitializeComponent();
this.DataContext = this;
this.Closing += ClientOrderEditDialog_Closing;
this.Loaded += ClientOrderEditDialog_Loaded;
}
private void ClientOrderEditDialog_Loaded(object sender, RoutedEventArgs e)
{
if(AuthenticatedUser.Instance.PrimaryClientId == 1134)
{
this.TabItemPatientDistribution.Visibility = Visibility.Visible;
}
if(string.IsNullOrEmpty(this.m_ClientOrderClone.ReportCopyTo) == false)
{
if (string.IsNullOrEmpty(this.m_ClientOrderClone.ReportCopyTo) == false)
{
string[] commaSplit = this.m_ClientOrderClone.ReportCopyTo.Split(',');
if (commaSplit.Length == 2)
{
int physicianid = Convert.ToInt32(commaSplit[1]);
int clientId = Convert.ToInt32(commaSplit[0]);
if (this.m_PhysicianClientCollection.Exists(physicianid, clientId) == true)
{
this.m_SelectedPhysicianClient = this.m_PhysicianClientCollection.Get(physicianid, clientId);
}
}
}
this.NotifyPropertyChanged(string.Empty);
}
}
private void ClientOrderEditDialog_Closing(object sender, CancelEventArgs e)
{
MethodResult methodResult = this.m_ClientOrderClone.IsOkToInsert();
if (methodResult.Success == true)
{
APIResult clientOrderSaveResult = this.m_ClientOrderClone.Save();
if (clientOrderSaveResult.Status == "ERROR")
{
MessageBox.Show("An error occurred saving your work, an email has been sent to the development team to fix the problem. The application will close now.");
System.Windows.Application.Current.Shutdown();
}
else
{
this.m_ClientOrder.UpdateFromClone(this.m_ClientOrderClone);
}
}
else
{
MessageBoxResult messageBoxResult = MessageBox.Show(methodResult.GetMessage(), "Continue without saving?", MessageBoxButton.YesNo);
if(messageBoxResult == MessageBoxResult.No)
{
e.Cancel = true;
}
}
}
public PhysicianClient SelectedPhysicianClient
{
get { return this.m_SelectedPhysicianClient; }
set { this.m_SelectedPhysicianClient = value; }
}
public Visibility NextButtonVisibility
{
get { return this.m_NextButtonVisibility; }
}
public Visibility DoneButtonVisibility
{
get { return this.m_DoneButtonVisibility; }
}
public Visibility BackButtonVisibility
{
get { return this.m_BackButtonVisibility; }
}
public ClientOrder ClientOrderClone
{
get { return this.m_ClientOrderClone; }
}
public ClientOrderDetail ClientOrderDetail
{
get { return this.m_ClientOrderDetail; }
}
public PhysicianCollection PhysicianCollection
{
get { return this.m_PhysicianCollection; }
}
public PhysicianClientCollection PhysicianClientCollection
{
get { return this.m_PhysicianClientCollection; }
}
public AuthenticatedUser AuthenticatedUser
{
get { return this.m_AthenticatedUser; }
}
public EthnicityDictionary EthnicityDictionary
{
get { return this.m_EthnicityDictionary; }
}
public RaceDictionary RaceDictionary
{
get { return this.m_RaceDictionary; }
}
public StateCollection StateCollection
{
get { return this.m_StateCollection; }
}
public OrderValidationCollection OrderValidationCollection
{
get { return this.m_OrderValidationCollection; }
}
private void TabControlTabs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int tabCount = this.TabControlTabs.Items.Count;
if(this.TabControlTabs.SelectedIndex < tabCount - 1)
{
this.m_NextButtonVisibility = Visibility.Visible;
}
else
{
this.m_NextButtonVisibility = Visibility.Collapsed;
}
if (this.TabControlTabs.SelectedIndex > 0)
{
this.m_BackButtonVisibility = Visibility.Visible;
}
else
{
this.m_BackButtonVisibility = Visibility.Collapsed;
}
if (this.TabControlTabs.SelectedIndex == tabCount - 1)
{
this.m_DoneButtonVisibility = Visibility.Visible;
}
else
{
this.m_DoneButtonVisibility = Visibility.Collapsed;
}
this.NotifyPropertyChanged(string.Empty);
}
private void ButtonNext_Click(object sender, RoutedEventArgs e)
{
int tabIndex = this.TabControlTabs.SelectedIndex;
if(tabIndex < this.TabControlTabs.Items.Count -1)
{
tabIndex += 1;
this.TabControlTabs.SelectedIndex = tabIndex;
this.NotifyPropertyChanged(string.Empty);
}
}
private void ButtonBack_Click(object sender, RoutedEventArgs e)
{
int tabIndex = this.TabControlTabs.SelectedIndex;
if(tabIndex > 0)
{
tabIndex -= 1;
this.TabControlTabs.SelectedIndex = tabIndex;
this.NotifyPropertyChanged(string.Empty);
}
}
private void ButtonSetProvider_Click(object sender, RoutedEventArgs e)
{
if(this.ListViewProviders.SelectedItem!= null)
{
Physician physician = (Physician)this.ListViewProviders.SelectedItem;
this.m_ClientOrderClone.SetPhysician(physician);
}
else
{
MessageBox.Show("Please select a Provider to set.");
}
}
public void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private void ButtonSubmitOrder_Click(object sender, RoutedEventArgs e)
{
this.m_ClientOrderClone.SetPriority();
this.m_OrderValidationCollection = new OrderValidationCollection();
this.m_OrderValidationCollection.Validate(this.m_ClientOrderClone);
this.NotifyPropertyChanged(string.Empty);
}
private void ButtonPrintOrder_Click(object sender, RoutedEventArgs e)
{
ClientOrderDataSheet clientOrderDataSheet = new ClientOrderDataSheet(this.m_ClientOrderClone);
XpsDocumentViewer documentViewer = new XpsDocumentViewer();
documentViewer.LoadDocument(clientOrderDataSheet.FixedDocument);
documentViewer.ShowDialog();
}
private void ButtonDone_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void ListBoxItemAsymptomatic_Unselected(object sender, RoutedEventArgs e)
{
this.ListBoxSurgeryLocation.SelectedIndex = -1;
this.ListBoxAsymptomaticType.SelectedIndex = -1;
this.ListBoxSurgeryType.SelectedIndex = -1;
this.m_ClientOrderClone.SurgeryDate = null;
}
private void ListBoxItem_Unselected(object sender, RoutedEventArgs e)
{
this.ListBoxSurgeryLocation.SelectedIndex = -1;
this.ListBoxSurgeryType.SelectedIndex = -1;
this.m_ClientOrderClone.SurgeryDate = null;
}
private void ListBoxItemSymptomaticType_Unselected(object sender, RoutedEventArgs e)
{
this.ListBoxSymptomaticType.SelectedIndex = -1;
this.ListBoxSymptomaticPatientType.SelectedIndex = -1;
}
private void ButtonPrintPrintBarcode_Click(object sender, RoutedEventArgs e)
{
string collectionDate = string.Empty;
if (this.m_ClientOrderClone.CollectionDate.HasValue == true) collectionDate = this.m_ClientOrderClone.CollectionDate.Value.ToString("MM/dd/yyyy");
string zplCommandText = ContainerLabel.GetOneRow(this.m_ClientOrderClone.PLastName, this.m_ClientOrderClone.PFirstName, collectionDate);
string printer = LocalSettings.Instance.BarcodeLabelPrinter;
if(string.IsNullOrEmpty(printer) == false)
{
RawPrinterHelper.SendStringToPrinter(printer, zplCommandText);
}
else
{
MessageBox.Show("Please select a printer in settings.");
}
}
private void ListBoxItemSymptomaticPatient_Unselected(object sender, RoutedEventArgs e)
{
this.ListBoxSymptomaticPatientType.SelectedIndex = -1;
}
private void ButtonSetSurgeon_Click(object sender, RoutedEventArgs e)
{
if(this.ListViewPhysicianClient.SelectedItem != null)
{
PhysicianClient physicianClient = (PhysicianClient)this.ListViewPhysicianClient.SelectedItem;
this.SetSelectedPhysicianClient(physicianClient);
this.NotifyPropertyChanged(string.Empty);
}
}
private void SetSelectedPhysicianClient(PhysicianClient physicianClient)
{
this.m_ClientOrderClone.ReportCopyTo = physicianClient.GetIdString();
if (string.IsNullOrEmpty(this.m_ClientOrderClone.ReportCopyTo) == false)
{
string[] commaSplit = this.m_ClientOrderClone.ReportCopyTo.Split(',');
if (commaSplit.Length == 2)
{
int physicianid = Convert.ToInt32(commaSplit[1]);
int clientId = Convert.ToInt32(commaSplit[0]);
if (this.m_PhysicianClientCollection.Exists(physicianid, clientId) == true)
{
this.m_SelectedPhysicianClient = this.m_PhysicianClientCollection.Get(physicianid, clientId);
}
}
this.NotifyPropertyChanged("SelectPhysicianClient");
}
}
private void HyperLinkSendTestText_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.m_ClientOrderClone.PPhone) == false)
{
JObject jsonRequest = APIRequestHelper.GetSendTextMessage(this.m_ClientOrderClone.PPhone, "This text is to confirm that a SARS-CoV-2 test has been ordered with Yellowstone Pathology Institute. You will receive a text at this number when your result is complete.");
APIResult apiResult = APIRequestHelper.SubmitAPIRequestMessage(jsonRequest);
MessageBox.Show($"A text was sent to {this.m_ClientOrderClone.PPhone}");
}
else
{
MessageBox.Show("You must enter a phone number to use this function.");
}
}
private void HyperLinkSendTestEmail_Click(object sender, RoutedEventArgs e)
{
if(string.IsNullOrEmpty(this.m_ClientOrderClone.EmailAddress) == false)
{
JObject jsonRequest = APIRequestHelper.GetSendEmailMessage(this.m_ClientOrderClone.EmailAddress, "A SARS-CoV-2 test has been ordered with Yellowstone Pathology Institute.", "This email is to confirm that a SARS-CoV-2 test has been ordered with Yellowstone Pathology Institute. You will receive an email at this address when your result is complete.");
APIResult apiResult = APIRequestHelper.SubmitAPIRequestMessage(jsonRequest);
MessageBox.Show($"An email was sent to {this.m_ClientOrderClone.EmailAddress}");
}
else
{
MessageBox.Show("You must enter an email address to use this function.");
}
}
private void ComboBoxClient_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.IsLoaded == true && this.ComboBoxClient.SelectedItem != null)
{
Client client = (Client)this.ComboBoxClient.SelectedItem;
this.ClientOrderClone.ClientId = client.ClientId;
if (client.ClientId == 266)
{
this.m_ClientOrderClone.ProviderId = "1972692416";
this.m_ClientOrderClone.ProviderLastName = "Durden";
this.m_ClientOrderClone.ProviderFirstName = "Angela";
this.m_ClientOrderClone.ProviderName = "Angela Durden, M.D.";
}
}
}
private void ButtonClearSurgeon_Click(object sender, RoutedEventArgs e)
{
this.m_SelectedPhysicianClient = null;
this.m_ClientOrderClone.ReportCopyTo = null;
this.NotifyPropertyChanged(string.Empty);
}
}
}