Доделал
This commit is contained in:
parent
578f9735f4
commit
21bbcf3794
@ -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
|
||||
Description = description ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -120,4 +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="ColumnDescription.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -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<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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user