From 546e3a889876ba57099fb750f2ac8f59fe1ca205 Mon Sep 17 00:00:00 2001 From: Felandil Date: Tue, 18 Jun 2019 12:10:55 +0200 Subject: [PATCH] add Java checks --- .../Exception/JavaHomeNotSetException.cs | 8 ++++ .../Exception/JavaNotInstalledException.cs | 8 ++++ Synthea.Iota.Core/Services/FhirInteractor.cs | 2 +- .../Services/SyntheaInstaller.cs | 23 ++++++++-- Synthea.Iota.Core/Services/SyntheaRunner.cs | 5 +++ Synthea.Iota.Core/Synthea.Iota.Core.csproj | 2 + Synthea.Iota.Ui/MainWindow.xaml.cs | 45 ++++++++++++++++++- Synthea.Iota.Ui/PatientList.xaml.cs | 2 + 8 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 Synthea.Iota.Core/Exception/JavaHomeNotSetException.cs create mode 100644 Synthea.Iota.Core/Exception/JavaNotInstalledException.cs diff --git a/Synthea.Iota.Core/Exception/JavaHomeNotSetException.cs b/Synthea.Iota.Core/Exception/JavaHomeNotSetException.cs new file mode 100644 index 0000000..a69ec7d --- /dev/null +++ b/Synthea.Iota.Core/Exception/JavaHomeNotSetException.cs @@ -0,0 +1,8 @@ +namespace Synthea.Iota.Core.Exception +{ + using System; + + public class JavaHomeNotSetException : Exception + { + } +} \ No newline at end of file diff --git a/Synthea.Iota.Core/Exception/JavaNotInstalledException.cs b/Synthea.Iota.Core/Exception/JavaNotInstalledException.cs new file mode 100644 index 0000000..17c6419 --- /dev/null +++ b/Synthea.Iota.Core/Exception/JavaNotInstalledException.cs @@ -0,0 +1,8 @@ +namespace Synthea.Iota.Core.Exception +{ + using System; + + public class JavaNotInstalledException : Exception + { + } +} \ No newline at end of file diff --git a/Synthea.Iota.Core/Services/FhirInteractor.cs b/Synthea.Iota.Core/Services/FhirInteractor.cs index 201dfe3..0e3b685 100644 --- a/Synthea.Iota.Core/Services/FhirInteractor.cs +++ b/Synthea.Iota.Core/Services/FhirInteractor.cs @@ -19,7 +19,7 @@ public static ParsedResource CreateResource(ParsedResource resource) var patientRepository = new SqlLitePatientRepository(); var referencedResource = patientRepository.GetResource(resource.PatientId); - if (resource.TypeName != "Patient" && !referencedResource.IsIotaResource) + if ((referencedResource == null && resource.TypeName != "Patient") || (resource.TypeName != "Patient" && referencedResource != null && !referencedResource.IsIotaResource)) { throw new MissingReferenceException(); } diff --git a/Synthea.Iota.Core/Services/SyntheaInstaller.cs b/Synthea.Iota.Core/Services/SyntheaInstaller.cs index 8ce2006..39d9107 100644 --- a/Synthea.Iota.Core/Services/SyntheaInstaller.cs +++ b/Synthea.Iota.Core/Services/SyntheaInstaller.cs @@ -4,11 +4,15 @@ using System.IO; using System.IO.Compression; + using Microsoft.Win32; + using Newtonsoft.Json; using RestSharp; using RestSharp.Extensions; + using Synthea.Iota.Core.Exception; + public static class SyntheaInstaller { public static event EventHandler DownloadLatest; @@ -26,6 +30,8 @@ public static string InstallOrUpdate() Directory.CreateDirectory("Synthea"); } + CheckJavaInstallation(); + VersionCheck?.Invoke("SyntheaInstaller", EventArgs.Empty); var client = new RestClient("https://github.com/synthetichealth/synthea"); @@ -40,9 +46,12 @@ public static string InstallOrUpdate() } DownloadLatest?.Invoke("SyntheaInstaller", EventArgs.Empty); - client.DownloadData(new RestRequest($"/archive/{tag}.zip")).SaveAs("synthea.zip"); - ZipFile.ExtractToDirectory("synthea.zip", "Synthea"); - File.Delete("synthea.zip"); + client.DownloadData(new RestRequest($"/archive/{tag}.zip")).SaveAs("synthea.temp"); + ZipFile.ExtractToDirectory("synthea.temp", "Synthea"); + if (File.Exists("synthea.temp")) + { + File.Delete("synthea.temp"); + } InstallLatest?.Invoke("SyntheaInstaller", EventArgs.Empty); var synthea = SyntheaRunner.StartSynthea("-p 1", currentVersion); @@ -54,5 +63,13 @@ public static string InstallOrUpdate() SetupComplete?.Invoke("SyntheaInstaller", EventArgs.Empty); return currentVersion; } + + private static void CheckJavaInstallation() + { + if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("JAVA_HOME"))) + { + throw new JavaHomeNotSetException(); + } + } } } \ No newline at end of file diff --git a/Synthea.Iota.Core/Services/SyntheaRunner.cs b/Synthea.Iota.Core/Services/SyntheaRunner.cs index a72a711..5afdd22 100644 --- a/Synthea.Iota.Core/Services/SyntheaRunner.cs +++ b/Synthea.Iota.Core/Services/SyntheaRunner.cs @@ -101,6 +101,11 @@ private static List ParseSyntheaData(string currentVersion) { var outputDirectory = $"{GetSyntheaDirectory(currentVersion)}\\output\\fhir"; var parsedPatients = ParsePatientFromFiles(Directory.GetFiles(outputDirectory)); + parsedPatients.ForEach(p => p.Resources.ForEach(r => + { + r.Id = r.Resource.Id; + r.PatientId = p.Resources[0].Resource.Id; + })); Directory.Delete(outputDirectory, true); return parsedPatients; diff --git a/Synthea.Iota.Core/Synthea.Iota.Core.csproj b/Synthea.Iota.Core/Synthea.Iota.Core.csproj index 591a01c..22cd5e1 100644 --- a/Synthea.Iota.Core/Synthea.Iota.Core.csproj +++ b/Synthea.Iota.Core/Synthea.Iota.Core.csproj @@ -132,6 +132,8 @@ + + diff --git a/Synthea.Iota.Ui/MainWindow.xaml.cs b/Synthea.Iota.Ui/MainWindow.xaml.cs index 9b01117..64688cb 100644 --- a/Synthea.Iota.Ui/MainWindow.xaml.cs +++ b/Synthea.Iota.Ui/MainWindow.xaml.cs @@ -9,6 +9,7 @@ using Microsoft.Win32; using Synthea.Iota.Core.Entity; + using Synthea.Iota.Core.Exception; using Synthea.Iota.Core.Services; using Synthea.Iota.Ui; using Synthea.Iota.Ui.Services; @@ -66,7 +67,49 @@ private void InitializeSynthea() })); }; - Task.Run(() => ApplicationManager.CurrentSyntheaVersion = SyntheaInstaller.InstallOrUpdate()); + Task.Run(() => + { + try + { + ApplicationManager.CurrentSyntheaVersion = SyntheaInstaller.InstallOrUpdate(); + } + catch (JavaNotInstalledException) + { + this.Dispatcher.BeginInvoke( + new Action( + () => + { + MessageBox.Show( + "Synthea needs the Java 1.8 JDK or higher to be installed. Please go to https://www.oracle.com/technetwork/java/javase/downloads/index.html and install the latest JDK version.", + "Java not installed or incorrect version!"); + + Application.Current.Shutdown(); + })); + } + catch (JavaHomeNotSetException) + { + this.Dispatcher.BeginInvoke( + new Action( + () => + { + MessageBox.Show( + "Please set the java home variable to your JDK installation (see https://www.google.com/search?q=how+to+set+java_home&oq=how+to+set+java)", + "Java path (JAVA_HOME) not set!"); + + Application.Current.Shutdown(); + })); + } + catch (Exception exception) + { + this.Dispatcher.BeginInvoke( + new Action( + () => + { + MessageBox.Show(exception.StackTrace, exception.Message); + Application.Current.Shutdown(); + })); + } + }); } private void GeneratePatients_OnClick(object sender, RoutedEventArgs e) diff --git a/Synthea.Iota.Ui/PatientList.xaml.cs b/Synthea.Iota.Ui/PatientList.xaml.cs index dc02c59..bea9cb0 100644 --- a/Synthea.Iota.Ui/PatientList.xaml.cs +++ b/Synthea.Iota.Ui/PatientList.xaml.cs @@ -86,6 +86,7 @@ private void UploadResource(TreeViewItem treeViewItem, ParsedResource resource) var spinner = new LoadingSpinner(); spinner.SetText("Creating resource on Tangle"); ApplicationManager.SetContent(spinner); + ApplicationManager.MainWindow.MainMenu.IsEnabled = false; spinner.Start(); @@ -159,6 +160,7 @@ private void UploadResource(TreeViewItem treeViewItem, ParsedResource resource) new Action( () => { + ApplicationManager.MainWindow.MainMenu.IsEnabled = true; ApplicationManager.SetContent(this); })); }