diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs
index 0745d4f..1c79b3d 100644
--- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs
+++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Entities/DrugMedicalHistory.cs
@@ -15,16 +15,16 @@ public class DrugMedicalHistory // Тоже самое что FeedFeedRepleshme
//public int MedicalHistoryId { get; private set; }
- //public string Description { get; private set; }
+ public string Description { get; private set; } = string.Empty;
- public static DrugMedicalHistory CreateEntity(int id, int drugId)
+ public static DrugMedicalHistory CreateEntity(int id, int drugId, string description)
{
return new DrugMedicalHistory
{
Id = id,
DrugId = drugId,
- // MedicalHistoryId = medicalHistoryId,
- // Description = description
+ //MedicalHistoryId = medicalHistoryId,
+ Description = description ?? string.Empty
};
}
}
diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs
index 13238ca..ca2f20c 100644
--- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs
+++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.Designer.cs
@@ -37,6 +37,7 @@
labelDoctor = new Label();
comboBoxDoctor = new ComboBox();
ColumnDrug = new DataGridViewComboBoxColumn();
+ ColumnDescription = new DataGridViewTextBoxColumn();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@@ -98,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[] { ColumnDrug });
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnDrug, ColumnDescription });
dataGridView.Location = new Point(9, 26);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
@@ -135,6 +136,13 @@
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);
@@ -165,5 +173,6 @@
private Label labelDoctor;
private ComboBox comboBoxDoctor;
private DataGridViewComboBoxColumn ColumnDrug;
+ private DataGridViewTextBoxColumn ColumnDescription;
}
}
\ No newline at end of file
diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs
index 90cdd3e..2b617c9 100644
--- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs
+++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.cs
@@ -91,7 +91,7 @@ _medicalHistoryRepository.ReadMedicalHistory();
{
continue;
}
- list.Add(DrugMedicalHistory.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnDrug"].Value)));
+ list.Add(DrugMedicalHistory.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnDrug"].Value), row.Cells["ColumnDescription"].Value?.ToString()));
}
return list;
}
diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx
index cf50a0f..fb5ab64 100644
--- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx
+++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Forms/FormMedicalHistory.resx
@@ -120,4 +120,7 @@
True
+
+ True
+
\ No newline at end of file
diff --git a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs
index 9ca514b..fa4e999 100644
--- a/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs
+++ b/RegistrationPatientsPolyclinic/RegistrationPatientsPolyclinic/Repositories/Implementations/MedicalHistoryRepository.cs
@@ -1,7 +1,12 @@
-using RegistrationPatientsPolyclinic.Entities;
+using Dapper;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using Npgsql;
+using RegistrationPatientsPolyclinic.Entities;
using RegistrationPatientsPolyclinic.Entities.Enums;
using System;
using System.Collections.Generic;
+using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -10,20 +15,95 @@ namespace RegistrationPatientsPolyclinic.Repositories.Implementations;
public class MedicalHistoryRepository : IMedicalHistoryRepository
{
+ private readonly IConnectionString _connectionString;
+ private readonly ILogger _logger;
+ public MedicalHistoryRepository(IConnectionString connectionString,
+ ILogger logger)
+ {
+ _connectionString = connectionString;
+ _logger = logger;
+ }
+
public void CreateMedicalHistory(MedicalHistory medicalHistory)
{
+ _logger.LogInformation("Добавление объекта");
+ _logger.LogDebug("Объект: {json}",
+ JsonConvert.SerializeObject(medicalHistory));
+ try
+ {
+ using var connection = new
+ NpgsqlConnection(_connectionString.ConnectionString);
+ connection.Open();
+ using var transaction = connection.BeginTransaction();
+ var queryInsert = @"
+INSERT INTO MedicalHistory (PatientId, DoctorId, VisitDate)
+VALUES (@PatientId, @DoctorId, @VisitDate);
+SELECT MAX(Id) FROM MedicalHistory";
+ var medicalHistoryId =
+ connection.QueryFirst(queryInsert, medicalHistory, transaction);
+ var querySubInsert = @"
+INSERT INTO DrugMedicalHistory (DrugId, MedicalHistoryId, Description)
+VALUES (@DrugId,@MedicalHistoryId, @Description)";
+ foreach (var elem in medicalHistory.DrugMedicalHistory)
+ {
+ connection.Execute(querySubInsert, new
+ {
+ elem.DrugId,
+ medicalHistoryId,
+ elem.Description
+ }, transaction);
+ }
+ transaction.Commit();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при добавлении объекта");
+ throw;
+ }
}
public void DeletemedicalHistory(int id)
{
-
+ _logger.LogInformation("Удаление объекта");
+ _logger.LogDebug("Объект: {id}", id);
+ try
+ {
+ using var connection = new
+ NpgsqlConnection(_connectionString.ConnectionString);
+ var queryDelete = @"
+DELETE FROM MedicalHistory
+WHERE Id=@id";
+ connection.Execute(queryDelete, new { id });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при удалении объекта");
+ throw;
+ }
}
public IEnumerable ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null, int? DoctorId = null)
{
- return [];
+ _logger.LogInformation("Получение всех объектов");
+ try
+ {
+ using var connection = new
+ NpgsqlConnection(_connectionString.ConnectionString);
+ var querySelect = @"SELECT * FROM MedicalHistory";
+ var medicalHistory =
+ connection.Query(querySelect);
+ _logger.LogDebug("Полученные объекты: {json}",
+ JsonConvert.SerializeObject(medicalHistory));
+ return medicalHistory;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка при чтении объектов");
+ throw;
+ }
+
}
}