Skip to content

Commit

Permalink
TMH | Zafar, Veena | Adds utility to convert url containing pdf data …
Browse files Browse the repository at this point in the history
…to base 64 encoded string
  • Loading branch information
Veena-tw committed Aug 27, 2020
1 parent 130d1f5 commit f055fcc
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/In.ProjectEKA.TMHHip/DataFlow/Collect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace In.ProjectEKA.TMHHip.DataFlow
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -178,13 +179,14 @@ private static async Task<Option<DiagnosticReportResponse>> FetchDiagnosticRepor
var code = new Code(reportAsPdf.ReportText);
var subject = new Subject(patientName);
var performer = new Performer(reportAsPdf.Performer);
var presentedForm = new PresentedForm(reportAsPdf.ContentType, "", reportAsPdf.ReportTitle);
var presentedForm = new PresentedForm(reportAsPdf.ContentType, PdfToBase64(reportAsPdf.ReportUrl),
reportAsPdf.ReportTitle);
var pdfResource = new DiagnosticReportPDFResource(HiType.DiagnosticReport, id, pdfText, "final", code,
subject, reportAsPdf.EffectiveDateTime, reportAsPdf.Issued, new List<Performer> {performer},
new List<PresentedForm> {presentedForm}, reportAsPdf.ReportConclusion);
representations.Add(new DiagnosticReportPdfRepresentation(uuid,pdfResource));
representations.Add(new DiagnosticReportPdfRepresentation(uuid, pdfResource));
}

if (!representations.Any())
{
return Option.None<DiagnosticReportResponse>();
Expand Down Expand Up @@ -644,5 +646,17 @@ private static void LogDataRequest(DataRequest request)
$" To date:{request.DateRange.To}, " +
$"CallbackUrl:{request.DataPushUrl}");
}

private static string PdfToBase64(string pdfUrl)
{
string base64String;
using (WebClient client = new WebClient())
{
var bytes = client.DownloadData(pdfUrl);
base64String = Convert.ToBase64String(bytes);
}

return base64String;
}
}
}

0 comments on commit f055fcc

Please sign in to comment.