Skip to content

Commit

Permalink
add Java checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Felandil committed Jun 18, 2019
1 parent e2013a1 commit 546e3a8
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Synthea.Iota.Core/Exception/JavaHomeNotSetException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Synthea.Iota.Core.Exception
{
using System;

public class JavaHomeNotSetException : Exception
{
}
}
8 changes: 8 additions & 0 deletions Synthea.Iota.Core/Exception/JavaNotInstalledException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Synthea.Iota.Core.Exception
{
using System;

public class JavaNotInstalledException : Exception
{
}
}
2 changes: 1 addition & 1 deletion Synthea.Iota.Core/Services/FhirInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
23 changes: 20 additions & 3 deletions Synthea.Iota.Core/Services/SyntheaInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

Expand All @@ -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);
Expand All @@ -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();
}
}
}
}
5 changes: 5 additions & 0 deletions Synthea.Iota.Core/Services/SyntheaRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ private static List<ParsedPatient> 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;
Expand Down
2 changes: 2 additions & 0 deletions Synthea.Iota.Core/Synthea.Iota.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
<ItemGroup>
<Compile Include="Entity\ParsedPatient.cs" />
<Compile Include="Entity\ParsedResource.cs" />
<Compile Include="Exception\JavaHomeNotSetException.cs" />
<Compile Include="Exception\JavaNotInstalledException.cs" />
<Compile Include="Exception\MissingReferenceException.cs" />
<Compile Include="Exception\ResourceException.cs" />
<Compile Include="Extensions\ResourceExtensions.cs" />
Expand Down
45 changes: 44 additions & 1 deletion Synthea.Iota.Ui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Synthea.Iota.Ui/PatientList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -159,6 +160,7 @@ private void UploadResource(TreeViewItem treeViewItem, ParsedResource resource)
new Action(
() =>
{
ApplicationManager.MainWindow.MainMenu.IsEnabled = true;
ApplicationManager.SetContent(this);
}));
}
Expand Down

0 comments on commit 546e3a8

Please sign in to comment.