PIBD-22. Denisov V.D. LabWork_2 #3

Closed
kisame wants to merge 6 commits from LabWork_2 into LabWork_1
23 changed files with 744 additions and 158 deletions

View File

@ -12,14 +12,14 @@ public enum DrugsNames
None = 0,
Paracetamol = 1,
Ibuprofen = 2,
Aspirin = 4,
Antibiotic = 8,
Antihistamine = 16,
Insulin = 32,
}
}

View File

@ -30,25 +30,23 @@ namespace ProjectPolyclinic.Forms
}
private readonly IDoctorRepository _doctorRepository;
private int? _doctorId;
public int Id
{
set
{
try
{
_doctorId = value;
var doctor = _doctorRepository.ReadDoctorById(value);
if (doctor == null)
{
throw new InvalidDataException(nameof(doctor));
}
textBoxFirstName.Text = doctor.First_Name;
textBoxLastName.Text = doctor.Last_Name;
numericUpDownRoom.Value = doctor.Room;
@ -58,20 +56,20 @@ namespace ProjectPolyclinic.Forms
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) ||
numericUpDownRoom.Value < 1 ||
comboBoxSpecialization.SelectedItem == null ||
comboBoxSpecializationLevel.SelectedItem == null)
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) ||
string.IsNullOrWhiteSpace(textBoxLastName.Text) ||
numericUpDownRoom.Value < 1 ||
comboBoxSpecialization.SelectedItem == null ||
comboBoxSpecializationLevel.SelectedItem == null)
{
throw new Exception("Имеются незаполненные поля");
}
@ -94,6 +92,7 @@ namespace ProjectPolyclinic.Forms
}
private void buttonCancel_Click(object sender, EventArgs e) => Close();
private Doctor CreateDoctor(int id) =>

View File

@ -34,33 +34,37 @@
comboBoxDoctor = new ComboBox();
label4 = new Label();
dateTimePicker = new DateTimePicker();
label1 = new Label();
label2 = new Label();
numericCount = new NumericUpDown();
numericPay = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericCount).BeginInit();
((System.ComponentModel.ISupportInitialize)numericPay).BeginInit();
SuspendLayout();
//
// labelDoctor
//
labelDoctor.AutoSize = true;
labelDoctor.Location = new Point(35, 43);
labelDoctor.Location = new Point(31, 32);
labelDoctor.Name = "labelDoctor";
labelDoctor.Size = new Size(43, 20);
labelDoctor.Size = new Size(34, 15);
labelDoctor.TabIndex = 0;
labelDoctor.Text = "Врач";
//
// buttonCancel
//
buttonCancel.Location = new Point(240, 143);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Location = new Point(210, 228);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(106, 39);
buttonCancel.Size = new Size(93, 29);
buttonCancel.TabIndex = 11;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// buttonSave
//
buttonSave.Location = new Point(35, 143);
buttonSave.Margin = new Padding(3, 4, 3, 4);
buttonSave.Location = new Point(31, 228);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(106, 39);
buttonSave.Size = new Size(93, 29);
buttonSave.TabIndex = 10;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
@ -70,18 +74,17 @@
//
comboBoxDoctor.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxDoctor.FormattingEnabled = true;
comboBoxDoctor.Location = new Point(193, 40);
comboBoxDoctor.Margin = new Padding(3, 4, 3, 4);
comboBoxDoctor.Location = new Point(169, 30);
comboBoxDoctor.Name = "comboBoxDoctor";
comboBoxDoctor.Size = new Size(153, 28);
comboBoxDoctor.Size = new Size(134, 23);
comboBoxDoctor.TabIndex = 12;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(35, 99);
label4.Location = new Point(31, 74);
label4.Name = "label4";
label4.Size = new Size(54, 20);
label4.Size = new Size(43, 15);
label4.TabIndex = 17;
label4.Text = "Месяц";
//
@ -89,26 +92,66 @@
//
dateTimePicker.CustomFormat = "MMMM yyyy";
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.Location = new Point(193, 94);
dateTimePicker.Location = new Point(169, 70);
dateTimePicker.Margin = new Padding(3, 2, 3, 2);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(153, 27);
dateTimePicker.Size = new Size(134, 23);
dateTimePicker.TabIndex = 22;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(31, 116);
label1.Name = "label1";
label1.Size = new Size(113, 15);
label1.TabIndex = 23;
label1.Text = "Кол-во посещений";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(31, 153);
label2.Name = "label2";
label2.Size = new Size(47, 15);
label2.TabIndex = 24;
label2.Text = "Оплата";
//
// numericCount
//
numericCount.Location = new Point(169, 114);
numericCount.Maximum = new decimal(new int[] { 999999, 0, 0, 0 });
numericCount.Name = "numericCount";
numericCount.Size = new Size(134, 23);
numericCount.TabIndex = 27;
//
// numericPay
//
numericPay.Location = new Point(169, 151);
numericPay.Maximum = new decimal(new int[] { 999999, 0, 0, 0 });
numericPay.Name = "numericPay";
numericPay.Size = new Size(134, 23);
numericPay.TabIndex = 28;
//
// FormDoctorPayment
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(370, 207);
ClientSize = new Size(324, 272);
Controls.Add(numericPay);
Controls.Add(numericCount);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dateTimePicker);
Controls.Add(label4);
Controls.Add(comboBoxDoctor);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelDoctor);
Margin = new Padding(3, 4, 3, 4);
Name = "FormDoctorPayment";
StartPosition = FormStartPosition.CenterScreen;
Text = "Оплата врачу";
((System.ComponentModel.ISupportInitialize)numericCount).EndInit();
((System.ComponentModel.ISupportInitialize)numericPay).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -121,5 +164,9 @@
private ComboBox comboBoxDoctor;
private Label label4;
private DateTimePicker dateTimePicker;
private Label label1;
private Label label2;
private NumericUpDown numericCount;
private NumericUpDown numericPay;
}
}

View File

@ -17,14 +17,16 @@ public partial class FormDoctorPayment : Form
{
private readonly IDoctorPayRepository _doctorPayRepository;
public FormDoctorPayment(IDoctorPayRepository doctorPayRepository, IDoctorRepository doctorRepository)
public FormDoctorPayment(IDoctorPayRepository doctorPayRepository,
IDoctorRepository doctorRepository)
{
InitializeComponent();
_doctorPayRepository = doctorPayRepository ??
throw new ArgumentNullException(nameof(doctorPayRepository));
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
comboBoxDoctor.DisplayMember = "Firts_Name";
comboBoxDoctor.DisplayMember = "Last_Name";
comboBoxDoctor.ValueMember = "Id";
}
@ -37,13 +39,13 @@ public partial class FormDoctorPayment : Form
throw new Exception("Имеются незаполненные поля.");
}
string month = dateTimePicker.Value.ToString();
//сделать запрос на счет пациентов у каждого врача в medicalhis
_doctorPayRepository.CreateDoctorPayments(DoctorPay.CreateElement(0, (int)comboBoxDoctor.SelectedValue!, month, 0, 0));
int doctorId = (int)comboBoxDoctor.SelectedValue!;
string month = dateTimePicker.Value.ToString("yyyy-MM");
int patientCount = (int)numericCount.Value;
int payment = (int)numericPay.Value;
var doctorPay = DoctorPay.CreateElement(0, doctorId, month, patientCount, payment);
_doctorPayRepository.CreateDoctorPayments(doctorPay);
Close();
}

View File

@ -34,7 +34,7 @@ public partial class FormDoctors : Form
_doctorRepository = doctorRepository ??
throw new ArgumentNullException(nameof(doctorRepository));
}
private void FormDoctors_Load(object sender, EventArgs e)
{
@ -103,11 +103,11 @@ public partial class FormDoctors : Form
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormDoctor>();
@ -117,7 +117,12 @@ public partial class FormDoctors : Form
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

View File

@ -34,24 +34,27 @@
labelGrams = new Label();
labelDescription = new Label();
checkedListBoxName = new CheckedListBox();
textBoxGrams = new TextBox();
textBoxDescription = new TextBox();
numericGrams = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericGrams).BeginInit();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(177, 302);
buttonCancel.Location = new Point(202, 403);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(93, 29);
buttonCancel.Size = new Size(106, 39);
buttonCancel.TabIndex = 8;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// buttonSave
//
buttonSave.Location = new Point(38, 302);
buttonSave.Location = new Point(43, 403);
buttonSave.Margin = new Padding(3, 4, 3, 4);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(93, 29);
buttonSave.Size = new Size(106, 39);
buttonSave.TabIndex = 7;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
@ -60,68 +63,75 @@
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(38, 44);
labelName.Location = new Point(43, 59);
labelName.Name = "labelName";
labelName.Size = new Size(59, 15);
labelName.Size = new Size(77, 20);
labelName.TabIndex = 9;
labelName.Text = "Название";
//
// labelGrams
//
labelGrams.AutoSize = true;
labelGrams.Location = new Point(38, 188);
labelGrams.Location = new Point(43, 251);
labelGrams.Name = "labelGrams";
labelGrams.Size = new Size(60, 15);
labelGrams.Size = new Size(76, 20);
labelGrams.TabIndex = 10;
labelGrams.Text = "Грамовка";
//
// labelDescription
//
labelDescription.AutoSize = true;
labelDescription.Location = new Point(38, 236);
labelDescription.Location = new Point(43, 315);
labelDescription.Name = "labelDescription";
labelDescription.Size = new Size(45, 15);
labelDescription.Size = new Size(57, 20);
labelDescription.TabIndex = 11;
labelDescription.Text = "Рецепт";
//
// checkedListBoxName
//
checkedListBoxName.FormattingEnabled = true;
checkedListBoxName.Location = new Point(136, 44);
checkedListBoxName.Location = new Point(155, 59);
checkedListBoxName.Margin = new Padding(3, 4, 3, 4);
checkedListBoxName.Name = "checkedListBoxName";
checkedListBoxName.Size = new Size(161, 94);
checkedListBoxName.Size = new Size(183, 114);
checkedListBoxName.TabIndex = 12;
//
// textBoxGrams
//
textBoxGrams.Location = new Point(136, 185);
textBoxGrams.Name = "textBoxGrams";
textBoxGrams.Size = new Size(161, 23);
textBoxGrams.TabIndex = 13;
//
// textBoxDescription
//
textBoxDescription.Location = new Point(136, 233);
textBoxDescription.Location = new Point(155, 311);
textBoxDescription.Margin = new Padding(3, 4, 3, 4);
textBoxDescription.Name = "textBoxDescription";
textBoxDescription.Size = new Size(161, 23);
textBoxDescription.Size = new Size(183, 27);
textBoxDescription.TabIndex = 14;
//
// numericGrams
//
numericGrams.Location = new Point(155, 249);
numericGrams.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
numericGrams.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericGrams.Name = "numericGrams";
numericGrams.Size = new Size(183, 27);
numericGrams.TabIndex = 15;
numericGrams.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// FormDrug
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(309, 357);
ClientSize = new Size(353, 476);
Controls.Add(numericGrams);
Controls.Add(textBoxDescription);
Controls.Add(textBoxGrams);
Controls.Add(checkedListBoxName);
Controls.Add(labelDescription);
Controls.Add(labelGrams);
Controls.Add(labelName);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Margin = new Padding(3, 4, 3, 4);
Name = "FormDrug";
StartPosition = FormStartPosition.CenterScreen;
Text = "Лекарство";
((System.ComponentModel.ISupportInitialize)numericGrams).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -134,7 +144,7 @@
private Label labelGrams;
private Label labelDescription;
private CheckedListBox checkedListBoxName;
private TextBox textBoxGrams;
private TextBox textBoxDescription;
private NumericUpDown numericGrams;
}
}

View File

@ -39,7 +39,7 @@ public partial class FormDrug : Form
checkedListBoxName.SetItemChecked(checkedListBoxName.Items.IndexOf(elem), true);
}
}
textBoxGrams.Text = drag.Grams.ToString();
numericGrams.Text = drag.Grams.ToString();
textBoxDescription.Text = drag.Description;
_dragId = value;
@ -69,7 +69,7 @@ public partial class FormDrug : Form
{
try
{
if (string.IsNullOrWhiteSpace(textBoxGrams.Text) || string.IsNullOrWhiteSpace(textBoxDescription.Text) ||
if (string.IsNullOrWhiteSpace(textBoxDescription.Text) ||
checkedListBoxName.CheckedItems.Count == 0)
{
throw new Exception("Имеется незаполненные поля");
@ -104,7 +104,7 @@ public partial class FormDrug : Form
drugName |= (DrugsNames)elem;
}
return Drug.CreateElement(id, drugName, Convert.ToInt32(textBoxGrams.Text), textBoxDescription.Text);
return Drug.CreateElement(id, drugName, (int)numericGrams.Value, textBoxDescription.Text);
}

View File

@ -95,7 +95,7 @@ public partial class FormDrugs : Form
try
{
var form = _container.Resolve<FormDoctor>();
var form = _container.Resolve<FormDrug>();
form.Id = findId;
form.ShowDialog();
LoadList();

View File

@ -34,12 +34,12 @@
comboBoxDoctor = new ComboBox();
groupBox = new GroupBox();
dataGridView = new DataGridView();
ColumnDrug = new DataGridViewComboBoxColumn();
DrugCount = new DataGridViewTextBoxColumn();
label = new Label();
comboBoxStatus = new ComboBox();
buttonCancel = new Button();
buttonSave = new Button();
ColumnDrug = new DataGridViewComboBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -99,7 +99,7 @@
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug, DrugCount });
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug, ColumnCount });
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(3, 24);
dataGridView.Margin = new Padding(3, 4, 3, 4);
@ -111,20 +111,6 @@
dataGridView.Size = new Size(263, 301);
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.AutoSize = true;
@ -165,6 +151,20 @@
buttonSave.UseVisualStyleBackColor = true;
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
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -202,6 +202,6 @@
private Button buttonCancel;
private Button buttonSave;
private DataGridViewComboBoxColumn ColumnDrug;
private DataGridViewTextBoxColumn DrugCount;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -37,7 +37,7 @@ public partial class FormMedicalHistory : Form
comboBoxPacient.ValueMember = "Id";
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
comboBoxDoctor.DisplayMember = "First_Name";
comboBoxDoctor.DisplayMember = "Last_Name";
comboBoxDoctor.ValueMember = "Id";
ColumnDrug.DataSource = drugRepository.ReadDrug();
@ -67,7 +67,6 @@ public partial class FormMedicalHistory : Form
);
_medicalHistoryRepository.CreateMedicalHistory(medicalHistory);
MessageBox.Show("История болезни сохранена.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
catch (Exception ex)

View File

@ -120,13 +120,7 @@
<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>
</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">
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -93,7 +93,6 @@ public partial class FormPatients : Form
{
return;
}
try
{
var form = _container.Resolve<FormPatient>();
@ -103,7 +102,8 @@ public partial class FormPatients : Form
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

View File

@ -1,6 +1,10 @@
using ProjectPolyclinic.Repositories.Implementations;
using ProjectPolyclinic.Repositories;
using Unity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Unity.Microsoft.Logging;
namespace ProjectPolyclinic
{
@ -22,7 +26,7 @@ namespace ProjectPolyclinic
{
var container = new UnityContainer();
// зарегестрируем зависимость
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IPatientRepository, PatientRepository>();
container.RegisterType<IDoctorRepository, DoctorRepository>();
@ -30,10 +34,22 @@ namespace ProjectPolyclinic
container.RegisterType<IMedicalHistoryRepository, MedicalHistoryRepository>();
container.RegisterType<IDrugRepository, DrugRepository>();
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;
}
}
}

View File

@ -9,7 +9,18 @@
</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="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
@ -39,4 +50,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

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

View File

@ -11,11 +11,5 @@ public interface IDoctorPayRepository
{
IEnumerable<DoctorPay> ReadDoctorPayments();
DoctorPay ReadDoctorPaymentsById(int id);
void CreateDoctorPayments(DoctorPay doctorPayments);
void UpdateDoctorPayments(DoctorPay doctorPayments);
void DeleteDoctorPayments(int id);
}

View File

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

View File

@ -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.Collections.Generic;
using System.Linq;
@ -9,28 +13,65 @@ namespace ProjectPolyclinic.Repositories.Implementations;
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()
{
return [];
}
public DoctorPay ReadDoctorPaymentsById(int id)
{
return DoctorPay.CreateElement(0, 0, string.Empty, 0, 0);
}
_logger.LogInformation("Получение всех объектов");
try
{
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();
}
}
}

View File

@ -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 System;
using System.Collections.Generic;
@ -10,28 +14,141 @@ namespace ProjectPolyclinic.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
{
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)
{
_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;
}
}
}

View File

@ -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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
namespace ProjectPolyclinic.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 drugs (DrugsNames, grams, Description)
VALUES (@DrugsNames, @Grams, @Description)";
connection.Execute(queryInsert, 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 drugs 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 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)
{
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;
}
}
}

View File

@ -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 System;
using System.Collections.Generic;
@ -10,19 +14,105 @@ namespace ProjectPolyclinic.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)
{
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)
{
_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)
{
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;
}
}
}

View File

@ -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.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
@ -9,25 +14,145 @@ namespace ProjectPolyclinic.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
{
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)
{
_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()
{
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)
{
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)
{
_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;
}
}
}

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/Polyclinic_log.txt",
"rollingInterval": "Day"
}
}
]
}
}