Modified how attachments are pushed to the API.

Added support for BMP and GIF image types.
This commit is contained in:
goomatt33 2024-03-25 13:21:14 -04:00
parent f31302438d
commit 205b3d8014
10 changed files with 202 additions and 17 deletions

View File

@ -59,11 +59,22 @@ namespace PWAPPv2
SupportedImageTypes.Add(".jpeg");
SupportedImageTypes.Add(".jpg");
SupportedImageTypes.Add(".png");
SupportedImageTypes.Add(".gif");
SupportedImageTypes.Add(".bmp");
try
{
args = App.Args;
if(args.Length == 0)
{
throw new NoArgumentsException();
}
}
catch (NoArgumentsException)
{
System.Windows.MessageBox.Show("No Patient ID was selected.\nPlease select a patient and retry the referral.");
return;
}
catch (Exception)
{ }
@ -431,4 +442,9 @@ namespace PWAPPv2
}
}
public class NoArgumentsException : Exception
{
}
}

View File

@ -230,6 +230,8 @@
<Compile Include="Source\Attachments\AttachmentFactory.cs" />
<Compile Include="Source\Attachments\FileHandler.cs" />
<Compile Include="Source\Attachments\PWAttachment.cs" />
<Compile Include="Source\Attachments\PWBaseAttachment.cs" />
<Compile Include="Source\Attachments\PWFileUpload.cs" />
<Compile Include="Source\Config\Configuration.cs" />
<Compile Include="Source\Database\DatabaseConfig.cs" />
<Compile Include="Source\Database\DatabaseConnection.cs" />
@ -237,6 +239,7 @@
<Compile Include="Source\DataObjects\Attachment.cs" />
<Compile Include="Source\DataObjects\ComboBoxData.cs" />
<Compile Include="Source\DataObjects\Exceptions.cs" />
<Compile Include="Source\DataObjects\PWFile.cs" />
<Compile Include="Source\DataObjects\PWImage.cs" />
<Compile Include="Source\DataObjects\NumValList.cs" />
<Compile Include="Source\DataObjects\NumValPair.cs" />

View File

@ -1,4 +1,5 @@
using PWAPPv2.Source.DataObjects;
using Microsoft.Identity.Client;
using PWAPPv2.Source.DataObjects;
using System;
using System.Collections.Generic;
using System.Linq;
@ -49,5 +50,29 @@ namespace PWAPPv2.Source.Attachments
return attachment;
}
public static PWBaseAttachment BuildBaseAttachment(string token, PWImage image)
{
PWBaseAttachment attachment = new PWBaseAttachment();
attachment.AttToken = token.Replace("\"", "");
attachment.ThumbExists = true;
attachment.ZoomExists = true;
attachment.FileDate = "";
attachment.FileName = image.ShortFileName();
attachment.FileType = image.FileType;
return attachment;
}
public static PWBaseAttachment BuildBaseAttachment(string token, PWPdf pdf)
{
PWBaseAttachment attachment = new PWBaseAttachment();
attachment.AttToken = token.Replace("\"", "");
attachment.ThumbExists = false;
attachment.ZoomExists = true;
attachment.FileDate = "";
attachment.FileName = pdf.ShortFileName();
attachment.FileType = "application/pdf";
return attachment;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.Attachments
{
public class AttachmentResponse
{
}
}

View File

@ -37,7 +37,10 @@ namespace PWAPPv2.Source.Attachments
SupportedImageTypes.Add(".jpeg");
SupportedImageTypes.Add(".jpg");
SupportedImageTypes.Add(".png");
//SupportedImageTypes.Add(".tiff");
SupportedImageTypes.Add(".tiff");
SupportedImageTypes.Add(".tif");
SupportedImageTypes.Add(".gif");
SupportedImageTypes.Add(".bmp");
SupportedDocumentTypes.Clear();
SupportedDocumentTypes.Add(".pdf");
@ -108,23 +111,50 @@ namespace PWAPPv2.Source.Attachments
}
foreach(DataObjects.Attachment attachment in Attachments)
{
PWAttachment att = null;
//PWAttachment att = null;
PWBaseAttachment ba = null;
List<PWFileUpload> fileUploads = new List<PWFileUpload>();
if (attachment.image != null)
{
att = AttachmentFactory.BuildAttachment(credentials, token, attachment.image);
//att = AttachmentFactory.BuildAttachment(credentials, token, attachment.image);
ba = AttachmentFactory.BuildBaseAttachment(token, attachment.image);
//fileUploads.Add(attachment.image.GetFileUploads(attachment.co))
string json = JsonSerializer.Serialize(ba);
string contId = connection.SendPostWithCredsInHeader("api/PWAddAttachment", json);
contId = contId.Replace("\"", "").Replace("\\n", "").Trim();
fileUploads = attachment.image.GetFileUploads(token, contId);
foreach(PWFileUpload file in fileUploads)
{
json = JsonSerializer.Serialize(file);
connection.SendPostWithCredsInHeader("api/PWUploadFile", json);
}
}
else if (attachment.pdf != null)
{
att = AttachmentFactory.BuildAttachment(credentials, token, attachment.pdf);
//att = AttachmentFactory.BuildAttachment(credentials, token, attachment.pdf);
ba = AttachmentFactory.BuildBaseAttachment(token, attachment.pdf);
string json = JsonSerializer.Serialize(ba);
string contId = connection.SendPostWithCredsInHeader("api/PWAddAttachment", json);
fileUploads = attachment.pdf.GetFileUploads(token, contId);
foreach (PWFileUpload file in fileUploads)
{
json = JsonSerializer.Serialize(file);
connection.SendPostWithCredsInHeader("api/PWUploadFile", json);
}
}
if (att == null)
{
throw new AttachmentTypeNotYetSupportedException();
}
string json = JsonSerializer.Serialize(att);
connection.SendPostWithCredsInHeader("api/PWAttachment", json);
//if (att == null)
//{
// throw new AttachmentTypeNotYetSupportedException();
//}
//string json = JsonSerializer.Serialize(att);
//connection.SendPostWithCredsInHeader("api/PWAttachment", json);
//json = JsonSerializer.Serialize(ba);
//connection.SendPostWithCredsInHeader("api/PWAddAttachment", json);
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.Attachments
{
public class PWBaseAttachment
{
public string AttToken { get; set; }
public string FileName { get; set; }
public bool ThumbExists { get; set; }
public bool ZoomExists { get; set; }
public string FileDate { get; set; }
public string FileType { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.Attachments
{
public class PWFileUpload
{
public string Base64Content { get; set; }
public string AttToken { get; set; }
public string ContentId { get; set; }
public string Tag { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.DataObjects
{
interface PWFile
{
List<Attachments.PWFileUpload> GetFileUploads(string attToken, string ContentId);
}
}

View File

@ -1,11 +1,14 @@
using System;
using PWAPPv2.Source.Attachments;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
namespace PWAPPv2.Source.DataObjects
{
public class PWImage
public class PWImage : PWFile
{
private string ImagePath;
@ -30,14 +33,26 @@ namespace PWAPPv2.Source.DataObjects
string extension = Path.GetExtension(path).ToLower();
if(extension == ".jpeg" || extension == ".jpg")
if (extension == ".jpeg" || extension == ".jpg")
{
FileType = "image/jpeg";
}
else if(extension == ".png")
else if (extension == ".png")
{
FileType = "image/png";
}
else if (extension == ".tiff" || extension == ".tif")
{
FileType = "image/tiff";
}
else if(extension == ".gif")
{
FileType = "image/gif";
}
else if(extension == ".bmp")
{
FileType = "image/bmp";
}
//bmp = (Bitmap)System.Drawing.Image.FromFile(ImagePath);
//thumb = resize(bmp, 50, 50);
@ -118,5 +133,29 @@ namespace PWAPPv2.Source.DataObjects
return str;
}
public List<PWFileUpload> GetFileUploads(string attToken, string ContentId)
{
List<PWFileUpload> fileUploads = new List<PWFileUpload>();
PWFileUpload baseImage = new PWFileUpload();
baseImage.ContentId = ContentId;
baseImage.Base64Content = GetBase64String();
baseImage.AttToken = attToken;
PWFileUpload zoom = new PWFileUpload();
zoom.Base64Content = GetBase64ZoomString();
zoom.ContentId = ContentId;
zoom.Tag = "_zoom";
zoom.AttToken = attToken;
PWFileUpload thumb = new PWFileUpload();
thumb.Base64Content= GetBase64ThumbString();
thumb.ContentId = ContentId;
thumb.Tag = "_th";
thumb.AttToken = attToken;
fileUploads.Add(baseImage);
fileUploads.Add(zoom);
fileUploads.Add(thumb);
return fileUploads;
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using PWAPPv2.Source.Attachments;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -7,7 +8,7 @@ using System.Threading.Tasks;
namespace PWAPPv2.Source.DataObjects
{
public class PWPdf
public class PWPdf : PWFile
{
public string path;
@ -23,6 +24,17 @@ namespace PWAPPv2.Source.DataObjects
return Convert.ToBase64String(bytes);
}
public List<PWFileUpload> GetFileUploads(string attToken, string ContentId)
{
List<PWFileUpload> fileUploads = new List<PWFileUpload>();
PWFileUpload file = new PWFileUpload();
file.Base64Content = GetBase64String();
file.ContentId = ContentId;
file.AttToken = attToken;
fileUploads.Add(file);
return fileUploads;
}
public string ShortFileName()
{
return path.Substring(path.LastIndexOf("\\") + 1);