From e8d4571560dbbf041a1630fd77b05e8b2a50147a Mon Sep 17 00:00:00 2001 From: Bulat Date: Sun, 8 Dec 2024 15:13:32 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs index 571f9f3..cb6320e 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace RegistrationPatientsPolyclinic.Entities; -public class DoctorPayments +public class DoctorPayments // Проверка класса { public int Id { get; private set; } -- 2.25.1 From 2fc385294351942daf1d5c97c6b6bf309fda4cae Mon Sep 17 00:00:00 2001 From: Bulat Date: Wed, 18 Dec 2024 13:34:48 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B0=D0=B9?= =?UTF-8?q?=D0=B7=D0=B8=D0=BD=D0=B3=D0=B81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Doctor.cs | 7 +- .../Entities/DoctorPayments.cs | 13 +++- .../Entities/Drug.cs | 4 + .../Entities/DrugMedicalHistory.cs | 1 + .../Entities/MedicalHistory.cs | 25 +++++- .../Entities/Patient.cs | 11 ++- .../Forms/FormDoctorPayment.cs | 2 +- .../Forms/FormDoctorPayments.cs | 7 +- .../Forms/FormDoctors.cs | 7 +- .../Forms/FormDrugs.cs | 6 +- .../Forms/FormMedicalHistories.cs | 7 +- .../Forms/FormMedicalHistory.cs | 4 +- .../Forms/FormPatients.cs | 7 +- .../DoctorPaymentsRepository.cs | 8 +- .../MedicalHistoryRepository.cs | 77 +++++++++++-------- 15 files changed, 139 insertions(+), 47 deletions(-) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs index 35283da..b1e00d3 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs @@ -1,6 +1,7 @@ using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,11 +11,15 @@ namespace RegistrationPatientsPolyclinic.Entities; public class Doctor { public int Id { get; private set; } - + [DisplayName("Имя")] public string First_Name { get; private set; } = string.Empty; + [DisplayName("Фамилия")] public string Last_Name { get; private set; } = string.Empty; + public string FullName => $"{Last_Name} {First_Name}"; + + [DisplayName("Должность")] public DoctorPost DoctorPost { get; private set; } // объявляется свойство DoctorPost, которое имеет тип DoctorPost public static Doctor CreateEntity(int id, string first_Name, string last_Name, DoctorPost doctorPost) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs index cb6320e..29399fe 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs @@ -1,23 +1,32 @@ using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RegistrationPatientsPolyclinic.Entities; -public class DoctorPayments // Проверка класса +public class DoctorPayments { public int Id { get; private set; } - + [Browsable(false)] public int IdDoctor { get; private set; } + [DisplayName("Доктор")] + public string DoctorName { get; private set; } = string.Empty; + + [DisplayName("Месяц")] public string Month { get; private set; } = string.Empty; + [DisplayName("Количество пациентов")] public int Count_Patient { get; private set; } + + [DisplayName("Дата оплаты")] public DateTime DoctorPaymentData { get; private set; } + [DisplayName("Оплата")] public int Payment { get; private set; } public static DoctorPayments CreateElement(int id, int idDoctor, string month, int count_patient, int payment) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs index d9be20a..fdb03f1 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs @@ -1,6 +1,7 @@ using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,10 +12,13 @@ public class Drug // Наподобие Feed { public int Id { get; private set; } + [DisplayName("Название лекарства")] public DrugName DrugName { get; private set; } + [DisplayName("Количество")] public int Grams { get; private set; } + [DisplayName("Описание")] public string Description { get; private set; } = string.Empty; public static Drug CreateElement(int id, DrugName name, int grams, string description) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs index 23dc566..c0f0a42 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs @@ -13,6 +13,7 @@ public class DrugMedicalHistory // Тоже самое что FeedFeedRepleshme public int DrugId { get; private set; } + public string DrugName { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty; diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs index 5408a96..a6d3ebe 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs @@ -1,6 +1,7 @@ using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,14 +12,28 @@ public class MedicalHistory // сущность пополнения, напо { public int Id { get; private set; } + [Browsable(false)] public int PatientId { get; private set; } + [DisplayName("Имя пациента")] + public string PatientName { get; private set; } = string.Empty; + + [Browsable(false)] public int DoctorId { get; private set; } + [DisplayName("Имя доктора")] + public string DoctorName { get; private set; } = string.Empty; + [DisplayName("Дата приема")] public DateTime VisitDate { get; private set; } + [DisplayName("Таблетки")] + public string Drug => DrugMedicalHistory != null ? + string.Join(", ", DrugMedicalHistory.Select(x => $"{x.Id} {x.Description}")) : + string.Empty; + + [Browsable(false)] public IEnumerable DrugMedicalHistory { get; set; } = []; public static MedicalHistory CreateEntity(int id, int patientId, int doctorId, @@ -33,7 +48,7 @@ public class MedicalHistory // сущность пополнения, напо DrugMedicalHistory = drugMedicalHistory }; } - + /* public static MedicalHistory CreateOpeartion(TempDrugMedicalHistory tempDrugMedicalHistory, IEnumerable drugMedicalHistories) { return new MedicalHistory @@ -45,4 +60,12 @@ public class MedicalHistory // сущность пополнения, напо DrugMedicalHistory = drugMedicalHistories }; } + */ + public void SetProductMaterial(IEnumerable drugMedicalHistory) + { + if (drugMedicalHistory != null && drugMedicalHistory.Any()) + { + DrugMedicalHistory = drugMedicalHistory; + } + } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs index 70cb6e3..0a01f1d 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,15 +11,17 @@ public class Patient { public int Id { get; private set; } - public string First_Name { get; private set; } = string .Empty; // string.Empty - означает, что по умолчанию это свойство будет содержать пустую строку, а не null(то же самое "") + [DisplayName("Имя")] + public string First_Name { get; private set; } = string .Empty; + [DisplayName("Фамилия")] public string Last_Name { get; private set; } = string.Empty; + + public string FullName => $"{First_Name} {Last_Name}"; + [DisplayName("Контактный номер")] public string ContactNumber { get; private set; } - - // ТУТ СДЕЛАЕМ СТАТИСТИЧЕСКИЙ МЕТОД, который будет отвечать за создание объекта - public static Patient CreateEntity(int id, string first_Name, string last_Name, string contactNumber) { return new Patient diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs index 791c85b..6dff994 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs @@ -23,7 +23,7 @@ namespace RegistrationPatientsPolyclinic.Forms throw new ArgumentNullException(nameof(doctorPaymentsRepository)); comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); - comboBoxDoctor.DisplayMember = "Firts_Name"; + comboBoxDoctor.DisplayMember = "FullName"; comboBoxDoctor.ValueMember = "Id"; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayments.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayments.cs index bca62ed..8305333 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayments.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayments.cs @@ -52,7 +52,12 @@ namespace RegistrationPatientsPolyclinic.Forms } } - private void LoadList() => dataGridView.DataSource = _doctorPaymentsRepository.ReadDoctorPayments(); + private void LoadList() + { + dataGridView.DataSource = _doctorPaymentsRepository.ReadDoctorPayments(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Month"].DefaultCellStyle.Format = "yyyy-dd"; + } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs index 6ac9389..1c90a95 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs @@ -45,7 +45,12 @@ namespace RegistrationPatientsPolyclinic.Forms } // отдельный метод который будет загружать в GridView - private void LoadList() => dataGridView.DataSource = _doctorRepository.ReadDoctors(); + private void LoadList() + { + dataGridView.DataSource = _doctorRepository.ReadDoctors(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) // возвращает смог н извлечь или нет diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs index 23e5537..612baa9 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs @@ -29,7 +29,11 @@ namespace RegistrationPatientsPolyclinic.Forms } - private void LoadList() => dataGridView.DataSource = _dragRepository.ReadDrug(); + private void LoadList() + { + dataGridView.DataSource = _dragRepository.ReadDrug(); + dataGridView.Columns["Id"].Visible = false; + } private void buttonAdd_Click(object sender, EventArgs e) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistories.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistories.cs index 839eab8..6bea7b3 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistories.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistories.cs @@ -52,7 +52,12 @@ namespace RegistrationPatientsPolyclinic.Forms } } - private void LoadList() => dataGridView.DataSource = _medicalHistoryRepository.ReadMedicalHistory(); + private void LoadList() + { + dataGridView.DataSource = _medicalHistoryRepository.ReadMedicalHistory(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["VisitDate"].DefaultCellStyle.Format = "dd.MM.yyyy"; + } private void buttonDel_Click(object sender, EventArgs e) { diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs index 7404038..5fbb40b 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs @@ -32,12 +32,12 @@ namespace RegistrationPatientsPolyclinic.Forms throw new ArgumentNullException(nameof(medicalHistoryRepository)); comboBoxPacient.DataSource = patientRepository.ReadPatient(); // передает набор всех пациентов - comboBoxPacient.DisplayMember = "First_Name"; // отображение в combobox + comboBoxPacient.DisplayMember = "FullName"; // отображение в combobox comboBoxPacient.ValueMember = "Id"; comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); - comboBoxDoctor.DisplayMember = "First_Name"; + comboBoxDoctor.DisplayMember = "FullName"; comboBoxDoctor.ValueMember = "Id"; ColumnDrug.DataSource = drugRepository.ReadDrug(); diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatients.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatients.cs index 1ec5ec3..265ef22 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatients.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatients.cs @@ -99,7 +99,12 @@ namespace RegistrationPatientsPolyclinic.Forms // отдельный метод который будет загружать в GridView - private void LoadList() => dataGridView.DataSource = _pacientRepository.ReadPatient(); + private void LoadList() + { + dataGridView.DataSource = _pacientRepository.ReadPatient(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) // возвращает смог н извлечь или нет diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs index b1c5d0d..5394d98 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs @@ -47,7 +47,9 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)"; } + + public IEnumerable ReadDoctorPayments() { _logger.LogInformation("Получение всех объектов"); @@ -55,7 +57,10 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)"; { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM DoctorPayments"; + var querySelect = @"SELECT fa.*, + CONCAT(e.Last_Name, ' ', e.First_Name) AS DoctorName + FROM DoctorPayments fa + LEFT JOIN Doctor e ON e.Id = fa.IdDoctor"; var doctorPayments = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", @@ -70,6 +75,7 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)"; } + } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs index b2f8a1c..366b606 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs @@ -85,7 +85,7 @@ WHERE Id=@id"; } } - + /* public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) { _logger.LogInformation("Получение всех объектов"); @@ -111,8 +111,8 @@ WHERE Id=@id"; throw; } } - - /* + */ + public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) { _logger.LogInformation("Получение всех объектов"); @@ -120,44 +120,61 @@ WHERE Id=@id"; { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM MedicalHistory"; - var medicalHistory = - connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(medicalHistory)); - return medicalHistory; - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка при чтении объектов"); - throw; - } + //var querySelect = @"SELECT * FROM MedicalHistory"; + /* var querySelect = @"SELECT mh.*, + CONCAT(p.LastName, ' ', p.FirstName) as PatientName, + CONCAT(d.LastName, ' ', d.FirstName) as DoctorName, + dmh.DrugId, + dmh.Description + dr.DrugName AS drugName + FROM MedicalHistory mh + LEFT JOIN Patient p on p.Id = mh.PatientId + LEFT JOIN Doctor d on d.Id = mh.DoctorId + INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id + LEFT JOIN Drug dr on dr.Id = dmh.DrugId";*/ - } - */ - /* - public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) - { - _logger.LogInformation("Получение всех объектов"); - try - { - using var connection = new - NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT mh.*, dmh.DrugId, dmh.Description + var querySelect = @"SELECT mh.*, + CONCAT(p.Last_Name, ' ', p.First_Name) as PatientName, + CONCAT(d.Last_Name, ' ', d.First_Name) as DoctorName, + dmh.Id AS Id, dmh.DrugId AS drugId, dmh.Description AS Description FROM MedicalHistory mh - INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id"; + LEFT JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id + LEFT JOIN Patient p ON p.Id = mh.PatientId + LEFT JOIN doctor d ON d.Id = mh.DoctorId + "; + + var historyDict = new Dictionary>(); var medicalHistory = - connection.Query(querySelect); + connection.Query(querySelect, + (history, drugMedicalHistory) => + { + if (!historyDict.TryGetValue(history.Id, out var drugs)) + { + drugs = new List(); + historyDict.Add(history.Id, drugs); + } + if (drugMedicalHistory != null && drugMedicalHistory.Id > 0) + { + drugs.Add(DrugMedicalHistory.CreateEntity(drugMedicalHistory.Id, drugMedicalHistory.DrugId, drugMedicalHistory.Description)); + } + return history; + }, splitOn: "Id");//, param: new { dateForm, dateTo, DoctorId, PatientId}); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(medicalHistory)); - return medicalHistory; + return historyDict.Select(x => + { + var mh = medicalHistory.First(y => y.Id == x.Key); + mh.SetProductMaterial(x.Value); + return mh; + }).ToArray(); } catch (Exception ex) { _logger.LogError(ex, "Ошибка при чтении объектов"); throw; } - }*/ + } } -- 2.25.1 From 0046fdf9b7f9d54ffb284523639a92551fdb252c Mon Sep 17 00:00:00 2001 From: Bulat Date: Thu, 19 Dec 2024 14:42:11 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=BF=D0=BE=D0=BC=D0=B5=D0=BD=D1=8F=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/MedicalHistory.cs | 4 +- .../Reports/TableReport.cs | 76 ++++++++++++++++--- .../Repositories/IDoctorPaymentsRepository.cs | 4 +- .../Repositories/IMedicalHistoryRepository.cs | 6 -- .../DoctorPaymentsRepository.cs | 22 +++++- .../MedicalHistoryRepository.cs | 51 ++++++++----- .../Implementations/QueryBuilder.cs | 33 ++++++++ 7 files changed, 153 insertions(+), 43 deletions(-) create mode 100644 RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/QueryBuilder.cs diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs index a6d3ebe..b84239d 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs @@ -27,12 +27,12 @@ public class MedicalHistory // сущность пополнения, напо [DisplayName("Дата приема")] public DateTime VisitDate { get; private set; } - [DisplayName("Таблетки")] + + public string Drug => DrugMedicalHistory != null ? string.Join(", ", DrugMedicalHistory.Select(x => $"{x.Id} {x.Description}")) : string.Empty; - [Browsable(false)] public IEnumerable DrugMedicalHistory { get; set; } = []; diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs index 779aea8..2a3438a 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs @@ -20,20 +20,24 @@ internal class TableReport private readonly IDoctorPaymentsRepository _doctorPaymentsRepository; + private readonly IDrugRepository _drugRepository; + private readonly ILogger _logger; - internal static readonly string[] item = ["Дата", "Описание", "Количество лекарства"]; + internal static readonly string[] item = ["Доктор", "Описание", "Количество пациентов"]; - public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, ILogger logger) + public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, IDrugRepository drugRepository, ILogger logger) { _medicalHistoryRepository = medicalHistoryRepository ?? throw new ArgumentNullException(nameof(medicalHistoryRepository)); ; _doctorPaymentsRepository = doctorPaymentsRepository ?? throw new ArgumentNullException(nameof(doctorPaymentsRepository)); + _drugRepository = drugRepository ?? + throw new ArgumentNullException(nameof(drugRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } - + public bool CreateTable(string filePath, int drugId, DateTime startDate, DateTime endDate) { try @@ -62,12 +66,11 @@ internal class TableReport /// ВНИЗУ БЫЛ ПРАВИЛЬНЫЙ - + /* private List GetData(int drugId, DateTime startDate, DateTime endDate) { var data = _medicalHistoryRepository - .ReadMedicalHistory() - .Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId) ) + .ReadMedicalHistory(dateForm: startDate,dateTo : endDate, null, null) .Select(x => new { Date = x.VisitDate, @@ -85,18 +88,69 @@ internal class TableReport return new List() { item } .Union( data - .Select(x => new string[] {x.Date.ToString(), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Select(x => new string[] {x.Date.ToString("dd.MM.yyyy"), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) .Union( new List() { new string[] { "Всего", data.Sum(x => x.CountOut ?? 0).ToString(), string.Empty } }) .ToList(); } + */ - + /* + private List GetData(int drugId, DateTime startDate, DateTime endDate) + { + var data = _medicalHistoryRepository + .ReadMedicalHistory() + .Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId)) + .Select(x => new + { + Date = x.VisitDate, + 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 })) + .OrderBy(x => x.Date); - - + return new List() { item } + .Union( + 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 } }) + .ToList(); + } + */ - + private List GetData(int drugId, DateTime startDate, DateTime endDate) + { + var data = _medicalHistoryRepository + .ReadMedicalHistory() + .Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId)) + .Select(x => new + { + Date = x.DoctorId, + CountIn = x.DrugMedicalHistory.FirstOrDefault(y => y.DrugId == drugId)?.Description, + CountOut = (int?)null + }) + .Union( + _doctorPaymentsRepository + .ReadDoctorPayments() + .Where(x => x.Id != 0) + .Select(x => new { Date = x.IdDoctor, CountIn = (string?)null, CountOut = (int?)x.Count_Patient })) + .OrderBy(x => x.Date); + + + return new List() { item } + .Union( + data + .Select(x => new string[] { x.Date.ToString(), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) + .Union( + new List() { new string[] { "Всего", string.Empty, data.Sum(x => x.CountOut ?? 0).ToString() } }) + .ToList(); + } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs index bb151d8..4b65f1b 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs @@ -9,8 +9,8 @@ namespace RegistrationPatientsPolyclinic.Repositories; public interface IDoctorPaymentsRepository { - IEnumerable ReadDoctorPayments(); - + //IEnumerable ReadDoctorPayments(); + IEnumerable ReadDoctorPayments(int? doctorId = null, string month = null); void CreateDoctorPayments(DoctorPayments doctorPayments); diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs index 7979ac9..c32625a 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs @@ -13,12 +13,6 @@ public interface IMedicalHistoryRepository IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть - - /* - IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, - int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть - - */ void CreateMedicalHistory(MedicalHistory medicalHistory); // объекь будет заносится в список diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs index 5394d98..b2bac8a 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs @@ -1,4 +1,6 @@ using Dapper; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; @@ -50,19 +52,31 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)"; - public IEnumerable ReadDoctorPayments() + public IEnumerable ReadDoctorPayments(int? doctorId = null, string month = null) { _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + + if (doctorId.HasValue) + { + builder.AddCondition("fa.IdDoctor = @doctorId"); + } + if (!string.IsNullOrEmpty(month)) + { + builder.AddCondition("fa.Month = @month"); + } + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT fa.*, + var querySelect = $@"SELECT fa.*, CONCAT(e.Last_Name, ' ', e.First_Name) AS DoctorName FROM DoctorPayments fa - LEFT JOIN Doctor e ON e.Id = fa.IdDoctor"; + LEFT JOIN Doctor e ON e.Id = fa.IdDoctor + {builder.Build()}"; var doctorPayments = - connection.Query(querySelect); + connection.Query(querySelect, new { doctorId , month }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(doctorPayments)); return doctorPayments; diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs index 366b606..0695d4b 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs @@ -1,4 +1,5 @@ using Dapper; +using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; @@ -24,7 +25,7 @@ public class MedicalHistoryRepository : IMedicalHistoryRepository _logger = logger; } - + public void CreateMedicalHistory(MedicalHistory medicalHistory) { _logger.LogInformation("Добавление объекта"); @@ -63,7 +64,7 @@ VALUES (@DrugId,@MedicalHistoryId, @Description)"; } } - + public void DeletemedicalHistory(int id) { @@ -113,27 +114,40 @@ WHERE Id=@id"; } */ + + // ВНИЗУ САМЫЙ ПОСЛЕДНИЙ ПРАВИЛЬНЫЙ!!!! + + public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) { _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + + if (dateForm.HasValue) + { + builder.AddCondition("mh.VisitDate >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("mh.VisitDate <= @dateTo"); + } + if (DoctorId.HasValue) + { + builder.AddCondition("mh.DoctorId = @DoctorId"); + } + if (PatientId.HasValue) + { + builder.AddCondition("mh.PatientId = @PatientId"); + } + + + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - //var querySelect = @"SELECT * FROM MedicalHistory"; - /* var querySelect = @"SELECT mh.*, - CONCAT(p.LastName, ' ', p.FirstName) as PatientName, - CONCAT(d.LastName, ' ', d.FirstName) as DoctorName, - dmh.DrugId, - dmh.Description - dr.DrugName AS drugName - FROM MedicalHistory mh - LEFT JOIN Patient p on p.Id = mh.PatientId - LEFT JOIN Doctor d on d.Id = mh.DoctorId - INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id - LEFT JOIN Drug dr on dr.Id = dmh.DrugId";*/ - var querySelect = @"SELECT mh.*, + var querySelect = $@"SELECT mh.*, CONCAT(p.Last_Name, ' ', p.First_Name) as PatientName, CONCAT(d.Last_Name, ' ', d.First_Name) as DoctorName, dmh.Id AS Id, dmh.DrugId AS drugId, dmh.Description AS Description @@ -141,7 +155,7 @@ WHERE Id=@id"; LEFT JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id LEFT JOIN Patient p ON p.Id = mh.PatientId LEFT JOIN doctor d ON d.Id = mh.DoctorId - "; + {builder.Build()}"; var historyDict = new Dictionary>(); var medicalHistory = @@ -158,7 +172,7 @@ WHERE Id=@id"; drugs.Add(DrugMedicalHistory.CreateEntity(drugMedicalHistory.Id, drugMedicalHistory.DrugId, drugMedicalHistory.Description)); } return history; - }, splitOn: "Id");//, param: new { dateForm, dateTo, DoctorId, PatientId}); + }, splitOn: "Id", param: new { dateForm, dateTo, DoctorId, PatientId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(medicalHistory)); @@ -175,8 +189,9 @@ WHERE Id=@id"; throw; } } + + } - diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/QueryBuilder.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..3fb2627 --- /dev/null +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/QueryBuilder.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RegistrationPatientsPolyclinic.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}"; + } +} -- 2.25.1 From 911e9f8393615f76155aef10f533c972525a93b0 Mon Sep 17 00:00:00 2001 From: Bulat Date: Thu, 19 Dec 2024 15:13:00 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/DrugMedicalHistory.cs | 7 +- .../Entities/MedicalHistory.cs | 15 +-- .../Forms/FormDrugReport.Designer.cs | 18 +-- .../Forms/FormDrugReport.cs | 21 ++-- .../Forms/FormMedicalHistory.cs | 4 +- .../Reports/ChartReport.cs | 40 ++++-- .../Reports/TableReport.cs | 118 +++++++++++++++--- .../MedicalHistoryRepository.cs | 14 ++- 8 files changed, 180 insertions(+), 57 deletions(-) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs index c0f0a42..caf9098 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs @@ -17,15 +17,16 @@ public class DrugMedicalHistory // Тоже самое что FeedFeedRepleshme public string Description { get; private set; } = string.Empty; + public int MedicalHistoryId { get; private set; } - - public static DrugMedicalHistory CreateEntity(int id, int drugId, string description) + public static DrugMedicalHistory CreateEntity(int id, int drugId, string description, int medicalHistoryId) { return new DrugMedicalHistory { Id = id, DrugId = drugId, - Description = description ?? string.Empty + Description = description ?? string.Empty, + MedicalHistoryId = medicalHistoryId }; } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs index b84239d..f01decc 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs @@ -28,13 +28,14 @@ public class MedicalHistory // сущность пополнения, напо public DateTime VisitDate { get; private set; } - - public string Drug => DrugMedicalHistory != null ? - string.Join(", ", DrugMedicalHistory.Select(x => $"{x.Id} {x.Description}")) : - string.Empty; - [Browsable(false)] - public IEnumerable DrugMedicalHistory { get; set; } = []; + public IEnumerable DrugMedicalHistory { get; set; } = []; + + + [DisplayName("Назначенные лекарства")] + public string DrugsSummary => string.Join(", ", DrugMedicalHistory + .Select(d => $" {d.DrugId}, {d.Description}")); + public static MedicalHistory CreateEntity(int id, int patientId, int doctorId, IEnumerable drugMedicalHistory) @@ -61,7 +62,7 @@ public class MedicalHistory // сущность пополнения, напо }; } */ - public void SetProductMaterial(IEnumerable drugMedicalHistory) + public void SetDrugMedHistory(IEnumerable drugMedicalHistory) { if (drugMedicalHistory != null && drugMedicalHistory.Any()) { diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.Designer.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.Designer.cs index b135844..e87e4f0 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.Designer.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.Designer.cs @@ -31,7 +31,7 @@ dateTimePickerStart = new DateTimePicker(); textBoxFilePath = new TextBox(); buttonSelectFilePath = new Button(); - comboBoxDrug = new ComboBox(); + comboBoxDoctor = new ComboBox(); dateTimePickerEnd = new DateTimePicker(); labelFilePath = new Label(); labelDrug = new Label(); @@ -65,13 +65,13 @@ buttonSelectFilePath.UseVisualStyleBackColor = true; buttonSelectFilePath.Click += buttonSelectFilePath_Click; // - // comboBoxDrug + // comboBoxDoctor // - comboBoxDrug.FormattingEnabled = true; - comboBoxDrug.Location = new Point(140, 143); - comboBoxDrug.Name = "comboBoxDrug"; - comboBoxDrug.Size = new Size(125, 28); - comboBoxDrug.TabIndex = 3; + comboBoxDoctor.FormattingEnabled = true; + comboBoxDoctor.Location = new Point(140, 143); + comboBoxDoctor.Name = "comboBoxDoctor"; + comboBoxDoctor.Size = new Size(125, 28); + comboBoxDoctor.TabIndex = 3; // // dateTimePickerEnd // @@ -137,7 +137,7 @@ Controls.Add(labelDrug); Controls.Add(labelFilePath); Controls.Add(dateTimePickerEnd); - Controls.Add(comboBoxDrug); + Controls.Add(comboBoxDoctor); Controls.Add(buttonSelectFilePath); Controls.Add(textBoxFilePath); Controls.Add(dateTimePickerStart); @@ -152,7 +152,7 @@ private DateTimePicker dateTimePickerStart; private TextBox textBoxFilePath; private Button buttonSelectFilePath; - private ComboBox comboBoxDrug; + private ComboBox comboBoxDoctor; private DateTimePicker dateTimePickerEnd; private Label labelFilePath; private Label labelDrug; diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.cs index b30e10e..c84e8ec 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugReport.cs @@ -17,15 +17,15 @@ namespace RegistrationPatientsPolyclinic.Forms { private readonly IUnityContainer _container; - public FormDrugReport(IUnityContainer container, IDrugRepository drugRepository) + public FormDrugReport(IUnityContainer container, IDrugRepository drugRepository, IDoctorRepository doctorRepository) { InitializeComponent(); _container = container ?? throw new ArgumentNullException(nameof(container)); - comboBoxDrug.DataSource = drugRepository.ReadDrug(); - comboBoxDrug.DisplayMember = "Name"; - comboBoxDrug.ValueMember = "Id"; + comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); + comboBoxDoctor.DisplayMember = "FullName"; + comboBoxDoctor.ValueMember = "Id"; } @@ -50,16 +50,21 @@ namespace RegistrationPatientsPolyclinic.Forms { throw new Exception("Отсутствует имя файла для отчета"); } - if (comboBoxDrug.SelectedIndex < 0) + if (comboBoxDoctor.SelectedIndex < 0) { - throw new Exception("Не выбран корм"); + throw new Exception("Не выбран врач"); } if (dateTimePickerEnd.Value <= dateTimePickerStart.Value) { throw new Exception("Дата начала должна быть раньше даты окончания"); } - if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxDrug.SelectedValue!, - dateTimePickerStart.Value, dateTimePickerEnd.Value)) + + // Приведение дат к началу и концу месяца + var startDate = new DateTime(dateTimePickerStart.Value.Year, dateTimePickerStart.Value.Month, 1); + var endDate = new DateTime(dateTimePickerEnd.Value.Year, dateTimePickerEnd.Value.Month, 1).AddMonths(1).AddDays(-1); + + if (_container.Resolve().CreateTable(textBoxFilePath.Text, (int)comboBoxDoctor.SelectedValue!, + startDate, endDate)) { MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs index 5fbb40b..657d9c9 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs @@ -91,10 +91,10 @@ _medicalHistoryRepository.ReadMedicalHistory(); { continue; } - list.Add(DrugMedicalHistory.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnDrug"].Value), row.Cells["ColumnDescription"].Value?.ToString())); + list.Add(DrugMedicalHistory.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnDrug"].Value), row.Cells["ColumnDescription"].Value?.ToString(), 0)); } return list.GroupBy(x => x.DrugId, x => x.Description, (id, description) => - DrugMedicalHistory.CreateEntity(0, id, string.Join(", ", description))).ToList(); + DrugMedicalHistory.CreateEntity(0, id, string.Join(", ", description), 0)).ToList(); } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs index 2584078..bf87118 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using RegistrationPatientsPolyclinic.Repositories; +using RegistrationPatientsPolyclinic.Repositories.Implementations; using System; using System.Collections.Generic; using System.Linq; @@ -14,10 +15,12 @@ internal class ChartReport private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly ILogger _logger; - public ChartReport(IMedicalHistoryRepository medicalHistoryRepository, ILogger logger) + public ChartReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, ILogger logger) { _medicalHistoryRepository = medicalHistoryRepository ?? throw new ArgumentNullException(nameof(medicalHistoryRepository)); + _doctorPaymentsRepository = doctorPaymentsRepository ?? + throw new ArgumentNullException(nameof(doctorPaymentsRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -27,8 +30,8 @@ internal class ChartReport try { new PdfBuilder(filePath) - .AddHeader("Пополенение лекарства") - .AddPieChart("Виды лекарства", GetData(dateTime)) + .AddHeader($"Выписанные лекарства на {dateTime:dd.MM.yyyy}") + .AddPieChart("Соотношение выписанных лекарств по врачам", GetData(dateTime)) .Build(); return true; } @@ -41,12 +44,33 @@ internal class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { // Получаем все медицинские истории за указанную дату - var medicalHistories = _medicalHistoryRepository.ReadMedicalHistory(dateTime, dateTime); + var medicalHistories = _medicalHistoryRepository.ReadMedicalHistory(null, null, null, null); - // Группируем по идентификатору пациента и считаем количество посещений - return medicalHistories - .GroupBy(mh => mh.PatientId) - .Select(g => (Caption: $"Patient {g.Key}", Value: (double)g.Count())) + // Фильтруем истории, где есть назначения лекарств + 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.DoctorName, + (doctorName, group) => new + { + DoctorName = doctorName, + TotalDrugAssignments = group + .SelectMany(mh => mh.DrugMedicalHistory) + .Count() // Считаем количество назначений лекарств + } + ) + .ToList(); + + // Преобразуем данные в формат, подходящий для диаграммы + var result = groupedData + .Select(x => (Caption: x.DoctorName, Value: (double)x.TotalDrugAssignments)) + .ToList(); + + return result; } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs index 2a3438a..1b14c80 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs @@ -22,11 +22,13 @@ internal class TableReport private readonly IDrugRepository _drugRepository; + private readonly IDoctorRepository _doctorRepository; + private readonly ILogger _logger; - internal static readonly string[] item = ["Доктор", "Описание", "Количество пациентов"]; + internal static readonly string[] item = ["Id врача", "Количество пациентов", "Выплаты"]; - public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, IDrugRepository drugRepository, ILogger logger) + public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, IDoctorRepository doctorRepository, IDrugRepository drugRepository, ILogger logger) { _medicalHistoryRepository = medicalHistoryRepository ?? throw new ArgumentNullException(nameof(medicalHistoryRepository)); ; @@ -34,27 +36,35 @@ internal class TableReport throw new ArgumentNullException(nameof(doctorPaymentsRepository)); _drugRepository = drugRepository ?? throw new ArgumentNullException(nameof(drugRepository)); + _doctorRepository = doctorRepository ?? + throw new ArgumentNullException(nameof(IMedicalHistoryRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } - public bool CreateTable(string filePath, int drugId, DateTime startDate, DateTime endDate) + public bool CreateTable(string filePath, int doctorId, DateTime startDate, DateTime endDate) { try { - var data = GetData(drugId, startDate, endDate); - var columnsWidths = new int[] {10, 15, 15 }; + var startOfMonth = new DateTime(startDate.Year, startDate.Month, 1); + var endOfMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1).AddDays(-1); - if (columnsWidths.Length != data.First().Length) - { - throw new InvalidOperationException("Количество ширин столбцов не соответствует количеству данных."); - } + // Получаем данные для таблицы и имя врача + var (tableData, doctorFullName) = GetData(doctorId, startOfMonth, endOfMonth); - new ExcelBuilder(filePath) - .AddHeader("Сводка по движению лекарство", 0, 3) - .AddParagraph("за период", 0) - .AddTable(columnsWidths, data) - .Build(); + var excelBuilder = new ExcelBuilder(filePath) + .AddHeader("Сводка по оплате", 0, 3) + .AddParagraph($"За период с {startOfMonth:MMMM yyyy} по {endOfMonth:MMMM yyyy}", 0) + .AddParagraph($"Врач: {doctorFullName}", 0) + .AddTable(new[] { 25, 25, 25 }, tableData); + + excelBuilder.AddParagraph("", 0); + + excelBuilder + .AddHeader("Назначенные лекарства", 0, 2) + .AddTable(new[] { 25, 25 }, GetDrugData(doctorId, startOfMonth, endOfMonth)); + + excelBuilder.Build(); return true; } catch (Exception ex) @@ -126,6 +136,8 @@ internal class TableReport */ + // ВНИЗУ САМЫЙ ПОСЛЕДНИЙ!!! + /* private List GetData(int drugId, DateTime startDate, DateTime endDate) { var data = _medicalHistoryRepository @@ -153,4 +165,82 @@ internal class TableReport new List() { new string[] { "Всего", string.Empty, data.Sum(x => x.CountOut ?? 0).ToString() } }) .ToList(); } + */ + + private (List, string) GetData(int doctorId, DateTime startOfMonth, DateTime endOfMonth) + { + var data = _doctorPaymentsRepository + .ReadDoctorPayments() + .Where(x => + { + var IdDoctorss = x.IdDoctor; + return IdDoctorss == doctorId; + }) + .Select(x => new + { + DoctorName = x.DoctorName, // Предполагается, что есть поле DoctorName + CountOfPatients = x.Count_Patient, + Payments = x.Payment + }) + .ToList(); + + var doctorName = data.FirstOrDefault()?.DoctorName ?? "Неизвестный врач"; + + var result = new List() + { + new[] { "Имя Врача", "Количество пациентов", "Выплаты" } + } + .Union( + data.Select(x => new string[] + { + x.DoctorName, + x.CountOfPatients.ToString(), + x.Payments.ToString() + }) + ) + .Union( + new[] + { + new string[] + { + "Всего", + data.Sum(x => x.CountOfPatients).ToString(), + data.Sum(x => x.Payments).ToString() + } + } + ) + .ToList(); + + return (result, doctorName); + } + + private List GetDrugData(int doctorId, DateTime startOfMonth, DateTime endOfMonth) + { + var medicalHistories = _medicalHistoryRepository + .ReadMedicalHistory(startOfMonth, endOfMonth, doctorId, null) // Исправлено + .Where(mh => mh.DrugMedicalHistory != null && mh.DrugMedicalHistory.Any()) + .ToList(); + + _logger.LogDebug("Полученные медицинские истории с лекарствами: {data}", JsonConvert.SerializeObject(medicalHistories)); + + var drugData = medicalHistories + .SelectMany(mh => mh.DrugMedicalHistory.Select(drug => new + { + Date = mh.VisitDate, + Count = drug.Description + })) + .OrderBy(x => x.Date) + .ToList(); + + var result = new List { new[] { "Дата", "Назначенные лекарства" } }; + + result.AddRange(drugData.Select(item => new string[] + { + item.Date.ToString("dd MMMM yyyy"), + item.Count.ToString() + })); + + + return result; + } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs index 0695d4b..347617c 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs @@ -150,26 +150,28 @@ WHERE Id=@id"; var querySelect = $@"SELECT mh.*, CONCAT(p.Last_Name, ' ', p.First_Name) as PatientName, CONCAT(d.Last_Name, ' ', d.First_Name) as DoctorName, - dmh.Id AS Id, dmh.DrugId AS drugId, dmh.Description AS Description + dmh.Id AS Id, dmh.DrugId AS drugId,dmh.MedicalHistoryId AS MedicalHistoryId, dmh.Description FROM MedicalHistory mh LEFT JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id LEFT JOIN Patient p ON p.Id = mh.PatientId LEFT JOIN doctor d ON d.Id = mh.DoctorId {builder.Build()}"; - + _logger.LogDebug("SQL запрос: {query}", querySelect); + _logger.LogDebug("Параметры: dateForm = {dateForm}, dateTo = {dateTo}, doctorId = {doctorId}, patientId = {patientId}", + dateForm, dateTo, DoctorId, PatientId); var historyDict = new Dictionary>(); var medicalHistory = connection.Query(querySelect, - (history, drugMedicalHistory) => + (history, drug) => { if (!historyDict.TryGetValue(history.Id, out var drugs)) { drugs = new List(); historyDict.Add(history.Id, drugs); } - if (drugMedicalHistory != null && drugMedicalHistory.Id > 0) + if (drug != null && drug.Id > 0) { - drugs.Add(DrugMedicalHistory.CreateEntity(drugMedicalHistory.Id, drugMedicalHistory.DrugId, drugMedicalHistory.Description)); + drugs.Add(DrugMedicalHistory.CreateEntity(drug.Id, drug.DrugId, drug.Description, drug.MedicalHistoryId)); } return history; }, splitOn: "Id", param: new { dateForm, dateTo, DoctorId, PatientId }); @@ -179,7 +181,7 @@ WHERE Id=@id"; return historyDict.Select(x => { var mh = medicalHistory.First(y => y.Id == x.Key); - mh.SetProductMaterial(x.Value); + mh.SetDrugMedHistory(x.Value); return mh; }).ToArray(); } -- 2.25.1 From a30b24aaa1dc3a477d8ac9e69546dbac2152dc74 Mon Sep 17 00:00:00 2001 From: Bulat Date: Thu, 19 Dec 2024 20:14:02 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20Date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/DoctorPayments.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs index 29399fe..46b95c4 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs @@ -24,8 +24,8 @@ public class DoctorPayments public int Count_Patient { get; private set; } - [DisplayName("Дата оплаты")] - public DateTime DoctorPaymentData { get; private set; } + //[DisplayName("Дата оплаты")] + //public DateTime DoctorPaymentData { get; private set; } [DisplayName("Оплата")] public int Payment { get; private set; } @@ -37,7 +37,7 @@ public class DoctorPayments IdDoctor = idDoctor, Month = month, Count_Patient = count_patient, - DoctorPaymentData = DateTime.Now, + // DoctorPaymentData = DateTime.Now, Payment = payment }; } -- 2.25.1 From 0d85b6f4b4ff9a4b81405fec5a92557ba3ff9ab2 Mon Sep 17 00:00:00 2001 From: Bulat Date: Fri, 20 Dec 2024 10:01:46 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D1=87?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=8C=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Doctor.cs | 2 +- .../Entities/DoctorPayments.cs | 3 --- .../Entities/Drug.cs | 2 +- .../Entities/DrugMedicalHistory.cs | 2 +- .../Entities/MedicalHistory.cs | 16 ++-------------- .../Forms/FormDoctor.cs | 4 +--- .../Forms/FormDoctorPayment.cs | 4 ---- .../Forms/FormDoctors.cs | 6 +----- .../Reports/TableReport.cs | 4 ++-- 9 files changed, 9 insertions(+), 34 deletions(-) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs index b1e00d3..4850987 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Doctor.cs @@ -20,7 +20,7 @@ public class Doctor public string FullName => $"{Last_Name} {First_Name}"; [DisplayName("Должность")] - public DoctorPost DoctorPost { get; private set; } // объявляется свойство DoctorPost, которое имеет тип DoctorPost + public DoctorPost DoctorPost { get; private set; } public static Doctor CreateEntity(int id, string first_Name, string last_Name, DoctorPost doctorPost) { diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs index 46b95c4..15228cd 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DoctorPayments.cs @@ -24,8 +24,6 @@ public class DoctorPayments public int Count_Patient { get; private set; } - //[DisplayName("Дата оплаты")] - //public DateTime DoctorPaymentData { get; private set; } [DisplayName("Оплата")] public int Payment { get; private set; } @@ -37,7 +35,6 @@ public class DoctorPayments IdDoctor = idDoctor, Month = month, Count_Patient = count_patient, - // DoctorPaymentData = DateTime.Now, Payment = payment }; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs index fdb03f1..5225770 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Drug.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace RegistrationPatientsPolyclinic.Entities; -public class Drug // Наподобие Feed +public class Drug { public int Id { get; private set; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs index caf9098..4ab6e2c 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace RegistrationPatientsPolyclinic.Entities; -public class DrugMedicalHistory // Тоже самое что FeedFeedRepleshments +public class DrugMedicalHistory { public int Id { get; private set; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs index f01decc..6cd71bc 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace RegistrationPatientsPolyclinic.Entities; -public class MedicalHistory // сущность пополнения, наподобие FeedReplenushment +public class MedicalHistory { public int Id { get; private set; } @@ -49,19 +49,7 @@ public class MedicalHistory // сущность пополнения, напо DrugMedicalHistory = drugMedicalHistory }; } - /* - public static MedicalHistory CreateOpeartion(TempDrugMedicalHistory tempDrugMedicalHistory, IEnumerable drugMedicalHistories) - { - return new MedicalHistory - { - Id = tempDrugMedicalHistory.Id, - PatientId = tempDrugMedicalHistory.PatientId, - DoctorId = tempDrugMedicalHistory.DoctorId, - VisitDate = tempDrugMedicalHistory.VisitDate, - DrugMedicalHistory = drugMedicalHistories - }; - } - */ + public void SetDrugMedHistory(IEnumerable drugMedicalHistory) { if (drugMedicalHistory != null && drugMedicalHistory.Any()) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctor.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctor.cs index 6965cc6..a611eb1 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctor.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctor.cs @@ -16,8 +16,6 @@ namespace RegistrationPatientsPolyclinic.Forms { public partial class FormDoctor : Form { - // Понадобиться интерфейс работника - // так же будет сеттер с id private readonly IDoctorRepository _doctorRepository; @@ -53,7 +51,7 @@ namespace RegistrationPatientsPolyclinic.Forms _doctorRepository = doctorRepository ?? throw new ArgumentNullException(nameof(doctorRepository)); - comboBoxPost.DataSource = Enum.GetValues(typeof(DoctorPost)); // вытащи значение из этого перечисления, вернет массив строк, т.е. массив тпеих элементов(DoctorPost) + comboBoxPost.DataSource = Enum.GetValues(typeof(DoctorPost)); } private void ButtonSave_Click(object sender, EventArgs e) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs index 6dff994..f5be442 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs @@ -36,18 +36,15 @@ namespace RegistrationPatientsPolyclinic.Forms throw new Exception("Имеются не заполненные поля"); } - // Получаем значение из первой строки колонки ColumnMonth string month = dataGridViewPayment.Rows[0].Cells["ColumnMonth"].Value?.ToString(); int countPatient = int.Parse(dataGridViewPayment.Rows[0].Cells["ColumnCount"].Value?.ToString() ?? "0"); int payment = int.Parse(dataGridViewPayment.Rows[0].Cells["ColumnPayment"].Value?.ToString() ?? "0"); - // Проверяем, что месяц не пустой if (string.IsNullOrEmpty(month)) { throw new Exception("Месяц не заполнен"); } - // Создаем элемент DoctorPayments _doctorPaymentsRepository.CreateDoctorPayments(DoctorPayments.CreateElement(0, (int)comboBoxDoctor.SelectedValue!, month, countPatient, payment)); @@ -71,7 +68,6 @@ namespace RegistrationPatientsPolyclinic.Forms { continue; } - // ДОДЕЛАТЬ!!! list.Add(DoctorPayments.CreateElement(0, 0, row.Cells["ColumnMonth"].Value.ToString(), Convert.ToInt32(row.Cells["ColumnCount"].Value), Convert.ToInt32(row.Cells["ColumnPayment"].Value))); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs index 1c90a95..a29e80a 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs @@ -15,8 +15,6 @@ namespace RegistrationPatientsPolyclinic.Forms { public partial class FormDoctors : Form { - // Здесь понадобится экземпляр IUnity контейнер через который мы будем создавать объекты FormDoctor и вызывать его - // IPatientRepository через который мы будем получать список private readonly IUnityContainer _container; @@ -25,7 +23,7 @@ namespace RegistrationPatientsPolyclinic.Forms public FormDoctors(IUnityContainer container, IDoctorRepository doctorRepository) { InitializeComponent(); - _container = container ?? // мы получаем через контейнер объект + _container = container ?? throw new ArgumentNullException(nameof(container)); _doctorRepository = doctorRepository ?? throw new ArgumentNullException(nameof(doctorRepository)); ; @@ -33,7 +31,6 @@ namespace RegistrationPatientsPolyclinic.Forms private void FormDoctors_Load(object sender, EventArgs e) { - // метод, при загрузки формы будет прогружаться все данные try { LoadList(); @@ -43,7 +40,6 @@ namespace RegistrationPatientsPolyclinic.Forms MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - // отдельный метод который будет загружать в GridView private void LoadList() { diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs index 1b14c80..3059bab 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/TableReport.cs @@ -57,13 +57,13 @@ internal class TableReport .AddParagraph($"За период с {startOfMonth:MMMM yyyy} по {endOfMonth:MMMM yyyy}", 0) .AddParagraph($"Врач: {doctorFullName}", 0) .AddTable(new[] { 25, 25, 25 }, tableData); - + /* excelBuilder.AddParagraph("", 0); excelBuilder .AddHeader("Назначенные лекарства", 0, 2) .AddTable(new[] { 25, 25 }, GetDrugData(doctorId, startOfMonth, endOfMonth)); - + */ excelBuilder.Build(); return true; } -- 2.25.1 From cd7f7ae1ef1dc12ed2b9bf8fd401c7def73b39cf Mon Sep 17 00:00:00 2001 From: Bulat Date: Fri, 20 Dec 2024 10:08:48 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B3=D1=83=D1=8E=20=D1=87=D0=B0=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B5=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormDoctors.cs | 2 +- .../Forms/FormDrug.cs | 5 ++- .../Reports/ChartReport.cs | 6 +--- .../Repositories/IDoctorPaymentsRepository.cs | 1 - .../Repositories/IDrugMedicalHistory.cs | 4 +-- .../Repositories/IMedicalHistoryRepository.cs | 4 +-- .../Repositories/IPatientRepository.cs | 11 +++---- .../MedicalHistoryRepository.cs | 32 +------------------ 8 files changed, 13 insertions(+), 52 deletions(-) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs index a29e80a..36ed46d 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctors.cs @@ -49,7 +49,7 @@ namespace RegistrationPatientsPolyclinic.Forms } - private bool TryGetIdentifierFromSelectedRow(out int id) // возвращает смог н извлечь или нет + private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; if (dataGridView.SelectedRows.Count < 1) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.cs index 53c7c91..fbab324 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.cs @@ -32,7 +32,6 @@ namespace RegistrationPatientsPolyclinic.Forms { throw new InvalidDataException(nameof(drag)); } - // проходимся по всем значениям перечисления foreach (DrugName elem in Enum.GetValues(typeof(DrugName))) { if ((elem & drag.DrugName) != 0) @@ -57,10 +56,10 @@ namespace RegistrationPatientsPolyclinic.Forms InitializeComponent(); _drugRepository = drugRepository?? throw new ArgumentNullException(nameof(drugRepository)); - // вытаскиваем все значения + foreach(var elem in Enum.GetValues(typeof(DrugName))) { - checkedListBoxName.Items.Add(elem); // заполняем поэлементно значения + checkedListBoxName.Items.Add(elem); } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs index bf87118..13af507 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Reports/ChartReport.cs @@ -43,16 +43,13 @@ internal class ChartReport } 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.DoctorName, @@ -61,12 +58,11 @@ internal class ChartReport DoctorName = doctorName, TotalDrugAssignments = group .SelectMany(mh => mh.DrugMedicalHistory) - .Count() // Считаем количество назначений лекарств + .Count() } ) .ToList(); - // Преобразуем данные в формат, подходящий для диаграммы var result = groupedData .Select(x => (Caption: x.DoctorName, Value: (double)x.TotalDrugAssignments)) .ToList(); diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs index 4b65f1b..ff85ddb 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs @@ -9,7 +9,6 @@ namespace RegistrationPatientsPolyclinic.Repositories; public interface IDoctorPaymentsRepository { - //IEnumerable ReadDoctorPayments(); IEnumerable ReadDoctorPayments(int? doctorId = null, string month = null); void CreateDoctorPayments(DoctorPayments doctorPayments); diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugMedicalHistory.cs index 264724a..35c5321 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugMedicalHistory.cs @@ -10,9 +10,9 @@ namespace RegistrationPatientsPolyclinic.Repositories; public interface IDrugMedicalHistory { - IEnumerable ReadDragMedicalHistory(int? drugId, string description); // чтение всего + IEnumerable ReadDragMedicalHistory(int? drugId, string description); - void CreateDrugMedicalHistory(DrugMedicalHistory drugHistory); // создание объекта + void CreateDrugMedicalHistory(DrugMedicalHistory drugHistory); void DeleteDrugMedicalHistory(int Id); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs index c32625a..f320a62 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IMedicalHistoryRepository.cs @@ -11,9 +11,9 @@ public interface IMedicalHistoryRepository { IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, - int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть + int? DoctorId = null); - void CreateMedicalHistory(MedicalHistory medicalHistory); // объекь будет заносится в список + void CreateMedicalHistory(MedicalHistory medicalHistory); void DeletemedicalHistory(int id); diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IPatientRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IPatientRepository.cs index 3cc9133..0c50cf3 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IPatientRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IPatientRepository.cs @@ -7,18 +7,15 @@ using System.Threading.Tasks; namespace RegistrationPatientsPolyclinic.Repositories; -/// -/// Операцию read (чтение) разобьем на 2 метода: получение коллекции и получений одной записи по идентификатору. -/// public interface IPatientRepository { - IEnumerable ReadPatient(); // метод получения всего списка (в данном случае пациентов) + IEnumerable ReadPatient(); - Patient ReadPatientById(int id); // получение по id + Patient ReadPatientById(int id); - void CreatPatient(Patient patient); // метод для того чтобы добавить в существующую коллекцию пациента + void CreatPatient(Patient patient); - void UpdatePatient(Patient patient); // метод на изменение + void UpdatePatient(Patient patient); void DeletePatient(int id); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs index 347617c..2edebe7 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs @@ -86,37 +86,7 @@ WHERE Id=@id"; } } - /* - public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) - { - _logger.LogInformation("Получение всех объектов"); - try - { - using var connection = new - NpgsqlConnection(_connectionString.ConnectionString); - //var querySelect = @"SELECT * FROM MedicalHistory"; - var querySelect = @"SELECT mh.*, dmh.DrugId, dmh.Description - FROM MedicalHistory mh - INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id"; - var medicalHistory = - connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(medicalHistory)); - return medicalHistory.GroupBy(x => x.Id, y => y, - (key, value) => MedicalHistory.CreateOpeartion(value.First(), - value.Select(z => DrugMedicalHistory.CreateEntity(0, z.DrugId, z.Description)))).ToList(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка при чтении объектов"); - throw; - } - } - */ - - - // ВНИЗУ САМЫЙ ПОСЛЕДНИЙ ПРАВИЛЬНЫЙ!!!! - + public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) { -- 2.25.1