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; } - }*/ + } }