2024-05-16 01:41:37 +04:00
|
|
|
|
using MedicalDatabaseContracts;
|
|
|
|
|
using MedicalDatabaseContracts.Models;
|
|
|
|
|
using MedicalDatabaseContracts.SearchModels;
|
|
|
|
|
using MedicalDatabaseContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace MedicalView.Visits
|
2024-05-15 12:26:19 +04:00
|
|
|
|
{
|
2024-05-15 15:27:40 +04:00
|
|
|
|
public partial class FormVisit : FormAbstractDetail
|
2024-05-15 12:26:19 +04:00
|
|
|
|
{
|
2024-05-16 01:41:37 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ILogic<Visit, VisitViewModel, VisitSearchModel> _visitLogic;
|
|
|
|
|
private readonly ILogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel> _diagnoseLogic;
|
|
|
|
|
private readonly ILogic<Doctor, DoctorViewModel, DoctorSearchModel> _doctorLogic;
|
|
|
|
|
private readonly ILogic<Patient, PatientViewModel, PatientSearchModel> _patientLogic;
|
2024-05-17 01:11:47 +04:00
|
|
|
|
private readonly ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel> _specLogic;
|
2024-05-16 01:41:37 +04:00
|
|
|
|
public FormVisit(
|
|
|
|
|
ILogger<FormVisit> logger,
|
|
|
|
|
ILogic<Visit, VisitViewModel, VisitSearchModel> visitLogic,
|
|
|
|
|
ILogic<Diagnose, DiagnoseViewModel, DiagnoseSearchModel> diagnoseLogic,
|
|
|
|
|
ILogic<Doctor, DoctorViewModel, DoctorSearchModel> doctorLogic,
|
2024-05-17 01:11:47 +04:00
|
|
|
|
ILogic<Patient, PatientViewModel, PatientSearchModel> patientLogic,
|
|
|
|
|
ILogic<Specialization, SpecializationViewModel, SpecializationSearchModel> specLogic)
|
2024-05-15 12:26:19 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-16 01:41:37 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_visitLogic = visitLogic;
|
|
|
|
|
_diagnoseLogic = diagnoseLogic;
|
|
|
|
|
_doctorLogic = doctorLogic;
|
|
|
|
|
_patientLogic = patientLogic;
|
2024-05-17 01:11:47 +04:00
|
|
|
|
_specLogic = specLogic;
|
2024-05-16 01:41:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ApplyToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxPatient.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите пациента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (comboBoxDoctor.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите врача", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Сохранение модели приема");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var model = new Visit
|
|
|
|
|
{
|
|
|
|
|
Id = ModelId ?? 0,
|
|
|
|
|
Comment = textBoxComment.Text,
|
|
|
|
|
PatientId = (comboBoxPatient.SelectedItem as PatientViewModel).Id,
|
|
|
|
|
DoctorId = (comboBoxDoctor.SelectedItem as DoctorViewModel).Id,
|
|
|
|
|
DiagnoseId = comboBoxDiagnose.SelectedItem != null ? (comboBoxDiagnose.SelectedItem as DiagnoseViewModel).Id : null,
|
|
|
|
|
Date = DateOnly.FromDateTime(datePicker.Value),
|
|
|
|
|
Time = TimeOnly.FromDateTime(timePicker.Value)
|
|
|
|
|
};
|
|
|
|
|
var operationResult = ModelId.HasValue ? _visitLogic.Update(model) : _visitLogic.Create(model);
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка сохранения модели приема");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CancelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormVisit_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-05-16 14:32:01 +04:00
|
|
|
|
var patients = _patientLogic.ReadList();
|
|
|
|
|
var doctors = _doctorLogic.ReadList();
|
|
|
|
|
var diagnoses = _diagnoseLogic.ReadList();
|
|
|
|
|
|
|
|
|
|
comboBoxPatient.DataSource = patients;
|
|
|
|
|
comboBoxPatient.SelectedIndex = -1;
|
|
|
|
|
|
|
|
|
|
comboBoxDoctor.DataSource = doctors;
|
|
|
|
|
comboBoxDoctor.SelectedIndex = -1;
|
|
|
|
|
|
|
|
|
|
comboBoxDiagnose.DataSource = diagnoses;
|
2024-05-16 22:45:48 +04:00
|
|
|
|
comboBoxDiagnose.SelectedIndex = -1;
|
2024-05-16 14:32:01 +04:00
|
|
|
|
|
2024-05-16 01:41:37 +04:00
|
|
|
|
if (ModelId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Получение модели приема");
|
|
|
|
|
var view = _visitLogic.ReadElement(ModelId.Value);
|
|
|
|
|
if (view != null)
|
|
|
|
|
{
|
|
|
|
|
textBoxComment.Text = view.Comment;
|
|
|
|
|
datePicker.Value = view.Date.ToDateTime(view.Time);
|
2024-05-17 01:11:47 +04:00
|
|
|
|
timePicker.Value = view.Date.ToDateTime(view.Time);
|
2024-05-16 01:41:37 +04:00
|
|
|
|
if (view.DiagnoseId != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxDiagnose.SelectedIndex = diagnoses.FindIndex(x => x.Id == view.DiagnoseId);
|
|
|
|
|
}
|
|
|
|
|
comboBoxDoctor.SelectedIndex = doctors.FindIndex(x => x.Id == view.DoctorId);
|
|
|
|
|
comboBoxPatient.SelectedIndex = patients.FindIndex(x => x.Id == view.PatientId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения модели приема");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-15 12:26:19 +04:00
|
|
|
|
}
|
2024-05-17 01:11:47 +04:00
|
|
|
|
|
|
|
|
|
public void DeleteAllDatabaseData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Удаление всех данных БД");
|
|
|
|
|
_visitLogic.DeleteAll();
|
|
|
|
|
_diagnoseLogic.DeleteAll();
|
|
|
|
|
_doctorLogic.DeleteAll();
|
|
|
|
|
_specLogic.DeleteAll();
|
|
|
|
|
_patientLogic.DeleteAll();
|
|
|
|
|
MessageBox.Show("Все данные успешно удалены", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения модели приема");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GenerateRandomDatabaseData()
|
|
|
|
|
{
|
|
|
|
|
int specsCount = 100;
|
|
|
|
|
int diagnosesCount = 100;
|
|
|
|
|
int doctorsCount = 100;
|
|
|
|
|
int patientsCount = 100;
|
|
|
|
|
int visitsCount = 100;
|
|
|
|
|
|
|
|
|
|
double avgInsertSpecsTimer = 0;
|
|
|
|
|
double avgInsertDiagnosesTimer = 0;
|
|
|
|
|
double avgInsertDoctorsTimer = 0;
|
|
|
|
|
double avgInsertPatientsTimer = 0;
|
|
|
|
|
double avgInsertVisitsTimer = 0;
|
|
|
|
|
double temp = 0;
|
|
|
|
|
|
|
|
|
|
Random rnd = new();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < specsCount; i++)
|
|
|
|
|
{
|
|
|
|
|
_specLogic.Create(new Specialization
|
|
|
|
|
{
|
|
|
|
|
Name = i.ToString(),
|
|
|
|
|
IsPediatric = Convert.ToBoolean(rnd.Next(2)),
|
|
|
|
|
IsTherapeutic = Convert.ToBoolean(rnd.Next(2))
|
|
|
|
|
}, out temp);
|
|
|
|
|
avgInsertSpecsTimer += temp;
|
|
|
|
|
}
|
|
|
|
|
avgInsertSpecsTimer /= specsCount;
|
|
|
|
|
|
|
|
|
|
var specs = _specLogic.ReadList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < diagnosesCount; i++)
|
|
|
|
|
{
|
|
|
|
|
_diagnoseLogic.Create(new Diagnose
|
|
|
|
|
{
|
|
|
|
|
Name = i.ToString()
|
|
|
|
|
}, out temp);
|
|
|
|
|
avgInsertDiagnosesTimer += temp;
|
|
|
|
|
}
|
|
|
|
|
avgInsertDiagnosesTimer /= diagnosesCount;
|
|
|
|
|
|
|
|
|
|
var diagnoses = _diagnoseLogic.ReadList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < doctorsCount; i++)
|
|
|
|
|
{
|
|
|
|
|
_doctorLogic.Create(new Doctor {
|
|
|
|
|
Name = i.ToString(),
|
|
|
|
|
Surname = i.ToString(),
|
|
|
|
|
Patronymic = i.ToString(),
|
|
|
|
|
PhoneNumber = i.ToString(),
|
|
|
|
|
SpecializationId = specs[rnd.Next(specs.Count)].Id
|
|
|
|
|
}, out temp);
|
|
|
|
|
avgInsertDoctorsTimer += temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
avgInsertDoctorsTimer /= doctorsCount;
|
|
|
|
|
|
|
|
|
|
var doctors = _doctorLogic.ReadList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < patientsCount; i++)
|
|
|
|
|
{
|
|
|
|
|
_patientLogic.Create(new Patient {
|
|
|
|
|
Name = i.ToString(),
|
|
|
|
|
Surname = i.ToString(),
|
|
|
|
|
Patronymic = i.ToString(),
|
|
|
|
|
PhoneNumber = i.ToString(),
|
|
|
|
|
Birthday = new DateTime(2021, 12, 21),
|
|
|
|
|
Gender = rnd.Next(2) == 0 ? "М" : "Ж",
|
|
|
|
|
Height = rnd.Next(100, 250),
|
|
|
|
|
Weight = rnd.Next(50, 100)
|
|
|
|
|
}, out temp);
|
|
|
|
|
avgInsertPatientsTimer += temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
avgInsertPatientsTimer /= patientsCount;
|
|
|
|
|
var patients = _patientLogic.ReadList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < visitsCount; i++)
|
|
|
|
|
{
|
|
|
|
|
_visitLogic.Create(new Visit {
|
|
|
|
|
Date = new DateOnly(2021, 12, 12),
|
|
|
|
|
Time = new TimeOnly(12, 34),
|
|
|
|
|
PatientId = patients[rnd.Next(patients.Count)].Id,
|
|
|
|
|
DoctorId = doctors[rnd.Next(doctors.Count)].Id,
|
|
|
|
|
DiagnoseId = diagnoses[rnd.Next(diagnoses.Count)].Id,
|
|
|
|
|
Comment = "iusnefiuesnfes yf ey fiuewfwe fhweiufiuefiuweh fwehf uewyiufwe fuewoiuf oweyiuf weuif ioewfuyewuif yweufoiwefuywef"
|
|
|
|
|
}, out temp);
|
|
|
|
|
avgInsertVisitsTimer += temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
avgInsertVisitsTimer /= visitsCount;
|
|
|
|
|
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
"Данные успешно сгенерированы!\n\n" +
|
|
|
|
|
"Среднее время вставки:\n" +
|
|
|
|
|
$"Специализации: {specsCount} шт : {avgInsertSpecsTimer} мск\n" +
|
|
|
|
|
$"Диагнозы: {diagnosesCount} шт : {avgInsertDiagnosesTimer} мск\n" +
|
|
|
|
|
$"Врачи: {doctorsCount} шт : {avgInsertDoctorsTimer} мск\n" +
|
|
|
|
|
$"Пациенты: {patientsCount} шт : {avgInsertPatientsTimer} мск\n" +
|
|
|
|
|
$"Приемы: {visitsCount} шт : {avgInsertVisitsTimer} мск\n",
|
|
|
|
|
"Успех",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
2024-05-15 12:26:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|