private List <AnalysisRequestReportModel> GetReportDatasource(DataLibrary.Models.ReportModels.AnalysisRequestReportModel reportModel) { //map AnalysisRequestReport var report = new AnalysisRequestReportModel() { SampleSite = reportModel.SampleSite, CollectedDate = reportModel.CollectedDate, ReceivedDate = reportModel.ReceivedDate, EpisodeNumber = reportModel.EpisodeNumber, QcCalValidatedBy = reportModel.QcCalValidatedBy, ReportedAt = reportModel.ReportedAt, ReceivedBy = reportModel.ReceivedBy, AnalysedBy = reportModel.AnalysedBy, InstituteAssignedPatientId = reportModel.InstituteAssignedPatientId, SampleProcessedAt = reportModel.SampleProcessedAt }; //Map patient var patient = new Patient() { NidPp = reportModel.Patient.NidPp.Trim(), Fullname = reportModel.Patient.Fullname.Trim(), AgeSex = reportModel.Patient.AgeSex, Birthdate = reportModel.Patient.Birthdate, Address = reportModel.Patient.Address, Nationality = reportModel.Patient.Nationality }; //map Assays var assays = new BindingList <Assays>(); foreach (var assay in reportModel.Assays) { assays.Add(new Assays() { Cin = assay.Cin, Discipline = assay.Discipline, Assay = assay.Assay, Result = assay.Result, Unit = assay.Unit, DisplayNormalRange = assay.DisplayNormalRange, Comment = assay.Comment, SortOrder = assay.SortOrder, PrimaryHeader = assay.PrimaryHeader, SecondaryHeader = assay.SecondaryHeader }); } //add patient and assays to report report.Assays = assays; report.Patient = patient; report.PrintedDate = DateTime.Now.ToString("dd-MM-yyyy HH:mm"); //add report to a list of reports to make it compatible as datasource var reportDatasource = new List <AnalysisRequestReportModel>(); report.SetPdf417String(); reportDatasource.Add(report); return(reportDatasource); }
private void MapDataToReport(DataLibrary.Models.ReportModels.AnalysisRequestReportModel reportModel) { //Show a message if no results are validated for the analysis request. if (reportModel is null) { XtraMessageBox.Show("No results validated for the selected analysis request.\nCannot generate report."); DisposeMe(); return; } //ReportTemplates[0] The ZERO need to be handled dynamically to be truly extensible var xtraReport = _reportExtensions.ReportTemplates[0] .Execute((ReportTemplate)_cinAndReportId.ReportIndex, GetReportDatasource(reportModel)); xtraReport.RequestParameters = false; xtraReport.DisplayName = $"{Tag}_{RemoveInvalidCharactersForExport(reportModel.Patient.Fullname)} ({RemoveInvalidCharactersForExport(reportModel.Patient.NidPp)}"; #if DEBUG xtraReport.DrawWatermark = true; #endif if (_cinAndReportId.Action == ReportActionModel.Export) { var settings = new Properties.Settings(); string exportDirectoryStructure = $"{DateTime.Today:yyyy}\\{DateTime.Today:MMMM}\\{DateTime.Today:dd}\\{reportModel.SampleSite.Trim()}"; var exportDirPath = $"{settings.ReportExportBasePath}\\{exportDirectoryStructure}"; try { ExportReport(xtraReport, exportDirPath); } catch (Exception ex) { XtraMessageBox.Show($"Error exporting report. Please fing the details below.\n{ex.Message}\n{ex.StackTrace}\nExport path: {exportDirPath}"); //prompt for user to select a temp export path var folderBrowserDialog = new XtraFolderBrowserDialog(); // Show the FolderBrowserDialog. DialogResult result = folderBrowserDialog.ShowDialog(); if (result == DialogResult.OK) { exportDirPath = $"{folderBrowserDialog.SelectedPath}\\{exportDirectoryStructure}"; ExportReport(xtraReport, exportDirPath); } } } if (_cinAndReportId.Action == ReportActionModel.Print) { xtraReport.PrinterName = "DocumentPrinter"; xtraReport.CreateDocument(); xtraReport.Print(); } //Close this form DisposeMe(); }