поменяю
This commit is contained in:
parent
2fc3852943
commit
0046fdf9b7
@ -27,12 +27,12 @@ public class MedicalHistory // сущность пополнения, напо
|
|||||||
[DisplayName("Дата приема")]
|
[DisplayName("Дата приема")]
|
||||||
public DateTime VisitDate { get; private set; }
|
public DateTime VisitDate { get; private set; }
|
||||||
|
|
||||||
[DisplayName("Таблетки")]
|
|
||||||
|
|
||||||
public string Drug => DrugMedicalHistory != null ?
|
public string Drug => DrugMedicalHistory != null ?
|
||||||
string.Join(", ", DrugMedicalHistory.Select(x => $"{x.Id} {x.Description}")) :
|
string.Join(", ", DrugMedicalHistory.Select(x => $"{x.Id} {x.Description}")) :
|
||||||
string.Empty;
|
string.Empty;
|
||||||
|
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public IEnumerable<DrugMedicalHistory> DrugMedicalHistory { get; set; } = [];
|
public IEnumerable<DrugMedicalHistory> DrugMedicalHistory { get; set; } = [];
|
||||||
|
|
||||||
|
@ -20,16 +20,20 @@ internal class TableReport
|
|||||||
|
|
||||||
private readonly IDoctorPaymentsRepository _doctorPaymentsRepository;
|
private readonly IDoctorPaymentsRepository _doctorPaymentsRepository;
|
||||||
|
|
||||||
|
private readonly IDrugRepository _drugRepository;
|
||||||
|
|
||||||
private readonly ILogger<TableReport> _logger;
|
private readonly ILogger<TableReport> _logger;
|
||||||
|
|
||||||
internal static readonly string[] item = ["Дата", "Описание", "Количество лекарства"];
|
internal static readonly string[] item = ["Доктор", "Описание", "Количество пациентов"];
|
||||||
|
|
||||||
public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, ILogger<TableReport> logger)
|
public TableReport(IMedicalHistoryRepository medicalHistoryRepository, IDoctorPaymentsRepository doctorPaymentsRepository, IDrugRepository drugRepository, ILogger<TableReport> logger)
|
||||||
{
|
{
|
||||||
_medicalHistoryRepository = medicalHistoryRepository ??
|
_medicalHistoryRepository = medicalHistoryRepository ??
|
||||||
throw new ArgumentNullException(nameof(medicalHistoryRepository)); ;
|
throw new ArgumentNullException(nameof(medicalHistoryRepository)); ;
|
||||||
_doctorPaymentsRepository = doctorPaymentsRepository ??
|
_doctorPaymentsRepository = doctorPaymentsRepository ??
|
||||||
throw new ArgumentNullException(nameof(doctorPaymentsRepository));
|
throw new ArgumentNullException(nameof(doctorPaymentsRepository));
|
||||||
|
_drugRepository = drugRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(drugRepository));
|
||||||
_logger = logger ??
|
_logger = logger ??
|
||||||
throw new ArgumentNullException(nameof(logger));
|
throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
@ -62,12 +66,11 @@ internal class TableReport
|
|||||||
|
|
||||||
/// ВНИЗУ БЫЛ ПРАВИЛЬНЫЙ
|
/// ВНИЗУ БЫЛ ПРАВИЛЬНЫЙ
|
||||||
|
|
||||||
|
/*
|
||||||
private List<string[]> GetData(int drugId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int drugId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _medicalHistoryRepository
|
var data = _medicalHistoryRepository
|
||||||
.ReadMedicalHistory()
|
.ReadMedicalHistory(dateForm: startDate,dateTo : endDate, null, null)
|
||||||
.Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId) )
|
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
Date = x.VisitDate,
|
Date = x.VisitDate,
|
||||||
@ -85,18 +88,69 @@ internal class TableReport
|
|||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(
|
.Union(
|
||||||
data
|
data
|
||||||
.Select(x => new string[] {x.Date.ToString(), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty }))
|
.Select(x => new string[] {x.Date.ToString("dd.MM.yyyy"), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty }))
|
||||||
.Union(
|
.Union(
|
||||||
new List<string[]>() { new string[] { "Всего", data.Sum(x => x.CountOut ?? 0).ToString(), string.Empty } })
|
new List<string[]>() { new string[] { "Всего", data.Sum(x => x.CountOut ?? 0).ToString(), string.Empty } })
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
private List<string[]> GetData(int drugId, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
var data = _medicalHistoryRepository
|
||||||
|
.ReadMedicalHistory()
|
||||||
|
.Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId))
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
Date = x.VisitDate,
|
||||||
|
CountIn = x.DrugMedicalHistory.FirstOrDefault(y => y.DrugId == drugId)?.Description,
|
||||||
|
CountOut = (int?)null
|
||||||
|
})
|
||||||
|
.Union(
|
||||||
|
_doctorPaymentsRepository
|
||||||
|
.ReadDoctorPayments()
|
||||||
|
.Where(x => x.DoctorPaymentData >= startDate && x.DoctorPaymentData <= endDate)
|
||||||
|
.Select(x => new { Date = x.DoctorPaymentData, CountIn = (string?)null, CountOut = (int?)x.Count_Patient }))
|
||||||
|
.OrderBy(x => x.Date);
|
||||||
|
|
||||||
|
|
||||||
|
return new List<string[]>() { item }
|
||||||
|
.Union(
|
||||||
|
data
|
||||||
|
.Select(x => new string[] { x.Date.ToString(), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty }))
|
||||||
|
.Union(
|
||||||
|
new List<string[]>() { new string[] { "Всего", data.Sum(x => x.CountOut ?? 0).ToString(), string.Empty } })
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
private List<string[]> GetData(int drugId, DateTime startDate, DateTime endDate)
|
||||||
|
{
|
||||||
|
var data = _medicalHistoryRepository
|
||||||
|
.ReadMedicalHistory()
|
||||||
|
.Where(x => x.VisitDate >= startDate && x.VisitDate <= endDate && x.DrugMedicalHistory.Any(y => y.DrugId == drugId))
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
Date = x.DoctorId,
|
||||||
|
CountIn = x.DrugMedicalHistory.FirstOrDefault(y => y.DrugId == drugId)?.Description,
|
||||||
|
CountOut = (int?)null
|
||||||
|
})
|
||||||
|
.Union(
|
||||||
|
_doctorPaymentsRepository
|
||||||
|
.ReadDoctorPayments()
|
||||||
|
.Where(x => x.Id != 0)
|
||||||
|
.Select(x => new { Date = x.IdDoctor, CountIn = (string?)null, CountOut = (int?)x.Count_Patient }))
|
||||||
|
.OrderBy(x => x.Date);
|
||||||
|
|
||||||
|
|
||||||
|
return new List<string[]>() { item }
|
||||||
|
.Union(
|
||||||
|
data
|
||||||
|
.Select(x => new string[] { x.Date.ToString(), x.CountIn ?? string.Empty, x.CountOut?.ToString() ?? string.Empty }))
|
||||||
|
.Union(
|
||||||
|
new List<string[]>() { new string[] { "Всего", string.Empty, data.Sum(x => x.CountOut ?? 0).ToString() } })
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ namespace RegistrationPatientsPolyclinic.Repositories;
|
|||||||
|
|
||||||
public interface IDoctorPaymentsRepository
|
public interface IDoctorPaymentsRepository
|
||||||
{
|
{
|
||||||
IEnumerable<DoctorPayments> ReadDoctorPayments();
|
//IEnumerable<DoctorPayments> ReadDoctorPayments();
|
||||||
|
IEnumerable<DoctorPayments> ReadDoctorPayments(int? doctorId = null, string month = null);
|
||||||
|
|
||||||
void CreateDoctorPayments(DoctorPayments doctorPayments);
|
void CreateDoctorPayments(DoctorPayments doctorPayments);
|
||||||
|
|
||||||
|
@ -13,12 +13,6 @@ public interface IMedicalHistoryRepository
|
|||||||
IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null,
|
IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null,
|
||||||
int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть
|
int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
IEnumerable<TempDrugMedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? PatientId = null,
|
|
||||||
int? DoctorId = null); // по этим параметрам можно не весь список читать, а только какую то часть
|
|
||||||
|
|
||||||
*/
|
|
||||||
void CreateMedicalHistory(MedicalHistory medicalHistory); // объекь будет заносится в список
|
void CreateMedicalHistory(MedicalHistory medicalHistory); // объекь будет заносится в список
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
|
using DocumentFormat.OpenXml.Bibliography;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
@ -50,19 +52,31 @@ VALUES (@IdDoctor, @Month, @Count_Patient, @Payment)";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<DoctorPayments> ReadDoctorPayments()
|
public IEnumerable<DoctorPayments> ReadDoctorPayments(int? doctorId = null, string month = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
|
||||||
|
if (doctorId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("fa.IdDoctor = @doctorId");
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(month))
|
||||||
|
{
|
||||||
|
builder.AddCondition("fa.Month = @month");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new
|
using var connection = new
|
||||||
NpgsqlConnection(_connectionString.ConnectionString);
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT fa.*,
|
var querySelect = $@"SELECT fa.*,
|
||||||
CONCAT(e.Last_Name, ' ', e.First_Name) AS DoctorName
|
CONCAT(e.Last_Name, ' ', e.First_Name) AS DoctorName
|
||||||
FROM DoctorPayments fa
|
FROM DoctorPayments fa
|
||||||
LEFT JOIN Doctor e ON e.Id = fa.IdDoctor";
|
LEFT JOIN Doctor e ON e.Id = fa.IdDoctor
|
||||||
|
{builder.Build()}";
|
||||||
var doctorPayments =
|
var doctorPayments =
|
||||||
connection.Query<DoctorPayments>(querySelect);
|
connection.Query<DoctorPayments>(querySelect, new { doctorId , month });
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(doctorPayments));
|
JsonConvert.SerializeObject(doctorPayments));
|
||||||
return doctorPayments;
|
return doctorPayments;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
@ -113,27 +114,40 @@ WHERE Id=@id";
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// ВНИЗУ САМЫЙ ПОСЛЕДНИЙ ПРАВИЛЬНЫЙ!!!!
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
|
||||||
|
if (dateForm.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("mh.VisitDate >= @dateForm");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("mh.VisitDate <= @dateTo");
|
||||||
|
}
|
||||||
|
if (DoctorId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("mh.DoctorId = @DoctorId");
|
||||||
|
}
|
||||||
|
if (PatientId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("mh.PatientId = @PatientId");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using var connection = new
|
using var connection = new
|
||||||
NpgsqlConnection(_connectionString.ConnectionString);
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
//var querySelect = @"SELECT * FROM MedicalHistory";
|
|
||||||
/* var querySelect = @"SELECT mh.*,
|
|
||||||
CONCAT(p.LastName, ' ', p.FirstName) as PatientName,
|
|
||||||
CONCAT(d.LastName, ' ', d.FirstName) as DoctorName,
|
|
||||||
dmh.DrugId,
|
|
||||||
dmh.Description
|
|
||||||
dr.DrugName AS drugName
|
|
||||||
FROM MedicalHistory mh
|
|
||||||
LEFT JOIN Patient p on p.Id = mh.PatientId
|
|
||||||
LEFT JOIN Doctor d on d.Id = mh.DoctorId
|
|
||||||
INNER JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id
|
|
||||||
LEFT JOIN Drug dr on dr.Id = dmh.DrugId";*/
|
|
||||||
|
|
||||||
var querySelect = @"SELECT mh.*,
|
var querySelect = $@"SELECT mh.*,
|
||||||
CONCAT(p.Last_Name, ' ', p.First_Name) as PatientName,
|
CONCAT(p.Last_Name, ' ', p.First_Name) as PatientName,
|
||||||
CONCAT(d.Last_Name, ' ', d.First_Name) as DoctorName,
|
CONCAT(d.Last_Name, ' ', d.First_Name) as DoctorName,
|
||||||
dmh.Id AS Id, dmh.DrugId AS drugId, dmh.Description AS Description
|
dmh.Id AS Id, dmh.DrugId AS drugId, dmh.Description AS Description
|
||||||
@ -141,7 +155,7 @@ WHERE Id=@id";
|
|||||||
LEFT JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id
|
LEFT JOIN DrugMedicalHistory dmh ON dmh.MedicalHistoryId = mh.Id
|
||||||
LEFT JOIN Patient p ON p.Id = mh.PatientId
|
LEFT JOIN Patient p ON p.Id = mh.PatientId
|
||||||
LEFT JOIN doctor d ON d.Id = mh.DoctorId
|
LEFT JOIN doctor d ON d.Id = mh.DoctorId
|
||||||
";
|
{builder.Build()}";
|
||||||
|
|
||||||
var historyDict = new Dictionary<int, List<DrugMedicalHistory>>();
|
var historyDict = new Dictionary<int, List<DrugMedicalHistory>>();
|
||||||
var medicalHistory =
|
var medicalHistory =
|
||||||
@ -158,7 +172,7 @@ WHERE Id=@id";
|
|||||||
drugs.Add(DrugMedicalHistory.CreateEntity(drugMedicalHistory.Id, drugMedicalHistory.DrugId, drugMedicalHistory.Description));
|
drugs.Add(DrugMedicalHistory.CreateEntity(drugMedicalHistory.Id, drugMedicalHistory.DrugId, drugMedicalHistory.Description));
|
||||||
}
|
}
|
||||||
return history;
|
return history;
|
||||||
}, splitOn: "Id");//, param: new { dateForm, dateTo, DoctorId, PatientId});
|
}, splitOn: "Id", param: new { dateForm, dateTo, DoctorId, PatientId });
|
||||||
|
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(medicalHistory));
|
JsonConvert.SerializeObject(medicalHistory));
|
||||||
@ -175,8 +189,9 @@ WHERE Id=@id";
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace RegistrationPatientsPolyclinic.Repositories.Implementations;
|
||||||
|
|
||||||
|
internal class QueryBuilder
|
||||||
|
{
|
||||||
|
private readonly StringBuilder _builder;
|
||||||
|
public QueryBuilder()
|
||||||
|
{
|
||||||
|
_builder = new();
|
||||||
|
}
|
||||||
|
public QueryBuilder AddCondition(string condition)
|
||||||
|
{
|
||||||
|
if (_builder.Length > 0)
|
||||||
|
{
|
||||||
|
_builder.Append(" AND ");
|
||||||
|
}
|
||||||
|
_builder.Append(condition);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public string Build()
|
||||||
|
{
|
||||||
|
if (_builder.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
return $"WHERE {_builder}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user