diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs index 0745d4f..1c79b3d 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs @@ -15,16 +15,16 @@ public class DrugMedicalHistory // Тоже самое что FeedFeedRepleshme //public int MedicalHistoryId { get; private set; } - //public string Description { get; private set; } + public string Description { get; private set; } = string.Empty; - public static DrugMedicalHistory CreateEntity(int id, int drugId) + public static DrugMedicalHistory CreateEntity(int id, int drugId, string description) { return new DrugMedicalHistory { Id = id, DrugId = drugId, - // MedicalHistoryId = medicalHistoryId, - // Description = description + //MedicalHistoryId = medicalHistoryId, + Description = description ?? string.Empty }; } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs index e15c2e2..a9bab71 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/MedicalHistory.cs @@ -15,11 +15,9 @@ public class MedicalHistory // сущность пополнения, напо public int DoctorId { get; private set; } - // public Diagnosis Diagnosis { get; private set; } public DateTime VisitDate { get; private set; } - // public Status Status { get; private set; } public IEnumerable DrugMedicalHistory { get; private set; } = []; @@ -31,9 +29,7 @@ public class MedicalHistory // сущность пополнения, напо Id = id, PatientId = patientId, DoctorId = doctorId, - // Diagnosis = diagnosis, VisitDate = DateTime.Now, - // Status = status, DrugMedicalHistory = drugMedicalHistory }; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs index 2ab6bfa..70cb6e3 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/Patient.cs @@ -10,7 +10,7 @@ public class Patient { public int Id { get; private set; } - public string Firts_Name { get; private set; } = string .Empty; // string.Empty - означает, что по умолчанию это свойство будет содержать пустую строку, а не null(то же самое "") + public string First_Name { get; private set; } = string .Empty; // string.Empty - означает, что по умолчанию это свойство будет содержать пустую строку, а не null(то же самое "") public string Last_Name { get; private set; } = string.Empty; @@ -19,12 +19,12 @@ public class Patient // ТУТ СДЕЛАЕМ СТАТИСТИЧЕСКИЙ МЕТОД, который будет отвечать за создание объекта - public static Patient CreateEntity(int id, string firts_Name, string last_Name, string contactNumber) + public static Patient CreateEntity(int id, string first_Name, string last_Name, string contactNumber) { return new Patient { Id = id, - Firts_Name = firts_Name, + First_Name = first_Name, Last_Name = last_Name, ContactNumber = contactNumber }; diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/FormPolyclinic.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/FormPolyclinic.cs index 4b5fdf7..7bcd0ee 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/FormPolyclinic.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/FormPolyclinic.cs @@ -67,7 +67,7 @@ namespace RegistrationPatientsPolyclinic { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); } catch (Exception ex) { diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs index 2c7c665..791c85b 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDoctorPayment.cs @@ -38,8 +38,8 @@ namespace RegistrationPatientsPolyclinic.Forms // Получаем значение из первой строки колонки ColumnMonth string month = dataGridViewPayment.Rows[0].Cells["ColumnMonth"].Value?.ToString(); - int countPatient = int.Parse(dataGridViewPayment.Rows[0].Cells["Column2"].Value?.ToString() ?? "0"); - int payment = int.Parse(dataGridViewPayment.Rows[0].Cells["Column3"].Value?.ToString() ?? "0"); + 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)) diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.Designer.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.Designer.cs index 7c6a744..ca35cdc 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.Designer.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrug.Designer.cs @@ -41,7 +41,7 @@ // labelName // labelName.AutoSize = true; - labelName.Location = new Point(25, 34); + labelName.Location = new Point(23, 34); labelName.Name = "labelName"; labelName.Size = new Size(49, 20); labelName.TabIndex = 0; @@ -50,7 +50,7 @@ // labelGrams // labelGrams.AutoSize = true; - labelGrams.Location = new Point(25, 91); + labelGrams.Location = new Point(23, 148); labelGrams.Name = "labelGrams"; labelGrams.Size = new Size(51, 20); labelGrams.TabIndex = 1; @@ -59,7 +59,7 @@ // labelDescription // labelDescription.AutoSize = true; - labelDescription.Location = new Point(25, 142); + labelDescription.Location = new Point(16, 200); labelDescription.Name = "labelDescription"; labelDescription.Size = new Size(85, 20); labelDescription.TabIndex = 2; @@ -67,14 +67,14 @@ // // textBoxGrams // - textBoxGrams.Location = new Point(137, 88); + textBoxGrams.Location = new Point(137, 148); textBoxGrams.Name = "textBoxGrams"; textBoxGrams.Size = new Size(125, 27); textBoxGrams.TabIndex = 4; // // buttonSave // - buttonSave.Location = new Point(16, 317); + buttonSave.Location = new Point(7, 344); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); buttonSave.TabIndex = 6; @@ -84,7 +84,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(168, 317); + buttonCancel.Location = new Point(168, 344); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); buttonCancel.TabIndex = 7; @@ -94,7 +94,7 @@ // // textBoxDescription // - textBoxDescription.Location = new Point(137, 142); + textBoxDescription.Location = new Point(137, 200); textBoxDescription.Multiline = true; textBoxDescription.Name = "textBoxDescription"; textBoxDescription.Size = new Size(125, 123); @@ -105,7 +105,7 @@ checkedListBoxName.FormattingEnabled = true; checkedListBoxName.Location = new Point(137, 34); checkedListBoxName.Name = "checkedListBoxName"; - checkedListBoxName.Size = new Size(150, 26); + checkedListBoxName.Size = new Size(150, 92); checkedListBoxName.TabIndex = 9; // // FormDrug diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs index 3ee7682..23e5537 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormDrugs.cs @@ -75,7 +75,7 @@ namespace RegistrationPatientsPolyclinic.Forms try { - var form = _container.Resolve(); + var form = _container.Resolve(); form.Id = findId; form.ShowDialog(); LoadList(); @@ -88,7 +88,15 @@ namespace RegistrationPatientsPolyclinic.Forms private void FormDrags_Load(object sender, EventArgs e) { - + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private bool TryGetIdentifierFromSelectedRow(out int id) // возвращает смог н извлечь или нет diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs index 3bda3cf..ca2f20c 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs @@ -34,11 +34,10 @@ labelPacient = new Label(); groupBox1 = new GroupBox(); dataGridView = new DataGridView(); - ColumnDiagnosis = new DataGridViewComboBoxColumn(); - ColumnStatus = new DataGridViewComboBoxColumn(); - ColumnDrug = new DataGridViewComboBoxColumn(); labelDoctor = new Label(); comboBoxDoctor = new ComboBox(); + ColumnDrug = new DataGridViewComboBoxColumn(); + ColumnDescription = new DataGridViewTextBoxColumn(); groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -100,7 +99,7 @@ dataGridView.AllowUserToResizeRows = false; dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDiagnosis, ColumnStatus, ColumnDrug }); + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug, ColumnDescription }); dataGridView.Location = new Point(9, 26); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; @@ -110,31 +109,6 @@ dataGridView.Size = new Size(510, 188); dataGridView.TabIndex = 0; // - // ColumnDiagnosis - // - ColumnDiagnosis.HeaderText = "Диагноз"; - ColumnDiagnosis.MinimumWidth = 6; - ColumnDiagnosis.Name = "ColumnDiagnosis"; - ColumnDiagnosis.Resizable = DataGridViewTriState.True; - ColumnDiagnosis.SortMode = DataGridViewColumnSortMode.Automatic; - ColumnDiagnosis.Width = 125; - // - // ColumnStatus - // - ColumnStatus.HeaderText = "Статус"; - ColumnStatus.MinimumWidth = 6; - ColumnStatus.Name = "ColumnStatus"; - ColumnStatus.Width = 125; - // - // ColumnDrug - // - ColumnDrug.HeaderText = "Лекарство"; - ColumnDrug.MinimumWidth = 6; - ColumnDrug.Name = "ColumnDrug"; - ColumnDrug.Resizable = DataGridViewTriState.True; - ColumnDrug.SortMode = DataGridViewColumnSortMode.Automatic; - ColumnDrug.Width = 125; - // // labelDoctor // labelDoctor.AutoSize = true; @@ -153,6 +127,22 @@ comboBoxDoctor.Size = new Size(151, 28); comboBoxDoctor.TabIndex = 16; // + // ColumnDrug + // + ColumnDrug.HeaderText = "Лекарство"; + ColumnDrug.MinimumWidth = 6; + ColumnDrug.Name = "ColumnDrug"; + ColumnDrug.Resizable = DataGridViewTriState.True; + ColumnDrug.SortMode = DataGridViewColumnSortMode.Automatic; + ColumnDrug.Width = 125; + // + // ColumnDescription + // + ColumnDescription.HeaderText = "Описание"; + ColumnDescription.MinimumWidth = 6; + ColumnDescription.Name = "ColumnDescription"; + ColumnDescription.Width = 125; + // // FormMedicalHistory // AutoScaleDimensions = new SizeF(8F, 20F); @@ -180,10 +170,9 @@ private Label labelPacient; private GroupBox groupBox1; private DataGridView dataGridView; - private DataGridViewComboBoxColumn ColumnDiagnosis; - private DataGridViewComboBoxColumn ColumnStatus; - private DataGridViewComboBoxColumn ColumnDrug; private Label labelDoctor; private ComboBox comboBoxDoctor; + private DataGridViewComboBoxColumn ColumnDrug; + private DataGridViewTextBoxColumn ColumnDescription; } } \ No newline at end of file diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs index 90cdd3e..2b617c9 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs @@ -91,7 +91,7 @@ _medicalHistoryRepository.ReadMedicalHistory(); { continue; } - list.Add(DrugMedicalHistory.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnDrug"].Value))); + list.Add(DrugMedicalHistory.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnDrug"].Value), row.Cells["ColumnDescription"].Value?.ToString())); } return list; } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx index f8b0fa0..fb5ab64 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx @@ -117,13 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - True + + True + \ No newline at end of file diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatient.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatient.cs index 4a0db59..87f3fc0 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatient.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormPatient.cs @@ -36,7 +36,7 @@ namespace RegistrationPatientsPolyclinic.Forms throw new InvalidDataException(nameof(patient)); // если не находим выкидываем ошибку } // Если все норм, то пытаемся заполнить поля - textBoxName.Text = patient.Firts_Name; + textBoxName.Text = patient.First_Name; textBoxLastName.Text = patient.Last_Name; textBoxContactNumber.Text = patient.ContactNumber; _patientId = value; diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Program.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Program.cs index 0deec3f..ad84fe0 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Program.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Program.cs @@ -1,6 +1,10 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using RegistrationPatientsPolyclinic.Repositories; using RegistrationPatientsPolyclinic.Repositories.Implementations; +using Serilog; using Unity; +using Unity.Microsoft.Logging; namespace RegistrationPatientsPolyclinic { @@ -26,14 +30,31 @@ namespace RegistrationPatientsPolyclinic // + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + + container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); container.RegisterType(); + container.RegisterType(); return container; } + + private static LoggerFactory CreateLoggerFactory() + { + var loggerFactory = new LoggerFactory(); + loggerFactory.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .Build()) + .CreateLogger()); + return loggerFactory; + } + } } \ No newline at end of file diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic.csproj b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic.csproj index c77a06e..2efeb50 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic.csproj +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic.csproj @@ -10,7 +10,19 @@ + + + + + + + + + + + + @@ -28,4 +40,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IConnectionString.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IConnectionString.cs new file mode 100644 index 0000000..d99e765 --- /dev/null +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IConnectionString.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RegistrationPatientsPolyclinic.Repositories; + +public interface IConnectionString +{ + string ConnectionString { get; } +} diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs index 63515e3..bb151d8 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDoctorPaymentsRepository.cs @@ -9,13 +9,9 @@ namespace RegistrationPatientsPolyclinic.Repositories; public interface IDoctorPaymentsRepository { - IEnumerable ReadDoctorPayments(); + IEnumerable ReadDoctorPayments(); - DoctorPayments ReadDoctorPaymentsById(int id); void CreateDoctorPayments(DoctorPayments doctorPayments); - void UpdateDoctorPayments(DoctorPayments doctorPayments); - - void DeleteDoctorPayments(int id); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugRepository.cs index 50fc6d2..9f64064 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/IDrugRepository.cs @@ -13,9 +13,9 @@ public interface IDrugRepository Drug ReadDrugById(int id); - void CreateDrug(Drug drag); + void CreateDrug(Drug drug); - void UpdateDrug(Drug drag); + void UpdateDrug(Drug drug); void DeleteDrug(int id); } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/ConnectionString.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..13924a6 --- /dev/null +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/ConnectionString.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RegistrationPatientsPolyclinic.Repositories.Implementations; + +public class ConnectionString : IConnectionString +{ + string IConnectionString.ConnectionString => "Server=localhost,5432;Database=polyclinic;Uid=postgres;Pwd=postgres;"; +} diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs index c70b5be..7bcfd5c 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorPaymentsRepository.cs @@ -1,7 +1,14 @@ -using RegistrationPatientsPolyclinic.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using RegistrationPatientsPolyclinic.Entities; +using Serilog.Core; using System; using System.Collections.Generic; +using System.Data.SqlClient; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -9,25 +16,59 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations; public class DoctorPaymentsRepository : IDoctorPaymentsRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public DoctorPaymentsRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateDoctorPayments(DoctorPayments doctorPayments) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(doctorPayments)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO DoctorPayments (IdDoctor, Month, Count_Patient, Payment) +VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)"; + connection.Execute(queryInsert, doctorPayments); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } - public void DeleteDoctorPayments(int id) + public IEnumerable ReadDoctorPayments() { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM DoctorPayments"; + var doctorPayments = + connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(doctorPayments)); + return doctorPayments; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } - public IEnumerable ReadDoctorPayments() - { - return []; - } - public DoctorPayments ReadDoctorPaymentsById(int id) - { - return DoctorPayments.CreateElement(0, 0, string.Empty, 0, 0); - } - public void UpdateDoctorPayments(DoctorPayments doctorPayments) - { - } } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorRepository.cs index 488d638..1c7e9c8 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DoctorRepository.cs @@ -1,4 +1,8 @@ -using RegistrationPatientsPolyclinic.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using RegistrationPatientsPolyclinic.Entities; using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; @@ -10,25 +14,123 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations; public class DoctorRepository : IDoctorRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public DoctorRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateDoctor(Doctor doctor) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(doctor)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO Doctor (First_Name, Last_Name, DoctorPost) +VALUES (@First_Name, @Last_Name, @DoctorPost)"; + connection.Execute(queryInsert, doctor); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + public void UpdateDoctor(Doctor doctor) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(doctor)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Doctor +SET +First_Name=@First_Name, +Last_Name=@Last_Name, +DoctorPost=@DoctorPost +WHERE Id=@Id"; + connection.Execute(queryUpdate, doctor); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } - public void DeleteDoctor(int id) { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Doctor +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Doctor ReadDoctorById(int id) { - return Doctor.CreateEntity(0, string.Empty, string.Empty, DoctorPost.None); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Doctor +WHERE Id=@id"; + var doctor = connection.QueryFirst(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(doctor)); + return doctor; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadDoctors() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Doctor"; + var doctor = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(doctor)); + return doctor; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } - public void UpdateDoctor(Doctor doctor) - { - } + } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DrugRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DrugRepository.cs index c64d8e9..1c22d04 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DrugRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/DrugRepository.cs @@ -1,4 +1,8 @@ -using RegistrationPatientsPolyclinic.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using RegistrationPatientsPolyclinic.Entities; using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; @@ -10,28 +14,124 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations; public class DrugRepository : IDrugRepository { - public void CreateDrug(Drug drag) + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public DrugRepository(IConnectionString connectionString, ILogger logger) { - + _connectionString = connectionString; + _logger = logger; + } + public void CreateDrug(Drug drug) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(drug)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO Drug (DrugName, Grams, Description) +VALUES (@DrugName, @Grams, @Description)"; + connection.Execute(queryInsert, drug); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + public void UpdateDrug(Drug drug) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(drug)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Drug +SET +DrugName=@DrugName, +Grams=@Grams, +Description=@Description +WHERE Id=@Id"; + connection.Execute(queryUpdate, drug); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } public void DeleteDrug(int id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Drug +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public IEnumerable ReadDrug() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Drug"; + var drug = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(drug)); + return drug; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public Drug ReadDrugById(int id) { - return Drug.CreateElement(0, DrugName.None, 0, string.Empty); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Drug +WHERE Id=@id"; + var patient = connection.QueryFirst(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(patient)); + return patient; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } - public void UpdateDrug(Drug drag) - { - - } -} + +} \ No newline at end of file diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs index a16c292..fa4e999 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs @@ -1,7 +1,12 @@ -using RegistrationPatientsPolyclinic.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using RegistrationPatientsPolyclinic.Entities; using RegistrationPatientsPolyclinic.Entities.Enums; using System; using System.Collections.Generic; +using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,22 +15,95 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations; public class MedicalHistoryRepository : IMedicalHistoryRepository { + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + public MedicalHistoryRepository(IConnectionString connectionString, + ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateMedicalHistory(MedicalHistory medicalHistory) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(medicalHistory)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + connection.Open(); + using var transaction = connection.BeginTransaction(); + var queryInsert = @" +INSERT INTO MedicalHistory (PatientId, DoctorId, VisitDate) +VALUES (@PatientId, @DoctorId, @VisitDate); +SELECT MAX(Id) FROM MedicalHistory"; + var medicalHistoryId = + connection.QueryFirst(queryInsert, medicalHistory, transaction); + var querySubInsert = @" +INSERT INTO DrugMedicalHistory (DrugId, MedicalHistoryId, Description) +VALUES (@DrugId,@MedicalHistoryId, @Description)"; + foreach (var elem in medicalHistory.DrugMedicalHistory) + { + connection.Execute(querySubInsert, new + { + elem.DrugId, + medicalHistoryId, + elem.Description + }, transaction); + } + transaction.Commit(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public void DeletemedicalHistory(int id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM MedicalHistory +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + 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; + } + } - - } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/PatientRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/PatientRepository.cs index 1dbcbda..c33d043 100644 --- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/PatientRepository.cs +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/PatientRepository.cs @@ -1,6 +1,12 @@ -using RegistrationPatientsPolyclinic.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using RegistrationPatientsPolyclinic.Entities; +using Serilog.Core; using System; using System.Collections.Generic; +using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,25 +15,129 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations; public class PatientRepository : IPatientRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public PatientRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreatPatient(Patient patient) { - } + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(patient)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO patient (First_Name, Last_Name, ContactNumber) +VALUES (@First_Name, @Last_Name, @ContactNumber)"; + connection.Execute(queryInsert, patient); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + + } + public void UpdatePatient(Patient patient) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(patient)); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Patient +SET +First_Name=@First_Name, +Last_Name=@Last_Name, +ContactNumber=@ContactNumber +WHERE Id=@Id"; + connection.Execute(queryUpdate, patient); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + + } public void DeletePatient(int id) { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Patient +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } public IEnumerable ReadPatient() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Patient"; + var patient = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(patient)); + return patient; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } public Patient ReadPatientById(int id) { - return Patient.CreateEntity(0, string.Empty, string.Empty, string.Empty); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new + NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Patient +WHERE Id=@id"; + var patient = connection.QueryFirst(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(patient)); + return patient; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } - public void UpdatePatient(Patient patient) - { - } + } diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/appsettings.json b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/appsettings.json new file mode 100644 index 0000000..aaf8a2b --- /dev/null +++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/polyclinic_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file