2готово
This commit is contained in:
parent
b2bb2766fb
commit
4c9a5d26ae
@ -30,25 +30,23 @@ namespace ProjectPolyclinic.Forms
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private readonly IDoctorRepository _doctorRepository;
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
|
||||||
private int? _doctorId;
|
private int? _doctorId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int Id
|
public int Id
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_doctorId = value;
|
||||||
var doctor = _doctorRepository.ReadDoctorById(value);
|
var doctor = _doctorRepository.ReadDoctorById(value);
|
||||||
if (doctor == null)
|
if (doctor == null)
|
||||||
{
|
{
|
||||||
throw new InvalidDataException(nameof(doctor));
|
throw new InvalidDataException(nameof(doctor));
|
||||||
}
|
}
|
||||||
|
|
||||||
textBoxFirstName.Text = doctor.First_Name;
|
textBoxFirstName.Text = doctor.First_Name;
|
||||||
textBoxLastName.Text = doctor.Last_Name;
|
textBoxLastName.Text = doctor.Last_Name;
|
||||||
numericUpDownRoom.Value = doctor.Room;
|
numericUpDownRoom.Value = doctor.Room;
|
||||||
@ -58,20 +56,20 @@ namespace ProjectPolyclinic.Forms
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void buttonSave_Click(object sender, EventArgs e)
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) ||
|
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) ||
|
||||||
numericUpDownRoom.Value < 1 ||
|
string.IsNullOrWhiteSpace(textBoxLastName.Text) ||
|
||||||
comboBoxSpecialization.SelectedItem == null ||
|
numericUpDownRoom.Value < 1 ||
|
||||||
comboBoxSpecializationLevel.SelectedItem == null)
|
comboBoxSpecialization.SelectedItem == null ||
|
||||||
|
comboBoxSpecializationLevel.SelectedItem == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
@ -94,6 +92,7 @@ namespace ProjectPolyclinic.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
private Doctor CreateDoctor(int id) =>
|
private Doctor CreateDoctor(int id) =>
|
||||||
|
@ -34,6 +34,10 @@
|
|||||||
comboBoxDoctor = new ComboBox();
|
comboBoxDoctor = new ComboBox();
|
||||||
label4 = new Label();
|
label4 = new Label();
|
||||||
dateTimePicker = new DateTimePicker();
|
dateTimePicker = new DateTimePicker();
|
||||||
|
label1 = new Label();
|
||||||
|
label2 = new Label();
|
||||||
|
textBoxCount = new TextBox();
|
||||||
|
textBoxPay = new TextBox();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// labelDoctor
|
// labelDoctor
|
||||||
@ -47,7 +51,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCancel
|
// buttonCancel
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(240, 143);
|
buttonCancel.Location = new Point(240, 304);
|
||||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonCancel.Name = "buttonCancel";
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Size = new Size(106, 39);
|
buttonCancel.Size = new Size(106, 39);
|
||||||
@ -57,7 +61,7 @@
|
|||||||
//
|
//
|
||||||
// buttonSave
|
// buttonSave
|
||||||
//
|
//
|
||||||
buttonSave.Location = new Point(35, 143);
|
buttonSave.Location = new Point(35, 304);
|
||||||
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonSave.Name = "buttonSave";
|
buttonSave.Name = "buttonSave";
|
||||||
buttonSave.Size = new Size(106, 39);
|
buttonSave.Size = new Size(106, 39);
|
||||||
@ -94,11 +98,47 @@
|
|||||||
dateTimePicker.Size = new Size(153, 27);
|
dateTimePicker.Size = new Size(153, 27);
|
||||||
dateTimePicker.TabIndex = 22;
|
dateTimePicker.TabIndex = 22;
|
||||||
//
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(35, 155);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(142, 20);
|
||||||
|
label1.TabIndex = 23;
|
||||||
|
label1.Text = "Кол-во посещений";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(35, 204);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(59, 20);
|
||||||
|
label2.TabIndex = 24;
|
||||||
|
label2.Text = "Оплата";
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
textBoxCount.Location = new Point(193, 152);
|
||||||
|
textBoxCount.Name = "textBoxCount";
|
||||||
|
textBoxCount.Size = new Size(153, 27);
|
||||||
|
textBoxCount.TabIndex = 25;
|
||||||
|
//
|
||||||
|
// textBoxPay
|
||||||
|
//
|
||||||
|
textBoxPay.Location = new Point(193, 201);
|
||||||
|
textBoxPay.Name = "textBoxPay";
|
||||||
|
textBoxPay.Size = new Size(153, 27);
|
||||||
|
textBoxPay.TabIndex = 26;
|
||||||
|
//
|
||||||
// FormDoctorPayment
|
// FormDoctorPayment
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(370, 207);
|
ClientSize = new Size(370, 363);
|
||||||
|
Controls.Add(textBoxPay);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(label1);
|
||||||
Controls.Add(dateTimePicker);
|
Controls.Add(dateTimePicker);
|
||||||
Controls.Add(label4);
|
Controls.Add(label4);
|
||||||
Controls.Add(comboBoxDoctor);
|
Controls.Add(comboBoxDoctor);
|
||||||
@ -121,5 +161,9 @@
|
|||||||
private ComboBox comboBoxDoctor;
|
private ComboBox comboBoxDoctor;
|
||||||
private Label label4;
|
private Label label4;
|
||||||
private DateTimePicker dateTimePicker;
|
private DateTimePicker dateTimePicker;
|
||||||
|
private Label label1;
|
||||||
|
private Label label2;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private TextBox textBoxPay;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,14 +17,16 @@ public partial class FormDoctorPayment : Form
|
|||||||
{
|
{
|
||||||
|
|
||||||
private readonly IDoctorPayRepository _doctorPayRepository;
|
private readonly IDoctorPayRepository _doctorPayRepository;
|
||||||
public FormDoctorPayment(IDoctorPayRepository doctorPayRepository, IDoctorRepository doctorRepository)
|
|
||||||
|
public FormDoctorPayment(IDoctorPayRepository doctorPayRepository,
|
||||||
|
IDoctorRepository doctorRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_doctorPayRepository = doctorPayRepository ??
|
_doctorPayRepository = doctorPayRepository ??
|
||||||
throw new ArgumentNullException(nameof(doctorPayRepository));
|
throw new ArgumentNullException(nameof(doctorPayRepository));
|
||||||
|
|
||||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||||
comboBoxDoctor.DisplayMember = "Firts_Name";
|
comboBoxDoctor.DisplayMember = "Last_Name";
|
||||||
comboBoxDoctor.ValueMember = "Id";
|
comboBoxDoctor.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,18 +34,20 @@ public partial class FormDoctorPayment : Form
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (comboBoxDoctor.SelectedIndex < 0)
|
if (comboBoxDoctor.SelectedIndex < 0 ||
|
||||||
|
string.IsNullOrWhiteSpace(textBoxCount.Text) ||
|
||||||
|
string.IsNullOrWhiteSpace(textBoxPay.Text))
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля.");
|
throw new Exception("Имеются незаполненные поля.");
|
||||||
}
|
}
|
||||||
|
|
||||||
string month = dateTimePicker.Value.ToString();
|
int doctorId = (int)comboBoxDoctor.SelectedValue!;
|
||||||
|
string month = dateTimePicker.Value.ToString("yyyy-MM");
|
||||||
//сделать запрос на счет пациентов у каждого врача в medicalhis
|
int patientCount = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
int payment = Convert.ToInt32(textBoxPay.Text);
|
||||||
_doctorPayRepository.CreateDoctorPayments(DoctorPay.CreateElement(0, (int)comboBoxDoctor.SelectedValue!, month, 0, 0));
|
|
||||||
|
|
||||||
|
|
||||||
|
var doctorPay = DoctorPay.CreateElement(0, doctorId, month, patientCount, payment);
|
||||||
|
_doctorPayRepository.CreateDoctorPayments(doctorPay);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -103,11 +103,11 @@ public partial class FormDoctors : Form
|
|||||||
|
|
||||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var form = _container.Resolve<FormDoctor>();
|
var form = _container.Resolve<FormDoctor>();
|
||||||
@ -117,7 +117,12 @@ public partial class FormDoctors : Form
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public partial class FormDrugs : Form
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var form = _container.Resolve<FormDoctor>();
|
var form = _container.Resolve<FormDrug>();
|
||||||
form.Id = findId;
|
form.Id = findId;
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
LoadList();
|
LoadList();
|
||||||
|
@ -34,12 +34,12 @@
|
|||||||
comboBoxDoctor = new ComboBox();
|
comboBoxDoctor = new ComboBox();
|
||||||
groupBox = new GroupBox();
|
groupBox = new GroupBox();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
ColumnDrug = new DataGridViewComboBoxColumn();
|
|
||||||
DrugCount = new DataGridViewTextBoxColumn();
|
|
||||||
label = new Label();
|
label = new Label();
|
||||||
comboBoxStatus = new ComboBox();
|
comboBoxStatus = new ComboBox();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
buttonSave = new Button();
|
buttonSave = new Button();
|
||||||
|
ColumnDrug = new DataGridViewComboBoxColumn();
|
||||||
|
ColumnCount = new DataGridViewTextBoxColumn();
|
||||||
groupBox.SuspendLayout();
|
groupBox.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -99,7 +99,7 @@
|
|||||||
dataGridView.AllowUserToResizeColumns = false;
|
dataGridView.AllowUserToResizeColumns = false;
|
||||||
dataGridView.AllowUserToResizeRows = false;
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug, DrugCount });
|
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug, ColumnCount });
|
||||||
dataGridView.Dock = DockStyle.Fill;
|
dataGridView.Dock = DockStyle.Fill;
|
||||||
dataGridView.Location = new Point(3, 24);
|
dataGridView.Location = new Point(3, 24);
|
||||||
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||||
@ -111,20 +111,6 @@
|
|||||||
dataGridView.Size = new Size(263, 301);
|
dataGridView.Size = new Size(263, 301);
|
||||||
dataGridView.TabIndex = 0;
|
dataGridView.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// ColumnDrug
|
|
||||||
//
|
|
||||||
ColumnDrug.HeaderText = "Лекарство";
|
|
||||||
ColumnDrug.MinimumWidth = 6;
|
|
||||||
ColumnDrug.Name = "ColumnDrug";
|
|
||||||
ColumnDrug.Width = 125;
|
|
||||||
//
|
|
||||||
// DrugCount
|
|
||||||
//
|
|
||||||
DrugCount.HeaderText = "Количество";
|
|
||||||
DrugCount.MinimumWidth = 6;
|
|
||||||
DrugCount.Name = "DrugCount";
|
|
||||||
DrugCount.Width = 125;
|
|
||||||
//
|
|
||||||
// label
|
// label
|
||||||
//
|
//
|
||||||
label.AutoSize = true;
|
label.AutoSize = true;
|
||||||
@ -165,6 +151,20 @@
|
|||||||
buttonSave.UseVisualStyleBackColor = true;
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
buttonSave.Click += buttonSave_Click;
|
buttonSave.Click += buttonSave_Click;
|
||||||
//
|
//
|
||||||
|
// ColumnDrug
|
||||||
|
//
|
||||||
|
ColumnDrug.HeaderText = "Лекарство";
|
||||||
|
ColumnDrug.MinimumWidth = 6;
|
||||||
|
ColumnDrug.Name = "ColumnDrug";
|
||||||
|
ColumnDrug.Width = 125;
|
||||||
|
//
|
||||||
|
// ColumnCount
|
||||||
|
//
|
||||||
|
ColumnCount.HeaderText = "Количество";
|
||||||
|
ColumnCount.MinimumWidth = 6;
|
||||||
|
ColumnCount.Name = "ColumnCount";
|
||||||
|
ColumnCount.Width = 125;
|
||||||
|
//
|
||||||
// FormMedicalHistory
|
// FormMedicalHistory
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -202,6 +202,6 @@
|
|||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private DataGridViewComboBoxColumn ColumnDrug;
|
private DataGridViewComboBoxColumn ColumnDrug;
|
||||||
private DataGridViewTextBoxColumn DrugCount;
|
private DataGridViewTextBoxColumn ColumnCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ public partial class FormMedicalHistory : Form
|
|||||||
comboBoxPacient.ValueMember = "Id";
|
comboBoxPacient.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||||
comboBoxDoctor.DisplayMember = "First_Name";
|
comboBoxDoctor.DisplayMember = "Last_Name";
|
||||||
comboBoxDoctor.ValueMember = "Id";
|
comboBoxDoctor.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnDrug.DataSource = drugRepository.ReadDrug();
|
ColumnDrug.DataSource = drugRepository.ReadDrug();
|
||||||
@ -67,7 +67,6 @@ public partial class FormMedicalHistory : Form
|
|||||||
);
|
);
|
||||||
|
|
||||||
_medicalHistoryRepository.CreateMedicalHistory(medicalHistory);
|
_medicalHistoryRepository.CreateMedicalHistory(medicalHistory);
|
||||||
MessageBox.Show("История болезни сохранена.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -120,13 +120,7 @@
|
|||||||
<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>
|
||||||
<metadata name="DrugCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColumnCount.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="DrugCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -93,7 +93,6 @@ public partial class FormPatients : Form
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var form = _container.Resolve<FormPatient>();
|
var form = _container.Resolve<FormPatient>();
|
||||||
@ -103,7 +102,8 @@ public partial class FormPatients : Form
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
using ProjectPolyclinic.Repositories.Implementations;
|
using ProjectPolyclinic.Repositories.Implementations;
|
||||||
using ProjectPolyclinic.Repositories;
|
using ProjectPolyclinic.Repositories;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
|
||||||
namespace ProjectPolyclinic
|
namespace ProjectPolyclinic
|
||||||
{
|
{
|
||||||
@ -22,7 +26,7 @@ namespace ProjectPolyclinic
|
|||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
|
|
||||||
// зарегестрируем зависимость
|
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||||
|
|
||||||
container.RegisterType<IPatientRepository, PatientRepository>();
|
container.RegisterType<IPatientRepository, PatientRepository>();
|
||||||
container.RegisterType<IDoctorRepository, DoctorRepository>();
|
container.RegisterType<IDoctorRepository, DoctorRepository>();
|
||||||
@ -30,10 +34,22 @@ namespace ProjectPolyclinic
|
|||||||
container.RegisterType<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
container.RegisterType<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
||||||
container.RegisterType<IDrugRepository, DrugRepository>();
|
container.RegisterType<IDrugRepository, DrugRepository>();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,18 @@
|
|||||||
</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="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>
|
||||||
@ -39,4 +50,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 ProjectPolyclinic.Repositories;
|
||||||
|
|
||||||
|
public interface IConnectionString
|
||||||
|
{
|
||||||
|
public string ConnectionString { get; }
|
||||||
|
}
|
@ -11,11 +11,5 @@ public interface IDoctorPayRepository
|
|||||||
{
|
{
|
||||||
IEnumerable<DoctorPay> ReadDoctorPayments();
|
IEnumerable<DoctorPay> ReadDoctorPayments();
|
||||||
|
|
||||||
DoctorPay ReadDoctorPaymentsById(int id);
|
|
||||||
|
|
||||||
void CreateDoctorPayments(DoctorPay doctorPayments);
|
void CreateDoctorPayments(DoctorPay doctorPayments);
|
||||||
|
|
||||||
void UpdateDoctorPayments(DoctorPay doctorPayments);
|
|
||||||
|
|
||||||
void DeleteDoctorPayments(int id);
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace ProjectPolyclinic.Repositories.Implementations;
|
||||||
|
|
||||||
|
public class ConnectionString : IConnectionString
|
||||||
|
{
|
||||||
|
|
||||||
|
string IConnectionString.ConnectionString =>
|
||||||
|
"Server=localhost, Port=5432;Database=polyclinicotp;User Id=postgres;Password=postgres;";
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,8 @@
|
|||||||
using ProjectPolyclinic.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPolyclinic.Entities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -9,28 +13,65 @@ namespace ProjectPolyclinic.Repositories.Implementations;
|
|||||||
|
|
||||||
public class DoctorPayRepository : IDoctorPayRepository
|
public class DoctorPayRepository : IDoctorPayRepository
|
||||||
{
|
{
|
||||||
public void CreateDoctorPayments(DoctorPay doctorPayments)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<DoctorPayRepository> _logger;
|
||||||
|
|
||||||
|
public DoctorPayRepository(IConnectionString connectionString, ILogger<DoctorPayRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteDoctorPayments(int id)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
public void CreateDoctorPayments(DoctorPay doctorPayments)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
|
||||||
|
var query = @"
|
||||||
|
INSERT INTO doctor_pay (IdDoctor, Month, Count_Patient, Payment)
|
||||||
|
VALUES (@DoctorId, @Month, @CountPatient, @Payment)";
|
||||||
|
|
||||||
|
connection.Execute(query, new
|
||||||
|
{
|
||||||
|
DoctorId = doctorPayments.IdDoctor,
|
||||||
|
Month = doctorPayments.Month,
|
||||||
|
CountPatient = doctorPayments.Count_Patient,
|
||||||
|
Payment = doctorPayments.Payment
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при создании записи о платеже врачу");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<DoctorPay> ReadDoctorPayments()
|
public IEnumerable<DoctorPay> ReadDoctorPayments()
|
||||||
{
|
{
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public DoctorPay ReadDoctorPaymentsById(int id)
|
_logger.LogInformation("Получение всех объектов");
|
||||||
{
|
try
|
||||||
return DoctorPay.CreateElement(0, 0, string.Empty, 0, 0);
|
{
|
||||||
}
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM doctor_pay";
|
||||||
|
var professionalDevelopments =
|
||||||
|
connection.Query<DoctorPay>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(professionalDevelopments));
|
||||||
|
return professionalDevelopments;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateDoctorPayments(DoctorPay doctorPayments)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
using ProjectPolyclinic.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPolyclinic.Entities;
|
||||||
using ProjectPolyclinic.Entities.Enums;
|
using ProjectPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,28 +14,141 @@ namespace ProjectPolyclinic.Repositories.Implementations;
|
|||||||
|
|
||||||
public class DoctorRepository : IDoctorRepository
|
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)
|
public void CreateDoctor(Doctor doctor)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
}
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(doctor));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Doctors (first_name, last_name, room, specialization, specializationlevel)
|
||||||
|
VALUES (@First_Name, @Last_Name, @Room, @Specialization, @SpecializationLevel)";
|
||||||
|
|
||||||
public void DeleteDoctor(int id)
|
connection.Execute(queryInsert, doctor);
|
||||||
{
|
}
|
||||||
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
public Doctor ReadDoctorById(int id)
|
|
||||||
{
|
|
||||||
return Doctor.CreateEntity(0, string.Empty, string.Empty, 0, Specialization.None, SpecializationLevel.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Doctor> ReadDoctors()
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDoctor(Doctor doctor)
|
public void UpdateDoctor(Doctor doctor)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(doctor));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
// Проверяем, существует ли запись
|
||||||
|
var existingDoctor = connection.QueryFirstOrDefault<Doctor>("SELECT * FROM Doctors WHERE id = @Id", new { doctor.Id });
|
||||||
|
if (existingDoctor == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Запись с Id={Id} не найдена.", doctor.Id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Doctors
|
||||||
|
SET first_name = @First_Name,
|
||||||
|
last_name = @Last_Name,
|
||||||
|
room = @Room,
|
||||||
|
specialization = @Specialization,
|
||||||
|
specializationlevel = @SpecializationLevel
|
||||||
|
WHERE id = @Id";
|
||||||
|
|
||||||
|
var affectedRows = connection.Execute(queryUpdate, doctor);
|
||||||
|
|
||||||
|
if (affectedRows == 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Обновление не выполнено. Id={Id}.", doctor.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Запись успешно обновлена.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при обновлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void DeleteDoctor(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Doctors WHERE ID=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Doctor ReadDoctorById(int id)
|
||||||
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Doctors 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Doctors";
|
||||||
|
var doctors = connection.Query<Doctor>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(doctors));
|
||||||
|
return doctors;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,131 @@
|
|||||||
using ProjectPolyclinic.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPolyclinic.Entities;
|
||||||
using ProjectPolyclinic.Entities.Enums;
|
using ProjectPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectPolyclinic.Repositories.Implementations;
|
namespace ProjectPolyclinic.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 drugs (DrugsNames, grams, Description)
|
||||||
|
VALUES (@DrugsNames, @Grams, @Description)";
|
||||||
|
|
||||||
|
connection.Execute(queryInsert, 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 drugs 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 drugs";
|
||||||
|
var drugs = connection.Query<Drug>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(drugs));
|
||||||
|
return drugs;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drug ReadDrugById(int id)
|
public Drug ReadDrugById(int id)
|
||||||
{
|
{
|
||||||
return Drug.CreateElement(0, DrugsNames.None, 0, string.Empty);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM drugs WHERE Id=@id";
|
||||||
|
var drug = connection.QueryFirst<Drug>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(drug));
|
||||||
|
return drug;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDrug(Drug drag)
|
public void UpdateDrug(Drug drug)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(drug));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"UPDATE drugs SET
|
||||||
|
DrugsNames = @DrugsNames,
|
||||||
|
grams = @Grams,
|
||||||
|
Description= @Description
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryUpdate, drug);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
using ProjectPolyclinic.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPolyclinic.Entities;
|
||||||
using ProjectPolyclinic.Entities.Enums;
|
using ProjectPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -10,19 +14,105 @@ namespace ProjectPolyclinic.Repositories.Implementations;
|
|||||||
|
|
||||||
public class MedicalHistoryRepository : IMedicalHistoryRepository
|
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)
|
public void CreateMedicalHistory(MedicalHistory medicalHistory)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var queryInsertHistory = @"
|
||||||
|
INSERT INTO medical_history (PatientId, DoctorId, VisitDate, Status)
|
||||||
|
VALUES (@PatientId, @DoctorId, @VisitDate, @Status)
|
||||||
|
RETURNING id;";
|
||||||
|
var historyId = connection.ExecuteScalar<int>(queryInsertHistory, new
|
||||||
|
{
|
||||||
|
medicalHistory.PatientId,
|
||||||
|
medicalHistory.DoctorId,
|
||||||
|
medicalHistory.VisitDate,
|
||||||
|
Status = (int)medicalHistory.Status
|
||||||
|
}, transaction);
|
||||||
|
|
||||||
|
var queryInsertDrugs = @"
|
||||||
|
INSERT INTO drug_med_history (medical_history_id, drug_id, count)
|
||||||
|
VALUES (@MedicalHistoryId, @DrugId, @Count);";
|
||||||
|
|
||||||
|
foreach (var drug in medicalHistory.DrugMedHistory)
|
||||||
|
{
|
||||||
|
connection.Execute(queryInsertDrugs, new
|
||||||
|
{
|
||||||
|
MedicalHistoryId = historyId,
|
||||||
|
DrugId = drug.DrugId,
|
||||||
|
drug.Count
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении медицинской истории");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void DeletemedicalHistory(int id)
|
public void DeletemedicalHistory(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM medical_history 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)
|
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 medical_history";
|
||||||
|
var visitings =
|
||||||
|
connection.Query<MedicalHistory>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(visitings));
|
||||||
|
return visitings;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
using ProjectPolyclinic.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectPolyclinic.Entities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,25 +14,146 @@ namespace ProjectPolyclinic.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
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
//var queryInsert = @"";
|
||||||
|
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO patients (first_name, last_name, address, contactnumber)
|
||||||
|
VALUES (@First_Name, @Last_Name, @Address, @ContactNumber)";
|
||||||
|
|
||||||
|
connection.Execute(queryInsert, 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
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Patients WHERE ID=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Patient> ReadPatient()
|
public IEnumerable<Patient> ReadPatient()
|
||||||
{
|
{
|
||||||
return [];
|
//return [];
|
||||||
|
_logger.LogInformation("Получение всех объектов пациентов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Patients";
|
||||||
|
var patients = connection.Query<Patient>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные пациенты: {json}", JsonConvert.SerializeObject(patients));
|
||||||
|
return patients;
|
||||||
|
}
|
||||||
|
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, string.Empty);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Patients 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)
|
public void UpdatePatient(Patient patient)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(patient));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
|
||||||
|
// Проверяем, существует ли запись
|
||||||
|
var existingDoctor = connection.QueryFirstOrDefault<Patient>("SELECT * FROM Patients WHERE id = @Id", new { patient.Id });
|
||||||
|
if (existingDoctor == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Запись с Id={Id} не найдена.", patient.Id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE patients
|
||||||
|
SET first_name = @First_Name,
|
||||||
|
last_name = @Last_Name,
|
||||||
|
address = @Address,
|
||||||
|
contactnumber = @Contactnumber
|
||||||
|
WHERE id = @Id";
|
||||||
|
|
||||||
|
var affectedRows = connection.Execute(queryUpdate, patient);
|
||||||
|
|
||||||
|
if (affectedRows == 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Обновление не выполнено. Id={Id}.", patient.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Запись успешно обновлена.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при обновлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
ProjectPolyclinic/ProjectPolyclinic/appsettings.json
Normal file
15
ProjectPolyclinic/ProjectPolyclinic/appsettings.json
Normal file
@ -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