285 lines
8.6 KiB
C#
285 lines
8.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
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.IO;
|
|
using Microsoft.Win32;
|
|
|
|
/**
|
|
* TODO:
|
|
* * ADD API SUPPORT
|
|
*/
|
|
|
|
namespace PWAPPv2
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
static Source.APIConfig apiconfig = new Source.APIConfig();
|
|
static Source.Database.DatabaseConfig DataConfig;
|
|
|
|
static Source.API.APIConnection apiConnection;
|
|
Source.DataObjects.APICredentials apiCreds;
|
|
|
|
Source.DataObjects.ComboBoxData TypeBox;
|
|
Source.DataObjects.ComboBoxData ToBox;
|
|
Source.DataObjects.ComboBoxData FromBox;
|
|
|
|
string[] args;
|
|
|
|
Source.Patient patient;
|
|
|
|
List<Source.DataObjects.PWImage> images;
|
|
|
|
public MainWindow()
|
|
{
|
|
try
|
|
{
|
|
args = App.Args;
|
|
}
|
|
catch(Exception)
|
|
{ }
|
|
|
|
images = new List<Source.DataObjects.PWImage>();
|
|
|
|
apiconfig.LoadConfig("./Config/Config.xml");
|
|
DataConfig = new Source.Database.DatabaseConfig("./Config/Config.xml");
|
|
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig);
|
|
|
|
apiCreds = new Source.DataObjects.APICredentials(apiconfig);
|
|
|
|
apiConnection = new Source.API.APIConnection("http://apipatientweb.azurewebsites.net/",
|
|
apiCreds);
|
|
|
|
InitializeComponent();
|
|
|
|
PopulateComboBoxes();
|
|
|
|
patient = new Source.Patient();
|
|
|
|
patient.BuildFromDatabase(dbcon, args[0]);
|
|
|
|
this.DataContext = new Source.PatientGUIAdapter(patient);
|
|
|
|
}
|
|
|
|
private void PopulateComboBoxes()
|
|
{
|
|
PopulateReferTypesBox();
|
|
PopulateReferToBox();
|
|
PopulateReferFromBox();
|
|
}
|
|
|
|
private void PopulateReferTypesBox()
|
|
{
|
|
string ReferTypeString = apiConnection.SendPostRequestAsync("api/PWReferralTypes");
|
|
TypeBox = new Source.DataObjects.ReferralTypeBox(boxReferType, ReferTypeString);
|
|
|
|
}
|
|
|
|
private void PopulateReferToBox()
|
|
{
|
|
string ReferToString = apiConnection.SendPostRequestAsync("api/PWReferTo");
|
|
ToBox = new Source.DataObjects.ReferToBox(boxReferTo, ReferToString);
|
|
}
|
|
|
|
private void PopulateReferFromBox()
|
|
{
|
|
string ReferFromString = apiConnection.SendPostRequestAsync("api/PWReferFrom");
|
|
FromBox = new Source.DataObjects.ReferFromBox(boxReferFrom, ReferFromString);
|
|
}
|
|
|
|
private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void CheckBox_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void boxReferType_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
TypeBox.GetSelectedID();
|
|
}
|
|
catch(Source.DataObjects.ReferralTypeDefaultException)
|
|
{
|
|
|
|
}
|
|
catch(Source.DataObjects.InvalidReferralTypeException)
|
|
{
|
|
|
|
}
|
|
catch(NullReferenceException)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
//Cancel button
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
//OK Button
|
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
|
{
|
|
Source.DataObjects.Referral referral;
|
|
if(images.Count == 0)
|
|
{
|
|
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
|
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
|
(Source.DataObjects.ReferToBox)ToBox,
|
|
(Source.DataObjects.ReferFromBox)FromBox,
|
|
fieldRemakrs, contact, false);
|
|
}
|
|
else
|
|
{
|
|
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
|
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
|
(Source.DataObjects.ReferToBox)ToBox,
|
|
(Source.DataObjects.ReferFromBox)FromBox,
|
|
fieldRemakrs, contact, true);
|
|
}
|
|
|
|
try
|
|
{
|
|
string referralString = referral.ToJsonString();
|
|
string result = apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString);
|
|
if(images.Count > 0)
|
|
{
|
|
foreach(Source.DataObjects.PWImage im in images)
|
|
{
|
|
Source.DataObjects.Attachment att = new Source.DataObjects.Attachment(apiCreds, im, result);
|
|
string json = att.ToJsonString();
|
|
apiConnection.SendPostRequestAsync("api/PWAttachment", json);
|
|
}
|
|
MessageBox.Show("Referral added successfully!");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(result);
|
|
}
|
|
this.Close();
|
|
}
|
|
catch(Source.DataObjects.Referral.InvalidReferalDataException)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
//AddImage Button
|
|
private void Button_Click_2(object sender, RoutedEventArgs e)
|
|
{
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
openFileDialog.Multiselect = true;
|
|
openFileDialog.Filter = "Image files (*.jpg,*.jpeg)|*.jpg;*.jpeg";
|
|
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
|
|
|
|
if(openFileDialog.ShowDialog() == true)
|
|
{
|
|
foreach (string filename in openFileDialog.FileNames)
|
|
{
|
|
try
|
|
{
|
|
images.Add(new Source.DataObjects.PWImage(filename));
|
|
}
|
|
catch(NullReferenceException)
|
|
{
|
|
images = new List<Source.DataObjects.PWImage>();
|
|
images.Add(new Source.DataObjects.PWImage(filename));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
try
|
|
{
|
|
ImageList.Items.Clear();
|
|
foreach (Source.DataObjects.PWImage image in images)
|
|
{
|
|
ImageList.Items.Add(CreateImageGridItem(image));
|
|
}
|
|
}
|
|
catch(NullReferenceException)
|
|
{ }
|
|
|
|
}
|
|
|
|
private void Button_Click_3(object sender, RoutedEventArgs e)
|
|
{
|
|
int index = ImageList.SelectedIndex;
|
|
if(index == -1)
|
|
{
|
|
return;
|
|
}
|
|
images.RemoveAt(index);
|
|
try
|
|
{
|
|
ImageList.Items.Clear();
|
|
foreach (Source.DataObjects.PWImage image in images)
|
|
{
|
|
ImageList.Items.Add(CreateImageGridItem(image));
|
|
}
|
|
}
|
|
catch (NullReferenceException)
|
|
{ }
|
|
}
|
|
|
|
public Grid CreateImageGridItem(Source.DataObjects.PWImage image)
|
|
{
|
|
Grid imageGrid = new Grid();
|
|
imageGrid.Width = 477;
|
|
imageGrid.HorizontalAlignment = HorizontalAlignment.Left;
|
|
imageGrid.VerticalAlignment = VerticalAlignment.Top;
|
|
imageGrid.ShowGridLines = true;
|
|
imageGrid.Background = new SolidColorBrush(Colors.LightSteelBlue);
|
|
|
|
ColumnDefinition imageColumn = new ColumnDefinition();
|
|
imageColumn.Width = new GridLength(50);
|
|
ColumnDefinition textColumn = new ColumnDefinition();
|
|
textColumn.Width = new GridLength(427);
|
|
|
|
imageGrid.ColumnDefinitions.Add(imageColumn);
|
|
imageGrid.ColumnDefinitions.Add(textColumn);
|
|
|
|
Image addedImage = new Image();
|
|
addedImage.Source = image.GetBitmapImage();
|
|
|
|
TextBlock text = new TextBlock();
|
|
text.Text = image.GetPath();
|
|
text.FontSize = 12;
|
|
|
|
|
|
Grid.SetColumn(addedImage, 0);
|
|
Grid.SetColumn(text, 1);
|
|
|
|
imageGrid.Children.Add(addedImage);
|
|
imageGrid.Children.Add(text);
|
|
return imageGrid;
|
|
|
|
}
|
|
}
|
|
}
|