Доделать!
This commit is contained in:
parent
092d1c2c85
commit
09eea654df
@ -15,11 +15,9 @@ public class MedicalHistory // сущность пополнения, напо
|
|||||||
|
|
||||||
public int DoctorId { get; private set; }
|
public int DoctorId { get; private set; }
|
||||||
|
|
||||||
// public Diagnosis Diagnosis { get; private set; }
|
|
||||||
|
|
||||||
public DateTime VisitDate { get; private set; }
|
public DateTime VisitDate { get; private set; }
|
||||||
|
|
||||||
// public Status Status { get; private set; }
|
|
||||||
|
|
||||||
public IEnumerable<DrugMedicalHistory> DrugMedicalHistory { get; private set; } = [];
|
public IEnumerable<DrugMedicalHistory> DrugMedicalHistory { get; private set; } = [];
|
||||||
|
|
||||||
@ -31,9 +29,7 @@ public class MedicalHistory // сущность пополнения, напо
|
|||||||
Id = id,
|
Id = id,
|
||||||
PatientId = patientId,
|
PatientId = patientId,
|
||||||
DoctorId = doctorId,
|
DoctorId = doctorId,
|
||||||
// Diagnosis = diagnosis,
|
|
||||||
VisitDate = DateTime.Now,
|
VisitDate = DateTime.Now,
|
||||||
// Status = status,
|
|
||||||
DrugMedicalHistory = drugMedicalHistory
|
DrugMedicalHistory = drugMedicalHistory
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public class Patient
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
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;
|
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
|
return new Patient
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Firts_Name = firts_Name,
|
First_Name = first_Name,
|
||||||
Last_Name = last_Name,
|
Last_Name = last_Name,
|
||||||
ContactNumber = contactNumber
|
ContactNumber = contactNumber
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,7 @@ namespace RegistrationPatientsPolyclinic
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_container.Resolve<FormDrug>().ShowDialog();
|
_container.Resolve<FormDrugs>().ShowDialog();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -34,11 +34,9 @@
|
|||||||
labelPacient = new Label();
|
labelPacient = new Label();
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
ColumnDiagnosis = new DataGridViewComboBoxColumn();
|
|
||||||
ColumnStatus = new DataGridViewComboBoxColumn();
|
|
||||||
ColumnDrug = new DataGridViewComboBoxColumn();
|
|
||||||
labelDoctor = new Label();
|
labelDoctor = new Label();
|
||||||
comboBoxDoctor = new ComboBox();
|
comboBoxDoctor = new ComboBox();
|
||||||
|
ColumnDrug = new DataGridViewComboBoxColumn();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -100,7 +98,7 @@
|
|||||||
dataGridView.AllowUserToResizeRows = false;
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDiagnosis, ColumnStatus, ColumnDrug });
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug });
|
||||||
dataGridView.Location = new Point(9, 26);
|
dataGridView.Location = new Point(9, 26);
|
||||||
dataGridView.MultiSelect = false;
|
dataGridView.MultiSelect = false;
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
@ -110,31 +108,6 @@
|
|||||||
dataGridView.Size = new Size(510, 188);
|
dataGridView.Size = new Size(510, 188);
|
||||||
dataGridView.TabIndex = 0;
|
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
|
||||||
//
|
//
|
||||||
labelDoctor.AutoSize = true;
|
labelDoctor.AutoSize = true;
|
||||||
@ -153,6 +126,15 @@
|
|||||||
comboBoxDoctor.Size = new Size(151, 28);
|
comboBoxDoctor.Size = new Size(151, 28);
|
||||||
comboBoxDoctor.TabIndex = 16;
|
comboBoxDoctor.TabIndex = 16;
|
||||||
//
|
//
|
||||||
|
// ColumnDrug
|
||||||
|
//
|
||||||
|
ColumnDrug.HeaderText = "Лекарство";
|
||||||
|
ColumnDrug.MinimumWidth = 6;
|
||||||
|
ColumnDrug.Name = "ColumnDrug";
|
||||||
|
ColumnDrug.Resizable = DataGridViewTriState.True;
|
||||||
|
ColumnDrug.SortMode = DataGridViewColumnSortMode.Automatic;
|
||||||
|
ColumnDrug.Width = 125;
|
||||||
|
//
|
||||||
// FormMedicalHistory
|
// FormMedicalHistory
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -180,10 +162,8 @@
|
|||||||
private Label labelPacient;
|
private Label labelPacient;
|
||||||
private GroupBox groupBox1;
|
private GroupBox groupBox1;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private DataGridViewComboBoxColumn ColumnDiagnosis;
|
|
||||||
private DataGridViewComboBoxColumn ColumnStatus;
|
|
||||||
private DataGridViewComboBoxColumn ColumnDrug;
|
|
||||||
private Label labelDoctor;
|
private Label labelDoctor;
|
||||||
private ComboBox comboBoxDoctor;
|
private ComboBox comboBoxDoctor;
|
||||||
|
private DataGridViewComboBoxColumn ColumnDrug;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -117,12 +117,6 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<metadata name="ColumnDiagnosis.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnStatus.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="ColumnDrug.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColumnDrug.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
@ -36,7 +36,7 @@ namespace RegistrationPatientsPolyclinic.Forms
|
|||||||
throw new InvalidDataException(nameof(patient)); // если не находим выкидываем ошибку
|
throw new InvalidDataException(nameof(patient)); // если не находим выкидываем ошибку
|
||||||
}
|
}
|
||||||
// Если все норм, то пытаемся заполнить поля
|
// Если все норм, то пытаемся заполнить поля
|
||||||
textBoxName.Text = patient.Firts_Name;
|
textBoxName.Text = patient.First_Name;
|
||||||
textBoxLastName.Text = patient.Last_Name;
|
textBoxLastName.Text = patient.Last_Name;
|
||||||
textBoxContactNumber.Text = patient.ContactNumber;
|
textBoxContactNumber.Text = patient.ContactNumber;
|
||||||
_patientId = value;
|
_patientId = value;
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using RegistrationPatientsPolyclinic.Repositories;
|
using RegistrationPatientsPolyclinic.Repositories;
|
||||||
using RegistrationPatientsPolyclinic.Repositories.Implementations;
|
using RegistrationPatientsPolyclinic.Repositories.Implementations;
|
||||||
|
using Serilog;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
|
||||||
namespace RegistrationPatientsPolyclinic
|
namespace RegistrationPatientsPolyclinic
|
||||||
{
|
{
|
||||||
@ -26,14 +30,31 @@ namespace RegistrationPatientsPolyclinic
|
|||||||
|
|
||||||
// çàðåãåñòðèðóåì çàâèñèìîñòü
|
// çàðåãåñòðèðóåì çàâèñèìîñòü
|
||||||
|
|
||||||
|
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||||
|
|
||||||
|
|
||||||
container.RegisterType<IPatientRepository, PatientRepository>();
|
container.RegisterType<IPatientRepository, PatientRepository>();
|
||||||
container.RegisterType<IDoctorRepository, DoctorRepository>();
|
container.RegisterType<IDoctorRepository, DoctorRepository>();
|
||||||
container.RegisterType<IDoctorPaymentsRepository, DoctorPaymentsRepository>();
|
container.RegisterType<IDoctorPaymentsRepository, DoctorPaymentsRepository>();
|
||||||
container.RegisterType<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
container.RegisterType<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
||||||
container.RegisterType<IDrugRepository, DrugRepository>();
|
container.RegisterType<IDrugRepository, DrugRepository>();
|
||||||
container.RegisterType<IDrugMedicalHistory, DrugMedicalHistoryRepository>();
|
container.RegisterType<IDrugMedicalHistory, DrugMedicalHistoryRepository>();
|
||||||
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
return container;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,7 +10,19 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
||||||
<PackageReference Include="Unity" Version="5.11.10" />
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -28,4 +40,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -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; }
|
||||||
|
}
|
@ -13,9 +13,9 @@ public interface IDrugRepository
|
|||||||
|
|
||||||
Drug ReadDrugById(int id);
|
Drug ReadDrugById(int id);
|
||||||
|
|
||||||
void CreateDrug(Drug drag);
|
void CreateDrug(Drug drug);
|
||||||
|
|
||||||
void UpdateDrug(Drug drag);
|
void UpdateDrug(Drug drug);
|
||||||
|
|
||||||
void DeleteDrug(int id);
|
void DeleteDrug(int id);
|
||||||
}
|
}
|
||||||
|
@ -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;";
|
||||||
|
}
|
@ -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 RegistrationPatientsPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,28 +14,124 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations;
|
|||||||
|
|
||||||
public class DrugRepository : IDrugRepository
|
public class DrugRepository : IDrugRepository
|
||||||
{
|
{
|
||||||
public void CreateDrug(Drug drag)
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<DrugRepository> _logger;
|
||||||
|
|
||||||
|
public DrugRepository(IConnectionString connectionString, ILogger<DrugRepository> 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)
|
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<Drug> ReadDrug()
|
public IEnumerable<Drug> ReadDrug()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Drug";
|
||||||
|
var drug = connection.Query<Drug>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(drug));
|
||||||
|
return drug;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drug ReadDrugById(int id)
|
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<Drug>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(patient));
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDrug(Drug drag)
|
|
||||||
{
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,25 +15,129 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations;
|
|||||||
|
|
||||||
public class PatientRepository : IPatientRepository
|
public class PatientRepository : IPatientRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<PatientRepository> _logger;
|
||||||
|
|
||||||
|
public PatientRepository(IConnectionString connectionString, ILogger<PatientRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreatPatient(Patient patient)
|
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)
|
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<Patient> ReadPatient()
|
public IEnumerable<Patient> ReadPatient()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Patient";
|
||||||
|
var patient = connection.Query<Patient>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(patient));
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Patient ReadPatientById(int id)
|
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<Patient>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(patient));
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePatient(Patient patient)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/polyclinic_log.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user