надеюсь правильно
This commit is contained in:
parent
5def95e150
commit
db56d0594e
@ -1,6 +1,7 @@
|
|||||||
using ProjectPolyclinic.Entities.Enums;
|
using ProjectPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,17 +10,19 @@ namespace ProjectPolyclinic.Entities;
|
|||||||
|
|
||||||
public class Doctor
|
public class Doctor
|
||||||
{
|
{
|
||||||
|
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string First_Name { get; private set; } = string.Empty;
|
public string First_Name { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string Last_Name { get; private set; } = string.Empty;
|
public string Last_Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string FullName => $"{First_Name} {Last_Name}";
|
||||||
|
[DisplayName("Кабинет")]
|
||||||
public int Room { get; private set; }
|
public int Room { get; private set; }
|
||||||
|
[DisplayName("Специализация")]
|
||||||
public Specialization Specialization { get; private set; }
|
public Specialization Specialization { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Уровень специализации")]
|
||||||
public SpecializationLevel SpecializationLevel { get; private set; }
|
public SpecializationLevel SpecializationLevel { get; private set; }
|
||||||
|
|
||||||
public static Doctor CreateEntity(int id, string first_Name, string last_Name, int room, Specialization specialization, SpecializationLevel specializationLevel)
|
public static Doctor CreateEntity(int id, string first_Name, string last_Name, int room, Specialization specialization, SpecializationLevel specializationLevel)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,15 +9,18 @@ namespace ProjectPolyclinic.Entities;
|
|||||||
|
|
||||||
public class DoctorPay
|
public class DoctorPay
|
||||||
{
|
{
|
||||||
|
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int IdDoctor { get; private set; }
|
public int IdDoctor { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя врача")]
|
||||||
|
public string DoctorName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Месяц")]
|
||||||
public string Month { get; private set; } = string.Empty;
|
public string Month { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Количество пациентов")]
|
||||||
public int Count_Patient { get; private set; }
|
public int Count_Patient { get; private set; }
|
||||||
|
[DisplayName("Оплата")]
|
||||||
public int Payment { get; private set; }
|
public int Payment { get; private set; }
|
||||||
|
|
||||||
public static DoctorPay CreateElement(int id, int idDoctor, string month, int count_patient, int payment)
|
public static DoctorPay CreateElement(int id, int idDoctor, string month, int count_patient, int payment)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ProjectPolyclinic.Entities.Enums;
|
using ProjectPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -11,10 +12,12 @@ public class Drug
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Названия лекарств")]
|
||||||
public DrugsNames drugsNames { get; private set; }
|
public DrugsNames drugsNames { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Грамовка")]
|
||||||
public int Grams { get; private set; }
|
public int Grams { get; private set; }
|
||||||
|
[DisplayName("Рецепт")]
|
||||||
public string Description { get; private set; } = string.Empty;
|
public string Description { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static Drug CreateElement(int id, DrugsNames name, int grams, string description)
|
public static Drug CreateElement(int id, DrugsNames name, int grams, string description)
|
||||||
|
@ -12,10 +12,15 @@ public class DrugMedHistory
|
|||||||
|
|
||||||
public int DrugId { get; private set; }
|
public int DrugId { get; private set; }
|
||||||
|
|
||||||
|
public string DrugName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public int MedicalHistoryId { get; private set; }
|
public int MedicalHistoryId { get; private set; }
|
||||||
|
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
|
private IEnumerable<DrugMedHistory> _drugMedHistory = new List<DrugMedHistory>();
|
||||||
|
|
||||||
|
|
||||||
public static DrugMedHistory CreateEntity(int id, int drugId, int medicalHistoryId, int count)
|
public static DrugMedHistory CreateEntity(int id, int drugId, int medicalHistoryId, int count)
|
||||||
{
|
{
|
||||||
return new DrugMedHistory
|
return new DrugMedHistory
|
||||||
@ -26,4 +31,6 @@ public class DrugMedHistory
|
|||||||
Count = count
|
Count = count
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ProjectPolyclinic.Entities.Enums;
|
using ProjectPolyclinic.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,17 +11,25 @@ namespace ProjectPolyclinic.Entities;
|
|||||||
public class MedicalHistory
|
public class MedicalHistory
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int PatientId { get; private set; }
|
public int PatientId { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int DoctorId { get; private set; }
|
public int DoctorId { get; private set; }
|
||||||
|
[DisplayName("Имя пациента")]
|
||||||
|
public string PatientName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Имя врача")]
|
||||||
|
public string DoctorName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Время визита")]
|
||||||
public DateTime VisitDate { get; private set; }
|
public DateTime VisitDate { get; private set; }
|
||||||
|
[DisplayName("Состояние пациента")]
|
||||||
public Status Status { get; private set; }
|
public Status Status { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<DrugMedHistory> DrugMedHistory { get; private set; } = [];
|
public IEnumerable<DrugMedHistory> DrugMedHistory { get; private set; } = [];
|
||||||
|
|
||||||
|
[DisplayName("Назначенные лекарства")]
|
||||||
|
public string DrugsSummary => string.Join(", ", DrugMedHistory
|
||||||
|
.Select(d => $"Id: {d.DrugId}, Кол-во: {d.Count}"));
|
||||||
|
|
||||||
public static MedicalHistory CreateEntity(int id, int patientId,
|
public static MedicalHistory CreateEntity(int id, int patientId,
|
||||||
Status status, int doctorId, IEnumerable<DrugMedHistory> drugMedHistory)
|
Status status, int doctorId, IEnumerable<DrugMedHistory> drugMedHistory)
|
||||||
{
|
{
|
||||||
@ -35,20 +44,12 @@ public class MedicalHistory
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetDrugMedHistory(IEnumerable<DrugMedHistory> drugMedHistory)
|
||||||
public static MedicalHistory CreateEntity(TempMedicalHistory tempMedicalHistory,
|
|
||||||
IEnumerable<DrugMedHistory> drugMedHistory)
|
|
||||||
{
|
{
|
||||||
return new MedicalHistory
|
if (drugMedHistory != null)
|
||||||
{
|
{
|
||||||
Id = tempMedicalHistory.Id,
|
DrugMedHistory = drugMedHistory;
|
||||||
PatientId = tempMedicalHistory.PatientId,
|
}
|
||||||
DoctorId = tempMedicalHistory.DoctorId,
|
|
||||||
VisitDate = tempMedicalHistory.VisitDate,
|
|
||||||
Status = (Status)tempMedicalHistory.Status,
|
|
||||||
DrugMedHistory = drugMedHistory
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,15 +9,17 @@ namespace ProjectPolyclinic.Entities;
|
|||||||
|
|
||||||
public class Patient
|
public class Patient
|
||||||
{
|
{
|
||||||
|
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string First_Name { get; private set; } = string.Empty;
|
public string First_Name { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string Last_Name { get; private set; } = string.Empty;
|
public string Last_Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string FullName => $"{First_Name} {Last_Name}";
|
||||||
|
[DisplayName("Адрес")]
|
||||||
public string Address { get; private set; } = string.Empty;
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Номер телефона")]
|
||||||
public string ContactNumber { get; private set; } = string.Empty;
|
public string ContactNumber { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectPolyclinic.Entities;
|
|
||||||
|
|
||||||
//public class TempMedicalHistory
|
|
||||||
//{
|
|
||||||
// public int Id { get; set; }
|
|
||||||
// public int PatientId { get; set; }
|
|
||||||
// public int DoctorId { get; set; }
|
|
||||||
// public DateTime VisitDate { get; set; }
|
|
||||||
// public int Status { get; set; }
|
|
||||||
// public int DrugId { get; set; }
|
|
||||||
// public int Count { get; set; }
|
|
||||||
|
|
||||||
//}
|
|
||||||
public class TempMedicalHistory
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public int PatientId { get; set; }
|
|
||||||
public int DoctorId { get; set; }
|
|
||||||
public DateTime VisitDate { get; set; }
|
|
||||||
public int Status { get; set; }
|
|
||||||
|
|
||||||
// Поля для лекарств
|
|
||||||
public int DrugId { get; set; }
|
|
||||||
public int Count { get; set; }
|
|
||||||
}
|
|
||||||
|
|
@ -26,7 +26,7 @@ public partial class FormDoctorPayment : Form
|
|||||||
throw new ArgumentNullException(nameof(doctorPayRepository));
|
throw new ArgumentNullException(nameof(doctorPayRepository));
|
||||||
|
|
||||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||||
comboBoxDoctor.DisplayMember = "Last_Name";
|
comboBoxDoctor.DisplayMember = "FullName";
|
||||||
comboBoxDoctor.ValueMember = "Id";
|
comboBoxDoctor.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +47,12 @@ public partial class FormDoctorPayments : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void LoadList()
|
||||||
|
{
|
||||||
private void LoadList() => dataGridView.DataSource = _doctorPayRepository.ReadDoctorPayments();
|
dataGridView.DataSource = _doctorPayRepository.ReadDoctorPayments();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["Month"].DefaultCellStyle.Format = "yyyy-dd";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
|
@ -48,7 +48,12 @@ public partial class FormDoctors : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridView.DataSource = _doctorRepository.ReadDoctors();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = _doctorRepository.ReadDoctors();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["FullName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
@ -47,8 +47,11 @@ public partial class FormDrugs : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void LoadList()
|
||||||
private void LoadList() => dataGridView.DataSource = _dragRepository.ReadDrug();
|
{
|
||||||
|
dataGridView.DataSource = _dragRepository.ReadDrug();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,10 +48,13 @@ public partial class FormMedicalHistories : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadList()
|
||||||
private void LoadList() => dataGridView.DataSource = _medicalHistoryRepository.ReadMedicalHistory();
|
{
|
||||||
|
dataGridView.DataSource = _medicalHistoryRepository.ReadMedicalHistory();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["VisitDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||||
|
}
|
||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -33,11 +33,11 @@ public partial class FormMedicalHistory : Form
|
|||||||
throw new ArgumentNullException(nameof(medicalHistoryRepository));
|
throw new ArgumentNullException(nameof(medicalHistoryRepository));
|
||||||
|
|
||||||
comboBoxPacient.DataSource = patientRepository.ReadPatient();
|
comboBoxPacient.DataSource = patientRepository.ReadPatient();
|
||||||
comboBoxPacient.DisplayMember = "First_Name";
|
comboBoxPacient.DisplayMember = "FullName";
|
||||||
comboBoxPacient.ValueMember = "Id";
|
comboBoxPacient.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||||
comboBoxDoctor.DisplayMember = "Last_Name";
|
comboBoxDoctor.DisplayMember = "FullName";
|
||||||
comboBoxDoctor.ValueMember = "Id";
|
comboBoxDoctor.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnDrug.DataSource = drugRepository.ReadDrug();
|
ColumnDrug.DataSource = drugRepository.ReadDrug();
|
||||||
|
@ -49,7 +49,12 @@ public partial class FormPatients : Form
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void LoadList() => dataGridView.DataSource = _pacientRepository.ReadPatient();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = _pacientRepository.ReadPatient();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["FullName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace ProjectPolyclinic.Forms
|
|||||||
throw new ArgumentNullException(nameof(container));
|
throw new ArgumentNullException(nameof(container));
|
||||||
|
|
||||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||||
comboBoxDoctor.DisplayMember = "Last_Name";
|
comboBoxDoctor.DisplayMember = "FullName";
|
||||||
comboBoxDoctor.ValueMember = "Id";
|
comboBoxDoctor.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
private void buttonBuild_Click(object sender, EventArgs e)
|
private void buttonBuild_Click(object sender, EventArgs e)
|
||||||
|
@ -14,13 +14,14 @@ public class ChartReport
|
|||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool CreateChart(string filePath, DateTime dateTime)
|
public bool CreateChart(string filePath, DateTime dateTime)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Выписанные лекарства")
|
.AddHeader($"Выписанные лекарства на {dateTime:dd.MM.yyyy}")
|
||||||
.AddPieChart("Выписанные лекарства (Соотношение врачей и количества выписанных лекарств)", GetData(dateTime))
|
.AddPieChart("Соотношение выписанных лекарств по врачам", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -31,6 +32,7 @@ public class ChartReport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
var medicalHistories = _historyRepository.ReadMedicalHistory(null, null, null, null);
|
var medicalHistories = _historyRepository.ReadMedicalHistory(null, null, null, null);
|
||||||
@ -39,20 +41,22 @@ public class ChartReport
|
|||||||
.Where(mh => mh.VisitDate.Date == dateTime.Date)
|
.Where(mh => mh.VisitDate.Date == dateTime.Date)
|
||||||
.Where(mh => mh.DrugMedHistory != null && mh.DrugMedHistory.Any())
|
.Where(mh => mh.DrugMedHistory != null && mh.DrugMedHistory.Any())
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var groupedData = filteredHistories
|
var groupedData = filteredHistories
|
||||||
.GroupBy(
|
.GroupBy(
|
||||||
mh => mh.DoctorId,
|
mh => mh.DoctorName,
|
||||||
(key, group) => new
|
(doctorName, group) => new
|
||||||
{
|
{
|
||||||
DoctorId = key,
|
DoctorName = doctorName,
|
||||||
TotalDrugs = group
|
TotalDrugs = group
|
||||||
.SelectMany(mh => mh.DrugMedHistory)
|
.SelectMany(mh => mh.DrugMedHistory)
|
||||||
.Sum(dmh => dmh.Count)
|
.Sum(dmh => dmh.Count)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var result = groupedData
|
var result = groupedData
|
||||||
.Select(x => (x.DoctorId.ToString(), (double)x.TotalDrugs))
|
.Select(x => (Caption: x.DoctorName, Value: (double)x.TotalDrugs))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using ProjectPolyclinic.Repositories;
|
using ProjectPolyclinic.Repositories;
|
||||||
|
using ProjectPolyclinic.Repositories.Implementations;
|
||||||
|
|
||||||
namespace ProjectPolyclinic.Reports;
|
namespace ProjectPolyclinic.Reports;
|
||||||
|
|
||||||
@ -11,12 +12,15 @@ public class TableReport
|
|||||||
|
|
||||||
private readonly IDoctorPayRepository _doctorPayRepository;
|
private readonly IDoctorPayRepository _doctorPayRepository;
|
||||||
|
|
||||||
|
private readonly IDoctorRepository _doctorRepository;
|
||||||
|
|
||||||
private readonly ILogger<TableReport> _logger;
|
private readonly ILogger<TableReport> _logger;
|
||||||
|
|
||||||
internal static readonly string[] item = ["Id врача", "Дата", "Количество пациентов", "Выплаты"];
|
internal static readonly string[] item = ["Id врача", "Дата", "Количество пациентов", "Выплаты"];
|
||||||
|
|
||||||
public TableReport(IDoctorPayRepository doctorPayRepository,
|
public TableReport(IDoctorPayRepository doctorPayRepository,
|
||||||
IMedicalHistoryRepository medicalHistoryRepository, ILogger<TableReport> logger)
|
IMedicalHistoryRepository medicalHistoryRepository,
|
||||||
|
IDoctorRepository doctorRepository, ILogger<TableReport> logger)
|
||||||
{
|
{
|
||||||
_doctorPayRepository = doctorPayRepository ??
|
_doctorPayRepository = doctorPayRepository ??
|
||||||
throw new ArgumentNullException(nameof(IDoctorPayRepository));
|
throw new ArgumentNullException(nameof(IDoctorPayRepository));
|
||||||
@ -24,26 +28,30 @@ public class TableReport
|
|||||||
_medicalHistoryRepository = medicalHistoryRepository ??
|
_medicalHistoryRepository = medicalHistoryRepository ??
|
||||||
throw new ArgumentNullException(nameof(IMedicalHistoryRepository));
|
throw new ArgumentNullException(nameof(IMedicalHistoryRepository));
|
||||||
|
|
||||||
|
_doctorRepository = doctorRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(IMedicalHistoryRepository));
|
||||||
|
|
||||||
|
|
||||||
_logger = logger ??
|
_logger = logger ??
|
||||||
throw new ArgumentNullException(nameof(logger));
|
throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public bool CreateTable(string filePath, int doctorId, DateTime startDate, DateTime endDate)
|
public bool CreateTable(string filePath, int doctorId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Приведение дат к началу и концу месяцев
|
|
||||||
var startOfMonth = new DateTime(startDate.Year, startDate.Month, 1);
|
var startOfMonth = new DateTime(startDate.Year, startDate.Month, 1);
|
||||||
var endOfMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1).AddDays(-1);
|
var endOfMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1).AddDays(-1);
|
||||||
|
|
||||||
|
// Получаем данные для таблицы и имя врача
|
||||||
|
var (tableData, doctorFullName) = GetData(doctorId, startOfMonth, endOfMonth);
|
||||||
|
|
||||||
var excelBuilder = new ExcelBuilder(filePath)
|
var excelBuilder = new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по оплате", 0, 3)
|
.AddHeader("Сводка по оплате", 0, 3)
|
||||||
.AddParagraph($"За период с {startOfMonth:MM.yyyy} по {endOfMonth:MM.yyyy}", 0)
|
.AddParagraph($"За период с {startOfMonth:MMMM yyyy} по {endOfMonth:MMMM yyyy}", 0)
|
||||||
.AddParagraph($"Id врача: {doctorId}", 0)
|
.AddParagraph($"Врач: {doctorFullName}", 0)
|
||||||
.AddTable(new[] { 25, 25, 25 }, GetData(doctorId, startOfMonth, endOfMonth));
|
.AddTable(new[] { 25, 25, 25 }, tableData);
|
||||||
|
|
||||||
excelBuilder.AddParagraph("", 0);
|
excelBuilder.AddParagraph("", 0);
|
||||||
|
|
||||||
@ -61,8 +69,7 @@ public class TableReport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private (List<string[]>, string) GetData(int doctorId, DateTime startOfMonth, DateTime endOfMonth)
|
||||||
private List<string[]> GetData(int doctorId, DateTime startOfMonth, DateTime endOfMonth)
|
|
||||||
{
|
{
|
||||||
var data = _doctorPayRepository
|
var data = _doctorPayRepository
|
||||||
.ReadDoctorPayments()
|
.ReadDoctorPayments()
|
||||||
@ -73,50 +80,54 @@ public class TableReport
|
|||||||
})
|
})
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
|
DoctorName = x.DoctorName, // Предполагается, что есть поле DoctorName
|
||||||
Date = DateTime.ParseExact(x.Month, "yyyy-MM", System.Globalization.CultureInfo.InvariantCulture),
|
Date = DateTime.ParseExact(x.Month, "yyyy-MM", System.Globalization.CultureInfo.InvariantCulture),
|
||||||
CountOfPatients = x.Count_Patient,
|
CountOfPatients = x.Count_Patient,
|
||||||
Payments = x.Payment
|
Payments = x.Payment
|
||||||
})
|
})
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
var result = new List<string[]>
|
var doctorName = data.FirstOrDefault()?.DoctorName ?? "Неизвестный врач";
|
||||||
|
|
||||||
|
var result = new List<string[]>()
|
||||||
{
|
{
|
||||||
new[] { "Дата", "Количество пациентов", "Выплаты" }
|
new[] { "Дата", "Количество пациентов", "Выплаты" }
|
||||||
}
|
}
|
||||||
.Union(data.Select(x => new string[]
|
.Union(
|
||||||
{
|
data.Select(x => new string[]
|
||||||
x.Date.ToString("MMMM yyyy"),
|
{
|
||||||
x.CountOfPatients.ToString(),
|
x.Date.ToString("MMMM yyyy"),
|
||||||
x.Payments.ToString()
|
x.CountOfPatients.ToString(),
|
||||||
}))
|
x.Payments.ToString()
|
||||||
.Union(new[]
|
})
|
||||||
{
|
)
|
||||||
new string[]
|
.Union(
|
||||||
{
|
new[]
|
||||||
"Всего",
|
{
|
||||||
data.Sum(x => x.CountOfPatients).ToString(),
|
new string[]
|
||||||
data.Sum(x => x.Payments).ToString()
|
{
|
||||||
}
|
"Всего",
|
||||||
})
|
data.Sum(x => x.CountOfPatients).ToString(),
|
||||||
|
data.Sum(x => x.Payments).ToString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
return result;
|
return (result, doctorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string[]> GetDrugData(int doctorId, DateTime startOfMonth, DateTime endOfMonth)
|
private List<string[]> GetDrugData(int doctorId, DateTime startOfMonth, DateTime endOfMonth)
|
||||||
{
|
{
|
||||||
var medicalHistories = _medicalHistoryRepository
|
var medicalHistories = _medicalHistoryRepository
|
||||||
.ReadMedicalHistory(startOfMonth, endOfMonth, null, doctorId)
|
.ReadMedicalHistory(startOfMonth, endOfMonth, doctorId, null) // Исправлено
|
||||||
.Where(mh => mh.DoctorId == doctorId && mh.VisitDate >= startOfMonth && mh.VisitDate <= endOfMonth)
|
.Where(mh => mh.DrugMedHistory != null && mh.DrugMedHistory.Any())
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var result = new List<string[]>
|
_logger.LogDebug("Полученные медицинские истории с лекарствами: {data}", JsonConvert.SerializeObject(medicalHistories));
|
||||||
{
|
|
||||||
new[] { "Дата", "Назначенные лекарства" }
|
|
||||||
};
|
|
||||||
|
|
||||||
var sortedDrugData = medicalHistories
|
var drugData = medicalHistories
|
||||||
.Where(mh => mh.DrugMedHistory != null && mh.DrugMedHistory.Any())
|
|
||||||
.SelectMany(mh => mh.DrugMedHistory.Select(drug => new
|
.SelectMany(mh => mh.DrugMedHistory.Select(drug => new
|
||||||
{
|
{
|
||||||
Date = mh.VisitDate,
|
Date = mh.VisitDate,
|
||||||
@ -125,17 +136,20 @@ public class TableReport
|
|||||||
.OrderBy(x => x.Date)
|
.OrderBy(x => x.Date)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
result.AddRange(sortedDrugData
|
var result = new List<string[]> { new[] { "Дата", "Назначенные лекарства" } };
|
||||||
.Select(item => new string[]
|
|
||||||
{
|
|
||||||
item.Date.ToString("dd.MM.yyyy"),
|
|
||||||
item.Count.ToString()
|
|
||||||
}));
|
|
||||||
|
|
||||||
var totalDrugs = sortedDrugData.Sum(x => x.Count);
|
result.AddRange(drugData.Select(item => new string[]
|
||||||
|
{
|
||||||
|
item.Date.ToString("dd MMMM yyyy"),
|
||||||
|
item.Count.ToString()
|
||||||
|
}));
|
||||||
|
|
||||||
|
var totalDrugs = drugData.Sum(x => x.Count);
|
||||||
result.Add(new[] { "Всего", totalDrugs.ToString() });
|
result.Add(new[] { "Всего", totalDrugs.ToString() });
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -9,7 +9,9 @@ namespace ProjectPolyclinic.Repositories;
|
|||||||
|
|
||||||
public interface IDoctorPayRepository
|
public interface IDoctorPayRepository
|
||||||
{
|
{
|
||||||
IEnumerable<DoctorPay> ReadDoctorPayments();
|
//IEnumerable<DoctorPay> ReadDoctorPayments();
|
||||||
|
IEnumerable<DoctorPay> ReadDoctorPayments(int? doctorId = null, string month = null);
|
||||||
|
|
||||||
|
|
||||||
void CreateDoctorPayments(DoctorPay doctorPayments);
|
void CreateDoctorPayments(DoctorPay doctorPayments);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ namespace ProjectPolyclinic.Repositories;
|
|||||||
|
|
||||||
public interface IMedicalHistoryRepository
|
public interface IMedicalHistoryRepository
|
||||||
{
|
{
|
||||||
IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? DoctorId = null, int? PatientId = null);
|
IEnumerable<MedicalHistory> ReadMedicalHistory(DateTime? dateForm = null, DateTime? dateTo = null, int? doctorId = null, int? patientId = null);
|
||||||
|
|
||||||
|
|
||||||
void CreateMedicalHistory(MedicalHistory medicalHistory);
|
void CreateMedicalHistory(MedicalHistory medicalHistory);
|
||||||
|
|
||||||
|
@ -52,26 +52,42 @@ public class DoctorPayRepository : IDoctorPayRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<DoctorPay> ReadDoctorPayments()
|
public IEnumerable<DoctorPay> ReadDoctorPayments(int? doctorId = null, string month = null)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Получение данных об оплатах врачам");
|
||||||
_logger.LogInformation("Получение всех объектов");
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new
|
var builder = new QueryBuilder();
|
||||||
NpgsqlConnection(_connectionString.ConnectionString);
|
|
||||||
var querySelect = "SELECT * FROM doctor_pay";
|
if (doctorId.HasValue)
|
||||||
var professionalDevelopments =
|
{
|
||||||
connection.Query<DoctorPay>(querySelect);
|
builder.AddCondition("dp.IdDoctor = @doctorId");
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
}
|
||||||
JsonConvert.SerializeObject(professionalDevelopments));
|
if (!string.IsNullOrEmpty(month))
|
||||||
return professionalDevelopments;
|
{
|
||||||
|
builder.AddCondition("dp.Month = @month");
|
||||||
|
}
|
||||||
|
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = $@"
|
||||||
|
SELECT dp.*,
|
||||||
|
CONCAT(d.First_Name, ' ', d.Last_Name) as DoctorName
|
||||||
|
FROM doctor_pay dp
|
||||||
|
LEFT JOIN Doctors d ON dp.IdDoctor = d.Id
|
||||||
|
{builder.Build()}";
|
||||||
|
|
||||||
|
var doctorPayments = connection.Query<DoctorPay>(querySelect, new { doctorId, month });
|
||||||
|
|
||||||
|
_logger.LogDebug("Полученные записи об оплатах: {json}", JsonConvert.SerializeObject(doctorPayments));
|
||||||
|
|
||||||
|
return doctorPayments;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
_logger.LogError(ex, "Ошибка при чтении данных об оплатах врачей");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -92,32 +92,88 @@ public class MedicalHistoryRepository : IMedicalHistoryRepository
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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? doctorId = null, int? patientId = 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 NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
|
||||||
SELECT mh.*, dmh.drug_id AS DrugId, dmh.count AS Count
|
var querySelect = $@"
|
||||||
|
SELECT mh.*,
|
||||||
|
CONCAT(p.First_Name, ' ', p.Last_Name) AS PatientName,
|
||||||
|
CONCAT(d.First_Name, ' ', d.Last_Name) AS DoctorName, -- Исправлено
|
||||||
|
dmh.Id AS Id, dmh.drug_id AS DrugId, dmh.medical_history_id AS MedicalHistoryId, dmh.Count
|
||||||
FROM medical_history mh
|
FROM medical_history mh
|
||||||
LEFT JOIN drug_med_history dmh ON mh.id = dmh.medical_history_id";
|
LEFT JOIN drug_med_history dmh ON dmh.medical_history_id = mh.Id
|
||||||
|
LEFT JOIN patients p ON p.Id = mh.PatientId
|
||||||
|
LEFT JOIN doctors d ON d.Id = mh.DoctorId
|
||||||
|
{builder.Build()}";
|
||||||
|
|
||||||
var tempHistories = connection.Query<TempMedicalHistory>(querySelect);
|
_logger.LogDebug("SQL запрос: {query}", querySelect);
|
||||||
|
_logger.LogDebug("Параметры: dateForm = {dateForm}, dateTo = {dateTo}, doctorId = {doctorId}, patientId = {patientId}",
|
||||||
|
dateForm, dateTo, doctorId, patientId);
|
||||||
|
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(tempHistories));
|
var medicalHistoryDict = new Dictionary<int, List<DrugMedHistory>>();
|
||||||
|
|
||||||
return tempHistories.GroupBy(x => x.Id)
|
var medicalHistories = connection.Query<MedicalHistory, DrugMedHistory, MedicalHistory>(
|
||||||
.Select(group => MedicalHistory.CreateEntity(
|
querySelect,
|
||||||
group.First(),
|
(history, drug) =>
|
||||||
group.Select(d => DrugMedHistory.CreateEntity(0, d.DrugId, d.Id, d.Count))
|
{
|
||||||
)).ToList();
|
if (!medicalHistoryDict.TryGetValue(history.Id, out var drugs))
|
||||||
|
{
|
||||||
|
drugs = new List<DrugMedHistory>();
|
||||||
|
medicalHistoryDict.Add(history.Id, drugs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drug != null && drug.Id > 0)
|
||||||
|
{
|
||||||
|
drugs.Add(DrugMedHistory.CreateEntity(drug.Id, drug.DrugId, drug.MedicalHistoryId, drug.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
return history;
|
||||||
|
},
|
||||||
|
splitOn: "Id",
|
||||||
|
param: new { dateForm, dateTo, doctorId, patientId });
|
||||||
|
|
||||||
|
return medicalHistoryDict.Select(x =>
|
||||||
|
{
|
||||||
|
var mh = medicalHistories.First(y => y.Id == x.Key);
|
||||||
|
mh.SetDrugMedHistory(x.Value);
|
||||||
|
return mh;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
_logger.LogError(ex, "Ошибка при чтении медицинских историй");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectPolyclinic.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