diff --git a/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogix.cs b/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogix.cs new file mode 100644 index 0000000..98521ba --- /dev/null +++ b/Medical/MedicalBusinessLogic/BusinessLogics/VisitLogix.cs @@ -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 + { + private readonly IStorage _patientStorage; + private readonly IStorage _doctorStorage; + private readonly IStorage _diagnoseStorage; + public VisitLogix( + ILogger> logger, + IStorage storage, + IStorage patientStorage, + IStorage doctorStorage, + IStorage 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; + } + } + } + } +} diff --git a/Medical/MedicalDatabaseContracts/Models/AbstractPersonModel.cs b/Medical/MedicalDatabaseContracts/Models/AbstractPersonModel.cs index 000add9..49b5f50 100644 --- a/Medical/MedicalDatabaseContracts/Models/AbstractPersonModel.cs +++ b/Medical/MedicalDatabaseContracts/Models/AbstractPersonModel.cs @@ -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); + } } } diff --git a/Medical/MedicalDatabaseContracts/Models/Visit.cs b/Medical/MedicalDatabaseContracts/Models/Visit.cs index bb3120d..567f62d 100644 --- a/Medical/MedicalDatabaseContracts/Models/Visit.cs +++ b/Medical/MedicalDatabaseContracts/Models/Visit.cs @@ -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; } diff --git a/Medical/MedicalDatabaseContracts/SearchModels/VisitSearchModel.cs b/Medical/MedicalDatabaseContracts/SearchModels/VisitSearchModel.cs index 380b25e..4a8a9bd 100644 --- a/Medical/MedicalDatabaseContracts/SearchModels/VisitSearchModel.cs +++ b/Medical/MedicalDatabaseContracts/SearchModels/VisitSearchModel.cs @@ -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; } } } diff --git a/Medical/MedicalDatabaseContracts/ViewModels/VisitViewModel.cs b/Medical/MedicalDatabaseContracts/ViewModels/VisitViewModel.cs index edbaeab..5458f67 100644 --- a/Medical/MedicalDatabaseContracts/ViewModels/VisitViewModel.cs +++ b/Medical/MedicalDatabaseContracts/ViewModels/VisitViewModel.cs @@ -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("Пациент")]