From c9b5ee3355036f80cb181f331357f3c70c2e9f9c Mon Sep 17 00:00:00 2001 From: Veena Date: Fri, 28 Aug 2020 09:50:01 +0530 Subject: [PATCH] TMH | Zafar, Veena | Resolves codacy issues --- src/In.ProjectEKA.TMHHip/DataFlow/Collect.cs | 43 +++++++++---------- .../DiagnosticReportEndpointRepresentation.cs | 2 +- .../DataFlow/CollectTest.cs | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/In.ProjectEKA.TMHHip/DataFlow/Collect.cs b/src/In.ProjectEKA.TMHHip/DataFlow/Collect.cs index e19a2a787..7998a8d5a 100644 --- a/src/In.ProjectEKA.TMHHip/DataFlow/Collect.cs +++ b/src/In.ProjectEKA.TMHHip/DataFlow/Collect.cs @@ -169,30 +169,32 @@ private static async Task> FetchDiagnosticRepor private static async Task> FetchDiagnosticReportPdfsData( DataRequest dataRequest, List diagnosticReportAsPdfs, string patientName) { + LogDataRequest(dataRequest); var uuid = Uuid.Generate().Value; var id = uuid.Split(":").Last(); - var representations = new List(); - foreach (var reportAsPdf in diagnosticReportAsPdfs) - { - var pdfText = new Text("additional", - "
Unstructured data can be sent here
"); - var code = new Code(reportAsPdf.ReportText); - var subject = new Subject(patientName); - var performer = new Performer(reportAsPdf.Performer); - 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}, - new List {presentedForm}, reportAsPdf.ReportConclusion); - representations.Add(new DiagnosticReportPdfRepresentation(uuid, pdfResource)); - } + var representations = (from reportAsPdf in diagnosticReportAsPdfs + where WithinRange(dataRequest.DateRange, reportAsPdf.EffectiveDateTime) + let pdfText = + new Text("additional", + "
Unstructured data can be sent here
") + let code = new Code(reportAsPdf.ReportText) + let subject = new Subject(patientName) + let performer = new Performer(reportAsPdf.Performer) + let presentedForm = + new PresentedForm(reportAsPdf.ContentType, PdfToBase64(reportAsPdf.ReportUrl), + reportAsPdf.ReportTitle) + select new DiagnosticReportPDFResource(HiType.DiagnosticReport, id, pdfText, "final", code, subject, + reportAsPdf.EffectiveDateTime, reportAsPdf.Issued, new List {performer}, + new List {presentedForm}, reportAsPdf.ReportConclusion) + into pdfResource + select new DiagnosticReportPdfRepresentation(uuid, pdfResource)).ToList(); if (!representations.Any()) { return Option.None(); } - var diagnosticReportResponse = new DiagnosticReportResponse() + var diagnosticReportResponse = new DiagnosticReportResponse { Entry = representations, Id = Uuid.Generate().Value.Split(":").Last(), @@ -649,12 +651,9 @@ private static void LogDataRequest(DataRequest request) private static string PdfToBase64(string pdfUrl) { - string base64String; - using (WebClient client = new WebClient()) - { - var bytes = client.DownloadData(pdfUrl); - base64String = Convert.ToBase64String(bytes); - } + using var webClient = new WebClient(); + var bytes = webClient.DownloadData(pdfUrl); + var base64String = Convert.ToBase64String(bytes); return base64String; } diff --git a/src/In.ProjectEKA.TMHHip/DataFlow/Model/DiagnosticReportEndpointRepresentation.cs b/src/In.ProjectEKA.TMHHip/DataFlow/Model/DiagnosticReportEndpointRepresentation.cs index 729a2687c..bb48093b7 100644 --- a/src/In.ProjectEKA.TMHHip/DataFlow/Model/DiagnosticReportEndpointRepresentation.cs +++ b/src/In.ProjectEKA.TMHHip/DataFlow/Model/DiagnosticReportEndpointRepresentation.cs @@ -48,7 +48,7 @@ public class PayloadType { private string Text { get; set; } - private PayloadType(string text) + public PayloadType(string text) { Text = text; } diff --git a/test/In.ProjectEKA.TMHHipTest/DataFlow/CollectTest.cs b/test/In.ProjectEKA.TMHHipTest/DataFlow/CollectTest.cs index 29a3ded63..b4aa19378 100644 --- a/test/In.ProjectEKA.TMHHipTest/DataFlow/CollectTest.cs +++ b/test/In.ProjectEKA.TMHHipTest/DataFlow/CollectTest.cs @@ -125,7 +125,7 @@ private async void ReturnDiagnosticReportAsPdf() var diagReports = new List {diagReport}; var patientDataResponse = - JsonConvert.SerializeObject(new PatientData() {DiagnosticReportAsPdf = diagReports}); + JsonConvert.SerializeObject(new PatientData {DiagnosticReportAsPdf = diagReports}); var patient = new Patient {