diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs index 2584078..cadbe00 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs @@ -27,8 +27,8 @@ internal class ChartReport try { new PdfBuilder(filePath) - .AddHeader("Пополенение лекарства") - .AddPieChart("Виды лекарства", GetData(dateTime)) + .AddHeader("Количество посещений пациентов") + .AddPieChart("Пациенты", GetData(dateTime)) .Build(); return true; } @@ -38,6 +38,7 @@ internal class ChartReport return false; } } + /* private List<(string Caption, double Value)> GetData(DateTime dateTime) { // Получаем все медицинские истории за указанную дату @@ -49,4 +50,31 @@ internal class ChartReport .Select(g => (Caption: $"Patient {g.Key}", Value: (double)g.Count())) .ToList(); } + */ + private List<(string Caption, double Value)> GetData(DateTime dateTime) + { + var medicalHistories = _medicalHistoryRepository.ReadMedicalHistory(null, null, null, null); + + var filteredHistories = medicalHistories + .Where(mh => mh.VisitDate.Date == dateTime.Date) + .Where(mh => mh.DrugMedicalHistory != null && mh.DrugMedicalHistory.Any()) + .ToList(); + var groupedData = filteredHistories + .GroupBy( + mh => mh.DoctorId, + (key, group) => new + { + DoctorId = key, + TotalDrugs = group + .SelectMany(mh => mh.DrugMedicalHistory) + .Count() + } + ) + .ToList(); + var result = groupedData + .Select(x => (x.DoctorId.ToString(), (double)x.TotalDrugs)) + .ToList(); + + return result; + } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/PdfBuilder.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/PdfBuilder.cs index e626ae0..0939123 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/PdfBuilder.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/PdfBuilder.cs @@ -26,38 +26,38 @@ internal class PdfBuilder } _filePath = filePath; _document = new Document(); - DefineStyles(); + DefineStyles(); // настройка стиля } - public PdfBuilder AddHeader(string header) + public PdfBuilder AddHeader(string header) // Заголовок, header - это текст заголовка { - _document.AddSection().AddParagraph(header, "NormalBold"); + _document.AddSection().AddParagraph(header, "NormalBold"); // документу добавляется секция добавляется параграф return this; } - public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) + public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data) // метод добавления диаграммы круговой { if (data == null || data.Count == 0) { return this; } - var chart = new Chart(ChartType.Pie2D); - var series = chart.SeriesCollection.AddSeries(); + var chart = new Chart(ChartType.Pie2D); + var series = chart.SeriesCollection.AddSeries(); // добавляем серию series.Add(data.Select(x => x.Value).ToArray()); - var xseries = chart.XValues.AddXSeries(); + var xseries = chart.XValues.AddXSeries(); // добавляем подписи xseries.Add(data.Select(x => x.Caption).ToArray()); - chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Type = DataLabelType.Percent; // вывод ввиде прицентов chart.DataLabel.Position = DataLabelPosition.OutsideEnd; - chart.Width = Unit.FromCentimeter(16); + chart.Width = Unit.FromCentimeter(16); // ширина и высота chart.Height = Unit.FromCentimeter(12); - chart.TopArea.AddParagraph(title); - chart.XAxis.MajorTickMark = TickMarkType.Outside; - chart.YAxis.MajorTickMark = TickMarkType.Outside; + chart.TopArea.AddParagraph(title); // заголовок добавляется + chart.XAxis.MajorTickMark = TickMarkType.Outside; // настраиваем где у нас будут подписи + chart.YAxis.MajorTickMark = TickMarkType.Outside; // настраиваем где у нас будут подписи chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; - chart.TopArea.AddLegend(); - _document.LastSection.Add(chart); + chart.TopArea.AddLegend(); // где у нас будет легенда + _document.LastSection.Add(chart); // в документ добавляем нашу таблицу return this; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs index 8abee14..393ea3e 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs @@ -22,7 +22,7 @@ internal class TableReport private readonly ILogger _logger; - internal static readonly string[] item = ["Дата", "Описание", "Количество пациентов"]; + internal static readonly string[] item = ["Id доктора", "Описание", "Количество пациентов"]; public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, ILogger logger) { @@ -70,15 +70,15 @@ internal class TableReport .Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId) ) .Select(x => new { - Date = x.VisitDate, + Date = x.DoctorId, CountIn = x.DrugMedicalHistory.FirstOrDefault(y => y.DrugId == drugId)?.Description, CountOut = (int?)null }) .Union( _doctorPaymentsRepository .ReadDoctorPayments() - .Where(x => x.DoctorPaymentData >= startDate && x.DoctorPaymentData <= endDate) - .Select(x => new {Date = x.DoctorPaymentData, CountIn = (string?)null, CountOut = (int?)x.Count_Patient })) + .Where(x => x.IdDoctor!=0) + .Select(x => new {Date = x.IdDoctor, CountIn = (string?)null, CountOut = (int?)x.Count_Patient })) .OrderBy(x => x.Date); @@ -87,7 +87,7 @@ internal class TableReport data .Select(x => new string[] {x.Date.ToString(), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) .Union( - new List() { new string[] { "Всего", data.Sum(x => x.CountOut ?? 0).ToString(), string.Empty } }) + new List() { new string[] { "Всего", string.Empty, data.Sum(x => x.CountOut ?? 0).ToString() } }) .ToList(); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/WordBuilder.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/WordBuilder.cs index ca72689..5f04319 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/WordBuilder.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/WordBuilder.cs @@ -38,11 +38,13 @@ internal class WordBuilder public WordBuilder AddHeader(string header) { - // код ставки заголовка - var paragraph = _body.AppendChild(new Paragraph()); - var run = paragraph.AppendChild(new Run()); + // код ставки заголовка в документ Word + var paragraph = _body.AppendChild(new Paragraph()); // в body добавляем новый элемент дочерний это будет параграф + var run = paragraph.AppendChild(new Run()); // добавление блока + // жирный шрифт var runProperties = run.AppendChild(new RunProperties()); runProperties.AppendChild(new Bold()); + // добавляем текст run.AppendChild(new Text(header)); return this; @@ -50,7 +52,7 @@ internal class WordBuilder public WordBuilder AddParagraph(string text) { - // код ставки заголовка + // код ставки параграфа var paragraph = _body.AppendChild(new Paragraph()); var run = paragraph.AppendChild(new Run()); @@ -59,7 +61,12 @@ internal class WordBuilder } public WordBuilder AddTable(int[] widths, List data) - { + { // int[] width - будет передаваться массив intов + // Табличка в Word состоит из 3-ех блоков + // 1-ый блок: свойство . Здесь будем задавать границы + // 2-ой блок: колонки или Grid там передадим информацию по колонкам, какие колонки и какая у каждого ширина + // 3-ий блок: строчки, заполняем строчки с данными + // widths - ширина колонок if (widths == null || widths.Length == 0) { throw new ArgumentNullException(nameof(widths)); @@ -68,13 +75,14 @@ internal class WordBuilder { throw new ArgumentNullException(nameof(data)); } - if (data.Any(x => x.Length != widths.Length)) + if (data.Any(x => x.Length != widths.Length)) // использьем LinQ метод Any { throw new InvalidOperationException("widths.Length != data.Length"); } - + // создаем таблицу + // 1-ый блок свойства var table = new Table(); - table.AppendChild(new TableProperties( + table.AppendChild(new TableProperties( // мы здесь задаем границы new TableBorders( new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 12 }, @@ -86,24 +94,26 @@ internal class WordBuilder )); // Заголовок + // идем заполнять строчки, var tr = new TableRow(); for (var j = 0; j < widths.Length; ++j) { - tr.Append(new TableCell( - new TableCellProperties(new TableCellWidth() + tr.Append(new TableCell( // первая строчка, TableCell - это ячейка + new TableCellProperties(new TableCellWidth() // в первой строчке в свойствах проставлем ширину Width = widths[j].ToString() { Width = - widths[j].ToString() + widths[j].ToString() // заполняем ширину ячейки }), - new Paragraph(new Run(new RunProperties(new Bold()), new - Text(data.First()[j]))))); + new Paragraph(new Run(new RunProperties(new Bold()), new // заголовок делаем что у нас он жирный Bold(), это шапка каждой таблицы + Text(data.First()[j]))))); // Через LinQ метод вытаскиваем First, некий Text data.First() - берем элемент из первой строки } - table.Append(tr); + table.Append(tr); // заполнили первую строчку добавили в табличку // Данные - table.Append(data.Skip(1).Select(x => - new TableRow(x.Select(y => new TableCell(new Paragraph(new - Run(new Text(y)))))))); + // теперь просто заполняем данные + table.Append(data.Skip(1).Select(x => // LinQ метод data.Skip(1) - пропускаем первую запись, которая у нас шапка таблицы + new TableRow(x.Select(y => new TableCell(new Paragraph(new // а для всех остальных мы берем элемент data(список) + Run(new Text(y)))))))); // и основе каждого списка создаем объект TableRow, которого через x.Select заполняет ячейки _body.Append(table); return this; }