Реализовал логику для приемов
This commit is contained in:
parent
06c2363ee3
commit
853e3105e7
97
Medical/MedicalBusinessLogic/BusinessLogics/VisitLogix.cs
Normal file
97
Medical/MedicalBusinessLogic/BusinessLogics/VisitLogix.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,5 +8,9 @@ namespace MedicalDatabaseContracts.Models
|
|||||||
public string Surname { get; set; } = string.Empty;
|
public string Surname { get; set; } = string.Empty;
|
||||||
public string? Patronymic { get; set; }
|
public string? Patronymic { get; set; }
|
||||||
public string PhoneNumber { get; set; } = string.Empty;
|
public string PhoneNumber { get; set; } = string.Empty;
|
||||||
|
public string GetFIO()
|
||||||
|
{
|
||||||
|
return string.Join(" ", Surname, Name, Patronymic ?? string.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{
|
{
|
||||||
public int PatientId { get; set; }
|
public int PatientId { get; set; }
|
||||||
public int DoctorId { get; set; }
|
public int DoctorId { get; set; }
|
||||||
public int DiagnoseId { get; set; }
|
public int? DiagnoseId { get; set; }
|
||||||
public string? Comment { get; set; }
|
public string? Comment { get; set; }
|
||||||
public DateOnly Date { get; set; }
|
public DateOnly Date { get; set; }
|
||||||
public TimeOnly Time { get; set; }
|
public TimeOnly Time { get; set; }
|
||||||
|
@ -8,5 +8,9 @@
|
|||||||
public TimeOnly? TimeFrom { get; set; }
|
public TimeOnly? TimeFrom { get; set; }
|
||||||
public TimeOnly? TimeTo { get; set; }
|
public TimeOnly? TimeTo { get; set; }
|
||||||
public TimeOnly? Time { 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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ namespace MedicalDatabaseContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int PatientId { get; set; }
|
public int PatientId { get; set; }
|
||||||
public int DoctorId { get; set; }
|
public int DoctorId { get; set; }
|
||||||
public int DiagnoseId { get; set; }
|
public int? DiagnoseId { get; set; }
|
||||||
[DisplayName("Комментарий")]
|
[DisplayName("Комментарий")]
|
||||||
public string Comment { get; set; } = string.Empty;
|
public string Comment { get; set; } = string.Empty;
|
||||||
[DisplayName("Пациент")]
|
[DisplayName("Пациент")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user