Улучшайзинги1

This commit is contained in:
Bulat 2024-12-18 13:34:48 +04:00
parent e8d4571560
commit 2fc3852943
15 changed files with 139 additions and 47 deletions

View File

@ -1,6 +1,7 @@
using RegistrationPatientsPolyclinic.Entities.Enums; using RegistrationPatientsPolyclinic.Entities.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,11 +11,15 @@ namespace RegistrationPatientsPolyclinic.Entities;
public class Doctor public class Doctor
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Имя")]
public string First_Name { get; private set; } = string.Empty; public string First_Name { get; private set; } = string.Empty;
[DisplayName("Фамилия")]
public string Last_Name { get; private set; } = string.Empty; 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 DoctorPost DoctorPost { get; private set; } // объявляется свойство DoctorPost, которое имеет тип DoctorPost
public static Doctor CreateEntity(int id, string first_Name, string last_Name, DoctorPost doctorPost) public static Doctor CreateEntity(int id, string first_Name, string last_Name, DoctorPost doctorPost)

View File

@ -1,23 +1,32 @@
using RegistrationPatientsPolyclinic.Entities.Enums; using RegistrationPatientsPolyclinic.Entities.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace RegistrationPatientsPolyclinic.Entities; namespace RegistrationPatientsPolyclinic.Entities;
public class DoctorPayments // Проверка класса public class DoctorPayments
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int IdDoctor { get; private set; } public int IdDoctor { get; private set; }
[DisplayName("Доктор")]
public string DoctorName { get; private set; } = string.Empty;
[DisplayName("Месяц")]
public string Month { get; private set; } = string.Empty; public string Month { get; private set; } = string.Empty;
[DisplayName("Количество пациентов")]
public int Count_Patient { get; private set; } public int Count_Patient { get; private set; }
[DisplayName("Дата оплаты")]
public DateTime DoctorPaymentData { get; private set; } public DateTime DoctorPaymentData { get; private set; }
[DisplayName("Оплата")]
public int Payment { get; private set; } public int Payment { get; private set; }
public static DoctorPayments CreateElement(int id, int idDoctor, string month, int count_patient, int payment) public static DoctorPayments CreateElement(int id, int idDoctor, string month, int count_patient, int payment)

View File

@ -1,6 +1,7 @@
using RegistrationPatientsPolyclinic.Entities.Enums; using RegistrationPatientsPolyclinic.Entities.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,10 +12,13 @@ public class Drug // Наподобие Feed
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Название лекарства")]
public DrugName DrugName { get; private set; } public DrugName DrugName { get; private set; }
[DisplayName("Количество")]
public int Grams { get; private set; } public int Grams { get; private set; }
[DisplayName("Описание")]
public string Description { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty;
public static Drug CreateElement(int id, DrugName name, int grams, string description) public static Drug CreateElement(int id, DrugName name, int grams, string description)

View File

@ -13,6 +13,7 @@ public class DrugMedicalHistory // Тоже самое что FeedFeedRepleshme
public int DrugId { get; private set; } public int DrugId { get; private set; }
public string DrugName { get; private set; } = string.Empty;
public string Description { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty;

View File

@ -1,6 +1,7 @@
using RegistrationPatientsPolyclinic.Entities.Enums; using RegistrationPatientsPolyclinic.Entities.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,14 +12,28 @@ public class MedicalHistory // сущность пополнения, напо
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Browsable(false)]
public int PatientId { get; private set; } public int PatientId { get; private set; }
[DisplayName("Имя пациента")]
public string PatientName { get; private set; } = string.Empty;
[Browsable(false)]
public int DoctorId { get; private set; } public int DoctorId { get; private set; }
[DisplayName("Имя доктора")]
public string DoctorName { get; private set; } = string.Empty;
[DisplayName("Дата приема")]
public DateTime VisitDate { get; private set; } 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> DrugMedicalHistory { get; set; } = []; public IEnumerable<DrugMedicalHistory> DrugMedicalHistory { get; set; } = [];
public static MedicalHistory CreateEntity(int id, int patientId, int doctorId, public static MedicalHistory CreateEntity(int id, int patientId, int doctorId,
@ -33,7 +48,7 @@ public class MedicalHistory // сущность пополнения, напо
DrugMedicalHistory = drugMedicalHistory DrugMedicalHistory = drugMedicalHistory
}; };
} }
/*
public static MedicalHistory CreateOpeartion(TempDrugMedicalHistory tempDrugMedicalHistory, IEnumerable<DrugMedicalHistory> drugMedicalHistories) public static MedicalHistory CreateOpeartion(TempDrugMedicalHistory tempDrugMedicalHistory, IEnumerable<DrugMedicalHistory> drugMedicalHistories)
{ {
return new MedicalHistory return new MedicalHistory
@ -45,4 +60,12 @@ public class MedicalHistory // сущность пополнения, напо
DrugMedicalHistory = drugMedicalHistories DrugMedicalHistory = drugMedicalHistories
}; };
} }
*/
public void SetProductMaterial(IEnumerable<DrugMedicalHistory> drugMedicalHistory)
{
if (drugMedicalHistory != null && drugMedicalHistory.Any())
{
DrugMedicalHistory = drugMedicalHistory;
}
}
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,15 +11,17 @@ public class Patient
{ {
public int Id { get; private set; } 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 Last_Name { get; private set; } = string.Empty;
public string FullName => $"{First_Name} {Last_Name}";
[DisplayName("Контактный номер")]
public string ContactNumber { get; private set; } public string ContactNumber { get; private set; }
// ТУТ СДЕЛАЕМ СТАТИСТИЧЕСКИЙ МЕТОД, который будет отвечать за создание объекта
public static Patient CreateEntity(int id, string first_Name, string last_Name, string contactNumber) public static Patient CreateEntity(int id, string first_Name, string last_Name, string contactNumber)
{ {
return new Patient return new Patient

View File

@ -23,7 +23,7 @@ namespace RegistrationPatientsPolyclinic.Forms
throw new ArgumentNullException(nameof(doctorPaymentsRepository)); throw new ArgumentNullException(nameof(doctorPaymentsRepository));
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
comboBoxDoctor.DisplayMember = "Firts_Name"; comboBoxDoctor.DisplayMember = "FullName";
comboBoxDoctor.ValueMember = "Id"; comboBoxDoctor.ValueMember = "Id";
} }

View File

@ -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";
}
} }

View File

@ -45,7 +45,12 @@ namespace RegistrationPatientsPolyclinic.Forms
} }
// отдельный метод который будет загружать в GridView // отдельный метод который будет загружать в 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) // возвращает смог н извлечь или нет private bool TryGetIdentifierFromSelectedRow(out int id) // возвращает смог н извлечь или нет

View File

@ -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) private void buttonAdd_Click(object sender, EventArgs e)

View File

@ -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) private void buttonDel_Click(object sender, EventArgs e)
{ {

View File

@ -32,12 +32,12 @@ namespace RegistrationPatientsPolyclinic.Forms
throw new ArgumentNullException(nameof(medicalHistoryRepository)); throw new ArgumentNullException(nameof(medicalHistoryRepository));
comboBoxPacient.DataSource = patientRepository.ReadPatient(); // передает набор всех пациентов comboBoxPacient.DataSource = patientRepository.ReadPatient(); // передает набор всех пациентов
comboBoxPacient.DisplayMember = "First_Name"; // отображение в combobox comboBoxPacient.DisplayMember = "FullName"; // отображение в combobox
comboBoxPacient.ValueMember = "Id"; comboBoxPacient.ValueMember = "Id";
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors(); comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
comboBoxDoctor.DisplayMember = "First_Name"; comboBoxDoctor.DisplayMember = "FullName";
comboBoxDoctor.ValueMember = "Id"; comboBoxDoctor.ValueMember = "Id";
ColumnDrug.DataSource = drugRepository.ReadDrug(); ColumnDrug.DataSource = drugRepository.ReadDrug();

View File

@ -99,7 +99,12 @@ namespace RegistrationPatientsPolyclinic.Forms
// отдельный метод который будет загружать в GridView // отдельный метод который будет загружать в 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) // возвращает смог н извлечь или нет private bool TryGetIdentifierFromSelectedRow(out int id) // возвращает смог н извлечь или нет

View File

@ -47,7 +47,9 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)";
} }
public IEnumerable<DoctorPayments> ReadDoctorPayments() public IEnumerable<DoctorPayments> ReadDoctorPayments()
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
@ -55,7 +57,10 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)";
{ {
using var connection = new using var connection = new
NpgsqlConnection(_connectionString.ConnectionString); 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 = var doctorPayments =
connection.Query<DoctorPayments>(querySelect); connection.Query<DoctorPayments>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
@ -70,6 +75,7 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)";
} }
} }

View File

@ -85,7 +85,7 @@ WHERE Id=@id";
} }
} }
/*
public IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) public IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null)
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
@ -111,8 +111,8 @@ WHERE Id=@id";
throw; throw;
} }
} }
*/
/*
public IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) public IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null)
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
@ -120,44 +120,61 @@ WHERE Id=@id";
{ {
using var connection = new using var connection = new
NpgsqlConnection(_connectionString.ConnectionString); NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM MedicalHistory"; //var querySelect = @"SELECT * FROM MedicalHistory";
var medicalHistory = /* var querySelect = @"SELECT mh.*,
connection.Query<MedicalHistory>(querySelect); CONCAT(p.LastName, ' ', p.FirstName) as PatientName,
_logger.LogDebug("Полученные объекты: {json}", CONCAT(d.LastName, ' ', d.FirstName) as DoctorName,
JsonConvert.SerializeObject(medicalHistory)); dmh.DrugId,
return medicalHistory; dmh.Description
} dr.DrugName AS drugName
catch (Exception ex) FROM MedicalHistory mh
{ LEFT JOIN Patient p on p.Id = mh.PatientId
_logger.LogError(ex, "Ошибка при чтении объектов"); LEFT JOIN Doctor d on d.Id = mh.DoctorId
throw; INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id
} LEFT JOIN Drug dr on dr.Id = dmh.DrugId";*/
} var querySelect = @"SELECT mh.*,
*/ CONCAT(p.Last_Name, ' ', p.First_Name) as PatientName,
/* CONCAT(d.Last_Name, ' ', d.First_Name) as DoctorName,
public IEnumerable<TempDrugMedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) dmh.Id AS Id, dmh.DrugId AS drugId, dmh.Description AS Description
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT mh.*, dmh.DrugId, dmh.Description
FROM MedicalHistory mh 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<int, List<DrugMedicalHistory>>();
var medicalHistory = var medicalHistory =
connection.Query<TempDrugMedicalHistory>(querySelect); connection.Query<MedicalHistory, DrugMedicalHistory, MedicalHistory>(querySelect,
(history, drugMedicalHistory) =>
{
if (!historyDict.TryGetValue(history.Id, out var drugs))
{
drugs = new List<DrugMedicalHistory>();
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}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(medicalHistory)); 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) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка при чтении объектов"); _logger.LogError(ex, "Ошибка при чтении объектов");
throw; throw;
} }
}*/ }
} }