Added support for PDFs and Images

This commit is contained in:
Matt Burke 2023-12-23 17:19:12 -05:00
parent 16a1c9a06f
commit 03e69393fc
8 changed files with 161 additions and 66 deletions

View File

@ -5,9 +5,7 @@ VisualStudioVersion = 17.7.34009.444
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PWAPPv2", "PWAPPv2\PWAPPv2.csproj", "{45E26AF8-41D7-4308-A2C8-D55A0350DB47}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PWAPPv2", "PWAPPv2\PWAPPv2.csproj", "{45E26AF8-41D7-4308-A2C8-D55A0350DB47}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PWAppUpdater", "PWAppUpdater\PWAppUpdater.csproj", "{B84B314C-C17A-42A3-BCAE-038F48343F5A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PWAppUpdaterForm", "PWAppUpdater2\PWAppUpdaterForm.csproj", "{093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PWAppUpdaterForm", "PWAppUpdater2\PWAppUpdaterForm.csproj", "{093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -19,10 +17,6 @@ Global
{45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Debug|Any CPU.Build.0 = Debug|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.ActiveCfg = Release|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.Build.0 = Release|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.Build.0 = Release|Any CPU
{B84B314C-C17A-42A3-BCAE-038F48343F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B84B314C-C17A-42A3-BCAE-038F48343F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B84B314C-C17A-42A3-BCAE-038F48343F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B84B314C-C17A-42A3-BCAE-038F48343F5A}.Release|Any CPU.Build.0 = Release|Any CPU
{093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Debug|Any CPU.Build.0 = Debug|Any CPU {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Release|Any CPU.ActiveCfg = Release|Any CPU {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -38,7 +38,7 @@ namespace PWAPPv2
Source.Patient patient; Source.Patient patient;
List<Source.DataObjects.PWImage> images; List<Source.DataObjects.Attachment> attachments;
//string ConfigPath = "C:\\PWAPP\\Config\\Config.xml"; //string ConfigPath = "C:\\PWAPP\\Config\\Config.xml";
@ -53,21 +53,21 @@ namespace PWAPPv2
} }
catch (Exception) catch (Exception)
{ } { }
ConfigPath = "C:\\PWAPP\\Config\\";
try try
{ {
//ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//ConfigPath = Path.Combine(ConfigPath, "PWAPP\\Config\\"); //ConfigPath = Path.Combine(ConfigPath, "PWAPP\\Config\\");
ConfigPath = "C:\\PWAPP\\Config\\";
practiceConfig = new Source.Config.Configuration(ConfigPath + "PracticeConfig.xml");
universalConfig = new Source.Config.Configuration(ConfigPath + "UniversalConfig.xml"); practiceConfig = new Source.Config.Configuration("C:\\PWAPP\\Config\\PracticeConfig.xml");
universalConfig = new Source.Config.Configuration("C:\\PWAPP\\App\\Config\\UniversalConfig.xml");
} }
catch catch
(Exception) (Exception ex)
{ {
System.Windows.MessageBox.Show("An error has occured in the configurations files."); System.Windows.MessageBox.Show("An error has occured in the configurations files.\n(" + ex.Message + ")");
} }
pwapiConnection = new Source.API.PWApiConnection(practiceConfig, universalConfig); pwapiConnection = new Source.API.PWApiConnection(practiceConfig, universalConfig);
@ -89,8 +89,12 @@ namespace PWAPPv2
p.StartInfo.UseShellExecute = false; p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardError = true;
p.StartInfo.Arguments = args[0]; try
if(System.Environment.OSVersion.Version.Major >= 6) {
p.StartInfo.Arguments = args[0];
}
catch { }
if (System.Environment.OSVersion.Version.Major >= 6)
{ {
p.StartInfo.Verb = "runas"; p.StartInfo.Verb = "runas";
} }
@ -106,8 +110,7 @@ namespace PWAPPv2
try try
{ {
images = new List<Source.DataObjects.PWImage>(); attachments = new List<Source.DataObjects.Attachment>();
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(practiceConfig); Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(practiceConfig);
@ -207,7 +210,8 @@ namespace PWAPPv2
private void Button_Click_1(object sender, RoutedEventArgs e) private void Button_Click_1(object sender, RoutedEventArgs e)
{ {
Source.DataObjects.Referral referral; Source.DataObjects.Referral referral;
if (images.Count == 0)
if (attachments.Count == 0)
{ {
referral = new Source.DataObjects.Referral(apiCreds, patient, referral = new Source.DataObjects.Referral(apiCreds, patient,
(Source.DataObjects.ReferralTypeBox)TypeBox, (Source.DataObjects.ReferralTypeBox)TypeBox,
@ -224,17 +228,20 @@ namespace PWAPPv2
fieldRemakrs, contact, true); fieldRemakrs, contact, true);
} }
try try
{ {
string referralString = referral.ToJsonString(); string referralString = referral.ToJsonString();
string result = pwapiConnection.SendReferral(referralString); //apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString); string result = pwapiConnection.SendReferral(referralString);
if (images.Count > 0)
if (attachments.Count > 0)
{ {
foreach (Source.DataObjects.PWImage im in images) foreach (Source.DataObjects.Attachment attachment in attachments)
{ {
Source.DataObjects.Attachment att = new Source.DataObjects.Attachment(apiCreds, im, result); attachment.Token = result;
string json = att.ToJsonString(); string json = attachment.ToJsonString();
apiConnection.SendPostRequestAsync("api/PWAttachment", json); apiConnection.SendPostWithCredsInHeader("api/PWAttachment", json);
} }
} }
@ -253,21 +260,41 @@ namespace PWAPPv2
{ {
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Multiselect = true; openFileDialog.Multiselect = true;
openFileDialog.Filter = "Image files (*.jpg,*.jpeg)|*.jpg;*.jpeg"; openFileDialog.Filter = "Attachment files (*.jpg,*.jpeg,*.pdf)|*.jpg;*.jpeg;*.pdf";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
foreach (string filename in openFileDialog.FileNames) foreach (string filename in openFileDialog.FileNames)
{ {
try if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".jpeg")
{ {
images.Add(new Source.DataObjects.PWImage(filename)); try
{
attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename)));
}
catch (NullReferenceException)
{
attachments = new List<Source.DataObjects.Attachment>
{
new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename))
};
}
} }
catch (NullReferenceException) if (Path.GetExtension(filename) == ".pdf")
{ {
images = new List<Source.DataObjects.PWImage>(); try
images.Add(new Source.DataObjects.PWImage(filename)); {
attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename)));
}
catch (NullReferenceException)
{
attachments = new List<Source.DataObjects.Attachment>()
{
new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename))
};
}
} }
} }
@ -276,9 +303,17 @@ namespace PWAPPv2
try try
{ {
ImageList.Items.Clear(); ImageList.Items.Clear();
foreach (Source.DataObjects.PWImage image in images)
foreach (var attachment in attachments)
{ {
ImageList.Items.Add(CreateImageGridItem(image)); if (attachment.image == null)
{
ImageList.Items.Add(CreateImageGridItem(new Source.DataObjects.PWImage("C:\\PWAPP\\App\\App\\pdf.jpg")));
}
else
{
ImageList.Items.Add(CreateImageGridItem(attachment.image));
}
} }
} }
catch (NullReferenceException) catch (NullReferenceException)
@ -293,13 +328,22 @@ namespace PWAPPv2
{ {
return; return;
} }
images.RemoveAt(index);
attachments.RemoveAt(index);
try try
{ {
ImageList.Items.Clear(); ImageList.Items.Clear();
foreach (Source.DataObjects.PWImage image in images)
foreach (var attachment in attachments)
{ {
ImageList.Items.Add(CreateImageGridItem(image)); if (attachment.image == null)
{
ImageList.Items.Add(CreateImageGridItem(new Source.DataObjects.PWImage("C:\\PWAPP\\App\\App\\pdf.jpg")));
}
else
{
ImageList.Items.Add(CreateImageGridItem(attachment.image));
}
} }
} }
catch (NullReferenceException) catch (NullReferenceException)

View File

@ -224,6 +224,7 @@
<Compile Include="Source\DataObjects\PWImage.cs" /> <Compile Include="Source\DataObjects\PWImage.cs" />
<Compile Include="Source\DataObjects\NumValList.cs" /> <Compile Include="Source\DataObjects\NumValList.cs" />
<Compile Include="Source\DataObjects\NumValPair.cs" /> <Compile Include="Source\DataObjects\NumValPair.cs" />
<Compile Include="Source\DataObjects\PWPdf.cs" />
<Compile Include="Source\DataObjects\ReferFromBox.cs" /> <Compile Include="Source\DataObjects\ReferFromBox.cs" />
<Compile Include="Source\DataObjects\Referral.cs" /> <Compile Include="Source\DataObjects\Referral.cs" />
<Compile Include="Source\DataObjects\ReferralTypeBox.cs" /> <Compile Include="Source\DataObjects\ReferralTypeBox.cs" />

View File

@ -27,6 +27,10 @@ namespace PWAPPv2.Source.API
Client.BaseAddress = new Uri(BaseURL); Client.BaseAddress = new Uri(BaseURL);
Client.DefaultRequestHeaders.Accept.Add( Client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json")); new MediaTypeWithQualityHeaderValue("application/json"));
Client.DefaultRequestHeaders.Add("UserID", Credentials.UserID);
Client.DefaultRequestHeaders.Add("Password", Credentials.Password);
Client.DefaultRequestHeaders.Add("PracticeID", Credentials.PracticeId);
Client.DefaultRequestHeaders.Add("ApiID", Credentials.APIid);
} }
@ -94,20 +98,17 @@ namespace PWAPPv2.Source.API
/// <exception cref="RequestFailedExcpetion"></exception> /// <exception cref="RequestFailedExcpetion"></exception>
public string SendPostWithCredsInHeader(string apiUri, string PostData) public string SendPostWithCredsInHeader(string apiUri, string PostData)
{ {
Client.DefaultRequestHeaders.Add("UserID", Credentials.UserID);
Client.DefaultRequestHeaders.Add("Password", Credentials.Password);
Client.DefaultRequestHeaders.Add("PracticeID", Credentials.PracticeId);
Client.DefaultRequestHeaders.Add("ApiID", Credentials.APIid);
StringContent content = new StringContent(PostData, Encoding.UTF8, "application/json"); StringContent content = new StringContent(PostData, Encoding.UTF8, "application/json");
string conts = content.ToString(); string conts = content.ToString();
var response = Client.PostAsync(apiUri, content).Result; var response = Client.PostAsync(apiUri, content).Result;
Client.DefaultRequestHeaders.Remove("UserID"); //Client.DefaultRequestHeaders.Remove("UserID");
Client.DefaultRequestHeaders.Remove("Password"); //Client.DefaultRequestHeaders.Remove("Password");
Client.DefaultRequestHeaders.Remove("PraticeID"); //Client.DefaultRequestHeaders.Remove("PraticeID");
Client.DefaultRequestHeaders.Remove("ApiID"); //Client.DefaultRequestHeaders.Remove("ApiID");
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {

View File

@ -3,32 +3,59 @@
class Attachment class Attachment
{ {
APICredentials Credentials; APICredentials Credentials;
PWImage image; public PWImage image { get; set; }
public PWPdf pdf { get; set; }
public string Token;
string Token; private string fileType { get; set; }
public Attachment(APICredentials credentials, PWImage pwImage)
public Attachment(APICredentials credentials, PWImage pwImage, string token)
{ {
Credentials = credentials; Credentials = credentials;
image = pwImage; image = pwImage;
Token = token; //Token = token;
pdf = null;
fileType = "image/jpeg";
}
public Attachment(APICredentials credentials, PWPdf pwPdf)
{
Credentials = credentials;
pdf = pwPdf;
image = null;
fileType = "application/pdf";
} }
public string ToJsonString() public string ToJsonString()
{ {
return "\"{" + Credentials.BuildJsonBodyContents() + if (fileType == "image/jpeg")
",'UserNum':'API'," + {
"'AttToken':'" + Token.Replace("\"", "") + "'," + return "\"{" + Credentials.BuildJsonBodyContents() +
"'FileName':'" + image.ShortFileName() + "'," + ",'UserNum':'API'," +
"'ContentType':'_1'," + "'AttToken':'" + Token.Replace("\"", "") + "'," +
"'ThumbExists':'1'," + "'FileName':'" + image.ShortFileName() + "'," +
"'ZoomExists':'1'," + "'ThumbExists':'1'," +
"'FileDate':''," + "'ZoomExists':'1'," +
"'Base64FileContents':'" + image.GetBase64String() + "',\n" + "'FileDate':''," +
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" + "'FileType':'" + fileType + "'," +
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\""; "'Base64FileContents':'" + image.GetBase64String() + "',\n" +
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
}
else
{
return "\"{" + Credentials.BuildJsonBodyContents() +
",'UserNum':'API'," +
"'AttToken':'" + Token.Replace("\"", "") + "'," +
"'FileName':'" + pdf.ShortFileName() + "'," +
"'ThumbExists':'0'," +
"'ZoomExists':'0'," +
"'FileDate':''," +
"'FileType':'" + fileType + "'," +
"'Base64FileContents':'" + pdf.GetBase64String() + "',\n" +
"'Base64ThumbContents':'',\n" +
"'Base64ZoomContents':''}\"";
}
} }
} }
} }

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.DataObjects
{
public class PWPdf
{
public string path;
public PWPdf(string path)
{
this.path = path;
}
public string GetBase64String()
{
byte[] bytes = File.ReadAllBytes(path);
return Convert.ToBase64String(bytes);
}
public string ShortFileName()
{
return path.Substring(path.LastIndexOf("\\") + 1);
}
}
}

View File

@ -20,6 +20,7 @@ namespace PWAppUpdater2
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
Directory.SetCurrentDirectory("C:\\PWAPP");
label1.Text = "Updating.... Please wait."; label1.Text = "Updating.... Please wait.";
label1.Update(); label1.Update();
progressBar1.Maximum = 8; progressBar1.Maximum = 8;
@ -27,7 +28,7 @@ namespace PWAppUpdater2
button1.Enabled = false; button1.Enabled = false;
try try
{ {
PWAppUpdater.Updater.Update("C:\\PWAPP\\App\\", progressBar1, StepInfo, "C:\\PWAPP\\Temp\\"); PWAppUpdater.Updater.Update("C:\\PWAPP\\App", progressBar1, StepInfo, "C:\\PWAPP\\Temp");
} }
catch (NoAuthException) catch (NoAuthException)
{ {

View File

@ -38,10 +38,6 @@ namespace PWAppUpdater
progress.PerformStep(); progress.PerformStep();
stepInfo.Text = "Removing old installation..."; stepInfo.Text = "Removing old installation...";
stepInfo.Update(); stepInfo.Update();
if (Directory.Exists(installPath))
{
Directory.Delete(installPath, true);
}
progress.PerformStep(); progress.PerformStep();
stepInfo.Text = "Creating new install directory..."; stepInfo.Text = "Creating new install directory...";
stepInfo.Update(); stepInfo.Update();