From b0c084ba0c9b251aa8ba6b6ea3b532939fa7598b Mon Sep 17 00:00:00 2001 From: sofya_zubkova Date: Wed, 18 Dec 2024 22:33:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Doctor.cs | 8 +++ .../Entities/Medicament.cs | 7 ++ .../Entities/MedicamentReception.cs | 3 +- .../Entities/Patient.cs | 12 +++- .../Entities/PatientDiagnosis.cs | 10 ++- .../Entities/Reception.cs | 36 +++++++++- .../Forms/FormDoctors.cs | 7 +- .../Forms/FormMedicaments.cs | 6 +- .../Forms/FormPatientDiagnosises.cs | 8 ++- .../Forms/FormPatientReport.Designer.cs | 1 + .../Forms/FormPatientReport.cs | 2 +- .../Forms/FormPatients.cs | 7 +- .../Forms/FormReception.cs | 6 +- ...ceptionDistributionDiagnosises.Designer.cs | 1 + .../Forms/FormReceptions.cs | 9 ++- .../Reports/ChartReport.cs | 21 ++---- .../Reports/TableReport.cs | 38 +++++----- .../Implementations/QueryBuilder.cs | 31 ++++++++ .../Implementations/ReceptionRepository.cs | 72 +++++++++++++++++-- 19 files changed, 230 insertions(+), 55 deletions(-) create mode 100644 ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/QueryBuilder.cs diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Doctor.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Doctor.cs index 30cc86a..76ebd0d 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Doctor.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Doctor.cs @@ -1,11 +1,19 @@ using ProjectPatientAccounting.Entities.Enums; +using System.ComponentModel; namespace ProjectPatientAccounting.Entities; public class Doctor { public int Id { get; private set; } + public string FullName => $"{Name} {Surname}"; + + [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Фамилия")] public string Surname { get; private set; } = string.Empty; + + [DisplayName("Номер участка")] public Area DoctorArea { get; private set; } public static Doctor CreateEntity(int id, string name, string surname, Area doctorArea) diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Medicament.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Medicament.cs index 10db1f2..3060863 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Medicament.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Medicament.cs @@ -1,11 +1,18 @@ using ProjectPatientAccounting.Entities.Enums; +using System.ComponentModel; namespace ProjectPatientAccounting.Entities; public class Medicament { public int Id { get; private set; } + + [DisplayName("Название")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Описание")] public string Description { get; private set; } = string.Empty; + + [DisplayName("Тип медикамента")] public TypeMedicament TypeMedicament { get; private set; } public static Medicament CreateEntity(int id, string name, string description, TypeMedicament typeMedicament) diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/MedicamentReception.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/MedicamentReception.cs index ceeada8..6ef6f0f 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/MedicamentReception.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/MedicamentReception.cs @@ -4,9 +4,10 @@ public class MedicamentReception { public int Id { get; private set; } public int MedicamentId { get; private set; } + public string MedicamentName { get; private set; } = string.Empty; public int Dosage { get; private set; } - public static MedicamentReception CreateElement(int id, int medicamentId, int dosage) + public static MedicamentReception CreateElement(int id, int medicamentId, int dosage) { return new MedicamentReception { diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Patient.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Patient.cs index df5beae..17e232e 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Patient.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Patient.cs @@ -1,11 +1,21 @@ -namespace ProjectPatientAccounting.Entities; +using System.ComponentModel; +namespace ProjectPatientAccounting.Entities; public class Patient { public int Id { get; private set; } + public string FullName => $"{Name} {Surname}"; + + [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Фамилия")] public string Surname { get; private set; } = string.Empty; + + [DisplayName("Номер телефона")] public string Telephone { get; private set; } = string.Empty; + + [DisplayName("Номер мед.карты")] public int NumMedCard { get; private set; } public static Patient CreateEntity(int id, string name, string surname, string telephone, int numMedCard) diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/PatientDiagnosis.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/PatientDiagnosis.cs index c2fb48e..db51545 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/PatientDiagnosis.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/PatientDiagnosis.cs @@ -1,11 +1,19 @@ using ProjectPatientAccounting.Entities.Enums; +using System.ComponentModel; namespace ProjectPatientAccounting.Entities; public class PatientDiagnosis { public int Id { get; private set; } - public string Name { get; private set; } = string.Empty; + public string FullName => $"{Name} {DiagnosisCode}"; + + [DisplayName("Название")] + public string Name { get; private set; } = string.Empty; + + [DisplayName("Код диагноза")] public int DiagnosisCode { get; private set; } + + [DisplayName("Статус диагноза")] public PatientDiagnosisStatus PatientDiagnosisStatus { get; private set; } public static PatientDiagnosis CreateEntity(int id, string name, int diagnosisCode, PatientDiagnosisStatus patientDiagnosisStatus) diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Reception.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Reception.cs index d73cb11..6a3d127 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Reception.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Entities/Reception.cs @@ -1,13 +1,40 @@ -namespace ProjectPatientAccounting.Entities; +using System.ComponentModel; +namespace ProjectPatientAccounting.Entities; public class Reception { public int Id { get; private set; } + + [Browsable(false)] public int PatientId { get; private set; } + + [Browsable(false)] public int DoctorId { get; private set; } + + [Browsable(false)] public int DiagnosisId { get; private set; } + + [DisplayName("Пациент")] + public string PatientName { get; private set; } = string.Empty; + + [DisplayName("Диагноз")] + public string DiagnosisName { get; private set; } = string.Empty; + + [DisplayName("Доктор")] + public string DoctorName { get; private set; } = string.Empty; + + [DisplayName("Дата приема")] public DateTime ReceptionDate { get; private set; } + + [DisplayName("Номер талона")] public int NumTicket { get; private set; } + + [DisplayName("Медикаменты")] + public string Medicament => MedicamentReceptions != null ? + string.Join(", ", MedicamentReceptions.Select(x => $"{x.MedicamentName} {x.Dosage}")) : + string.Empty; + + [Browsable(false)] public IEnumerable MedicamentReceptions { get; private set; } = []; public static Reception CreateOperation(int id, int patientId, int doctorId, int diagnosisId, int numTicket, IEnumerable medicamentReceptions) @@ -23,4 +50,11 @@ public class Reception MedicamentReceptions = medicamentReceptions }; } + public void SetMedicamentReceptions(IEnumerable medicamentReceptions) + { + if (medicamentReceptions != null && medicamentReceptions.Any()) + { + MedicamentReceptions = medicamentReceptions; + } + } } diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormDoctors.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormDoctors.cs index 7796df3..94893b9 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormDoctors.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormDoctors.cs @@ -29,7 +29,12 @@ public partial class FormDoctors : Form } } - private void LoadList() => dataGridViewDoctors.DataSource = _doctorRepository.ReadDoctors(); + private void LoadList() + { + dataGridViewDoctors.DataSource = _doctorRepository.ReadDoctors(); + dataGridViewDoctors.Columns["Id"].Visible = false; + dataGridViewDoctors.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormMedicaments.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormMedicaments.cs index afe0d19..ea0acb0 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormMedicaments.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormMedicaments.cs @@ -29,7 +29,11 @@ public partial class FormMedicaments : Form } } - private void LoadList() => dataGridViewMedicaments.DataSource = _medicamentRepository.ReadMedicaments(); + private void LoadList() + { + dataGridViewMedicaments.DataSource = _medicamentRepository.ReadMedicaments(); + dataGridViewMedicaments.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientDiagnosises.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientDiagnosises.cs index 94335ad..2696b96 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientDiagnosises.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientDiagnosises.cs @@ -30,8 +30,12 @@ public partial class FormPatientDiagnosises : Form } } - private void LoadList() => dataGridViewPatientDiagnosises.DataSource = - _patientDiagnosisRepository.ReadDiagnosises(); + private void LoadList() + { + dataGridViewPatientDiagnosises.DataSource = _patientDiagnosisRepository.ReadDiagnosises(); + dataGridViewPatientDiagnosises.Columns["Id"].Visible = false; + dataGridViewPatientDiagnosises.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.Designer.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.Designer.cs index e30989e..1f7f4d4 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.Designer.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.Designer.cs @@ -142,6 +142,7 @@ Controls.Add(dateTimePickerStartDate); Controls.Add(labelDoctor); Name = "FormPatientReport"; + StartPosition = FormStartPosition.CenterParent; Text = "Отчет по принятым пациентам"; ResumeLayout(false); PerformLayout(); diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.cs index 923e226..998bc6b 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatientReport.cs @@ -13,7 +13,7 @@ namespace ProjectPatientAccounting.Forms _container = container ?? throw new ArgumentNullException(nameof(container)); comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); - comboBoxDoctor.DisplayMember = "Surname"; + comboBoxDoctor.DisplayMember = "FullName"; comboBoxDoctor.ValueMember = "Id"; } diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatients.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatients.cs index d4fd531..6d861fb 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatients.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormPatients.cs @@ -30,7 +30,12 @@ public partial class FormPatients : Form } } - private void LoadList() => dataGridViewPatients.DataSource = _patientRepository.ReadPatients(); + private void LoadList() + { + dataGridViewPatients.DataSource = _patientRepository.ReadPatients(); + dataGridViewPatients.Columns["Id"].Visible = false; + dataGridViewPatients.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReception.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReception.cs index b3eb05b..247ee8e 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReception.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReception.cs @@ -15,15 +15,15 @@ namespace ProjectPatientAccounting.Forms throw new ArgumentNullException(nameof(receptionRepository)); comboBoxPatient.DataSource = patientRepository.ReadPatients(); - comboBoxPatient.DisplayMember = "Surname"; + comboBoxPatient.DisplayMember = "FullName"; comboBoxPatient.ValueMember = "Id"; comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); - comboBoxDoctor.DisplayMember = "Surname"; + comboBoxDoctor.DisplayMember = "FullName"; comboBoxDoctor.ValueMember = "Id"; comboBoxDiagnosis.DataSource = patientDiagnosisRepository.ReadDiagnosises(); - comboBoxDiagnosis.DisplayMember = "Name"; + comboBoxDiagnosis.DisplayMember = "FullName"; comboBoxDiagnosis.ValueMember = "Id"; ColumnType.DataSource = medicamentRepository.ReadMedicaments(); diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptionDistributionDiagnosises.Designer.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptionDistributionDiagnosises.Designer.cs index 417e680..66cf655 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptionDistributionDiagnosises.Designer.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptionDistributionDiagnosises.Designer.cs @@ -91,6 +91,7 @@ Controls.Add(labelFileName); Controls.Add(buttonSelectFileName); Name = "FormReceptionDistributionDiagnosises"; + StartPosition = FormStartPosition.CenterParent; Text = "Распределение диагнозов"; ResumeLayout(false); PerformLayout(); diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptions.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptions.cs index 0f96329..49c466f 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptions.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Forms/FormReceptions.cs @@ -28,9 +28,12 @@ public partial class FormReceptions : Form MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - private void LoadList() => dataGridViewReceptions.DataSource = - _receptionRepository.ReadReceptions(); + private void LoadList() + { + dataGridViewReceptions.DataSource = _receptionRepository.ReadReceptions(); + dataGridViewReceptions.Columns["Id"].Visible = false; + dataGridViewReceptions.Columns["ReceptionDate"].DefaultCellStyle.Format = "dd.MM.yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Reports/ChartReport.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Reports/ChartReport.cs index 7624fae..bfbe69f 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Reports/ChartReport.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Reports/ChartReport.cs @@ -22,7 +22,7 @@ namespace ProjectPatientAccounting.Reports { new PdfBuilder(filePath) .AddHeader("Статистика пациентов") - .AddPieChart("Поставленные диагнозы", GetData(dateTime)) + .AddPieChart($"Поставленные диагнозы на {dateTime: dd MMMM yyyy}", GetData(dateTime)) .Build(); return true; } @@ -35,22 +35,13 @@ namespace ProjectPatientAccounting.Reports private List<(string Caption, double Value)> GetData(DateTime dateTime) { - var receptions = _receptionRepository.ReadReceptions() - .Where(x => x.ReceptionDate.Date == dateTime.Date) - .ToList(); - - var totalReceptions = receptions.Count; - - return receptions - .GroupBy(x => x.DiagnosisId) - .Select(g => new - { - DiagnosisId = g.Key, - Count = g.Count() - }) - .Select(x => (x.DiagnosisId.ToString(), (double)x.Count / totalReceptions * 100)) + return _receptionRepository.ReadReceptions(dateFrom: dateTime.Date, dateTo:dateTime.Date.AddDays(1)) + .GroupBy(x => x.DiagnosisName, (key, group) => new { + DiagnosisName = key, Count = group.Sum(x => x.DiagnosisId) }) + .Select(x => (x.DiagnosisName, (double)x.Count)) .ToList(); } } } + diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Reports/TableReport.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Reports/TableReport.cs index 85b19c0..3b5a0f1 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Reports/TableReport.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Reports/TableReport.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using ProjectPatientAccounting.Entities.Enums; using ProjectPatientAccounting.Repositories; - +using System.Diagnostics; namespace ProjectPatientAccounting.Reports; internal class TableReport @@ -29,7 +29,7 @@ internal class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по движению пациентов", 0, 4) - .AddParagraph("за период", 0) + .AddParagraph($"за период c {startDate: dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0) .AddTable([15, 20, 25, 25], GetData(doctorId, startDate, endDate)) .Build(); return true; @@ -43,37 +43,38 @@ internal class TableReport private List GetData(int doctorId, DateTime startDate, DateTime endDate) { - var receptions = _receptionRepository.ReadReceptions(dateFrom:startDate, dateTo:endDate, doctorId).ToList(); + var receptions = _receptionRepository.ReadReceptions(dateFrom:startDate, dateTo:endDate, doctorId: doctorId).ToList(); var patients = _patientRepository.ReadPatients(); - var doctorNames = _doctorRepository.ReadDoctors().ToDictionary(d => d.Id, d => d.Surname); + var doctorNames = _doctorRepository.ReadDoctors().ToDictionary(d => d.Id, d => d.FullName); var diagnosisStatuses = _patientDiagnosisRepository.ReadDiagnosises().ToDictionary(d => d.Id, d => d.PatientDiagnosisStatus); - + Debug.WriteLine(receptions.Count); var data = receptions .Join(patients, r => r.PatientId, p => p.Id, (r, p) => new { - Date = r.ReceptionDate.Date, + Date = r.ReceptionDate.Date, DoctorId = r.DoctorId, DiagnosisId = r.DiagnosisId }) - .Where(x => x.DoctorId == doctorId) .OrderBy(x => x.Date) - .GroupBy(x => x.Date) + .GroupBy(x => new { x.Date, x.DoctorId }) .Select(g => new { - Date = g.Key, + Date = g.Key.Date, + DoctorId = g.Key.DoctorId, TotalPatients = g.Count(), RecoveredPatients = g.Count(x => diagnosisStatuses[x.DiagnosisId] == PatientDiagnosisStatus.Closed) }); - var result = new List { item }; + var result = new List { item }; foreach (var entry in data) { + result.Add(new string[] { - entry.Date.ToString("dd.MM.yyyy"), - doctorNames.ContainsKey(doctorId) ? doctorNames[doctorId] : string.Empty, - entry.TotalPatients.ToString("N0") ?? string.Empty, - entry.RecoveredPatients > 0 ? entry.RecoveredPatients.ToString("N0") : string.Empty + entry.Date.ToString("dd.MM.yyyy"), + doctorNames.ContainsKey(doctorId) ? doctorNames[doctorId] : string.Empty, + entry.TotalPatients.ToString("N0") ?? string.Empty, + entry.RecoveredPatients > 0 ? entry.RecoveredPatients.ToString("N0") : string.Empty }); } @@ -81,11 +82,12 @@ internal class TableReport var recoveredPatients = data.Sum(x => x.RecoveredPatients); result.Add(new string[] { - "Всего", - "", - totalPatients.ToString("N0"), - recoveredPatients.ToString("N0") + "Всего", + "", + totalPatients.ToString("N0"), + recoveredPatients.ToString("N0") }); + return result; } } diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/QueryBuilder.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..0b2a797 --- /dev/null +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/QueryBuilder.cs @@ -0,0 +1,31 @@ +using System.Text; +namespace ProjectPatientAccounting.Repositories.Implementations; + +internal class QueryBuilder +{ + private readonly StringBuilder _builder; + + public QueryBuilder() + { + _builder = new(); + } + + public QueryBuilder AddCondition(string condition) + { + if (_builder.Length > 0) + { + _builder.Append(" AND "); + } + _builder.Append(condition); + return this; + } + + public string Build() + { + if (_builder.Length == 0) + { + return string.Empty; + } + return $"WHERE {_builder}"; + } +} diff --git a/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/ReceptionRepository.cs b/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/ReceptionRepository.cs index 64376ac..9ff0186 100644 --- a/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/ReceptionRepository.cs +++ b/ProjectPatientAccounting/ProjectPatientAccounting/Repositories/Implementations/ReceptionRepository.cs @@ -85,13 +85,73 @@ public class ReceptionRepository : IReceptionRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM Receptions"; - var receptions = - connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(receptions)); - return receptions; + var builder = new QueryBuilder(); + if (dateFrom.HasValue) + { + builder.AddCondition("r.ReceptionDate >= @dateFrom"); + } + if (dateTo.HasValue) + { + builder.AddCondition("r.ReceptionDate <= @dateTo"); + } + if (patientId.HasValue) + { + builder.AddCondition("r.PatientId = @patientId"); + } + if (diagnosisId.HasValue) + { + builder.AddCondition("r.DiagnosisId = @diagnosisId"); + } + if (doctorId.HasValue) + { + builder.AddCondition("r.DoctorId = @doctorId"); + } + var querySelect = $@" + SELECT + r.*, + CONCAT(p.Name, ' ', p.Surname) AS PatientName, + CONCAT(pd.Name, ' ', pd.DiagnosisCode) AS DiagnosisName, + CONCAT(d.Name, ' ', d.Surname) AS DoctorName, + mr.MedicamentId, + m.Name AS MedicamentName, + mr.Dosage + + FROM Receptions r + LEFT JOIN Patients p ON p.Id = r.PatientId + LEFT JOIN PatientDiagnosises pd ON pd.Id = r.DiagnosisId + LEFT JOIN Doctors d ON d.Id = r.DoctorId + + INNER JOIN MedicamentReceptions mr ON mr.ReceptionId = r.Id + LEFT JOIN Medicaments m ON m.Id = mr.MedicamentId + + {builder.Build()}"; + + + var receptionDict = new Dictionary>(); + var receptions = connection.Query(querySelect, + (reception, medicamentReceptions) => + { + if (!receptionDict.TryGetValue(reception.Id, out var mr)) + { + mr = []; + receptionDict.Add(reception.Id, mr); + + } + mr.Add(medicamentReceptions); + return reception; + }, + splitOn: "MedicamentId", param: new { dateFrom, dateTo, patientId, diagnosisId, doctorId }); + + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(receptions)); + + return receptionDict.Select(x => + { + var r = receptions.First(y => y.Id == x.Key); + r.SetMedicamentReceptions(x.Value); + return r; + }).ToArray(); } + catch (Exception ex) { _logger.LogError(ex, "Ошибка при чтении объектов");