Лабораторная работа №4
This commit is contained in:
parent
887fb94e2d
commit
b0c084ba0c
@ -1,11 +1,19 @@
|
||||
using ProjectPatientAccounting.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
|
||||
public class Doctor
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string FullName => $"{Name} {Surname}";
|
||||
|
||||
[DisplayName("Имя")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Фамилия")]
|
||||
public string Surname { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Номер участка")]
|
||||
public Area DoctorArea { get; private set; }
|
||||
|
||||
public static Doctor CreateEntity(int id, string name, string surname, Area doctorArea)
|
||||
|
@ -1,11 +1,18 @@
|
||||
using ProjectPatientAccounting.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
|
||||
public class Medicament
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Описание")]
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Тип медикамента")]
|
||||
public TypeMedicament TypeMedicament { get; private set; }
|
||||
|
||||
public static Medicament CreateEntity(int id, string name, string description, TypeMedicament typeMedicament)
|
||||
|
@ -4,9 +4,10 @@ public class MedicamentReception
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int MedicamentId { get; private set; }
|
||||
public string MedicamentName { get; private set; } = string.Empty;
|
||||
public int Dosage { get; private set; }
|
||||
|
||||
public static MedicamentReception CreateElement(int id, int medicamentId, int dosage)
|
||||
public static MedicamentReception CreateElement(int id, int medicamentId, int dosage)
|
||||
{
|
||||
return new MedicamentReception
|
||||
{
|
||||
|
@ -1,11 +1,21 @@
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
|
||||
public class Patient
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string FullName => $"{Name} {Surname}";
|
||||
|
||||
[DisplayName("Имя")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Фамилия")]
|
||||
public string Surname { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Номер телефона")]
|
||||
public string Telephone { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Номер мед.карты")]
|
||||
public int NumMedCard { get; private set; }
|
||||
|
||||
public static Patient CreateEntity(int id, string name, string surname, string telephone, int numMedCard)
|
||||
|
@ -1,11 +1,19 @@
|
||||
using ProjectPatientAccounting.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
|
||||
public class PatientDiagnosis
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string FullName => $"{Name} {DiagnosisCode}";
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Код диагноза")]
|
||||
public int DiagnosisCode { get; private set; }
|
||||
|
||||
[DisplayName("Статус диагноза")]
|
||||
public PatientDiagnosisStatus PatientDiagnosisStatus { get; private set; }
|
||||
|
||||
public static PatientDiagnosis CreateEntity(int id, string name, int diagnosisCode, PatientDiagnosisStatus patientDiagnosisStatus)
|
||||
|
@ -1,13 +1,40 @@
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectPatientAccounting.Entities;
|
||||
|
||||
public class Reception
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int PatientId { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int DoctorId { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int DiagnosisId { get; private set; }
|
||||
|
||||
[DisplayName("Пациент")]
|
||||
public string PatientName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Диагноз")]
|
||||
public string DiagnosisName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Доктор")]
|
||||
public string DoctorName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата приема")]
|
||||
public DateTime ReceptionDate { get; private set; }
|
||||
|
||||
[DisplayName("Номер талона")]
|
||||
public int NumTicket { get; private set; }
|
||||
|
||||
[DisplayName("Медикаменты")]
|
||||
public string Medicament => MedicamentReceptions != null ?
|
||||
string.Join(", ", MedicamentReceptions.Select(x => $"{x.MedicamentName} {x.Dosage}")) :
|
||||
string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<MedicamentReception> MedicamentReceptions { get; private set; } = [];
|
||||
|
||||
public static Reception CreateOperation(int id, int patientId, int doctorId, int diagnosisId, int numTicket, IEnumerable<MedicamentReception> medicamentReceptions)
|
||||
@ -23,4 +50,11 @@ public class Reception
|
||||
MedicamentReceptions = medicamentReceptions
|
||||
};
|
||||
}
|
||||
public void SetMedicamentReceptions(IEnumerable<MedicamentReception> medicamentReceptions)
|
||||
{
|
||||
if (medicamentReceptions != null && medicamentReceptions.Any())
|
||||
{
|
||||
MedicamentReceptions = medicamentReceptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,12 @@ public partial class FormDoctors : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewDoctors.DataSource = _doctorRepository.ReadDoctors();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewDoctors.DataSource = _doctorRepository.ReadDoctors();
|
||||
dataGridViewDoctors.Columns["Id"].Visible = false;
|
||||
dataGridViewDoctors.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -29,7 +29,11 @@ public partial class FormMedicaments : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewMedicaments.DataSource = _medicamentRepository.ReadMedicaments();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewMedicaments.DataSource = _medicamentRepository.ReadMedicaments();
|
||||
dataGridViewMedicaments.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -30,8 +30,12 @@ public partial class FormPatientDiagnosises : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewPatientDiagnosises.DataSource =
|
||||
_patientDiagnosisRepository.ReadDiagnosises();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewPatientDiagnosises.DataSource = _patientDiagnosisRepository.ReadDiagnosises();
|
||||
dataGridViewPatientDiagnosises.Columns["Id"].Visible = false;
|
||||
dataGridViewPatientDiagnosises.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -142,6 +142,7 @@
|
||||
Controls.Add(dateTimePickerStartDate);
|
||||
Controls.Add(labelDoctor);
|
||||
Name = "FormPatientReport";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Отчет по принятым пациентам";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
@ -13,7 +13,7 @@ namespace ProjectPatientAccounting.Forms
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
|
||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||
comboBoxDoctor.DisplayMember = "Surname";
|
||||
comboBoxDoctor.DisplayMember = "FullName";
|
||||
comboBoxDoctor.ValueMember = "Id";
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,12 @@ public partial class FormPatients : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewPatients.DataSource = _patientRepository.ReadPatients();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewPatients.DataSource = _patientRepository.ReadPatients();
|
||||
dataGridViewPatients.Columns["Id"].Visible = false;
|
||||
dataGridViewPatients.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -15,15 +15,15 @@ namespace ProjectPatientAccounting.Forms
|
||||
throw new ArgumentNullException(nameof(receptionRepository));
|
||||
|
||||
comboBoxPatient.DataSource = patientRepository.ReadPatients();
|
||||
comboBoxPatient.DisplayMember = "Surname";
|
||||
comboBoxPatient.DisplayMember = "FullName";
|
||||
comboBoxPatient.ValueMember = "Id";
|
||||
|
||||
comboBoxDoctor.DataSource = doctorRepository.ReadDoctors();
|
||||
comboBoxDoctor.DisplayMember = "Surname";
|
||||
comboBoxDoctor.DisplayMember = "FullName";
|
||||
comboBoxDoctor.ValueMember = "Id";
|
||||
|
||||
comboBoxDiagnosis.DataSource = patientDiagnosisRepository.ReadDiagnosises();
|
||||
comboBoxDiagnosis.DisplayMember = "Name";
|
||||
comboBoxDiagnosis.DisplayMember = "FullName";
|
||||
comboBoxDiagnosis.ValueMember = "Id";
|
||||
|
||||
ColumnType.DataSource = medicamentRepository.ReadMedicaments();
|
||||
|
@ -91,6 +91,7 @@
|
||||
Controls.Add(labelFileName);
|
||||
Controls.Add(buttonSelectFileName);
|
||||
Name = "FormReceptionDistributionDiagnosises";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Распределение диагнозов";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
@ -28,9 +28,12 @@ public partial class FormReceptions : Form
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewReceptions.DataSource =
|
||||
_receptionRepository.ReadReceptions();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewReceptions.DataSource = _receptionRepository.ReadReceptions();
|
||||
dataGridViewReceptions.Columns["Id"].Visible = false;
|
||||
dataGridViewReceptions.Columns["ReceptionDate"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace ProjectPatientAccounting.Reports
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Статистика пациентов")
|
||||
.AddPieChart("Поставленные диагнозы", GetData(dateTime))
|
||||
.AddPieChart($"Поставленные диагнозы на {dateTime: dd MMMM yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -35,22 +35,13 @@ namespace ProjectPatientAccounting.Reports
|
||||
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
var receptions = _receptionRepository.ReadReceptions()
|
||||
.Where(x => x.ReceptionDate.Date == dateTime.Date)
|
||||
.ToList();
|
||||
|
||||
var totalReceptions = receptions.Count;
|
||||
|
||||
return receptions
|
||||
.GroupBy(x => x.DiagnosisId)
|
||||
.Select(g => new
|
||||
{
|
||||
DiagnosisId = g.Key,
|
||||
Count = g.Count()
|
||||
})
|
||||
.Select(x => (x.DiagnosisId.ToString(), (double)x.Count / totalReceptions * 100))
|
||||
return _receptionRepository.ReadReceptions(dateFrom: dateTime.Date, dateTo:dateTime.Date.AddDays(1))
|
||||
.GroupBy(x => x.DiagnosisName, (key, group) => new {
|
||||
DiagnosisName = key, Count = group.Sum(x => x.DiagnosisId) })
|
||||
.Select(x => (x.DiagnosisName, (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectPatientAccounting.Entities.Enums;
|
||||
using ProjectPatientAccounting.Repositories;
|
||||
|
||||
using System.Diagnostics;
|
||||
namespace ProjectPatientAccounting.Reports;
|
||||
|
||||
internal class TableReport
|
||||
@ -29,7 +29,7 @@ internal class TableReport
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по движению пациентов", 0, 4)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddParagraph($"за период c {startDate: dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||
.AddTable([15, 20, 25, 25], GetData(doctorId, startDate, endDate))
|
||||
.Build();
|
||||
return true;
|
||||
@ -43,37 +43,38 @@ internal class TableReport
|
||||
|
||||
private List<string[]> GetData(int doctorId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var receptions = _receptionRepository.ReadReceptions(dateFrom:startDate, dateTo:endDate, doctorId).ToList();
|
||||
var receptions = _receptionRepository.ReadReceptions(dateFrom:startDate, dateTo:endDate, doctorId: doctorId).ToList();
|
||||
var patients = _patientRepository.ReadPatients();
|
||||
var doctorNames = _doctorRepository.ReadDoctors().ToDictionary(d => d.Id, d => d.Surname);
|
||||
var doctorNames = _doctorRepository.ReadDoctors().ToDictionary(d => d.Id, d => d.FullName);
|
||||
var diagnosisStatuses = _patientDiagnosisRepository.ReadDiagnosises().ToDictionary(d => d.Id, d => d.PatientDiagnosisStatus);
|
||||
|
||||
Debug.WriteLine(receptions.Count);
|
||||
var data = receptions
|
||||
.Join(patients, r => r.PatientId, p => p.Id, (r, p) => new
|
||||
{
|
||||
Date = r.ReceptionDate.Date,
|
||||
Date = r.ReceptionDate.Date,
|
||||
DoctorId = r.DoctorId,
|
||||
DiagnosisId = r.DiagnosisId
|
||||
})
|
||||
.Where(x => x.DoctorId == doctorId)
|
||||
.OrderBy(x => x.Date)
|
||||
.GroupBy(x => x.Date)
|
||||
.GroupBy(x => new { x.Date, x.DoctorId })
|
||||
.Select(g => new
|
||||
{
|
||||
Date = g.Key,
|
||||
Date = g.Key.Date,
|
||||
DoctorId = g.Key.DoctorId,
|
||||
TotalPatients = g.Count(),
|
||||
RecoveredPatients = g.Count(x => diagnosisStatuses[x.DiagnosisId] == PatientDiagnosisStatus.Closed)
|
||||
});
|
||||
|
||||
var result = new List<string[]> { item };
|
||||
var result = new List<string[]> { item };
|
||||
foreach (var entry in data)
|
||||
{
|
||||
|
||||
result.Add(new string[]
|
||||
{
|
||||
entry.Date.ToString("dd.MM.yyyy"),
|
||||
doctorNames.ContainsKey(doctorId) ? doctorNames[doctorId] : string.Empty,
|
||||
entry.TotalPatients.ToString("N0") ?? string.Empty,
|
||||
entry.RecoveredPatients > 0 ? entry.RecoveredPatients.ToString("N0") : string.Empty
|
||||
entry.Date.ToString("dd.MM.yyyy"),
|
||||
doctorNames.ContainsKey(doctorId) ? doctorNames[doctorId] : string.Empty,
|
||||
entry.TotalPatients.ToString("N0") ?? string.Empty,
|
||||
entry.RecoveredPatients > 0 ? entry.RecoveredPatients.ToString("N0") : string.Empty
|
||||
});
|
||||
}
|
||||
|
||||
@ -81,11 +82,12 @@ internal class TableReport
|
||||
var recoveredPatients = data.Sum(x => x.RecoveredPatients);
|
||||
result.Add(new string[]
|
||||
{
|
||||
"Всего",
|
||||
"",
|
||||
totalPatients.ToString("N0"),
|
||||
recoveredPatients.ToString("N0")
|
||||
"Всего",
|
||||
"",
|
||||
totalPatients.ToString("N0"),
|
||||
recoveredPatients.ToString("N0")
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
using System.Text;
|
||||
namespace ProjectPatientAccounting.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}";
|
||||
}
|
||||
}
|
@ -85,13 +85,73 @@ public class ReceptionRepository : IReceptionRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Receptions";
|
||||
var receptions =
|
||||
connection.Query<Reception>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(receptions));
|
||||
return receptions;
|
||||
var builder = new QueryBuilder();
|
||||
if (dateFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.ReceptionDate >= @dateFrom");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.ReceptionDate <= @dateTo");
|
||||
}
|
||||
if (patientId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.PatientId = @patientId");
|
||||
}
|
||||
if (diagnosisId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.DiagnosisId = @diagnosisId");
|
||||
}
|
||||
if (doctorId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.DoctorId = @doctorId");
|
||||
}
|
||||
var querySelect = $@"
|
||||
SELECT
|
||||
r.*,
|
||||
CONCAT(p.Name, ' ', p.Surname) AS PatientName,
|
||||
CONCAT(pd.Name, ' ', pd.DiagnosisCode) AS DiagnosisName,
|
||||
CONCAT(d.Name, ' ', d.Surname) AS DoctorName,
|
||||
mr.MedicamentId,
|
||||
m.Name AS MedicamentName,
|
||||
mr.Dosage
|
||||
|
||||
FROM Receptions r
|
||||
LEFT JOIN Patients p ON p.Id = r.PatientId
|
||||
LEFT JOIN PatientDiagnosises pd ON pd.Id = r.DiagnosisId
|
||||
LEFT JOIN Doctors d ON d.Id = r.DoctorId
|
||||
|
||||
INNER JOIN MedicamentReceptions mr ON mr.ReceptionId = r.Id
|
||||
LEFT JOIN Medicaments m ON m.Id = mr.MedicamentId
|
||||
|
||||
{builder.Build()}";
|
||||
|
||||
|
||||
var receptionDict = new Dictionary<int, List<MedicamentReception>>();
|
||||
var receptions = connection.Query<Reception, MedicamentReception, Reception>(querySelect,
|
||||
(reception, medicamentReceptions) =>
|
||||
{
|
||||
if (!receptionDict.TryGetValue(reception.Id, out var mr))
|
||||
{
|
||||
mr = [];
|
||||
receptionDict.Add(reception.Id, mr);
|
||||
|
||||
}
|
||||
mr.Add(medicamentReceptions);
|
||||
return reception;
|
||||
},
|
||||
splitOn: "MedicamentId", param: new { dateFrom, dateTo, patientId, diagnosisId, doctorId });
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(receptions));
|
||||
|
||||
return receptionDict.Select(x =>
|
||||
{
|
||||
var r = receptions.First(y => y.Id == x.Key);
|
||||
r.SetMedicamentReceptions(x.Value);
|
||||
return r;
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
|
Loading…
Reference in New Issue
Block a user