Exemplo n.º 1
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var spinner = new LoadingSpinner();

            ApplicationManager.SetContent(spinner);

            spinner.Start();

            SyntheaRunner.StartingSynthea += (o, args) =>
            {
                this.Dispatcher.BeginInvoke(new Action(() => { spinner.SetText("Creating Patient records."); }));
            };

            SyntheaRunner.ParsingSyntheaData += (o, args) =>
            {
                this.Dispatcher.BeginInvoke(new Action(() => { spinner.SetText("Parsing Patient records."); }));
            };

            SyntheaRunner.StoringSyntheaData += (o, args) =>
            {
                this.Dispatcher.BeginInvoke(new Action(() => { spinner.SetText("Storing Patient records."); }));
            };

            SyntheaRunner.FinishedSynthea += (o, args) =>
            {
                this.Dispatcher.BeginInvoke(new Action(() => { ApplicationManager.SetContent(new PatientCreation()); }));
            };

            var amount        = ((TextBox)this.FindName("PatientAmount"))?.Text;
            var patientAmount = amount != null?int.Parse(amount) : 0;

            Task.Run(
                () =>
            {
                var patients = SyntheaRunner.CreatePatients(patientAmount, ApplicationManager.CurrentSyntheaVersion);
                this.Dispatcher.BeginInvoke(new Action(() => { ApplicationManager.SetContent(new PatientList(patients)); }));
            });
        }
Exemplo n.º 2
0
        private void UploadResource(TreeViewItem treeViewItem, ParsedResource resource)
        {
            try
            {
                var spinner = new LoadingSpinner();
                spinner.SetText("Creating resource on Tangle");
                ApplicationManager.SetContent(spinner);
                ApplicationManager.MainWindow.MainMenu.IsEnabled = false;

                spinner.Start();

                Task.Factory.StartNew(
                    () =>
                {
                    try
                    {
                        var updatedResource = FhirInteractor.CreateResource(resource);

                        this.Dispatcher.BeginInvoke(
                            new Action(
                                () =>
                        {
                            var newItem = this.CreateTreeViewItem(updatedResource);

                            foreach (ParsedPatient patient in this.Patients.ItemsSource)
                            {
                                if (patient.Resources.First().PatientId != updatedResource.PatientId)
                                {
                                    continue;
                                }

                                var resourceToUpdate = patient.Resources.First(r => r.Id == updatedResource.Id);
                                if (resourceToUpdate != null)
                                {
                                    resourceToUpdate.Resource = updatedResource.Resource;
                                }
                            }

                            var selectedIndex = this.PatientDetails.Items.IndexOf(treeViewItem);
                            this.PatientDetails.Items.RemoveAt(selectedIndex);
                            this.PatientDetails.Items.Insert(selectedIndex, newItem);

                            this.PatientDetails.Items.Refresh();
                            this.PatientDetails.UpdateLayout();

                            spinner.Stop();
                        }));
                    }
                    catch (MissingReferenceException)
                    {
                        this.Dispatcher.BeginInvoke(
                            new Action(
                                () =>
                        {
                            MessageBox.Show("Referenced resource not uploaded yet. Upload Patient record first.", "Creation Failed");
                        }));
                    }
                    catch (ResourceException exception)
                    {
                        this.Dispatcher.BeginInvoke(
                            new Action(
                                () =>
                        {
                            MessageBox.Show(exception.Outcome.ToFormattedJson(), "Creation Failed");
                        }));
                    }
                    catch (Exception exception)
                    {
                        this.Dispatcher.BeginInvoke(
                            new Action(
                                () =>
                        {
                            MessageBox.Show(exception.StackTrace, exception.Message);
                        }));
                    }
                    finally
                    {
                        this.Dispatcher.BeginInvoke(
                            new Action(
                                () =>
                        {
                            ApplicationManager.MainWindow.MainMenu.IsEnabled = true;
                            ApplicationManager.SetContent(this);
                        }));
                    }
                });
            }
            catch
            {
                // ignored
            }
        }