This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 575
/
Copy pathInsuranceClaimAutomation.xaml.cs
611 lines (536 loc) · 27.8 KB
/
InsuranceClaimAutomation.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Cognitive Services: http://www.microsoft.com/cognitive
//
// Microsoft Cognitive Services Github:
// https://github.com/Microsoft/Cognitive
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using IntelligentKioskSample.Models.InsuranceClaimAutomation;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models;
using Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training;
using ServiceHelpers;
using ServiceHelpers.Models.FormRecognizer;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
namespace IntelligentKioskSample.Views.InsuranceClaimAutomation
{
[KioskExperience(
Id = "InsuranceClaimAutomation",
DisplayName = "Insurance Claim Automation",
Description = "See how AI can help automate the filing of insurance claims",
ImagePath = "ms-appx:/Assets/DemoGallery/InsuranceClaimAutomation.jpg",
ExperienceType = ExperienceType.Business | ExperienceType.Guided | ExperienceType.Preview,
TechnologyArea = TechnologyAreaType.Vision,
TechnologiesUsed = TechnologyType.CustomVision | TechnologyType.FormRecognizer,
DateAdded = "2019/10/24")]
public sealed partial class InsuranceClaimAutomation : Page, INotifyPropertyChanged
{
private static readonly Guid FormRecognizerModelId = Guid.Empty; // Form Recognizer Model ID created with a Form Recognizer Key on the Settings page
private static readonly Guid ObjectDetectionModelId = Guid.Empty; // Custom Vision Object Detection Model ID created with a Custom Vision Key on the Settings page
private static readonly Guid ObjectClassificationModelId = Guid.Empty; // Custom Vision Object Classification Model ID created with a Custom Vision Key on the Settings page
private static readonly string DataGridAction = "DataGridAction";
private static readonly TokenOverlayInfo emptyRow = new TokenOverlayInfo() { Text = "---" };
private static readonly double MinProbability = 0.6;
private static readonly string ObjectName = "windshield";
private static readonly Dictionary<CustomFormFieldType, string> CustomFormFieldsDict = new Dictionary<CustomFormFieldType, string>()
{
{ CustomFormFieldType.CustomName, "name" },
{ CustomFormFieldType.Date, "date" },
{ CustomFormFieldType.WarrantyId, "warranty claim id" },
{ CustomFormFieldType.WarrantyAmount, "manufacturer warranty" },
{ CustomFormFieldType.Total, "total" }
};
private int claimId = 0;
private StorageFolder TempStorageFolder;
private StorageFile CurrentInputFormFile;
private ImageAnalyzer CurrentInputFormImage;
private ImageAnalyzer CurrentInputProductImage;
private CustomVisionTrainingClient trainingApi;
private CustomVisionPredictionClient predictionApi;
private FormRecognizerService formRecognizerService;
public event PropertyChangedEventHandler PropertyChanged;
private InputViewState inputImageViewState = InputViewState.NotSelected;
public InputViewState InputImageViewState
{
get { return inputImageViewState; }
set
{
inputImageViewState = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("InputImageViewState"));
ValidateInputParams();
}
}
private InputViewState inputFormViewState = InputViewState.NotSelected;
public InputViewState InputFormViewState
{
get { return inputFormViewState; }
set
{
inputFormViewState = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("InputFormViewState"));
ValidateInputParams();
}
}
public bool isFormImageSource = true;
public bool IsFormImageSource
{
get { return isFormImageSource; }
set
{
if (isFormImageSource != value)
{
isFormImageSource = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsFormImageSource"));
}
}
}
public ObservableCollection<InputSampleViewModel> ImageSampleCollection { get; set; } = new ObservableCollection<InputSampleViewModel>()
{
new InputSampleViewModel("ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/1.jpg"),
new InputSampleViewModel("ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/2.jpg"),
new InputSampleViewModel("ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/3.jpg"),
new InputSampleViewModel("ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/4.jpg")
};
public ObservableCollection<InputSampleViewModel> FormSampleCollection { get; set; } = new ObservableCollection<InputSampleViewModel>()
{
new InputSampleViewModel("Form1.jpg", "ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/Form1.jpg"),
new InputSampleViewModel("Form2.jpg", "ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/Form2.jpg"),
new InputSampleViewModel("Form3.jpg", "ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/Form3.jpg"),
new InputSampleViewModel("Form4.jpg", "ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/Form4.jpg"),
new InputSampleViewModel("Form5.jpg", "ms-appx:///Assets/DemoSamples/InsuranceClaimAutomation/Form5.jpg")
};
public ObservableCollection<DataGridViewModel> DataGridCollection { get; set; } = new ObservableCollection<DataGridViewModel>();
public InsuranceClaimAutomation()
{
this.InitializeComponent();
DataContext = this;
this.detailsViewControl.OnViewClosed += OnDetailsViewClosed;
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
bool enableFormRecognizerKeys = !string.IsNullOrEmpty(SettingsHelper.Instance.FormRecognizerApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.FormRecognizerApiKeyEndpoint);
bool enableCustomVisionKeys = !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionTrainingApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionResourceId);
bool enableModelIds = FormRecognizerModelId != Guid.Empty && ObjectDetectionModelId != Guid.Empty && ObjectClassificationModelId != Guid.Empty;
if (enableFormRecognizerKeys)
{
TempStorageFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("InsuranceClaimAutomation", CreationCollisionOption.OpenIfExists);
this.formRecognizerService = new FormRecognizerService(SettingsHelper.Instance.FormRecognizerApiKey, SettingsHelper.Instance.FormRecognizerApiKeyEndpoint);
}
if (enableCustomVisionKeys)
{
trainingApi = new CustomVisionTrainingClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.ApiKeyServiceClientCredentials(SettingsHelper.Instance.CustomVisionTrainingApiKey))
{
Endpoint = SettingsHelper.Instance.CustomVisionTrainingApiKeyEndpoint
};
predictionApi = new CustomVisionPredictionClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(SettingsHelper.Instance.CustomVisionPredictionApiKey))
{
Endpoint = SettingsHelper.Instance.CustomVisionPredictionApiKeyEndpoint
};
}
if (!enableFormRecognizerKeys || !enableCustomVisionKeys || !enableModelIds)
{
this.mainPage.IsEnabled = false;
await new MessageDialog("Please enter Custom Vision / Form Recognizer API Keys / Model Ids in the code behind of this demo.", "Missing API Keys").ShowAsync();
}
else
{
this.mainPage.IsEnabled = true;
await LoadDataGridCollectionAsync();
this.claimId = DataGridCollection.OrderByDescending(x => x.ClaimId).Select(x => x.ClaimId).FirstOrDefault();
}
base.OnNavigatedTo(e);
}
protected override async void OnNavigatedFrom(NavigationEventArgs e)
{
if (TempStorageFolder != null)
{
await TempStorageFolder.DeleteAsync();
}
base.OnNavigatedFrom(e);
}
private async Task LoadDataGridCollectionAsync()
{
try
{
this.progressRing.IsActive = true;
IList<DataGridViewModel> data = await InsuranceClaimDataLoader.GetDataAsync();
foreach (var item in data)
{
if (!string.IsNullOrEmpty(item.ProductImageUri))
{
item.ProductImage = new BitmapImage(new Uri(item.ProductImageUri));
}
if (!string.IsNullOrEmpty(item.FormImageUri))
{
item.FormImage = new BitmapImage(new Uri(item.FormImageUri));
}
}
DataGridCollection.Clear();
DataGridCollection.AddRange(data);
}
catch (Exception ex)
{
await Util.GenericApiCallExceptionHandler(ex, "Failure loading grid data");
}
finally
{
this.progressRing.IsActive = false;
}
}
private void AddImageButtonClicked(object sender, RoutedEventArgs e)
{
this.productImage.Source = null;
InputImageViewState = InputViewState.Selection;
}
private void AddFormFileButtonClicked(object sender, RoutedEventArgs e)
{
this.formImage.Source = null;
this.pdfViewerControl.Source = null;
InputFormViewState = InputViewState.Selection;
}
private async void OnInputImageSearchCompleted(object sender, ImageAnalyzer img)
{
if (img != null)
{
CurrentInputProductImage = img;
if (img.ImageUrl != null)
{
this.productImage.Source = new BitmapImage(new Uri(img.ImageUrl));
}
else if (img.GetImageStreamCallback != null)
{
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync((await img.GetImageStreamCallback()).AsRandomAccessStream());
this.productImage.Source = bitmapImage;
}
InputImageViewState = InputViewState.Selected;
}
}
private async void OnInputFormImageSearchCompleted(object sender, ImageAnalyzer img)
{
if (img != null)
{
IsFormImageSource = true;
CurrentInputFormImage = img;
if (img.ImageUrl != null)
{
this.formImage.Source = new BitmapImage(new Uri(img.ImageUrl));
}
else if (img.GetImageStreamCallback != null)
{
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync((await img.GetImageStreamCallback()).AsRandomAccessStream());
this.formImage.Source = bitmapImage;
}
}
InputFormViewState = InputViewState.Selected;
}
private async void OnInputFormFileSearchCompleted(object sender, StorageFile file)
{
if (file != null)
{
IsFormImageSource = false;
StorageFile localFile = await file.CopyAsync(TempStorageFolder, $"{Guid.NewGuid().ToString()}{file.FileType}");
this.pdfViewerControl.Source = new Uri(localFile.Path);
CurrentInputFormFile = localFile;
}
InputFormViewState = InputViewState.Selected;
}
private void ValidateInputParams()
{
this.submitClaimButton.IsEnabled = InputImageViewState == InputViewState.Selected && InputFormViewState == InputViewState.Selected;
}
private void OnCancelInputButtonClicked(object sender, RoutedEventArgs e)
{
if (sender is Button button)
{
if (button.Tag.ToString() == "image")
{
this.productImage.Source = null;
InputImageViewState = InputViewState.Selection;
this.inputImagePicker.RestartPicker();
}
else
{
this.formImage.Source = null;
this.pdfViewerControl.Source = null;
InputFormViewState = InputViewState.Selection;
this.inputFormPicker.RestartPicker();
}
}
}
private async void OnSubmitClaimButtonClicked(object sender, RoutedEventArgs e)
{
try
{
this.progressRing.IsActive = true;
CloseDetailsView();
if (CurrentInputProductImage != null && (CurrentInputFormImage != null || CurrentInputFormFile != null))
{
var claim = new DataGridViewModel(Guid.NewGuid())
{
ClaimId = ++claimId,
IsFormImage = IsFormImageSource,
CustomName = emptyRow,
Date = emptyRow,
WarrantyId = emptyRow,
Warranty = emptyRow,
InvoiceTotal = emptyRow
};
// store image file to local folder
if (CurrentInputProductImage.ImageUrl != null)
{
claim.ProductImageUri = CurrentInputProductImage.ImageUrl;
claim.ProductImage = new BitmapImage(new Uri(CurrentInputProductImage.ImageUrl));
}
else if (CurrentInputProductImage.GetImageStreamCallback != null)
{
StorageFile imageFile = await InsuranceClaimDataLoader.CreateFileInLocalFolderAsync(claim.Id, "ProductImage.jpg");
await Util.SaveBitmapToStorageFileAsync(await CurrentInputProductImage.GetImageStreamCallback(), imageFile);
claim.ProductImageUri = imageFile.Path;
claim.ProductImage = new BitmapImage(new Uri(imageFile.Path));
}
// store form file to local folder
if (isFormImageSource)
{
CurrentInputFormFile = await InsuranceClaimDataLoader.CreateFileInLocalFolderAsync(claim.Id, "FormImage.jpg");
if (CurrentInputFormImage?.ImageUrl != null)
{
claim.FormImageUri = CurrentInputFormImage.ImageUrl;
claim.FormImage = new BitmapImage(new Uri(CurrentInputFormImage.ImageUrl));
await Util.DownloadAndSaveBitmapAsync(CurrentInputFormImage.ImageUrl, CurrentInputFormFile);
}
else if (CurrentInputFormImage?.GetImageStreamCallback != null)
{
await Util.SaveBitmapToStorageFileAsync(await CurrentInputFormImage.GetImageStreamCallback(), CurrentInputFormFile);
claim.FormImageUri = CurrentInputFormFile.Path;
claim.FormImage = new BitmapImage(new Uri(CurrentInputFormFile.Path));
}
}
else if (CurrentInputFormFile != null)
{
StorageFile file = await InsuranceClaimDataLoader.CopyFileToLocalFolderAsync(CurrentInputFormFile, $"FormFile{CurrentInputFormFile.FileType}", claim.Id);
claim.FormFile = new Uri(file.Path);
}
DataGridCollection.Add(claim);
// show submitted form
this.inputSubmittedGrid.Visibility = Visibility.Visible;
// validate product image and form
await ProcessClaimAsync(claim);
// store current claim
await InsuranceClaimDataLoader.SaveOrUpdateDataAsync(claim);
// update datagrid collection
await LoadDataGridCollectionAsync();
}
}
catch (Exception ex)
{
await Util.GenericApiCallExceptionHandler(ex, "Failure processing claim");
}
finally
{
this.progressRing.IsActive = false;
}
}
private async Task ProcessClaimAsync(DataGridViewModel claim)
{
var extractedFieldsTask = AnalyzeFormFromFileAsync(CurrentInputFormFile);
var detectProductImageTask = AnalyzeProductImageAsync(ObjectDetectionModelId); // Custom Vision Object Detection
var classifyProductImageTask = AnalyzeProductImageAsync(ObjectClassificationModelId); // Custom Vision Object Classification
await Task.WhenAll(detectProductImageTask, classifyProductImageTask, extractedFieldsTask);
// Product validation
List<PredictionModel> detectionMatches = detectProductImageTask.Result?.Predictions?.Where(p => p.Probability >= MinProbability && p.TagName.ToLower().Contains(ObjectName)).ToList();
List<PredictionModel> classificationMatches = classifyProductImageTask.Result?.Predictions?.Where(p => p.Probability >= MinProbability && p.TagName.ToLower().Contains(ObjectName)).ToList();
bool isProductImage = detectionMatches != null && detectionMatches.Any() && classificationMatches != null && classificationMatches.Any();
claim.ProductImageValidStatus = isProductImage ? InputValidationStatus.Valid : InputValidationStatus.Invalid;
if (isProductImage)
{
claim.ObjectDetectionMatches = detectionMatches;
claim.ObjectClassificationMatches = classificationMatches;
}
// Form validation
var extractedFields = extractedFieldsTask.Result;
if (extractedFields != null)
{
claim.CustomName = extractedFields.FirstOrDefault(x => x.Item1.Text.ToLower().Contains(CustomFormFieldsDict[CustomFormFieldType.CustomName]))?.Item2 ?? emptyRow;
claim.Date = extractedFields.FirstOrDefault(x => x.Item1.Text.ToLower().Contains(CustomFormFieldsDict[CustomFormFieldType.Date]))?.Item2 ?? emptyRow;
claim.WarrantyId = extractedFields.FirstOrDefault(x => x.Item1.Text.ToLower().Contains(CustomFormFieldsDict[CustomFormFieldType.WarrantyId]))?.Item2 ?? emptyRow;
claim.Warranty = extractedFields.FirstOrDefault(x => x.Item1.Text.ToLower().Contains(CustomFormFieldsDict[CustomFormFieldType.WarrantyAmount]))?.Item2 ?? emptyRow;
claim.InvoiceTotal = extractedFields.FirstOrDefault(x => x.Item1.Text.ToLower().Contains(CustomFormFieldsDict[CustomFormFieldType.Total]))?.Item2 ?? emptyRow;
string[] fields = CustomFormFieldsDict.Select(f => f.Value).ToArray();
bool isValidForm = extractedFields.Any(e => fields.Any(f => e.Item1.Text.ToLower().Contains(f) && !string.IsNullOrEmpty(e.Item2.Text)));
claim.FormValidStatus = isValidForm ? InputValidationStatus.Valid : InputValidationStatus.Invalid;
}
else
{
claim.FormValidStatus = InputValidationStatus.Invalid;
}
}
private async Task<List<Tuple<TokenOverlayInfo, TokenOverlayInfo>>> AnalyzeFormFromFileAsync(StorageFile file)
{
if (file == null)
{
return null;
}
try
{
AnalyzeFormResult result = null;
string fileType = IsFormImageSource ? FormRecognizerService.ImageJpegContentType : FormRecognizerService.PdfContentType;
using (FileStream stream = new FileStream(file.Path, FileMode.Open))
{
result = await this.formRecognizerService.AnalyzeImageFormWithCustomModelAsync(FormRecognizerModelId, stream, fileType);
}
PageResult page = result?.PageResults.FirstOrDefault();
ReadResult pageInfo = result?.ReadResults.FirstOrDefault();
if (page != null && pageInfo != null)
{
double width = pageInfo.Width;
double height = pageInfo.Height;
var keyValuePairList = page.KeyValuePairs
.Where(x => !string.IsNullOrEmpty(x.Key?.Text) && x.Key?.BoundingBox != null) // showing pairs with non-empty keys
.Select(x => new Tuple<TokenOverlayInfo, TokenOverlayInfo>(
new TokenOverlayInfo(x.Key, width, height),
new TokenOverlayInfo(x.Value, width, height)
)).ToList();
return keyValuePairList;
}
}
catch (Exception ex)
{
await Util.GenericApiCallExceptionHandler(ex, "Failure recognizing form");
}
return null;
}
private async Task<ImagePrediction> AnalyzeProductImageAsync(Guid modelId)
{
ImagePrediction result = null;
try
{
var iteractions = await trainingApi.GetIterationsAsync(modelId);
var latestTrainedIteraction = iteractions.Where(i => i.Status == "Completed").OrderByDescending(i => i.TrainedAt.Value).FirstOrDefault();
if (latestTrainedIteraction == null)
{
throw new Exception("This project doesn't have any trained models yet.");
}
if (string.IsNullOrEmpty(latestTrainedIteraction.PublishName))
{
await trainingApi.PublishIterationAsync(modelId, latestTrainedIteraction.Id, publishName: latestTrainedIteraction.Id.ToString(), predictionId: SettingsHelper.Instance.CustomVisionPredictionResourceId);
latestTrainedIteraction = await trainingApi.GetIterationAsync(modelId, latestTrainedIteraction.Id);
}
if (CurrentInputProductImage?.ImageUrl != null)
{
result = await CustomVisionServiceHelper.ClassifyImageUrlWithRetryAsync(predictionApi, modelId, new ImageUrl(CurrentInputProductImage.ImageUrl), latestTrainedIteraction.PublishName);
}
else if (CurrentInputProductImage?.GetImageStreamCallback != null)
{
result = await CustomVisionServiceHelper.ClassifyImageWithRetryAsync(predictionApi, modelId, CurrentInputProductImage.GetImageStreamCallback, latestTrainedIteraction.PublishName);
}
}
catch (Exception ex)
{
await Util.GenericApiCallExceptionHandler(ex, "Custom Vision error analyzing product image");
}
return result;
}
private void AddAnotherClaimButtonClicked(object sender, RoutedEventArgs e)
{
InputImageViewState = InputViewState.NotSelected;
InputFormViewState = InputViewState.NotSelected;
this.inputSubmittedGrid.Visibility = Visibility.Collapsed;
CloseDetailsView();
}
private void DataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
{
bool isAction = this.dataGrid.Tag != null && this.dataGrid.Tag.ToString() == DataGridAction;
if (this.dataGrid.SelectedItem is DataGridViewModel selectedRow && !isAction)
{
this.detailsViewControl.OpenDetailsView(selectedRow);
this.detailsViewControl.Visibility = Visibility.Visible;
}
}
private void OnDetailsViewClosed(object sender, EventArgs args)
{
CloseDetailsView();
}
private void CloseDetailsView()
{
this.dataGrid.SelectedItem = null;
this.detailsViewControl.Visibility = Visibility.Collapsed;
}
private async void OnDeleteDataGridRowButtonClicked(object sender, RoutedEventArgs e)
{
try
{
this.dataGrid.Tag = DataGridAction;
var currentRow = (sender as Button)?.DataContext as DataGridViewModel;
if (currentRow != null)
{
ContentDialog dialog = new ContentDialog
{
Title = "Are you sure?",
Content = $"This operation will delete this claim permanently.",
PrimaryButtonText = "Delete",
SecondaryButtonText = "Cancel",
DefaultButton = ContentDialogButton.Secondary
};
ContentDialogResult result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
var itemToRemove = DataGridCollection.FirstOrDefault(x => x.Id == currentRow.Id);
bool entryRemovedFromFile = DataGridCollection.Remove(itemToRemove);
if (entryRemovedFromFile)
{
await InsuranceClaimDataLoader.DeleteDataAsync(new List<DataGridViewModel>() { itemToRemove });
}
}
}
}
catch (Exception ex)
{
await Util.GenericApiCallExceptionHandler(ex, "Failure deleting datagrid row");
}
finally
{
this.dataGrid.Tag = null;
this.dataGrid.SelectedItem = null;
}
}
}
}