Реализовал логику для приемов

This commit is contained in:
Никита Потапов 2024-05-15 02:21:25 +04:00
parent 06c2363ee3
commit 853e3105e7
5 changed files with 107 additions and 2 deletions

View File

@ -0,0 +1,97 @@
using MedicalDatabaseContracts;
using MedicalDatabaseContracts.Models;
using MedicalDatabaseContracts.SearchModels;
using MedicalDatabaseContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace MedicalBusinessLogic.BusinessLogics
{
public class VisitLogix : AbstractLogic<Visit, VisitViewModel, VisitSearchModel>
{
private readonly IStorage<Patient> _patientStorage;
private readonly IStorage<Doctor> _doctorStorage;
private readonly IStorage<Diagnose> _diagnoseStorage;
public VisitLogix(
ILogger<AbstractLogic<Visit, VisitViewModel, VisitSearchModel>> logger,
IStorage<Visit> storage,
IStorage<Patient> patientStorage,
IStorage<Doctor> doctorStorage,
IStorage<Diagnose> diagnoseStorage) : base(logger, storage)
{
_patientStorage = patientStorage;
_doctorStorage = doctorStorage;
_diagnoseStorage = diagnoseStorage;
}
protected override bool CheckModelBySearchModel(Visit model, VisitSearchModel searchModel)
{
if (searchModel.Id != null && searchModel.Id != model.Id)
return false;
if (searchModel.DoctorId != null && searchModel.DoctorId != model.DoctorId)
return false;
if (searchModel.DiagnoseId != null && searchModel.DiagnoseId != model.DiagnoseId)
return false;
if (searchModel.PatientId != null && searchModel.PatientId != model.PatientId)
return false;
if (!string.IsNullOrEmpty(searchModel.Comment))
{
if (model.Comment == null)
return false;
if (!model.Comment.Contains(searchModel.Comment))
return false;
}
if (searchModel.Date != null && model.Date != searchModel.Date)
return false;
if (searchModel.Time != null && model.Time != searchModel.Time)
return false;
return true;
}
protected override void CheckModelIsValid(Visit model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
else if (ReadList(new VisitSearchModel {
DoctorId = model.DoctorId,
Date = model.Date,
Time = model.Time
}).Count != 0)
{
throw new InvalidOperationException($"Запись приема к этому врачу на это время и дату уже есть");
}
}
protected override VisitViewModel GetViewModel(Visit model)
{
var visitViewModel = new VisitViewModel {
PatientId = model.PatientId,
DoctorId = model.DoctorId,
DiagnoseId = model.DiagnoseId,
Date = model.Date,
Time = model.Time,
Comment = model.Comment ?? string.Empty,
};
var patient = _patientStorage.Get(model.PatientId);
if (patient != null)
{
visitViewModel.PatientFIO = patient.GetFIO();
}
var doctor = _doctorStorage.Get(model.DoctorId);
if (doctor != null)
{
visitViewModel.DoctorFIO = doctor.GetFIO();
}
if (model.DiagnoseId != null)
{
var diagnose = _diagnoseStorage.Get(model.DiagnoseId.Value);
if (diagnose != null)
{
visitViewModel.DiagnoseName = diagnose.Name;
}
}
}
}
}

View File

@ -8,5 +8,9 @@ namespace MedicalDatabaseContracts.Models
public string Surname { get; set; } = string.Empty;
public string? Patronymic { get; set; }
public string PhoneNumber { get; set; } = string.Empty;
public string GetFIO()
{
return string.Join(" ", Surname, Name, Patronymic ?? string.Empty);
}
}
}

View File

@ -4,7 +4,7 @@
{
public int PatientId { get; set; }
public int DoctorId { get; set; }
public int DiagnoseId { get; set; }
public int? DiagnoseId { get; set; }
public string? Comment { get; set; }
public DateOnly Date { get; set; }
public TimeOnly Time { get; set; }

View File

@ -8,5 +8,9 @@
public TimeOnly? TimeFrom { get; set; }
public TimeOnly? TimeTo { get; set; }
public TimeOnly? Time { get; set; }
public string? Comment { get; set; }
public int? PatientId { get; set; }
public int? DoctorId { get; set; }
public int? DiagnoseId { get; set; }
}
}

View File

@ -6,7 +6,7 @@ namespace MedicalDatabaseContracts.ViewModels
{
public int PatientId { get; set; }
public int DoctorId { get; set; }
public int DiagnoseId { get; set; }
public int? DiagnoseId { get; set; }
[DisplayName("Комментарий")]
public string Comment { get; set; } = string.Empty;
[DisplayName("Пациент")]