ISEbd-21 Hairullov B.A. Lab_Work_02 #4
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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> 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
|
||||
};
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -67,7 +67,7 @@ namespace RegistrationPatientsPolyclinic
|
||||
{
|
||||
try
|
||||
{
|
||||
_container.Resolve<FormDrug>().ShowDialog();
|
||||
_container.Resolve<FormDrugs>().ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -75,7 +75,7 @@ namespace RegistrationPatientsPolyclinic.Forms
|
||||
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormDoctor>();
|
||||
var form = _container.Resolve<FormDrug>();
|
||||
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) // возвращает смог н извлечь или нет
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -117,13 +117,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</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">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ColumnDescription.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -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;
|
||||
|
@ -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<IPatientRepository, PatientRepository>();
|
||||
container.RegisterType<IDoctorRepository, DoctorRepository>();
|
||||
container.RegisterType<IDoctorPaymentsRepository, DoctorPaymentsRepository>();
|
||||
container.RegisterType<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
||||
container.RegisterType<IDrugRepository, DrugRepository>();
|
||||
container.RegisterType<IDrugMedicalHistory, DrugMedicalHistoryRepository>();
|
||||
container.RegisterType<IConnectionString, ConnectionString>();
|
||||
|
||||
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>
|
||||
|
||||
<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.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -28,4 +40,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</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; }
|
||||
}
|
@ -9,13 +9,9 @@ namespace RegistrationPatientsPolyclinic.Repositories;
|
||||
|
||||
public interface IDoctorPaymentsRepository
|
||||
{
|
||||
IEnumerable<IDoctorPaymentsRepository> ReadDoctorPayments();
|
||||
IEnumerable<DoctorPayments> ReadDoctorPayments();
|
||||
|
||||
DoctorPayments ReadDoctorPaymentsById(int id);
|
||||
|
||||
void CreateDoctorPayments(DoctorPayments doctorPayments);
|
||||
|
||||
void UpdateDoctorPayments(DoctorPayments doctorPayments);
|
||||
|
||||
void DeleteDoctorPayments(int id);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,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<DoctorPaymentsRepository> _logger;
|
||||
|
||||
public DoctorPaymentsRepository(IConnectionString connectionString, ILogger<DoctorPaymentsRepository> 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<DoctorPayments> ReadDoctorPayments()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM DoctorPayments";
|
||||
var doctorPayments =
|
||||
connection.Query<DoctorPayments>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(doctorPayments));
|
||||
return doctorPayments;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<IDoctorPaymentsRepository> ReadDoctorPayments()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public DoctorPayments ReadDoctorPaymentsById(int id)
|
||||
{
|
||||
return DoctorPayments.CreateElement(0, 0, string.Empty, 0, 0);
|
||||
}
|
||||
|
||||
public void UpdateDoctorPayments(DoctorPayments doctorPayments)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -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<DoctorRepository> _logger;
|
||||
|
||||
public DoctorRepository(IConnectionString connectionString, ILogger<DoctorRepository> 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<Doctor>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(doctor));
|
||||
return doctor;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Doctor> ReadDoctors()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Doctor";
|
||||
var doctor = connection.Query<Doctor>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(doctor));
|
||||
return doctor;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDoctor(Doctor doctor)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<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)
|
||||
{
|
||||
|
||||
_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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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,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<MedicalHistoryRepository> _logger;
|
||||
public MedicalHistoryRepository(IConnectionString connectionString,
|
||||
ILogger<MedicalHistoryRepository> 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<int>(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<MedicalHistory> 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<MedicalHistory>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(medicalHistory));
|
||||
return medicalHistory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<PatientRepository> _logger;
|
||||
|
||||
public PatientRepository(IConnectionString connectionString, ILogger<PatientRepository> 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<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)
|
||||
{
|
||||
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