diff --git a/PWAPPv2/MainWindow.xaml b/PWAPPv2/MainWindow.xaml
index 2173944..57a5183 100644
--- a/PWAPPv2/MainWindow.xaml
+++ b/PWAPPv2/MainWindow.xaml
@@ -94,9 +94,10 @@
-
-
+
+
+
diff --git a/PWAPPv2/MainWindow.xaml.cs b/PWAPPv2/MainWindow.xaml.cs
index 7901146..2e7c7ce 100644
--- a/PWAPPv2/MainWindow.xaml.cs
+++ b/PWAPPv2/MainWindow.xaml.cs
@@ -12,6 +12,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using System.IO;
+using Microsoft.Win32;
/**
* TODO:
@@ -39,6 +41,8 @@ namespace PWAPPv2
Source.Patient patient;
+ List images;
+
public MainWindow()
{
try
@@ -48,6 +52,8 @@ namespace PWAPPv2
catch(Exception)
{ }
+ images = new List();
+
apiconfig.LoadConfig("./Config/Config.xml");
DataConfig = new Source.Database.DatabaseConfig("./Config/Config.xml");
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig);
@@ -130,23 +136,51 @@ namespace PWAPPv2
}
}
+ //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 = new Source.DataObjects.Referral(apiCreds, patient,
- (Source.DataObjects.ReferralTypeBox)TypeBox,
- (Source.DataObjects.ReferToBox)ToBox,
- (Source.DataObjects.ReferFromBox)FromBox,
- fieldRemakrs, contact);
+ 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);
- MessageBox.Show(result);
+ 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)
@@ -154,5 +188,97 @@ namespace PWAPPv2
}
}
+
+ //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();
+ 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;
+
+ }
}
}
diff --git a/PWAPPv2/PWAPPv2.csproj b/PWAPPv2/PWAPPv2.csproj
index 3fa3d88..5f2858b 100644
--- a/PWAPPv2/PWAPPv2.csproj
+++ b/PWAPPv2/PWAPPv2.csproj
@@ -210,14 +210,17 @@
MSBuild:Compile
Designer
+
+
+
diff --git a/PWAPPv2/PwImage.cs b/PWAPPv2/PwImage.cs
new file mode 100644
index 0000000..6b5f444
--- /dev/null
+++ b/PWAPPv2/PwImage.cs
@@ -0,0 +1,6 @@
+namespace PWAPPv2
+{
+ internal class PwImage
+ {
+ }
+}
\ No newline at end of file
diff --git a/PWAPPv2/Source/DataObjects/Attachment.cs b/PWAPPv2/Source/DataObjects/Attachment.cs
new file mode 100644
index 0000000..2ef9eec
--- /dev/null
+++ b/PWAPPv2/Source/DataObjects/Attachment.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PWAPPv2.Source.DataObjects
+{
+ class Attachment
+ {
+ APICredentials Credentials;
+ PWImage image;
+
+ string Token;
+
+
+ public Attachment(APICredentials credentials, PWImage pwImage, string token)
+ {
+ Credentials = credentials;
+ image = pwImage;
+ Token = token;
+ }
+
+ public string ToJsonString()
+ {
+ return "\"{" + Credentials.BuildJsonBodyContents() +
+ ",'UserNum':'API'," +
+ "'AttToken':'" + Token.Replace("\"", "") + "'," +
+ "'FileName':'" + image.ShortFileName() + "'," +
+ "'ContentType':'_1'," +
+ "'ThumbExists':'1'," +
+ "'ZoomExists':'1'," +
+ "'FileDate':''," +
+ "'Base64FileContents':'" + image.GetBase64String() + "',\n" +
+ "'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
+ "'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
+ }
+
+ }
+}
diff --git a/PWAPPv2/Source/DataObjects/PWImage.cs b/PWAPPv2/Source/DataObjects/PWImage.cs
new file mode 100644
index 0000000..30ad628
--- /dev/null
+++ b/PWAPPv2/Source/DataObjects/PWImage.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+using System.Windows.Media;
+using System.Drawing;
+using System.IO;
+
+namespace PWAPPv2.Source.DataObjects
+{
+ public class PWImage
+ {
+
+ private string ImagePath;
+
+ private BitmapImage bitmap;
+
+
+ //private Bitmap bmp;
+ //private Bitmap thumb;
+ //private Bitmap zoom;
+ public PWImage(string path)
+ {
+ ImagePath = path;
+ bitmap = new BitmapImage();
+
+ bitmap.BeginInit();
+ bitmap.UriSource = new Uri(@ImagePath);
+ bitmap.DecodePixelWidth = 100;
+ bitmap.EndInit();
+
+ //bmp = (Bitmap)System.Drawing.Image.FromFile(ImagePath);
+ //thumb = resize(bmp, 50, 50);
+ //zoom = resize(bmp, bmp.Width, bmp.Height);
+
+ }
+
+ public string GetPath()
+ {
+ return ImagePath;
+ }
+
+ public BitmapImage GetBitmapImage()
+ {
+ return bitmap;
+ }
+
+ public string GetBase64String()
+ {
+ using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
+ {
+ using (MemoryStream m = new MemoryStream())
+ {
+ image.Save(m, image.RawFormat);
+ byte[] imageBytes = m.ToArray();
+
+ return Convert.ToBase64String(imageBytes);
+ }
+ }
+ }
+
+ public string GetBase64ThumbString()
+ {
+ using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
+ {
+ Image thumb = resize(image, new Size(50, 50));
+ using (MemoryStream m = new MemoryStream())
+ {
+ thumb.Save(m, image.RawFormat);
+ byte[] imageBytes = m.ToArray();
+
+ return Convert.ToBase64String(imageBytes);
+ }
+ }
+ }
+
+ public string GetBase64ZoomString()
+ {
+ using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
+ {
+ Image zoom = resize(image, new Size(image.Width + 800, image.Height + 800));
+ using (MemoryStream m = new MemoryStream())
+ {
+ zoom.Save(m, image.RawFormat);
+ byte[] imageBytes = m.ToArray();
+
+ return Convert.ToBase64String(imageBytes);
+ }
+ }
+ }
+
+ private Image resize(Image toResize, Size size)
+ {
+ return new Bitmap(toResize, size);
+ }
+
+ public string ShortFileName()
+ {
+ return ImagePath.Substring(ImagePath.LastIndexOf("\\") + 1);
+ }
+
+ }
+}
diff --git a/PWAPPv2/Source/DataObjects/Referral.cs b/PWAPPv2/Source/DataObjects/Referral.cs
index 1398690..9a5458a 100644
--- a/PWAPPv2/Source/DataObjects/Referral.cs
+++ b/PWAPPv2/Source/DataObjects/Referral.cs
@@ -20,7 +20,9 @@ namespace PWAPPv2.Source.DataObjects
RichTextBox RemarksBox;
CheckBox ContactBox;
- public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox)
+ bool Attachments;
+
+ public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox, bool attachments)
{
ApiCredentials = apiCredentials;
PatientData = patient;
@@ -29,6 +31,7 @@ namespace PWAPPv2.Source.DataObjects
ReferFrom = referFrom;
RemarksBox = remarksBox;
ContactBox = contactBox;
+ Attachments = attachments;
}
public string ToJsonString()
@@ -41,7 +44,11 @@ namespace PWAPPv2.Source.DataObjects
{
contact = 1;
}
-
+
+ string attachmentsText = "False";
+ if (Attachments)
+ attachmentsText = "True";
+
try
{
return "\"{" + ApiCredentials.BuildJsonBodyContents() + "," +
@@ -61,7 +68,7 @@ namespace PWAPPv2.Source.DataObjects
"'SubmittedBy':'" + ReferFrom.GetSelectedID() + "'," +
"'ToPracticeId':'" + ReferTo.GetSelectedPracticeID() + "'," +
"'ToDoctorID':'" + ReferTo.GetSelectedDoctorID() + "'," +
- "'Attachments':'False'," +
+ "'Attachments':'" + attachmentsText + "'," +
"'Remarks':'" + RemarksText + "'," +
"'Contact':'" + contact + "'}\"";
}