да, готово

This commit is contained in:
Adelina888 2024-12-12 17:12:18 +04:00
parent 36ae53c017
commit 441b9a1443
5 changed files with 84 additions and 7 deletions

View File

@ -0,0 +1,20 @@
using ProjectPolyclinic.Entities.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPolyclinic.Entities;
public class TempMedicines_Visiting
{
public int Id { get; private set; }
public int DoctorId { get; private set; }
public int PatientId { get; private set; }
public DiagnosisName DiagnosisName { get; private set; }
public DateTime VisitingTime { get; private set; }
public int VisitingId { get; private set; }
public int Count { get; private set; }
public int MedicinesId { get; private set; }
}

View File

@ -31,4 +31,16 @@ public class Visiting
Medicines = medicines
};
}
public static Visiting CreateOperation(TempMedicines_Visiting tempMedicines_Visiting, IEnumerable<Medicines_Visiting> medicines)
{
return new Visiting
{
Id = tempMedicines_Visiting.Id,
DoctorId = tempMedicines_Visiting.DoctorId,
PatientId = tempMedicines_Visiting.PatientId,
DiagnosisName = tempMedicines_Visiting.DiagnosisName,
VisitingTime = tempMedicines_Visiting.VisitingTime,
Medicines = medicines
};
}
}

View File

@ -30,7 +30,7 @@ internal class ChartReport
{
new PdfBuilder(filePath)
.AddHeader("Повышение квалификации врачей")
.AddPieChart("Количество повышение квалификации врачей", GetData(dateTime))
.AddPieChart("Количество повышений квалификации врачей", GetData(dateTime))
.Build();
return true;
}

View File

@ -13,12 +13,15 @@ internal class TableReport
{
private readonly IDoctorRepository _doctorRepository;
private readonly IVisitingRepository _visitingRepository;
private readonly IMedicationRepository _medicationRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Доктор", "Дата", "Количество визитов"];
public TableReport(IDoctorRepository doctorRepository, IVisitingRepository visitingRepository, ILogger<TableReport> logger)
internal static readonly string[] item = ["Визит","Доктор", "Дата", "Количество визитов","Количество медикаментов"];
public TableReport(IDoctorRepository doctorRepository, IVisitingRepository visitingRepository, IMedicationRepository medicationRepository, ILogger<TableReport> logger)
{
_doctorRepository = doctorRepository ?? throw new ArgumentNullException(nameof(doctorRepository));
_visitingRepository = visitingRepository ?? throw new ArgumentNullException(nameof(visitingRepository));
_medicationRepository = medicationRepository ?? throw new ArgumentNullException(nameof(medicationRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@ -30,7 +33,7 @@ internal class TableReport
new ExcelBuilder(filePath)
.AddHeader("Сводка по движению визитов", 0, 2)
.AddParagraph("за период", 0)
.AddTable([10, 15, 15], data)
.AddTable([10, 10,15, 15,15], data)
.Build();
return true;
}
@ -42,7 +45,7 @@ internal class TableReport
}
private List<string[]> GetData(int doctorId, DateTime startDate, DateTime endDate)
{
var visits = _visitingRepository.ReadVisiting()
/*var visits = _visitingRepository.ReadVisiting()
.Where(x => x.VisitingTime >= startDate && x.VisitingTime <= endDate && x.DoctorId == doctorId)
.Select(x => new
{
@ -64,6 +67,27 @@ internal class TableReport
.ToList();
return result;
return result;*/
var data = _visitingRepository
.ReadVisiting()
.Where(x => x.VisitingTime >= startDate && x.VisitingTime <= endDate && x.DoctorId == doctorId)
.Select(x => new
{
x.Id,
x.DoctorId,
Date = x.VisitingTime,
CountOfVisits = 1,
Medication = x.Medicines.Sum(m => m.Count)
})
.OrderBy(x => x.Date);
return
new List<string[]>() { item }
.Union(
data
.Select(x => new string[] { x.Id.ToString(), x.DoctorId.ToString(), x.Date.ToString(), x.CountOfVisits.ToString() ?? string.Empty, x.Medication.ToString() ?? string.Empty }))
.Union(
[["Всего ", "","", data.Sum(x => x.CountOfVisits).ToString(), data.Sum(x => x.Medication).ToString()]])
.ToList();
}
}

View File

@ -83,7 +83,7 @@ WHERE Id=@id";
public IEnumerable<Visiting> ReadVisiting(DateTime? dateForm = null, DateTime? dateTo = null, int? patientId = null, int? doctorId = null,int ? visitingId = null)
{
_logger.LogInformation("Получение всех объектов");
/*_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
@ -96,6 +96,27 @@ WHERE Id=@id";
return visitings;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}*/
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT v.*, mv.MedicinesId, mv.Count
FROM Visitings v
LEFT JOIN Medicines_Visiting mv ON v.Id = mv.VisitingId";
var visitings = connection.Query<TempMedicines_Visiting>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(visitings));
return visitings.GroupBy(x => x.Id, y => y,
(key, value) => Visiting.CreateOperation(value.First(),
value.Select(z => Medicines_Visiting.CreateElement(z.MedicinesId, z.VisitingId, z.Count)))).ToList();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;