diff --git a/.gitignore b/.gitignore index ca1c7a3..f31b01a 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,6 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +*.docx +*.xlsx +*.pdf \ No newline at end of file diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs index d78f272..9e42013 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/CourseLogic.cs @@ -12,7 +12,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics private ILogger _logger; private ICourseStorage _courseStorage; - public CourseLogic(ILogger logger, ICourseStorage courseStorage) + public CourseLogic(ILogger logger, ICourseStorage courseStorage) { _logger = logger; _courseStorage = courseStorage; @@ -58,14 +58,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics return element; } - public List? ReadList(CourseSearchModel? model) + public List ReadList(CourseSearchModel? model = null) { _logger.LogInformation("ReadList. Id:{Id}", model?.Id); var list = model == null ? _courseStorage.GetFullList() : _courseStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); - return null; + return new List(); } _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/DiagnoseLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/DiagnoseLogic.cs index d2d4e7b..80bd0db 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/DiagnoseLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/DiagnoseLogic.cs @@ -12,7 +12,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics private ILogger _logger; private IDiagnoseStorage _diagnoseStorage; - public DiagnoseLogic(ILogger logger, IDiagnoseStorage diagnoseStorage) + public DiagnoseLogic(ILogger logger, IDiagnoseStorage diagnoseStorage) { _logger = logger; _diagnoseStorage = diagnoseStorage; @@ -58,14 +58,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics return element; } - public List? ReadList(DiagnoseSearchModel? model) + public List ReadList(DiagnoseSearchModel? model = null) { _logger.LogInformation("ReadList. Name:{Name} Id:{Id}, UserId:{UserId}", model?.Name, model?.Id, model?.UserId); var list = model == null ? _diagnoseStorage.GetFullList() : _diagnoseStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); - return null; + return new List(); } _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs index 9995140..e626841 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ImplementerReportLogic.cs @@ -1,8 +1,14 @@ -using PolyclinicContracts.BindingModels; +using PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports; +using PolyclinicBusinessLogic.OfficePackage.HelperModels; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; +using PolyclinicDataModels.Models; namespace PolyclinicBusinessLogic.BusinessLogics { @@ -13,21 +19,35 @@ namespace PolyclinicBusinessLogic.BusinessLogics private readonly ICourseStorage _courseStorage; private readonly ISymptomStorage _symptomStorage; - public ImplementerReportLogic(IDiagnoseStorage diagnoseStorage, IMedicamentStorage medicamentStorage, ICourseStorage courseStorage, ISymptomStorage symptomStorage) + private readonly AbstractReportMedicamentsByDiagnosesSaveToExcel _saveToExcel; + private readonly AbstractReportMedicamentsByDiagnosesSaveToWord _saveToWord; + private readonly AbstractReportDiagnosesByPeriodSaveToPdf _saveToPdf; + + public ImplementerReportLogic( + IDiagnoseStorage diagnoseStorage, + IMedicamentStorage medicamentStorage, + ICourseStorage courseStorage, + ISymptomStorage symptomStorage, + AbstractReportMedicamentsByDiagnosesSaveToWord saveToWord, + AbstractReportDiagnosesByPeriodSaveToPdf saveToPdf, + AbstractReportMedicamentsByDiagnosesSaveToExcel saveToExcel) { _diagnoseStorage = diagnoseStorage; _medicamentStorage = medicamentStorage; _courseStorage = courseStorage; _symptomStorage = symptomStorage; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + _saveToExcel = saveToExcel; } - public List GetDiagnoses() + public ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd) { - var diagnoses = _diagnoseStorage.GetFullList(); + var diagnoses = _diagnoseStorage.GetFilteredList(new DiagnoseSearchModel { From = dateStart, To = dateEnd }); var courses = _courseStorage.GetFullList(); var symptomes = _symptomStorage.GetFullList(); - var result = new List(); + var report = new ReportDiagnosesByPeriodViewModel(); foreach (var diagnose in diagnoses) { @@ -35,38 +55,24 @@ namespace PolyclinicBusinessLogic.BusinessLogics var diagnoseSymptomes = symptomes.Where(x => x.SymptomDiagnoses.ContainsKey(diagnose.Id)).ToList(); if (diagnoseCourses.Count > 0 && diagnoseSymptomes.Count > 0) { - var dianoseReportModel = new ReportDiagnoseWithCoursesAndSymptomesViewModel { - DiagnoseId = diagnose.Id, - DiagnoseName = diagnose.Name, - DiagnoseComment = diagnose.Comment, - DiagnoseDateStart = diagnose.DateStartDiagnose, - DiagnoseDateStop = diagnose.DateStopDiagnose, - Courses = diagnoseCourses.Select(x => (x.DaysCount, x.PillsPerDay)).ToList(), - Symptomes = diagnoseSymptomes.Select(x => x.Name).ToList() - }; - result.Add(dianoseReportModel); + report.DiagnosesData.Add((diagnose, diagnoseSymptomes, diagnoseCourses)); } } - return result; + report.DateStart = dateStart; + report.DateEnd = dateEnd; + return report; } - public List GetMedicamentsByDiagnoses(ReportBindingModel model) + public List GetReportMedicamentsByDiagnoses(int[] diagnosesIds) { - var diagnoses = _diagnoseStorage - .GetFilteredList(new DiagnoseSearchModel - { - From = model.DateFrom, - To = model.DateTo - }); - - var symptomes = _symptomStorage - .GetFullList(); - + List diagnoseViewModels = diagnosesIds.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x })).ToList(); + + var symptomes = _symptomStorage.GetFullList(); var medicaments = _medicamentStorage.GetFullList(); - List result = new(); + List report = new(); - foreach (var diagnose in diagnoses) + foreach (var diagnose in diagnoseViewModels) { var diagnoseSymptomes = symptomes .Where(x => x.SymptomDiagnoses.ContainsKey(diagnose.Id)) @@ -76,32 +82,47 @@ namespace PolyclinicBusinessLogic.BusinessLogics { diagnoseMedicaments.AddRange(medicaments.Where(x => x.SymptomId == symptom.Id)); } - var diagnoseReportModel = new ReportMedicamentsByDiagnoseViewModel { - DiagnoseId = diagnose.Id, - DiagnoseName = diagnose.Name, - DiagnoseComment = diagnose.Comment, - DiagnoseDateStart = diagnose.DateStartDiagnose, - DiagnoseDateStop = diagnose.DateStopDiagnose, - Medicaments = diagnoseMedicaments.Distinct().Select(x => x.Name).ToList() - }; - result.Add(diagnoseReportModel); + + report.Add(new ReportMedicamentsByDiagnoseViewModel + { + Diagnose = diagnose, + Medicaments = diagnoseMedicaments.DistinctBy(x => x.Name).ToList() + }); } - return result; + return report; } - public void SaveOrdersToPdfFile(ReportBindingModel model) + public void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel) { - throw new NotImplementedException(); + _saveToPdf.CreateDoc(new PdfDiagnosesByPeriodInfo + { + Title = "Отчет по болезням за период с расшифровкой по симптомам и курсам", + DateFrom = reportModel.DateStart, + DateTo = reportModel.DateEnd, + FileName = reportInfo.FileName, + PeriodString = reportInfo.GetPeriodString(), + Report = reportModel + }); } - public void SaveSecureComponentToExcelFile(ReportBindingModel model) + public void SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List reportModel) { - throw new NotImplementedException(); + _saveToExcel.CreateReport(new ReportMedicamentsByDiagnosesInfo + { + FileName = reportInfo.FileName, + Title = "Лекарства по болезням", + ReportModel = reportModel + }); } - public void SaveSecuresToWordFile(ReportBindingModel model) + public void SaveReportMedicamentsByDiagnosesToWordFile(ReportBindingModel reportInfo, List reportModel) { - throw new NotImplementedException(); + _saveToWord.CreateDoc(new ReportMedicamentsByDiagnosesInfo + { + FileName = reportInfo.FileName, + Title = "Лекарства по болезням", + ReportModel = reportModel + }); } } } diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/MedicamentLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/MedicamentLogic.cs index 116abc8..9c7f2be 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/MedicamentLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/MedicamentLogic.cs @@ -95,14 +95,6 @@ namespace PolyclinicBusinessLogic.BusinessLogics { throw new ArgumentNullException("Какой-то неправильный идентификатор симптома...", nameof(model)); } - if (model.ProcedureId <= 0) - { - throw new ArgumentNullException("Какой-то неправильный идентификатор процедуры...", nameof(model)); - } - if (string.IsNullOrEmpty(model.Comment)) - { - throw new ArgumentNullException("Нет комментария", nameof(model.Comment)); - } if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Нет названия у препарата", nameof(model.Comment)); diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs index 789738b..4b4bf9e 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/ProcedureLogic.cs @@ -66,7 +66,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics if (list == null) { logger.LogWarning("ReadList return null list"); - return null; + return new List(); } logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs index 7f5c66c..d14c951 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/RecipeLogic.cs @@ -58,14 +58,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics return element; } - public List? ReadList(RecipeSearchModel? model) + public List? ReadList(RecipeSearchModel? model = null) { logger.LogInformation("ReadList. Comment:{Comment}. Id:{ Id}", model?.Comment, model?.Id); var list = model == null ? recipeStorage.GetFullList() : recipeStorage.GetFilteredList(model); if (list == null) { logger.LogWarning("ReadList return null list"); - return null; + return new List(); } logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; @@ -96,10 +96,6 @@ namespace PolyclinicBusinessLogic.BusinessLogics { throw new ArgumentNullException("Количество процедур не может быть равно нулю или быть меньше нуля", nameof(model)); } - if (string.IsNullOrEmpty(model.Comment)) - { - throw new ArgumentNullException("Нет комментария", nameof(model.Comment)); - } logger.LogInformation("Recipe. Comment:{Comment}. Id: { Id}", model.Comment, model.Id); } } diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SendMailLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SendMailLogic.cs new file mode 100644 index 0000000..cc8e021 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SendMailLogic.cs @@ -0,0 +1,44 @@ +using Microsoft.Extensions.Configuration; +using System.Net.Mail; +using System.Net; + +namespace PolyclinicBusinessLogic.BusinessLogics +{ + public class SendMailLogic + { + private readonly IConfiguration _configuration; + + public SendMailLogic(IConfiguration configuration) + { + _configuration = configuration; + } + + public void SendEmail(string toEmail, string subject, string attachmentPath) + { + var smtpSection = _configuration.GetSection("Smtp"); + + var client = new SmtpClient(smtpSection["Host"]) + { + Port = int.Parse(smtpSection["Port"]), + Credentials = new NetworkCredential(smtpSection["Username"], smtpSection["Password"]), + EnableSsl = bool.Parse(smtpSection["EnableSsl"]), + }; + + var mailMessage = new MailMessage + { + From = new MailAddress(smtpSection["Username"]), + Subject = subject, + }; + + mailMessage.To.Add(toEmail); + + if (!string.IsNullOrEmpty(attachmentPath)) + { + Attachment attachment = new Attachment(attachmentPath); + mailMessage.Attachments.Add(attachment); + } + + client.Send(mailMessage); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs index 47bb243..5d831aa 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs @@ -1,4 +1,8 @@ -using PolyclinicContracts.BindingModels; +using PolyclinicBusinessLogic.OfficePackage; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; @@ -15,34 +19,36 @@ namespace PolyclinicBusinessLogic.BusinessLogics private readonly ICourseStorage courseStorage; private readonly ISymptomStorage symptomStorage; private readonly IRecipeStorage recipeStorage; + + private readonly AbstractSaveToWordCoursesByProcedures saveToWord; + private readonly AbstractSaveToExcelCoursesByProcedure saveToExcel; + private readonly AbstractSaveToPdfProcedures saveToPdf; public SuretorReportLogic(IProcedureStorage procedureStorage, IMedicamentStorage medicamentStorage, - ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage) + ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage, + AbstractSaveToWordCoursesByProcedures saveToWord, AbstractSaveToExcelCoursesByProcedure saveToExcel, + AbstractSaveToPdfProcedures saveToPdf) { this.procedureStorage = procedureStorage; this.medicamentStorage = medicamentStorage; this.courseStorage = courseStorage; this.symptomStorage = symptomStorage; this.recipeStorage = recipeStorage; + this.saveToWord = saveToWord; + this.saveToExcel = saveToExcel; + this.saveToPdf = saveToPdf; } - public List GetProcedureCourses(ProcedureSearchModel model) + public List GetProcedureCourses(ProcedureSearchModel model) { var procedure = procedureStorage.GetElement(model); var courses = courseStorage.GetFullList(); var recipes = recipeStorage.GetFullList(); - var list = new List(); - - var record = new ReportCoursesByProcedureViewModel - { - Name = procedure!.Name, - Courses = new List<(int countDays, int pillsPerDay, string comment)>() - }; + var list = new List(); using var context = new PolyclinicDatabase(); var recipeProcedureId = context.RecipeProcedures .Where(x => x.ProcedureId == model.Id).Select(x => x.RecipeId).ToList(); - foreach (var recipe in recipes) { @@ -54,17 +60,16 @@ namespace PolyclinicBusinessLogic.BusinessLogics { if(recipe.CourseId == course.Id) { - record.Courses.Add((course.DaysCount, course.PillsPerDay, course.Comment)); + list.Add(course); } } } } } - list.Add(record); return list; } - public List GetProcedures(ReportBindingModel model) + public List GetProceduresByMedicametsAndSymptoms() { var procedures = procedureStorage.GetFullList(); var medicaments = medicamentStorage.GetFullList(); @@ -75,9 +80,10 @@ namespace PolyclinicBusinessLogic.BusinessLogics { var record = new ReportProceduresViewModel { + Id = procedure.Id, ProcedureName = procedure.Name, DateStartProcedure = procedure.DateStartProcedure, - DateStopProcedure = procedure.DateStopProcedure, + DateStopProcedure = procedure.DateStopProcedure ?? DateTime.MaxValue, MedicamentSymptom = new List<(string medicamentName, string symptomName)>() }; foreach (var medicament in medicaments) @@ -98,19 +104,36 @@ namespace PolyclinicBusinessLogic.BusinessLogics return list; } - public void SaveCoursesByProcedureToExcelFile(ReportBindingModel model) + public void SaveCoursesByProcedureToExcelFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode) { - throw new NotImplementedException(); + saveToExcel.CreateReport(new ExcelCoursesByProceduresInfo + { + FileName = model.FileName, + Title = "Курсы по процедуре" + $" '{procedureSearchMode.Name}'", + Courses = GetProcedureCourses(procedureSearchMode) + }); } - public void SaveCoursesByProcedureToWordFile(ReportBindingModel model) + public void SaveCoursesByProcedureToWordFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode) { - throw new NotImplementedException(); + saveToWord.CreateDoc(new WordCoursesByProceduresInfo + { + FileName = model.FileName, + Title = "Курсы по процедуре" + $" '{procedureSearchMode.Name}'", + Courses = GetProcedureCourses(procedureSearchMode) + }); } - public void SaveOrdersToPdfFile(ReportBindingModel model) + public void SaveProceduresToPdfFile(ReportBindingModel model) { - throw new NotImplementedException(); + saveToPdf.CreateDoc(new PdfProceduresByMedicamentsAndSymptomsInfo + { + FileName= model.FileName, + Title = "Отчет по процедурам с расшифровкой по симптомам и лекарствам", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo.Value, + Procedures = GetProceduresByMedicametsAndSymptoms() + }); } } } diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs index e7f264f..f52adc7 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs @@ -12,7 +12,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics private ILogger _logger; private ISymptomStorage _symptomStorage; - public SymptomLogic(ILogger logger, ISymptomStorage symptomStorage) + public SymptomLogic(ILogger logger, ISymptomStorage symptomStorage) { _logger = logger; _symptomStorage = symptomStorage; @@ -58,14 +58,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics return element; } - public List? ReadList(SymptomSearchModel? model) + public List ReadList(SymptomSearchModel? model = null) { _logger.LogInformation("ReadList. Name:{Name} Id:{Id}", model?.Name, model?.Id); var list = model == null ? _symptomStorage.GetFullList() : _symptomStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); - return null; + return new List(); } _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; @@ -73,7 +73,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics public bool Update(SymptomBindingModel model) { - CheckModel(model); + CheckModel(model, false); if (_symptomStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/UserLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/UserLogic.cs index 735bb03..fd621c4 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/UserLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/UserLogic.cs @@ -12,7 +12,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics private ILogger _logger; private IUserStorage _userStorage; - public UserLogic(ILogger logger, IUserStorage userStorage) + public UserLogic(ILogger logger, IUserStorage userStorage) { _logger = logger; _userStorage = userStorage; diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs new file mode 100644 index 0000000..fb7835c --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportDiagnosesByPeriodSaveToPdf.cs @@ -0,0 +1,76 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; +using PolyclinicContracts.ViewModels; + +namespace PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports +{ + public abstract class AbstractReportDiagnosesByPeriodSaveToPdf + { + public void CreateDoc(PdfDiagnosesByPeriodInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = info.PeriodString, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "3cm", "3cm", "3cm", "4cm", "5cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Название", "Начало", "Конец", "Симптомы", "Курсы" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var diagnoseData in info.Report.DiagnosesData) + { + var diagnose = diagnoseData.Diagnose; + CreateRow(new PdfRowParameters + { + Texts = new List + { + diagnose.Name, + diagnose.DateStartDiagnose.ToShortDateString(), + diagnose.DateStopDiagnose?.ToShortDateString() ?? string.Empty, + "", + "" + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left, + }); + int maxLength = Math.Max(diagnoseData.Symptomes.Count(), diagnoseData.Courses.Count()); + for (int i = 0; i < maxLength; i++) + { + SymptomViewModel? symptom = diagnoseData.Symptomes.Count() > i ? diagnoseData.Symptomes[i] : null; + CourseViewModel? course = diagnoseData.Courses.Count() > i ? diagnoseData.Courses[i] : null; + CreateRow(new PdfRowParameters + { + Texts = new List + { + "", + "", + "", + symptom?.Name ?? string.Empty, + (course == null ? string.Empty : $"#{course.Id} {course.Comment}") + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left, + }); + } + } + SavePdf(info); + } + + protected abstract void CreatePdf(PdfDiagnosesByPeriodInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfDiagnosesByPeriodInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportMedicamentsByDiagnosesSaveToExcel.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportMedicamentsByDiagnosesSaveToExcel.cs new file mode 100644 index 0000000..671baf2 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportMedicamentsByDiagnosesSaveToExcel.cs @@ -0,0 +1,58 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; + +namespace PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports +{ + public abstract class AbstractReportMedicamentsByDiagnosesSaveToExcel + { + public void CreateReport(ReportMedicamentsByDiagnosesInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var diagnoseMedicaments in info.ReportModel) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = diagnoseMedicaments.Diagnose.Name, + StyleInfo = ExcelStyleInfoType.Text + }); + if (diagnoseMedicaments.Medicaments.Count() > 0) + { + rowIndex++; + } + foreach (var medicament in diagnoseMedicaments.Medicaments) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = medicament.Name, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + rowIndex++; + } + SaveExcel(info); + } + protected abstract void CreateExcel(ReportMedicamentsByDiagnosesInfo info); + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + protected abstract void MergeCells(ExcelMergeParameters excelParams); + protected abstract void SaveExcel(ReportMedicamentsByDiagnosesInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportMedicamentsByDiagnosesSaveToWord.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportMedicamentsByDiagnosesSaveToWord.cs new file mode 100644 index 0000000..0891fc2 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractImplementerReports/AbstractReportMedicamentsByDiagnosesSaveToWord.cs @@ -0,0 +1,62 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; + +namespace PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports +{ + public abstract class AbstractReportMedicamentsByDiagnosesSaveToWord + { + public void CreateDoc(ReportMedicamentsByDiagnosesInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (info.Title, new WordTextProperties { Bold = true, Size = "32", }) + }, + TextProperties = new WordTextProperties + { + Size = "32", + JustificationType = WordJustificationType.Center + } + }); + foreach (var diagnoseMedicaments in info.ReportModel) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (diagnoseMedicaments.Diagnose.Name, new WordTextProperties{ Size = "24"}), + }, + + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + foreach (var med in diagnoseMedicaments.Medicaments) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (med.Name, new WordTextProperties{ Size = "24"}), + }, + + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + } + } + SaveWord(info); + } + protected abstract void CreateWord(ReportMedicamentsByDiagnosesInfo info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(ReportMedicamentsByDiagnosesInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToExcelCoursesByProcedure.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToExcelCoursesByProcedure.cs new file mode 100644 index 0000000..7c9aaf4 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToExcelCoursesByProcedure.cs @@ -0,0 +1,65 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; + +namespace PolyclinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelCoursesByProcedure + { + public void CreateReport(ExcelCoursesByProceduresInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var course in info.Courses) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Количество пилюль в день: " + course.PillsPerDay.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = "Количество дней: " + course.DaysCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelCoursesByProceduresInfo info); + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelCoursesByProceduresInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs new file mode 100644 index 0000000..dd731c6 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToPdfProcedures.cs @@ -0,0 +1,76 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; + +namespace PolyclinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfProcedures + { + public void CreateDoc(PdfProceduresByMedicamentsAndSymptomsInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "2cm", "3cm", "3cm", "4cm", "4cm", "4cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Период 'с'", "Период 'до'", "Процедура", "Лекарство", "Симптом" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var procedure in info.Procedures) + { + // Добавление строки с основной информацией о процедуре + CreateRow(new PdfRowParameters + { + Texts = new List + { + procedure.Id.ToString(), + procedure.DateStartProcedure.ToShortDateString(), + procedure.DateStopProcedure?.ToShortDateString() ?? "нет даты окончания процедуры", + procedure.ProcedureName, + "", + "" + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left, + }); + + foreach (var ms in procedure.MedicamentSymptom) + { + // Добавление строки для каждого лекарства и симптома без дублирования названия процедуры + CreateRow(new PdfRowParameters + { + Texts = new List + { + "", + "", + "", + "", + ms.medicamentName, + ms.symptomName + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left, + }); + } + } + SavePdf(info); + } + + protected abstract void CreatePdf(PdfProceduresByMedicamentsAndSymptomsInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfProceduresByMedicamentsAndSymptomsInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToWordCoursesByProcedures.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToWordCoursesByProcedures.cs new file mode 100644 index 0000000..d513b5d --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/AbstractSaveToWordCoursesByProcedures.cs @@ -0,0 +1,59 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; + +namespace PolyclinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordCoursesByProcedures + { + public void CreateDoc(WordCoursesByProceduresInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (info.Title, new WordTextProperties { Bold = true, Size = "32", }) + }, + TextProperties = new WordTextProperties + { + Size = "32", + JustificationType = WordJustificationType.Center + } + }); + foreach (var course in info.Courses) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Количество пилюль в день: " + course.PillsPerDay.ToString() + " единиц\t", new WordTextProperties{ Size = "24"}), + ("Количество дней приёма: " + course.DaysCount.ToString() + " дней", new WordTextProperties{ Size = "24"}), + }, + + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWord(info); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordCoursesByProceduresInfo info); + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordCoursesByProceduresInfo info); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..46f7c0c --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,9 @@ +namespace PolyclinicBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBorder + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..2da5db3 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,9 @@ +namespace PolyclinicBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Rigth + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/ReportType.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/ReportType.cs new file mode 100644 index 0000000..3d84e3e --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/ReportType.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperEnums +{ + public enum ReportType + { + Web = 0, + Email = 1, + Word = 2, + Excel = 3, + Pdf = 4, + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..5efdf5f --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,8 @@ +namespace PolyclinicBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelCellParameters.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelCellParameters.cs new file mode 100644 index 0000000..ccbc4e5 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelCellParameters.cs @@ -0,0 +1,13 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel +{ + public class ExcelCellParameters + { + public string ColumnName { get; set; } = string.Empty; + public uint RowIndex { get; set; } + public string Text { get; set; } = string.Empty; + public string CellReference => $"{ColumnName}{RowIndex}"; + public ExcelStyleInfoType StyleInfo { get; set; } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelCoursesByProceduresInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelCoursesByProceduresInfo.cs new file mode 100644 index 0000000..16a00f5 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelCoursesByProceduresInfo.cs @@ -0,0 +1,17 @@ +using PolyclinicContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel +{ + public class ExcelCoursesByProceduresInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public string ProcedureName { get; set; } = string.Empty; + public List Courses { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelMergeParameters.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelMergeParameters.cs new file mode 100644 index 0000000..2d51fa5 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Excel/ExcelMergeParameters.cs @@ -0,0 +1,9 @@ +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + public string CellToName { get; set; } = string.Empty; + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs new file mode 100644 index 0000000..ac6ed04 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfDiagnosesByPeriodInfo.cs @@ -0,0 +1,14 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF +{ + public class PdfDiagnosesByPeriodInfo + { + public string Title { get; set; } = string.Empty; + public string FileName { get; set; } = string.Empty; + public string PeriodString { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + public ReportDiagnosesByPeriodViewModel Report { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfParagraph.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfParagraph.cs new file mode 100644 index 0000000..de17a96 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfParagraph.cs @@ -0,0 +1,11 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs new file mode 100644 index 0000000..328cae7 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfProceduresByMedicamentsAndSymptomsInfo.cs @@ -0,0 +1,13 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF +{ + public class PdfProceduresByMedicamentsAndSymptomsInfo + { + public string Title { get; set; } = string.Empty; + public string FileName { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Procedures { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfRowParameters.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfRowParameters.cs new file mode 100644 index 0000000..b956d4e --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/PDF/PdfRowParameters.cs @@ -0,0 +1,11 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/ReportMedicamentsByDiagnosesInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/ReportMedicamentsByDiagnosesInfo.cs new file mode 100644 index 0000000..2ad92c9 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/ReportMedicamentsByDiagnosesInfo.cs @@ -0,0 +1,11 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels +{ + public class ReportMedicamentsByDiagnosesInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ReportModel { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs new file mode 100644 index 0000000..8f35c8a --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs @@ -0,0 +1,12 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Word +{ + public class WordCoursesByProceduresInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public string ProcedureName { get; set; } = string.Empty; + public List Courses { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordParagraph.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordParagraph.cs new file mode 100644 index 0000000..1476335 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordParagraph.cs @@ -0,0 +1,8 @@ +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Word +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordTextProperties.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordTextProperties.cs new file mode 100644 index 0000000..5e14f86 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordTextProperties.cs @@ -0,0 +1,11 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; + +namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Word +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + public bool Bold { get; set; } + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportDiagnosesByPeriodSaveToPdf.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportDiagnosesByPeriodSaveToPdf.cs new file mode 100644 index 0000000..ff26e20 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportDiagnosesByPeriodSaveToPdf.cs @@ -0,0 +1,99 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements.ImplementerReports +{ + public class ReportDiagnosesByPeriodSaveToPdf : AbstractReportDiagnosesByPeriodSaveToPdf + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfDiagnosesByPeriodInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfDiagnosesByPeriodInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportMedicamentsByDiagnosesSaveToExcel.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportMedicamentsByDiagnosesSaveToExcel.cs new file mode 100644 index 0000000..9bfac1f --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportMedicamentsByDiagnosesSaveToExcel.cs @@ -0,0 +1,336 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; +using PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports; +using PolyclinicBusinessLogic.OfficePackage.HelperModels; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements.ImplementerReports +{ + public class ReportMedicamentsByDiagnosesSaveToExcel : AbstractReportMedicamentsByDiagnosesSaveToExcel + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? _worksheet; + /// + /// Настройка стилей для файла + /// + /// + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + fonts.Append(fontUsual); + fonts.Append(fontTitle); + var fills = new Fills() { Count = 2U }; + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + var fill2 = new Fill(); + fill2.Append(new PatternFill() + { + PatternType = PatternValues.Gray125 + }); + fills.Append(fill1); + fills.Append(fill2); + var borders = new Borders() { Count = 2U }; + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + var borderThin = new Border(); + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + var rightBorder = new RightBorder() + { + Style = BorderStyleValues.Thin + }; + rightBorder.Append(new + DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + var bottomBorder = new BottomBorder() + { + Style = + BorderStyleValues.Thin + }; + bottomBorder.Append(new + DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + borders.Append(borderNoBorder); + borders.Append(borderThin); + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() + { + NumberFormatId = 0U, + FontId + = 0U, + FillId = 0U, + BorderId = 0U + }; + cellStyleFormats.Append(cellFormatStyle); + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() + { + NumberFormatId = 0U, + FontId = + 0U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + ApplyFont = true + }; + var cellFormatFontAndBorder = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 1U, + FormatId = 0U, + ApplyFont = true, + ApplyBorder = true + }; + var cellFormatTitle = new CellFormat() + { + NumberFormatId = 0U, + FontId + = 1U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + WrapText = true, + Horizontal = + HorizontalAlignmentValues.Center + }, + ApplyFont = true + }; + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + var cellStyles = new CellStyles() { Count = 1U }; + cellStyles.Append(new CellStyle() + { + Name = "Normal", + FormatId = 0U, + BuiltinId = 0U + }); + var differentialFormats = new + DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() + { Count = 0U }; + + var tableStyles = new TableStyles() + { + Count = 0U, + DefaultTableStyle = "TableStyleMedium2", + DefaultPivotStyle = "PivotStyleLight16" + }; + var stylesheetExtensionList = new StylesheetExtensionList(); + var stylesheetExtension1 = new StylesheetExtension() + { + Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" + }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() + { + DefaultSlicerStyle = "SlicerStyleLight1" + }); + var stylesheetExtension2 = new StylesheetExtension() + { + Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" + }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() + { + DefaultTimelineStyle = "TimeSlicerStyleLight1" + }); + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + /// + /// Получение номера стиля из типа + /// + /// + /// + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBorder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + protected override void CreateExcel(ReportMedicamentsByDiagnosesInfo info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, + SpreadsheetDocumentType.Workbook); + // Создаем книгу (в ней хранятся листы) + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + CreateStyles(workbookpart); + // Получаем/создаем хранилище текстов для книги + _shareStringPart = + _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? + _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : + _spreadsheetDocument.WorkbookPart.AddNewPart(); + // Создаем SharedStringTable, если его нет + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + // Создаем лист в книгу + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + // Добавляем лист в книгу + var sheets = + _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = + _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + _worksheet = worksheetPart.Worksheet; + } + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + // Ищем строку, либо добавляем ее + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + // Ищем нужную ячейку + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + // Все ячейки должны быть последовательно друг за другом расположены + // нужно определить, после какой вставлять + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = excelParams.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + // вставляем новый текст + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + protected override void SaveExcel(ReportMedicamentsByDiagnosesInfo info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportMedicamentsByDiagnosesSaveToWord.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportMedicamentsByDiagnosesSaveToWord.cs new file mode 100644 index 0000000..5faac48 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/ImplementerReports/ReportMedicamentsByDiagnosesSaveToWord.cs @@ -0,0 +1,121 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements.ImplementerReports +{ + public class ReportMedicamentsByDiagnosesSaveToWord : AbstractReportMedicamentsByDiagnosesSaveToWord + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + /// + /// Настройки страницы + /// + /// + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); + } + properties.AppendChild(paragraphMarkRunProperties); + return properties; + } + protected override void CreateWord(ReportMedicamentsByDiagnosesInfo info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = SpaceProcessingModeValues.Preserve + }); + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + protected override void SaveWord(ReportMedicamentsByDiagnosesInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToExcelCoursesByProcedure.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToExcelCoursesByProcedure.cs new file mode 100644 index 0000000..990784b --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToExcelCoursesByProcedure.cs @@ -0,0 +1,334 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Excel; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcelCoursesByProcedure : AbstractSaveToExcelCoursesByProcedure + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? _worksheet; + /// + /// Настройка стилей для файла + /// + /// + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + fonts.Append(fontUsual); + fonts.Append(fontTitle); + var fills = new Fills() { Count = 2U }; + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + var fill2 = new Fill(); + fill2.Append(new PatternFill() + { + PatternType = PatternValues.Gray125 + }); + fills.Append(fill1); + fills.Append(fill2); + var borders = new Borders() { Count = 2U }; + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + var borderThin = new Border(); + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + var rightBorder = new RightBorder() + { + Style = BorderStyleValues.Thin + }; + rightBorder.Append(new + DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + var bottomBorder = new BottomBorder() + { + Style = + BorderStyleValues.Thin + }; + bottomBorder.Append(new + DocumentFormat.OpenXml.Office2010.Excel.Color() + { Indexed = 64U }); + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + borders.Append(borderNoBorder); + borders.Append(borderThin); + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() + { + NumberFormatId = 0U, + FontId + = 0U, + FillId = 0U, + BorderId = 0U + }; + cellStyleFormats.Append(cellFormatStyle); + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() + { + NumberFormatId = 0U, + FontId = + 0U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + ApplyFont = true + }; + var cellFormatFontAndBorder = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 1U, + FormatId = 0U, + ApplyFont = true, + ApplyBorder = true + }; + var cellFormatTitle = new CellFormat() + { + NumberFormatId = 0U, + FontId + = 1U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + WrapText = true, + Horizontal = + HorizontalAlignmentValues.Center + }, + ApplyFont = true + }; + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + var cellStyles = new CellStyles() { Count = 1U }; + cellStyles.Append(new CellStyle() + { + Name = "Normal", + FormatId = 0U, + BuiltinId = 0U + }); + var differentialFormats = new + DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() + { Count = 0U }; + + var tableStyles = new TableStyles() + { + Count = 0U, + DefaultTableStyle = "TableStyleMedium2", + DefaultPivotStyle = "PivotStyleLight16" + }; + var stylesheetExtensionList = new StylesheetExtensionList(); + var stylesheetExtension1 = new StylesheetExtension() + { + Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" + }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() + { + DefaultSlicerStyle = "SlicerStyleLight1" + }); + var stylesheetExtension2 = new StylesheetExtension() + { + Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" + }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() + { + DefaultTimelineStyle = "TimeSlicerStyleLight1" + }); + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + /// + /// Получение номера стиля из типа + /// + /// + /// + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBorder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + protected override void CreateExcel(ExcelCoursesByProceduresInfo info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, + SpreadsheetDocumentType.Workbook); + // Создаем книгу (в ней хранятся листы) + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + CreateStyles(workbookpart); + // Получаем/создаем хранилище текстов для книги + _shareStringPart = + _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? + _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : + _spreadsheetDocument.WorkbookPart.AddNewPart(); + // Создаем SharedStringTable, если его нет + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + // Создаем лист в книгу + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + // Добавляем лист в книгу + var sheets = + _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = + _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + _worksheet = worksheetPart.Worksheet; + } + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + // Ищем строку, либо добавляем ее + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + // Ищем нужную ячейку + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + // Все ячейки должны быть последовательно друг за другом расположены + // нужно определить, после какой вставлять + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = excelParams.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + // вставляем новый текст + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + protected override void SaveExcel(ExcelCoursesByProceduresInfo info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfProcedures.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfProcedures.cs new file mode 100644 index 0000000..dbd07ba --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToPdfProcedures.cs @@ -0,0 +1,98 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.PDF; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfProcedures : AbstractSaveToPdfProcedures + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfProceduresByMedicamentsAndSymptomsInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfProceduresByMedicamentsAndSymptomsInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs new file mode 100644 index 0000000..1cfcb72 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs @@ -0,0 +1,122 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordCoursesByProcedure : AbstractSaveToWordCoursesByProcedures + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + /// + /// Настройки страницы + /// + /// + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); + } + properties.AppendChild(paragraphMarkRunProperties); + return properties; + } + protected override void CreateWord(WordCoursesByProceduresInfo info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = SpaceProcessingModeValues.Preserve + }); + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + protected override void SaveWord(WordCoursesByProceduresInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + } +} + + + diff --git a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj index f5e1d5c..fa12928 100644 --- a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj +++ b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj @@ -7,7 +7,9 @@ + + diff --git a/Polyclinic/PolyclinicContracts/BindingModels/CourseBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/CourseBindingModel.cs index ccca0c5..89e184e 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/CourseBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/CourseBindingModel.cs @@ -6,7 +6,7 @@ namespace PolyclinicContracts.BindingModels { public int DaysCount { get; set; } public int PillsPerDay { get; set; } - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; public Dictionary CourseDiagnoses { get; set; } = new(); public int Id { get; set; } } diff --git a/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs index 01877ac..90f9d3e 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/DiagnoseBindingModel.cs @@ -5,10 +5,10 @@ namespace PolyclinicContracts.BindingModels public class DiagnoseBindingModel : IDiagnoseModel { public string Name { get; set; } = string.Empty; - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } public int UserId { get; set; } public int Id { get; set; } - public DateTime DateStartDiagnose { get; } - public DateTime? DateStopDiagnose { get; } + public DateTime DateStartDiagnose { get; set; } + public DateTime? DateStopDiagnose { get; set; } } } diff --git a/Polyclinic/PolyclinicContracts/BindingModels/MedicamentBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/MedicamentBindingModel.cs index a53cfdb..3b19fb7 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/MedicamentBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/MedicamentBindingModel.cs @@ -6,8 +6,8 @@ namespace PolyclinicContracts.BindingModels { public int Id { get; set; } public int? SymptomId { get; set; } - public int ProcedureId { get; set; } + public int? ProcedureId { get; set; } public string Name { get; set; } = string.Empty; - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs index fefd338..12e49aa 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs @@ -7,7 +7,7 @@ namespace PolyclinicContracts.BindingModels public int Id { get; set; } public int UserId { get; set; } public string Name { get; set; } = string.Empty; - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; public DateTime DateStartProcedure { get; set; } = DateTime.Now; public DateTime? DateStopProcedure { get; set; } diff --git a/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs index 1e92b18..2d0f901 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs @@ -7,7 +7,7 @@ namespace PolyclinicContracts.BindingModels public int Id { get; set; } public int? CourseId { get; set; } public int ProceduresCount { get; set; } - public string Comment { get; set; } = string.Empty; - public Dictionary RecipeProcedures { get; } = new(); + public string? Comment { get; set; } = string.Empty; + public Dictionary RecipeProcedures { get; set; } = new(); } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs index 76607a0..a7a65f7 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs @@ -1,15 +1,33 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; +using System.Reflection; namespace PolyclinicContracts.BindingModels { public class ReportBindingModel { - public string FileName { get; set; } = string.Empty; + public string? FileName { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public string GetPeriodString() + { + string txt = ""; + if (DateFrom == null && DateTo == null) + { + txt = "за все время"; + } + else if (DateFrom == null) + { + txt = $"по {DateTo?.ToShortDateString()}"; + } + else if (DateTo == null) + { + txt = $"с {DateFrom?.ToShortDateString()}"; + } + else + { + txt = $"с {DateFrom?.ToShortDateString()} по {DateTo?.ToShortDateString()}"; + } + return txt; + } } } diff --git a/Polyclinic/PolyclinicContracts/BindingModels/SymptomBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/SymptomBindingModel.cs index 28a7699..091eb3e 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/SymptomBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/SymptomBindingModel.cs @@ -5,7 +5,7 @@ namespace PolyclinicContracts.BindingModels public class SymptomBindingModel : ISymptomModel { public string Name { get; set; } = string.Empty; - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; public Dictionary SymptomDiagnoses { get; set; } = new(); public int Id { get; set; } } diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ICourseLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ICourseLogic.cs index 1b9fc2c..ca6dba2 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ICourseLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ICourseLogic.cs @@ -6,7 +6,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts { public interface ICourseLogic { - List? ReadList(CourseSearchModel? model); + List ReadList(CourseSearchModel? model = null); CourseViewModel? ReadElement(CourseSearchModel model); bool Create(CourseBindingModel model); bool Update(CourseBindingModel model); diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IDiagnoseLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IDiagnoseLogic.cs index d931c6d..1b28ddc 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IDiagnoseLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IDiagnoseLogic.cs @@ -6,7 +6,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts { public interface IDiagnoseLogic { - List? ReadList(DiagnoseSearchModel? model); + List ReadList(DiagnoseSearchModel? model = null); DiagnoseViewModel? ReadElement(DiagnoseSearchModel model); bool Create(DiagnoseBindingModel model); bool Update(DiagnoseBindingModel model); diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs index c046a8a..0134200 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IImplementerReportLogic.cs @@ -1,14 +1,15 @@ using PolyclinicContracts.BindingModels; using PolyclinicContracts.ViewModels; +using PolyclinicDataModels.Models; namespace PolyclinicContracts.BusinessLogicsContracts { public interface IImplementerReportLogic { - List GetDiagnoses(); - List GetMedicamentsByDiagnoses(ReportBindingModel model); - void SaveSecuresToWordFile(ReportBindingModel model); - void SaveSecureComponentToExcelFile(ReportBindingModel model); - void SaveOrdersToPdfFile(ReportBindingModel model); + ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd); + List GetReportMedicamentsByDiagnoses(int[] diagnosesIds); + void SaveReportMedicamentsByDiagnosesToWordFile(ReportBindingModel reportInfo, List reportModel); + void SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List reportModel); + void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel); } } diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IProcedureLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IProcedureLogic.cs index 9928c08..43133a7 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IProcedureLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IProcedureLogic.cs @@ -6,7 +6,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts { public interface IProcedureLogic { - List? ReadList(ProcedureSearchModel? model); + List? ReadList(ProcedureSearchModel? model = null); ProcedureViewModel? ReadElement(ProcedureSearchModel model); bool Create(ProcedureBindingModel model); bool Update(ProcedureBindingModel model); diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IRecipeLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IRecipeLogic.cs index e5cd24c..c2ca304 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IRecipeLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/IRecipeLogic.cs @@ -6,7 +6,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts { public interface IRecipeLogic { - List? ReadList(RecipeSearchModel? model); + List? ReadList(RecipeSearchModel? model = null); RecipeViewModel? ReadElement(RecipeSearchModel model); bool Create(RecipeBindingModel model); bool Update(RecipeBindingModel model); diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs index 5ca5cd8..b7daa2e 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs @@ -12,30 +12,34 @@ namespace PolyclinicContracts.BusinessLogicsContracts public interface ISuretorReportLogic { /// - /// Получение списка компонент с указанием, в каких изделиях используются + /// Получение данных (списка) курсов по выбранным процедурам /// /// - List GetProcedureCourses(ProcedureSearchModel model); + List GetProcedureCourses(ProcedureSearchModel model); + /// - /// Получение списка заказов за определенный период + /// Получение списка процедур /// /// /// - List GetProcedures(ReportBindingModel model); + List GetProceduresByMedicametsAndSymptoms(); + /// - /// Сохранение компонент в файл-Word + /// Сохранение курсов по процедурам в файл-Word /// /// - void SaveCoursesByProcedureToWordFile(ReportBindingModel model); + void SaveCoursesByProcedureToWordFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode); + /// - /// Сохранение компонент с указаеним продуктов в файл-Excel + /// Сохранение курсов по процедурам в файл-Excel /// /// - void SaveCoursesByProcedureToExcelFile(ReportBindingModel model); + void SaveCoursesByProcedureToExcelFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode); + /// /// Сохранение заказов в файл-Pdf /// /// - void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveProceduresToPdfFile(ReportBindingModel model); } } diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISymptomLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISymptomLogic.cs index 6f0f2af..4a7d766 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISymptomLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISymptomLogic.cs @@ -6,7 +6,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts { public interface ISymptomLogic { - List? ReadList(SymptomSearchModel? model); + List ReadList(SymptomSearchModel? model = null); SymptomViewModel? ReadElement(SymptomSearchModel model); bool Create(SymptomBindingModel model); bool Update(SymptomBindingModel model); diff --git a/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs b/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs index 8131037..d3ee845 100644 --- a/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs +++ b/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs @@ -3,6 +3,6 @@ public class SymptomSearchModel { public int? Id { get; set; } - public string?Name { get; set; } + public string? Name { get; set; } } } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/CourseViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/CourseViewModel.cs index 55eb5f1..b6e7011 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/CourseViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/CourseViewModel.cs @@ -10,7 +10,7 @@ namespace PolyclinicContracts.ViewModels [DisplayName("Препарата в день")] public int PillsPerDay { get; set; } [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; public Dictionary CourseDiagnoses { get; set; } = new(); public int Id { get; set; } } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs index 96093b0..a727f22 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs @@ -1,5 +1,6 @@ using PolyclinicDataModels.Models; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; namespace PolyclinicContracts.ViewModels { @@ -9,7 +10,7 @@ namespace PolyclinicContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; [DisplayName("Дата 'от'")] public DateTime DateStartDiagnose { get; set; } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/MedicamentViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/MedicamentViewModel.cs index 516bfa1..1ae0728 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/MedicamentViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/MedicamentViewModel.cs @@ -6,11 +6,21 @@ namespace PolyclinicContracts.ViewModels public class MedicamentViewModel : IMedicamentModel { public int Id { get; set; } - public int ProcedureId { get; set; } + public int? ProcedureId { get; set; } public int? SymptomId { get; set; } + [DisplayName("Название медикамента")] public string Name { get; set; } = string.Empty; + + [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; + + + [DisplayName("Название симптома")] + public string SymptomName { get; set; } = string.Empty; + + [DisplayName("Название процедуры")] + public string ProcedureName { get; set; } = string.Empty; } } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs index e495dd5..08e9cf7 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs @@ -12,7 +12,7 @@ namespace PolyclinicContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; [DisplayName("Дата 'от'")] public DateTime DateStartProcedure { get; set; } = DateTime.Now; diff --git a/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs index cd8a8b2..19acfd3 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs @@ -11,7 +11,9 @@ namespace PolyclinicContracts.ViewModels public int ProceduresCount { get; set; } [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; + + [DisplayName("Номер курса")] public int? CourseId { get; set; } public Dictionary RecipeProcedures { get; } = new(); } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs index 7362ded..ba3df1f 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PolyclinicContracts.ViewModels +namespace PolyclinicContracts.ViewModels { public class ReportCoursesByProcedureViewModel { diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnoseWithCoursesAndSymptomesViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnoseWithCoursesAndSymptomesViewModel.cs deleted file mode 100644 index df52d06..0000000 --- a/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnoseWithCoursesAndSymptomesViewModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace PolyclinicContracts.ViewModels -{ - public class ReportDiagnoseWithCoursesAndSymptomesViewModel - { - public int DiagnoseId { get; set; } - public string DiagnoseName { get; set; } = string.Empty; - public string DiagnoseComment { get; set; } = string.Empty; - public DateTime DiagnoseDateStart { get; set; } - public DateTime? DiagnoseDateStop { get; set; } = null; - public List Symptomes { get; set; } = new(); - public List<(int DaysCount, int PillsPerDay)> Courses = new(); - } -} diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnosesByPeriodViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnosesByPeriodViewModel.cs new file mode 100644 index 0000000..0244acf --- /dev/null +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportDiagnosesByPeriodViewModel.cs @@ -0,0 +1,9 @@ +namespace PolyclinicContracts.ViewModels +{ + public class ReportDiagnosesByPeriodViewModel + { + public DateTime? DateStart { get; set; } + public DateTime? DateEnd { get; set; } + public List<(DiagnoseViewModel Diagnose, List Symptomes, List Courses)> DiagnosesData { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs index e9b3bf6..9663386 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportMedicamentsByDiagnoseViewModel.cs @@ -2,11 +2,7 @@ { public class ReportMedicamentsByDiagnoseViewModel { - public int DiagnoseId { get; set; } - public string DiagnoseName { get; set; } = string.Empty; - public string DiagnoseComment { get; set; } = string.Empty; - public DateTime DiagnoseDateStart { get; set; } - public DateTime? DiagnoseDateStop { get; set; } = null; - public List Medicaments = new(); + public DiagnoseViewModel Diagnose { get; set; } = new(); + public List Medicaments { get; set; } = new(); } } diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportProceduresViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportProceduresViewModel.cs index fcac7eb..0c92427 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/ReportProceduresViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportProceduresViewModel.cs @@ -1,14 +1,8 @@ -using PolyclinicDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PolyclinicContracts.ViewModels +namespace PolyclinicContracts.ViewModels { public class ReportProceduresViewModel { + public int Id { get; set; } public string ProcedureName { get; set; } = string.Empty; public DateTime DateStartProcedure { get; set; } public DateTime? DateStopProcedure { get; set;} diff --git a/Polyclinic/PolyclinicContracts/ViewModels/SymptomViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/SymptomViewModel.cs index d1e7b65..74629dd 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/SymptomViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/SymptomViewModel.cs @@ -8,7 +8,7 @@ namespace PolyclinicContracts.ViewModels [DisplayName("Название")] public string Name { get; set; } = string.Empty; [DisplayName("Комментарий")] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; public Dictionary SymptomDiagnoses { get; set; } = new(); public int Id { get; set; } } diff --git a/Polyclinic/PolyclinicDataModels/Enums/UserRole.cs b/Polyclinic/PolyclinicDataModels/Enums/UserRole.cs index 7c70dcd..da6ca84 100644 --- a/Polyclinic/PolyclinicDataModels/Enums/UserRole.cs +++ b/Polyclinic/PolyclinicDataModels/Enums/UserRole.cs @@ -2,10 +2,8 @@ { public enum UserRole { - Неизвестный = -1, - Администратор = 0, + Неизвестный = 0, Исполнитель = 1, Поручитель = 2, - Клиент = 3 } } diff --git a/Polyclinic/PolyclinicDataModels/Models/ICourseModel.cs b/Polyclinic/PolyclinicDataModels/Models/ICourseModel.cs index 152f061..5535fc7 100644 --- a/Polyclinic/PolyclinicDataModels/Models/ICourseModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/ICourseModel.cs @@ -4,7 +4,7 @@ { int DaysCount { get; } int PillsPerDay { get; } - string Comment { get; } + string? Comment { get; } Dictionary CourseDiagnoses { get; } } } diff --git a/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs b/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs index bdb1165..32c7ed1 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IDiagnoseModel.cs @@ -3,7 +3,7 @@ public interface IDiagnoseModel : IId { string Name { get; } - string Comment { get; } + string? Comment { get; } int UserId { get; } DateTime DateStartDiagnose { get; } DateTime? DateStopDiagnose { get; } diff --git a/Polyclinic/PolyclinicDataModels/Models/IMedicamentModel.cs b/Polyclinic/PolyclinicDataModels/Models/IMedicamentModel.cs index 9e7d161..80cdee8 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IMedicamentModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IMedicamentModel.cs @@ -3,8 +3,8 @@ public interface IMedicamentModel : IId { string Name { get; } - string Comment { get; } - int ProcedureId { get; } + string? Comment { get; } + int? ProcedureId { get; } int? SymptomId { get; } } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs b/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs index d40c210..e400ae3 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs @@ -3,7 +3,7 @@ public interface IProcedureModel : IId { string Name { get; } - string Comment { get; } + string? Comment { get; } int UserId { get; } DateTime DateStartProcedure { get; } DateTime? DateStopProcedure { get; } diff --git a/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs b/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs index 486c702..033300b 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs @@ -3,7 +3,7 @@ public interface IRecipeModel : IId { int ProceduresCount { get; set; } - string Comment { get; set; } + string? Comment { get; set; } int? CourseId { get; set; } Dictionary RecipeProcedures { get; } } diff --git a/Polyclinic/PolyclinicDataModels/Models/ISymptomModel.cs b/Polyclinic/PolyclinicDataModels/Models/ISymptomModel.cs index 5e0b0a3..932bbc7 100644 --- a/Polyclinic/PolyclinicDataModels/Models/ISymptomModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/ISymptomModel.cs @@ -3,7 +3,7 @@ public interface ISymptomModel : IId { string Name { get; } - string Comment { get; } + string? Comment { get; } Dictionary SymptomDiagnoses { get; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs index fccc716..acd0dea 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs @@ -31,12 +31,9 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(CourseSearchModel model) { var elements = GetFullList(); - foreach (var prop in model.GetType().GetProperties()) + if (model.Id != null) { - if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null) - { - elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList(); - } + elements = elements.Where(x => x.Id == model.Id).ToList(); } return elements; } @@ -67,14 +64,25 @@ namespace PolyclinicDatabaseImplement.Implements public CourseViewModel? Update(CourseBindingModel model) { using var context = new PolyclinicDatabase(); - var element = context.Courses.FirstOrDefault(x => x.Id == model.Id); - if (element == null) + using var transaction = context.Database.BeginTransaction(); + try { - return null; + var element = context.Courses.FirstOrDefault(x => x.Id == model.Id); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + element.UpdateDiagnoses(context, model); + transaction.Commit(); + return element.GetViewModel; + } + catch (Exception ex) + { + transaction.Rollback(); + throw; } - element.Update(model); - context.SaveChanges(); - return element.GetViewModel; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs index b2b0e4f..d80bbba 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs @@ -37,7 +37,7 @@ namespace PolyclinicDatabaseImplement.Implements public RecipeViewModel? GetElement(RecipeSearchModel bindingModel) { - if (!bindingModel.Id.HasValue || string.IsNullOrEmpty(bindingModel.Comment)) + if (!bindingModel.Id.HasValue) { return null; } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs index ce5759d..a532493 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; @@ -31,12 +32,13 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(SymptomSearchModel model) { var elements = GetFullList(); - foreach (var prop in model.GetType().GetProperties()) + if (model.Id != null) { - if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null) - { - elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList(); - } + elements = elements.Where(x => x.Id == model.Id).ToList(); + } + if (!model.Name.IsNullOrEmpty()) + { + elements = elements.Where(x => x.Name == model.Name).ToList(); } return elements; } @@ -67,14 +69,26 @@ namespace PolyclinicDatabaseImplement.Implements public SymptomViewModel? Update(SymptomBindingModel model) { using var context = new PolyclinicDatabase(); - var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id); - if (element == null) + using var transaction = context.Database.BeginTransaction(); + try { - return null; + var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + element.UpdateDiagnoses(context, model); + transaction.Commit(); + return element.GetViewModel; } - element.Update(model); - context.SaveChanges(); - return element.GetViewModel; + catch (Exception ex) + { + transaction.Rollback(); + throw; + } + } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/UserStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/UserStorage.cs index 657634a..a60d0cd 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/UserStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/UserStorage.cs @@ -31,13 +31,20 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(UserSearchModel model) { var elements = GetFullList(); - foreach (var prop in model.GetType().GetProperties()) + if (model.Id != null) { - if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null) - { - elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList(); - } - } + elements = elements.Where(x => x.Id == model.Id).ToList(); + } + if (!model.Email.IsNullOrEmpty()) + { + elements = elements.Where(x => x.Email == model.Email).ToList(); + + } + if (!model.Password.IsNullOrEmpty()) + { + elements = elements.Where(x => x.Password == model.Password).ToList(); + + } return elements; } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs index 64ec6dd..9c2af76 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240501145526_Init-Create.cs @@ -19,7 +19,7 @@ namespace PolyclinicDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), DaysCount = table.Column(type: "int", nullable: false), PillsPerDay = table.Column(type: "int", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false) + Comment = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -33,7 +33,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false) + Comment = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -63,7 +63,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ProceduresCount = table.Column(type: "int", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: true), CourseId = table.Column(type: "int", nullable: true) }, constraints: table => @@ -83,7 +83,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: true), UserId = table.Column(type: "int", nullable: false), DateStartDiagnose = table.Column(type: "datetime2", nullable: false), DateStopDiagnose = table.Column(type: "datetime2", nullable: true) @@ -109,7 +109,7 @@ namespace PolyclinicDatabaseImplement.Migrations Name = table.Column(type: "nvarchar(max)", nullable: false), DateStartProcedure = table.Column(type: "datetime2", nullable: false), DateStopProcedure = table.Column(type: "datetime2", nullable: true), - Comment = table.Column(type: "nvarchar(max)", nullable: false) + Comment = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { @@ -207,7 +207,7 @@ namespace PolyclinicDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: false), - Comment = table.Column(type: "nvarchar(max)", nullable: false), + Comment = table.Column(type: "nvarchar(max)", nullable: true), ProcedureId = table.Column(type: "int", nullable: false), SymptomId = table.Column(type: "int", nullable: false) }, diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240529231348_For-Medicaments.Designer.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240529231348_For-Medicaments.Designer.cs new file mode 100644 index 0000000..8ea70b9 --- /dev/null +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240529231348_For-Medicaments.Designer.cs @@ -0,0 +1,445 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SecuritySystemDatabaseImplement; + +#nullable disable + +namespace PolyclinicDatabaseImplement.Migrations +{ + [DbContext(typeof(PolyclinicDatabase))] + [Migration("20240529231348_For-Medicaments")] + partial class ForMedicaments + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Course", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("DaysCount") + .HasColumnType("int"); + + b.Property("PillsPerDay") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Courses"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.CourseDiagnose", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CourseId") + .HasColumnType("int"); + + b.Property("DiagnoseId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.HasIndex("DiagnoseId"); + + b.ToTable("CourseDiagnoses"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Diagnose", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("DateStartDiagnose") + .HasColumnType("datetime2"); + + b.Property("DateStopDiagnose") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Diagnoses"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Medicament", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.Property("SymptomId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProcedureId"); + + b.HasIndex("SymptomId"); + + b.ToTable("Medicaments"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Procedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("DateStartProcedure") + .HasColumnType("datetime2"); + + b.Property("DateStopProcedure") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("CourseId") + .HasColumnType("int"); + + b.Property("ProceduresCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.ToTable("Recipes"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.Property("RecipeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProcedureId"); + + b.HasIndex("RecipeId"); + + b.ToTable("RecipeProcedures"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Symptom", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Symptomes"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.SymptomDiagnose", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DiagnoseId") + .HasColumnType("int"); + + b.Property("SymptomId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DiagnoseId"); + + b.HasIndex("SymptomId"); + + b.ToTable("SymptomDiagnoses"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.SymptomRecipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RecipeId") + .HasColumnType("int"); + + b.Property("SymptomId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RecipeId"); + + b.HasIndex("SymptomId"); + + b.ToTable("SymptomRecipes"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Role") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.CourseDiagnose", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.Course", "Course") + .WithMany("Diagnoses") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PolyclinicDatabaseImplement.Models.Diagnose", "Diagnose") + .WithMany() + .HasForeignKey("DiagnoseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Course"); + + b.Navigation("Diagnose"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Diagnose", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Medicament", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.Procedure", "Procedure") + .WithMany() + .HasForeignKey("ProcedureId"); + + b.HasOne("PolyclinicDatabaseImplement.Models.Symptom", "Symptom") + .WithMany() + .HasForeignKey("SymptomId"); + + b.Navigation("Procedure"); + + b.Navigation("Symptom"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Procedure", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.Course", "Course") + .WithMany() + .HasForeignKey("CourseId"); + + b.Navigation("Course"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.Procedure", "Procedure") + .WithMany() + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PolyclinicDatabaseImplement.Models.Recipe", "Recipe") + .WithMany("Procedures") + .HasForeignKey("RecipeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Procedure"); + + b.Navigation("Recipe"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.SymptomDiagnose", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.Diagnose", "Diagnose") + .WithMany() + .HasForeignKey("DiagnoseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PolyclinicDatabaseImplement.Models.Symptom", "Symptom") + .WithMany("Diagnoses") + .HasForeignKey("SymptomId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Diagnose"); + + b.Navigation("Symptom"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.SymptomRecipe", b => + { + b.HasOne("PolyclinicDatabaseImplement.Models.Recipe", "Recipe") + .WithMany() + .HasForeignKey("RecipeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PolyclinicDatabaseImplement.Models.Symptom", "Symptom") + .WithMany() + .HasForeignKey("SymptomId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recipe"); + + b.Navigation("Symptom"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Course", b => + { + b.Navigation("Diagnoses"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => + { + b.Navigation("Procedures"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Symptom", b => + { + b.Navigation("Diagnoses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240529231348_For-Medicaments.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240529231348_For-Medicaments.cs new file mode 100644 index 0000000..04f4e94 --- /dev/null +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240529231348_For-Medicaments.cs @@ -0,0 +1,208 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PolyclinicDatabaseImplement.Migrations +{ + /// + public partial class ForMedicaments : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Medicaments_Procedures_ProcedureId", + table: "Medicaments"); + + migrationBuilder.DropForeignKey( + name: "FK_Medicaments_Symptomes_SymptomId", + table: "Medicaments"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Symptomes", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Recipes", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Procedures", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "SymptomId", + table: "Medicaments", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AlterColumn( + name: "ProcedureId", + table: "Medicaments", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Medicaments", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Diagnoses", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Courses", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + + migrationBuilder.AddForeignKey( + name: "FK_Medicaments_Procedures_ProcedureId", + table: "Medicaments", + column: "ProcedureId", + principalTable: "Procedures", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Medicaments_Symptomes_SymptomId", + table: "Medicaments", + column: "SymptomId", + principalTable: "Symptomes", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Medicaments_Procedures_ProcedureId", + table: "Medicaments"); + + migrationBuilder.DropForeignKey( + name: "FK_Medicaments_Symptomes_SymptomId", + table: "Medicaments"); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Symptomes", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Recipes", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Procedures", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "SymptomId", + table: "Medicaments", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ProcedureId", + table: "Medicaments", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Medicaments", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Diagnoses", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Comment", + table: "Courses", + type: "nvarchar(max)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Medicaments_Procedures_ProcedureId", + table: "Medicaments", + column: "ProcedureId", + principalTable: "Procedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Medicaments_Symptomes_SymptomId", + table: "Medicaments", + column: "SymptomId", + principalTable: "Symptomes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs index 0c34395..0e1ffea 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs @@ -31,7 +31,6 @@ namespace PolyclinicDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") - .IsRequired() .HasColumnType("nvarchar(max)"); b.Property("DaysCount") @@ -77,7 +76,6 @@ namespace PolyclinicDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") - .IsRequired() .HasColumnType("nvarchar(max)"); b.Property("DateStartDiagnose") @@ -109,18 +107,16 @@ namespace PolyclinicDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") - .IsRequired() .HasColumnType("nvarchar(max)"); b.Property("Name") .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("ProcedureId") + b.Property("ProcedureId") .HasColumnType("int"); b.Property("SymptomId") - .IsRequired() .HasColumnType("int"); b.HasKey("Id"); @@ -141,7 +137,6 @@ namespace PolyclinicDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") - .IsRequired() .HasColumnType("nvarchar(max)"); b.Property("DateStartProcedure") @@ -173,7 +168,6 @@ namespace PolyclinicDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") - .IsRequired() .HasColumnType("nvarchar(max)"); b.Property("CourseId") @@ -221,7 +215,6 @@ namespace PolyclinicDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Comment") - .IsRequired() .HasColumnType("nvarchar(max)"); b.Property("Name") @@ -341,15 +334,11 @@ namespace PolyclinicDatabaseImplement.Migrations { b.HasOne("PolyclinicDatabaseImplement.Models.Procedure", "Procedure") .WithMany() - .HasForeignKey("ProcedureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("ProcedureId"); b.HasOne("PolyclinicDatabaseImplement.Models.Symptom", "Symptom") .WithMany() - .HasForeignKey("SymptomId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("SymptomId"); b.Navigation("Procedure"); diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs index 59bd410..1ba4d2d 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs @@ -14,7 +14,7 @@ namespace PolyclinicDatabaseImplement.Models public int DaysCount { get; set; } [Required] public int PillsPerDay { get; set; } - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; [ForeignKey("CourseId")] public virtual List Diagnoses { get; set; } = new(); private Dictionary? _courseDiagnoses = null; @@ -34,7 +34,7 @@ namespace PolyclinicDatabaseImplement.Models } } - public static Course Create(PolyclinicDatabase context, CourseBindingModel model) + public static Course? Create(PolyclinicDatabase context, CourseBindingModel model) { return new Course() { @@ -71,8 +71,7 @@ namespace PolyclinicDatabaseImplement.Models if (courseDiagnoses != null && courseDiagnoses.Count > 0) { // удалили те, которых нет в модели - context.CourseDiagnoses.RemoveRange(courseDiagnoses - .Where(rec => !model.CourseDiagnoses.ContainsKey(rec.DiagnoseId))); + context.CourseDiagnoses.RemoveRange(courseDiagnoses); context.SaveChanges(); } var course = context.Courses.First(x => x.Id == Id); diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/CourseDiagnose.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/CourseDiagnose.cs index 5c8809f..36db203 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/CourseDiagnose.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/CourseDiagnose.cs @@ -9,7 +9,7 @@ namespace PolyclinicDatabaseImplement.Models public int CourseId { get; set; } [Required] public int DiagnoseId { get; set; } - public virtual Course Course { get; set; } = new(); - public virtual Diagnose Diagnose { get; set; } = new(); + public virtual Course? Course { get; set; } + public virtual Diagnose? Diagnose { get; set; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs index 526d6e1..7848b38 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Diagnose.cs @@ -9,8 +9,7 @@ namespace PolyclinicDatabaseImplement.Models { [Required] public string Name { get; set; } = string.Empty; - [Required] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } [Required] public int UserId { get; set; } @@ -18,7 +17,7 @@ namespace PolyclinicDatabaseImplement.Models public DateTime DateStartDiagnose { get; set; } = DateTime.Now; public DateTime? DateStopDiagnose { get; set; } public int Id { get; set; } - public virtual User User { get; set; } = new(); + public virtual User? User { get; set; } public static Diagnose? Create(DiagnoseBindingModel? model) { @@ -45,6 +44,8 @@ namespace PolyclinicDatabaseImplement.Models } Name = model.Name; Comment = model.Comment; + DateStartDiagnose = model.DateStartDiagnose; + DateStopDiagnose = model.DateStopDiagnose; } public DiagnoseViewModel GetViewModel => new() diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs index 1e01374..8e0f838 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs @@ -13,19 +13,16 @@ namespace PolyclinicDatabaseImplement.Models [Required] public string Name { get; set; } = string.Empty; - [Required] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; - [Required] - public int ProcedureId { get; set; } + public int? ProcedureId { get; set; } - [Required] public int? SymptomId { get; set; } public virtual Symptom? Symptom { get; set; } public virtual Procedure? Procedure { get; set; } - public static Medicament Create(MedicamentBindingModel bindingModel) + public static Medicament? Create(MedicamentBindingModel bindingModel) { return new Medicament() { @@ -41,6 +38,8 @@ namespace PolyclinicDatabaseImplement.Models { Name = bindingModel.Name; Comment = bindingModel.Comment; + ProcedureId = bindingModel.ProcedureId; + SymptomId = bindingModel.SymptomId; } public MedicamentViewModel GetViewModel => new() @@ -48,8 +47,10 @@ namespace PolyclinicDatabaseImplement.Models Id = Id, Name = Name, Comment = Comment, - ProcedureId = ProcedureId, - SymptomId = Symptom?.Id ?? null + ProcedureId = Procedure?.Id ?? null, + SymptomId = Symptom?.Id ?? null, + SymptomName = Symptom?.Name ?? string.Empty, + ProcedureName = Procedure?.Name ?? string.Empty, }; } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs index bbf91e7..baa756b 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs @@ -1,7 +1,6 @@ using PolyclinicContracts.BindingModels; using PolyclinicContracts.ViewModels; using PolyclinicDataModels.Models; -using SecuritySystemDatabaseImplement; using System.ComponentModel.DataAnnotations; namespace PolyclinicDatabaseImplement.Models @@ -19,13 +18,14 @@ namespace PolyclinicDatabaseImplement.Models [Required] public DateTime DateStartProcedure { get; set; } = DateTime.Now; public DateTime? DateStopProcedure { get; set; } - public virtual User User { get; set; } = new(); + public virtual User? User { get; set; } - [Required] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; - public static Procedure Create(ProcedureBindingModel bindingModel) + public static Procedure? Create(ProcedureBindingModel bindingModel) { + if (bindingModel == null) return null; + return new Procedure() { Id = bindingModel.Id, @@ -37,10 +37,17 @@ namespace PolyclinicDatabaseImplement.Models }; } - public void Update(ProcedureBindingModel bindingModel) + public void Update(ProcedureBindingModel? bindingModel) { + if (bindingModel == null) + { + return; + } + Name = bindingModel.Name; Comment = bindingModel.Comment; + DateStartProcedure = bindingModel.DateStartProcedure; + DateStopProcedure = bindingModel.DateStopProcedure; } public ProcedureViewModel GetViewModel => new() @@ -51,6 +58,6 @@ namespace PolyclinicDatabaseImplement.Models Comment = Comment, DateStartProcedure = DateStartProcedure, DateStopProcedure = DateStopProcedure, - }; + }; } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs index bf3a0c4..dabca05 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs @@ -14,10 +14,9 @@ namespace PolyclinicDatabaseImplement.Models [Required] public int ProceduresCount { get; set; } - [Required] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; public int? CourseId { get; set; } - public virtual Course Course { get; set; } = new(); + public virtual Course? Course { get; set; } private Dictionary? _recipeProcedures = null; @@ -37,7 +36,7 @@ namespace PolyclinicDatabaseImplement.Models } } - public static Recipe Create(PolyclinicDatabase database, RecipeBindingModel bindingModel) + public static Recipe? Create(PolyclinicDatabase database, RecipeBindingModel bindingModel) { return new Recipe() { @@ -47,7 +46,7 @@ namespace PolyclinicDatabaseImplement.Models CourseId = bindingModel.CourseId, Procedures = bindingModel.RecipeProcedures.Select(x => new RecipeProcedure { - Recipe = database.Recipes.First(y => y.Id == x.Key) + Procedure = database.Procedures.First(y => y.Id == x.Key), }).ToList() }; } @@ -64,17 +63,21 @@ namespace PolyclinicDatabaseImplement.Models Id = Id, ProceduresCount = ProceduresCount, Comment = Comment, - CourseId = Course?.Id ?? null, + CourseId = CourseId ?? null, }; public void UpdateProcedures(PolyclinicDatabase database, RecipeBindingModel bindingModel) { + if (database.Procedures.Count() == 0) + { + return; + } var RecipeProcedures = database.RecipeProcedures.Where(x => x.ProcedureId == bindingModel.Id).ToList(); if (RecipeProcedures != null) { // удалили те, которых нет в модели - database.RecipeProcedures.RemoveRange(RecipeProcedures.Where(rec => !bindingModel.RecipeProcedures.ContainsKey(rec.RecipeId))); + database.RecipeProcedures.RemoveRange(RecipeProcedures); database.SaveChanges(); } var Procedure = database.Procedures.First(x => x.Id == bindingModel.Id); @@ -85,6 +88,7 @@ namespace PolyclinicDatabaseImplement.Models Procedure = Procedure, Recipe = database.Recipes.First(x => x.Id == pc.Key) }); + database.SaveChanges(); } _recipeProcedures = null; } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs index 86b5369..dee6a7d 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs @@ -9,7 +9,7 @@ namespace PolyclinicDatabaseImplement.Models public int ProcedureId { get; set; } [Required] public int RecipeId { get; set; } - public virtual Procedure Procedure { get; set; } = new(); - public virtual Recipe Recipe { get; set; } = new(); + public virtual Procedure? Procedure { get; set; } + public virtual Recipe? Recipe { get; set; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs index 59f59ba..d8b93ca 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs @@ -11,8 +11,7 @@ namespace PolyclinicDatabaseImplement.Models { [Required] public string Name { get; set; } = string.Empty; - [Required] - public string Comment { get; set; } = string.Empty; + public string? Comment { get; set; } = string.Empty; [ForeignKey("SymptomId")] public virtual List Diagnoses { get; set; } = new(); private Dictionary? _symptomDiagnoses = null; @@ -33,7 +32,7 @@ namespace PolyclinicDatabaseImplement.Models } public int Id { get; set; } - public static Symptom Create(PolyclinicDatabase context, SymptomBindingModel model) + public static Symptom? Create(PolyclinicDatabase context, SymptomBindingModel model) { return new Symptom() { @@ -64,19 +63,18 @@ namespace PolyclinicDatabaseImplement.Models public void UpdateDiagnoses(PolyclinicDatabase context, SymptomBindingModel model) { var symptomDiagnoses = context.SymptomDiagnoses.Where(rec => rec.SymptomId == model.Id).ToList(); + if (symptomDiagnoses != null && symptomDiagnoses.Count > 0) { - // удалили те, которых нет в модели - context.SymptomDiagnoses.RemoveRange(symptomDiagnoses - .Where(rec => !model.SymptomDiagnoses.ContainsKey(rec.DiagnoseId))); + context.SymptomDiagnoses.RemoveRange(symptomDiagnoses); context.SaveChanges(); } - var course = context.Symptomes.First(x => x.Id == Id); + var symptom = context.Symptomes.First(x => x.Id == model.Id); foreach (var pc in model.SymptomDiagnoses) { context.SymptomDiagnoses.Add(new SymptomDiagnose { - Symptom = course, + Symptom = symptom, Diagnose = context.Diagnoses.First(x => x.Id == pc.Key), }); context.SaveChanges(); diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomDiagnose.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomDiagnose.cs index 7d8a399..8d3566b 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomDiagnose.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomDiagnose.cs @@ -9,7 +9,7 @@ namespace PolyclinicDatabaseImplement.Models public int SymptomId { get; set; } [Required] public int DiagnoseId { get; set; } - public virtual Symptom Symptom { get; set; } = new(); - public virtual Diagnose Diagnose { get; set; } = new(); + public virtual Symptom? Symptom { get; set; } + public virtual Diagnose? Diagnose { get; set; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomRecipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomRecipe.cs index 032ac33..4f758d0 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomRecipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/SymptomRecipe.cs @@ -9,7 +9,7 @@ namespace PolyclinicDatabaseImplement.Models public int SymptomId { get; set; } [Required] public int RecipeId { get; set; } - public virtual Symptom Symptom { get; set; } = new(); - public virtual Recipe Recipe { get; set; } = new(); + public virtual Symptom? Symptom { get; set; } + public virtual Recipe? Recipe { get; set; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs index 4773dc6..a2fe135 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/User.cs @@ -43,8 +43,6 @@ namespace PolyclinicDatabaseImplement.Models FIO = model.FIO; Email = model.Email; Password = model.Password; - Role = model.Role; - FIO = model.FIO; } public UserViewModel GetViewModel => new() diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/CoursesController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/CoursesController.cs new file mode 100644 index 0000000..4d92f34 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/CoursesController.cs @@ -0,0 +1,125 @@ +using Microsoft.AspNetCore.Mvc; +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicContracts.ViewModels; +using PolyclinicDataModels.Models; +using PolyclinicWebAppImplementer.Models; + +namespace PolyclinicWebAppImplementer.Controllers +{ + public class CoursesController : Controller + { + private readonly IDiagnoseLogic _diagnoseLogic; + private readonly ICourseLogic _courseLogic; + + public CoursesController(IDiagnoseLogic diagnoseLogic, ICourseLogic courseLogic) + { + _diagnoseLogic = diagnoseLogic; + _courseLogic = courseLogic; + } + + [HttpGet] + public IActionResult Index() + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + List courses = _courseLogic.ReadList(); + ViewData["Title"] = "Список курсов"; + return View("CoursesList", courses); + } + [HttpGet] + [HttpPost] + public IActionResult Add(CourseFormModel model, int[] selectedDiagnoses) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + if (HttpContext.Request.Method == "GET") + { + ViewData["Title"] = "Новый курс"; + model = new() + { + Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, false)).ToList() + }; + return View("CourseForm", model); + } + else + { + var allDiagnoses = _diagnoseLogic.ReadList(); + CourseBindingModel course = new CourseBindingModel + { + Comment = model.CourseViewModel.Comment, + DaysCount = model.CourseViewModel.DaysCount, + PillsPerDay = model.CourseViewModel.PillsPerDay, + CourseDiagnoses = selectedDiagnoses + .ToDictionary( + x => x, + x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel + ) + }; + _courseLogic.Create(course); + return RedirectToAction("Index"); + } + } + [HttpGet] + [HttpPost] + public IActionResult Edit(int id, CourseFormModel model, int[] selectedDiagnoses) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + if (HttpContext.Request.Method == "GET") + { + var obj = _courseLogic.ReadElement(new CourseSearchModel { Id = id }); + model = new() + { + CourseViewModel = obj, + Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, obj.CourseDiagnoses.ContainsKey(x.Id))).ToList() + }; + ViewData["Title"] = "Редактировать симптом"; + return View("CourseForm", model); + } + else + { + var allDiagnoses = _diagnoseLogic.ReadList(); + CourseBindingModel course = new CourseBindingModel + { + Id = id, + Comment = model.CourseViewModel.Comment, + DaysCount = model.CourseViewModel.DaysCount, + PillsPerDay = model.CourseViewModel.PillsPerDay, + CourseDiagnoses = selectedDiagnoses + .ToDictionary( + x => x, + x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel + ) + }; + _courseLogic.Update(course); + return RedirectToAction("Index"); + } + } + [HttpPost] + public IActionResult Delete(int id) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + var obj = _courseLogic.ReadElement(new CourseSearchModel { Id = id }); + if (obj != null) + { + _courseLogic.Delete(new CourseBindingModel { Id = obj.Id }); + } + return RedirectToAction("Index"); + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs new file mode 100644 index 0000000..4e84b9d --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/DiagnosesController.cs @@ -0,0 +1,118 @@ +using Microsoft.AspNetCore.Mvc; +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicContracts.ViewModels; +using PolyclinicWebAppImplementer.Models; +using System.Net; + +namespace PolyclinicWebAppImplementer.Controllers +{ + public class DiagnosesController : Controller + { + private readonly ILogger _logger; + private readonly IDiagnoseLogic _diagnoseLogic; + + public DiagnosesController(ILogger logger, IDiagnoseLogic diagnoseLogic) + { + _logger = logger; + _diagnoseLogic = diagnoseLogic; + } + + [HttpGet] + public IActionResult Index() + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + List diagnoses = _diagnoseLogic.ReadList(new DiagnoseSearchModel { UserId = currentUser.Id }); + ViewData["Title"] = "Список диагнозов"; + return View("DiagnosesList", diagnoses); + } + + [HttpGet] + [HttpPost] + public IActionResult Add(DiagnoseViewModel model) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + if (HttpContext.Request.Method == "GET") + { + ViewData["Title"] = "Новый диагноз"; + return View("DiagnoseForm"); + } + else + { + DiagnoseBindingModel diagnose = new DiagnoseBindingModel + { + UserId = currentUser.Id, + Name = model.Name, + Comment = model.Comment, + DateStartDiagnose = model.DateStartDiagnose, + DateStopDiagnose = model.DateStopDiagnose, + }; + _diagnoseLogic.Create(diagnose); + return RedirectToAction("Index"); + } + } + + [HttpGet] + [HttpPost] + public IActionResult Edit(int id, DiagnoseViewModel model) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + var obj = _diagnoseLogic.ReadElement(new DiagnoseSearchModel { Id = id }); + if (obj.UserId != currentUser.Id) + { + return StatusCode(403, "Нельзя редактировать чужой диагноз"); + } + if (HttpContext.Request.Method == "GET") + { + ViewData["Title"] = "Редактировать диагноз"; + return View("DiagnoseForm", obj); + } + else + { + DiagnoseBindingModel diagnose = new DiagnoseBindingModel + { + Id = model.Id, + Name = model.Name, + Comment = model.Comment, + DateStartDiagnose = model.DateStartDiagnose, + DateStopDiagnose = model.DateStopDiagnose, + }; + _diagnoseLogic.Update(diagnose); + return RedirectToAction("Index"); + } + } + + [HttpPost] + public IActionResult Delete(int id) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + var obj = _diagnoseLogic.ReadElement(new DiagnoseSearchModel { Id = id }); + if (obj.UserId != currentUser.Id) + { + return StatusCode(403, "Нельзя удалить чужой диагноз"); + } + if (obj != null) + { + _diagnoseLogic.Delete(new DiagnoseBindingModel { Id = obj.Id }); + } + return RedirectToAction("Index"); + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/HomeController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/HomeController.cs index 0eded61..157d1c1 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Controllers/HomeController.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/HomeController.cs @@ -17,79 +17,12 @@ namespace PolyclinicWebAppImplementer.Controllers { return View(); } - [HttpGet] - [HttpPost] - public IActionResult Course() - { - if (HttpContext.Request.Method == "POST") - { - return Redirect("~/Home/Courses"); - } - else - { - return View(); - } - } - public IActionResult Courses() - { - return View(); - } - public IActionResult Diagnose() - { - if (HttpContext.Request.Method == "POST") - { - return Redirect("~/Home/Diagnoses"); - } - else - { - return View(); - } - } - - public IActionResult Diagnoses() - { - return View(); - } - public IActionResult Symptom() - { - if (HttpContext.Request.Method == "POST") - { - return Redirect("~/Home/Symptomes"); - } - else - { - return View(); - } - } - public IActionResult Symptomes() - { - return View(); - } public IActionResult Privacy() { return View(); } - [HttpGet] - [HttpPost] - public IActionResult Login() - { - if (HttpContext.Request.Method == "POST") - { - return Redirect("~/"); - } - else - { - return View(); - } - } - - public IActionResult Register() - { - return View(); - } - [HttpGet] [HttpPost] public IActionResult AddRecipeToCourse() diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/RecipeController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/RecipeController.cs new file mode 100644 index 0000000..7528aaf --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/RecipeController.cs @@ -0,0 +1,72 @@ +using Microsoft.AspNetCore.Mvc; +using PolyclinicBusinessLogic.BusinessLogics; +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicWebAppImplementer.Models; + +namespace PolyclinicWebAppImplementer.Controllers +{ + public class RecipeController : Controller + { + private readonly IRecipeLogic _recipeLogic; + private readonly ICourseLogic _courseLogic; + + public RecipeController(IRecipeLogic recipeLogic, ICourseLogic courseLogic) + { + _recipeLogic = recipeLogic; + _courseLogic = courseLogic; + } + + [HttpGet] + [HttpPost] + public IActionResult LinkCourse(RecipeLinkCourseModel model) + { + var recipes = _recipeLogic.ReadList(); + var courses = _courseLogic.ReadList(); + var linkedRecipes = recipes + .Where(x => x.CourseId != null) + .Select(x => (x, _courseLogic.ReadElement(new CourseSearchModel { Id = x.CourseId }))).ToList(); + + if (HttpContext.Request.Method == "GET") + { + model = new() + { + Recipes = recipes, + Courses = courses, + LinkedRecipes = linkedRecipes + }; + + return View(model); + } + else + { + var recipe = _recipeLogic.ReadElement(new RecipeSearchModel { Id = model.RecipeId }); + var recipeBindingModel = new RecipeBindingModel + { + Id = recipe.Id, + ProceduresCount = recipe.ProceduresCount, + Comment = recipe.Comment, + RecipeProcedures = recipe.RecipeProcedures, + CourseId = model.CourseId + }; + _recipeLogic.Update(recipeBindingModel); + return RedirectToAction("LinkCourse"); + } + } + [HttpPost] + public IActionResult UnLinkCourse(int id) + { + var recipe = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id }); + var recipeBindingModel = new RecipeBindingModel + { + Id = recipe.Id, + ProceduresCount = recipe.ProceduresCount, + Comment = recipe.Comment, + RecipeProcedures = recipe.RecipeProcedures + }; + _recipeLogic.Update(recipeBindingModel); + return RedirectToAction("LinkCourse"); + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs new file mode 100644 index 0000000..0e67941 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs @@ -0,0 +1,132 @@ +using Microsoft.AspNetCore.Mvc; +using PolyclinicBusinessLogic.BusinessLogics; +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicContracts.ViewModels; +using PolyclinicWebAppImplementer.Models; + +namespace PolyclinicWebAppImplementer.Controllers +{ + public class ReportsController : Controller + { + private readonly IImplementerReportLogic _reportLogic; + private readonly IDiagnoseLogic _diagnoseLogic; + private readonly SendMailLogic _sendMailLogic; + + public ReportsController(IImplementerReportLogic reportLogic, IDiagnoseLogic diagnoseLogic, SendMailLogic sendMailLogic) + { + _reportLogic = reportLogic; + _diagnoseLogic = diagnoseLogic; + _sendMailLogic = sendMailLogic; + } + + [HttpGet] + [HttpPost] + public IActionResult DiagnosesByPeriod(DiagnosesByPeriodFormModel model) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + if (HttpContext.Request.Method == "GET") + { + return View(model); + } + else + { + var report = _reportLogic.GetReportDiagnosesByPeriod(model.DateStart, model.DateEnd); + if (model.ReportType == ReportType.Web) + { + model.Report = report; + } + else + { + ReportBindingModel reportInfo = new() + { + FileName = "diagnosesByPeriod.pdf", + DateFrom = model.DateStart, + DateTo = model.DateEnd + }; + + _reportLogic.SaveReportDiagnosesByPeriodToPdfFile(reportInfo, report); + + var fileName = reportInfo.FileName; + var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + + if (System.IO.File.Exists(filePath)) + { + try + { + string txt = reportInfo.GetPeriodString(); + var userEmail = currentUser.Email; + _sendMailLogic.SendEmail(userEmail, $"Здравствуйте, {currentUser.FIO}! В приложении отчет по болезням {txt} от {DateTime.Now.ToString()}", filePath); + + model.Message = $"Отчет в формате .pdf был отправлен на почту {currentUser.Email}"; + return View(model); + } + catch (Exception) + { + model.Error = $"Произошла ошибка при отправке отчета"; + } + } + else + { + model.Error = "Произошла ошибка при генерации отчета"; + } + } + return View(model); + } + } + + [HttpGet] + [HttpPost] + public IActionResult MedicamentsByDiagnoses(MedicamentsByDiagnosesFormModel model) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + var diagnoses = _diagnoseLogic.ReadList(new DiagnoseSearchModel { UserId = currentUser.Id }); + if (model.SelectedDiagnoses != null) + { + model.Diagnoses = diagnoses.Select(x => (x, model.SelectedDiagnoses.Contains(x.Id))).ToList(); + } + else + { + model.Diagnoses = diagnoses.Select(x => (x, false)).ToList(); + } + if (HttpContext.Request.Method == "GET") + { + return View(model); + } + else + { + var reportInfo = new ReportBindingModel(); + + var reportModel = _reportLogic.GetReportMedicamentsByDiagnoses(model.SelectedDiagnoses); + + if (model.ReportType == ReportType.Word) + { + reportInfo.FileName = model.FileName + ".docx"; + _reportLogic.SaveReportMedicamentsByDiagnosesToWordFile(reportInfo, reportModel); + } + else + { + reportInfo.FileName = model.FileName + ".xlsx"; + _reportLogic.SaveReportMedicamentsByDiagnosesToExcelFile(reportInfo, reportModel); + } + + var filePath = Path.Combine(Directory.GetCurrentDirectory(), reportInfo.FileName); + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + string mimeType = model.ReportType == ReportType.Word ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + + return File(fileBytes, mimeType, reportInfo.FileName); + } + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs new file mode 100644 index 0000000..6ff0b44 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs @@ -0,0 +1,121 @@ +using Microsoft.AspNetCore.Mvc; +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicContracts.ViewModels; +using PolyclinicDataModels.Models; +using PolyclinicWebAppImplementer.Models; + +namespace PolyclinicWebAppImplementer.Controllers +{ + public class SymptomesController : Controller + { + private readonly ISymptomLogic _symptomLogic; + private readonly IDiagnoseLogic _diagnoseLogic; + public SymptomesController(ISymptomLogic symptomLogic, IDiagnoseLogic diagnoseLogic) + { + _symptomLogic = symptomLogic; + _diagnoseLogic = diagnoseLogic; + } + [HttpGet] + public IActionResult Index() + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + List symptomes = _symptomLogic.ReadList(); + ViewData["Title"] = "Список симптомов"; + return View("SymptomesList", symptomes); + } + [HttpGet] + [HttpPost] + public IActionResult Add(SymptomFormModel model, int[] selectedDiagnoses) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + if (HttpContext.Request.Method == "GET") + { + ViewData["Title"] = "Новый симптом"; + model = new() + { + Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, false)).ToList() + }; + return View("SymptomForm", model); + } + else + { + var allDiagnoses = _diagnoseLogic.ReadList(); + SymptomBindingModel symptom = new SymptomBindingModel + { + Name = model.SymptomViewModel.Name, + Comment = model.SymptomViewModel.Comment, + SymptomDiagnoses = selectedDiagnoses + .ToDictionary( + x => x, + x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel + ) + }; + _symptomLogic.Create(symptom); + return RedirectToAction("Index"); + } + } + [HttpGet] + [HttpPost] + public IActionResult Edit(int id, SymptomFormModel model, int[] selectedDiagnoses) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + if (HttpContext.Request.Method == "GET") + { + var obj = _symptomLogic.ReadElement(new SymptomSearchModel { Id = id }); + model = new() + { + SymptomViewModel = obj, + Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, obj.SymptomDiagnoses.ContainsKey(x.Id))).ToList() + }; + ViewData["Title"] = "Редактировать симптом"; + return View("SymptomForm", model); + } + else + { + var allDiagnoses = _diagnoseLogic.ReadList(); + SymptomBindingModel symptom = new SymptomBindingModel + { + Id = id, + Name = model.SymptomViewModel.Name, + Comment = model.SymptomViewModel.Comment, + SymptomDiagnoses = selectedDiagnoses + .ToDictionary( + x => x, + x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel + ) + }; + _symptomLogic.Update(symptom); + return RedirectToAction("Index"); + } + } + [HttpPost] + public IActionResult Delete(int id) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login", "User"); + } + var obj = _symptomLogic.ReadElement(new SymptomSearchModel { Id = id }); + if (obj != null) + { + _symptomLogic.Delete(new SymptomBindingModel { Id = obj.Id }); + } + return RedirectToAction("Index"); + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs new file mode 100644 index 0000000..3253da8 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/UserController.cs @@ -0,0 +1,151 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; +using PolyclinicContracts.BindingModels; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.SearchModels; +using PolyclinicDataModels.Enums; +using PolyclinicDataModels.Models; +using PolyclinicWebAppImplementer.Models; + +namespace PolyclinicWebAppImplementer.Controllers +{ + public class UserController : Controller + { + private readonly IUserLogic _userLogic; + public UserController(IUserLogic userLogic) + { + _userLogic = userLogic; + } + + [HttpGet] + [HttpPost] + public IActionResult Login(LoginModel model) + { + var errors = new List(); + if (HttpContext.Request.Method == "POST") + { + var user = _userLogic.ReadElement(new UserSearchModel { Email = model.Email, Password = model.Password }); + if (user == null) + { + errors.Add("Неверные логин или пароль"); + } + else if (user.Role != UserRole.Исполнитель) + { + errors.Add("Пользователь имеет неразрешенную роль"); + } + if (errors.Count > 0) + { + model = new LoginModel + { + Errors = errors + }; + return View(model); + } + LoginManager.LogginedUser = user; + return RedirectToAction("", "Home"); + } + else + { + model = new(); + return View(model); + } + } + + [HttpGet] + [HttpPost] + public IActionResult Register(RegisterModel model) + { + var errors = new List(); + if (HttpContext.Request.Method == "POST") + { + if (_userLogic.ReadElement(new UserSearchModel { Email = model.Email }) != null) + { + errors.Add("Пользователь с таким Email уже есть"); + } + if (model.Password != model.ConfirmPassword) + { + errors.Add("Пароли не совпадают"); + } + if (errors.Count > 0) + { + model.Errors = errors; + model.Password = string.Empty; + model.ConfirmPassword = string.Empty; + return View(model); + } + var user = new UserBindingModel + { + FIO = model.FIO, + Email = model.Email, + Password = model.Password, + Role = UserRole.Исполнитель + }; + _userLogic.Create(user); + return RedirectToAction("Login"); + } + else + { + return View(model); + } + } + + [HttpPost] + public IActionResult Logout() + { + LoginManager.LogginedUser = null; + return RedirectToAction("Login"); + } + + [HttpGet] + [HttpPost] + public IActionResult Privacy(UserPrivacyModel model) + { + var currentUser = LoginManager.LogginedUser; + if (currentUser == null) + { + return RedirectToAction("Login"); + } + if (HttpContext.Request.Method == "POST") + { + var errors = new List(); + var checkedUser = _userLogic.ReadElement(new UserSearchModel { Email = model.Email }); + if (checkedUser != null && checkedUser.Id != LoginManager.LogginedUser.Id) + { + errors.Add("Пользователь с таким Email уже есть"); + } + if (model.Password != model.ConfirmPassword) + { + errors.Add("Пароли не совпадают"); + } + if (errors.Count > 0) + { + model.Errors = errors; + model.Password = string.Empty; + model.ConfirmPassword = string.Empty; + return View(model); + } + var user = new UserBindingModel + { + Id = currentUser.Id, + FIO = model.FIO, + Email = model.Email, + Password = model.Password.IsNullOrEmpty() ? LoginManager.LogginedUser.Password : model.Password, + }; + _userLogic.Update(user); + LoginManager.LogginedUser = _userLogic.ReadElement(new UserSearchModel { Id = model.Id }); + return RedirectToAction("Privacy"); + } + else + { + model = new() + { + Id = currentUser.Id, + FIO = currentUser.FIO, + Email = currentUser.Email, + Role = currentUser.Role + }; + return View(model); + } + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/LoginManager.cs b/Polyclinic/PolyclinicWebAppImplementer/LoginManager.cs new file mode 100644 index 0000000..7b6a301 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/LoginManager.cs @@ -0,0 +1,9 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer +{ + public static class LoginManager + { + public static UserViewModel? LogginedUser { get; set; } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/CourseFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/CourseFormModel.cs new file mode 100644 index 0000000..6938690 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/CourseFormModel.cs @@ -0,0 +1,10 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer.Models +{ + public class CourseFormModel + { + public CourseViewModel? CourseViewModel { get; set; } + public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs new file mode 100644 index 0000000..41d5df8 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/DiagnosesByPeriodFormModel.cs @@ -0,0 +1,18 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicContracts.ViewModels; +using System.ComponentModel; + +namespace PolyclinicWebAppImplementer.Models +{ + public class DiagnosesByPeriodFormModel + { + [DisplayName("Начало периода")] + public DateTime? DateStart { get; set; } + [DisplayName("Конец периода")] + public DateTime? DateEnd { get; set; } + public ReportType ReportType { get; set; } + public ReportDiagnosesByPeriodViewModel? Report { get; set; } + public string? Error { get; set; } + public string? Message { get; set; } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/LoginModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/LoginModel.cs new file mode 100644 index 0000000..268f137 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/LoginModel.cs @@ -0,0 +1,9 @@ +namespace PolyclinicWebAppImplementer.Models +{ + public class LoginModel + { + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public List Errors { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs new file mode 100644 index 0000000..fe0a13f --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/MedicamentsByDiagnosesFormModel.cs @@ -0,0 +1,13 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer.Models +{ + public class MedicamentsByDiagnosesFormModel + { + public string FileName { get; set; } + public ReportType ReportType { get; set; } + public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new(); + public int[]? SelectedDiagnoses { get; set; } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/RecipeLinkCourseModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/RecipeLinkCourseModel.cs new file mode 100644 index 0000000..b36d039 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/RecipeLinkCourseModel.cs @@ -0,0 +1,15 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer.Models +{ + public class RecipeLinkCourseModel + { + public List Recipes { get; set; } = new(); + public List Courses { get; set; } = new(); + public int? RecipeId { get; set; } + public int? CourseId { get; set; } + public RecipeViewModel? Recipe { get; set; } + public CourseViewModel? Course { get; set; } + public List<(RecipeViewModel Recipe, CourseViewModel Course)> LinkedRecipes { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs new file mode 100644 index 0000000..888e7b3 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/RegisterModel.cs @@ -0,0 +1,17 @@ +using System.ComponentModel; + +namespace PolyclinicWebAppImplementer.Models +{ + public class RegisterModel + { + [DisplayName("ФИО")] + public string FIO { get; set; } = string.Empty; + [DisplayName("Email")] + public string Email { get; set; } = string.Empty; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + [DisplayName("Повторите пароль")] + public string ConfirmPassword { get; set; } = string.Empty; + public List Errors { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs new file mode 100644 index 0000000..3364b2c --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs @@ -0,0 +1,10 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer.Models +{ + public class SymptomFormModel + { + public SymptomViewModel? SymptomViewModel { get; set; } + public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new(); + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/UserPrivacyModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/UserPrivacyModel.cs new file mode 100644 index 0000000..5fe99e2 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/UserPrivacyModel.cs @@ -0,0 +1,12 @@ +using PolyclinicDataModels.Enums; +using System.ComponentModel; + +namespace PolyclinicWebAppImplementer.Models +{ + public class UserPrivacyModel : RegisterModel + { + public int Id { get; set; } + [DisplayName("Роль")] + public UserRole Role { get; set; } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/PolyclinicWebAppImplementer.csproj b/Polyclinic/PolyclinicWebAppImplementer/PolyclinicWebAppImplementer.csproj index d723787..bc275c0 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/PolyclinicWebAppImplementer.csproj +++ b/Polyclinic/PolyclinicWebAppImplementer/PolyclinicWebAppImplementer.csproj @@ -1,56 +1,56 @@ - + - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - + + + Always + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + - - - + + + - - <_ContentIncludedByDefault Remove="Views\Home\Courses.cshtml" /> - <_ContentIncludedByDefault Remove="Views\Home\Diagnoses.cshtml" /> - + + <_ContentIncludedByDefault Remove="Views\Home\Courses.cshtml" /> + - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + diff --git a/Polyclinic/PolyclinicWebAppImplementer/Program.cs b/Polyclinic/PolyclinicWebAppImplementer/Program.cs index 0727468..b267cac 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Program.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Program.cs @@ -1,7 +1,42 @@ +using PolyclinicBusinessLogic.BusinessLogics; +using PolyclinicBusinessLogic.OfficePackage.AbstractImplementerReports; +using PolyclinicBusinessLogic.OfficePackage.Implements.ImplementerReports; +using PolyclinicContracts.BusinessLogicsContracts; +using PolyclinicContracts.StoragesContracts; +using PolyclinicDatabaseImplement.Implements; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); diff --git a/Polyclinic/PolyclinicWebAppImplementer/RestrictionEnum.cs b/Polyclinic/PolyclinicWebAppImplementer/RestrictionEnum.cs new file mode 100644 index 0000000..bfc2b92 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/RestrictionEnum.cs @@ -0,0 +1,9 @@ +namespace PolyclinicWebAppImplementer +{ + public enum PageVisible + { + AllowAnyBody = 0, + AllowOnlyAuthorized = 1, + AllowOnlyNotAuthorized = 2, + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs b/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs index 18c4257..71e2772 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs @@ -2,21 +2,18 @@ { public static class SiteMenuItems { - public static (string Url, string Title) Index = ("", "Главная"); - public static (string Url, string Title) Courses = ("Courses", "Курсы"); - public static (string Url, string Title) Diagnoses = ("Diagnoses", "Болезни"); - public static (string Url, string Title) Symptomes = ("Symptomes", "Симптомы"); - public static (string Url, string Title) Symptom = ("Symptom", "Симптом"); - public static (string Url, string Title) Diagnose = ("Diagnose", "Болезнь"); - public static (string Url, string Title) Course = ("Course", "Курс"); - public static (string Url, string Title) Login = ("Login", "Вход"); - public static (string Url, string Title) Register = ("Register", "Регистрация"); - public static (string Url, string Title) Privacy = ("Privacy", "Политика приватности"); - public static (string Url, string Title) AddRecipeToCourse = ("AddRecipeToCourse", "Привязка рецепта"); - public static (string Url, string Title) MedicamentsByDiagnoses = ("MedicamentsByDiagnoses", "Лекарства по болезням"); - public static (string Url, string Title) DiagnosesReport = ("DiagnosesReport", "Отчет по болезням"); + public static (string Controller, string Action, string Title, PageVisible Visible) Index = ("Home", "", "Главная", PageVisible.AllowAnyBody); + public static (string Controller, string Action, string Title, PageVisible Visible) Courses = ("Courses", "", "Курсы", PageVisible.AllowOnlyAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) Diagnoses = ("Diagnoses", "", "Болезни", PageVisible.AllowOnlyAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) Symptomes = ("Symptomes", "", "Симптомы", PageVisible.AllowOnlyAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) Login = ("User", "Login", "Вход", PageVisible.AllowOnlyNotAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) Register = ("User", "Register", "Регистрация", PageVisible.AllowOnlyNotAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) Privacy = ("User", "Privacy", "Личный кабинет", PageVisible.AllowOnlyAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) AddRecipeToCourse = ("Recipe", "LinkCourse", "Привязка рецептов", PageVisible.AllowOnlyAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) MedicamentsByDiagnoses = ("Reports", "MedicamentsByDiagnoses", "Отчет по лекарствам", PageVisible.AllowOnlyAuthorized); + public static (string Controller, string Action, string Title, PageVisible Visible) DiagnosesReport = ("Reports", "DiagnosesByPeriod", "Отчет по болезням", PageVisible.AllowOnlyAuthorized); - public static List<(string Url, string Title)> MenuItemsOrder = new List<(string Url, string Title)> + public static List<(string Controller, string Action, string Title, PageVisible Visible)> MenuItemsOrder = new List<(string Controller, string Action, string Title, PageVisible Visible)> { Index, Courses, Diagnoses, Symptomes, Login, Register, AddRecipeToCourse, MedicamentsByDiagnoses, DiagnosesReport }; diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Courses/CourseForm.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Courses/CourseForm.cshtml new file mode 100644 index 0000000..fabf0b0 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Courses/CourseForm.cshtml @@ -0,0 +1,54 @@ +@model CourseFormModel +

@ViewData["Title"]

+
+
+
Количество дней:
+
+
+
+
Количество препарата в день:
+
+
+
+
Коментарий:
+
+
+
+
    + @foreach (var item in Model.Diagnoses) + { + @if (LoginManager.LogginedUser.Id != item.Diagnose.UserId) + { + @if (item.IsChecked) + { + + } + else + { + + } + continue; + } +
  1. + @if (item.IsChecked) + { + + } + else + { + + } + +
  2. + } +
+
+
+
+ + @Html.ActionLink("Отмена", "", "Courses", null, new { @class = "btn btn-danger" }) +
+
+
diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Courses/CoursesList.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Courses/CoursesList.cshtml new file mode 100644 index 0000000..068a5c4 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Courses/CoursesList.cshtml @@ -0,0 +1,48 @@ +@using PolyclinicContracts.ViewModels +@model List +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.Courses; +} +
+ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
НомерКоличество днейКоличество препаратов в деньКомментарий
@item.Id@item.DaysCount@item.PillsPerDay@item.Comment +
+ +
+ + + + + +
+
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml new file mode 100644 index 0000000..e786401 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml @@ -0,0 +1,30 @@ +@using PolyclinicContracts.ViewModels +@model DiagnoseViewModel +

@ViewData["Title"]

+
+ +
+
Название:
+
+
+
+
Коментарий:
+
+
+
+
Начало:
+
+
+
+
Конец:
+
+
+
+
+ + @Html.ActionLink("Отмена", "", "Diagnoses", null, new { @class = "btn btn-danger" }) +
+
+
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs new file mode 100644 index 0000000..2956788 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PolyclinicWebAppImplementer.Views.Diagnoses +{ + public class DiagnoseFormModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml new file mode 100644 index 0000000..586dcf7 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml @@ -0,0 +1,50 @@ +@using PolyclinicContracts.ViewModels +@model List +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.Diagnoses; +} +
+ + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
НомерНазваниеНачалоКонецКомментарий
@item.Id@item.Name@item.DateStartDiagnose.ToShortDateString()@item.DateStopDiagnose?.ToShortDateString()@item.Comment +
+ +
+ + + + + +
+
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml.cs b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml.cs new file mode 100644 index 0000000..12bf410 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnosesList.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace PolyclinicWebAppImplementer.Views.Diagnoses +{ + public class IndexModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/AddRecipeToCourse.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/AddRecipeToCourse.cshtml deleted file mode 100644 index db4c20e..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/AddRecipeToCourse.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.AddRecipeToCourse; -} -

Привязка рецепта к курсу

-
-
-
-
Рецепт
- -
-
-
-
-
Курс
- -
-
-
-
- -
-
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Course.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Course.cshtml deleted file mode 100644 index 2e3efe0..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Course.cshtml +++ /dev/null @@ -1,60 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Course; -} -

Новый курс лечения

-
-
-
Количество дней:
-
-
-
-
Количество препарата в день:
-
-
-
-
Коментарий:
-
-
-
-
-
Болезни
- - -
-
-
-
    - @{ - for (int i = 0; i < 7; i++) - { -
  1. - - - - - - Выбранная болезнь -
  2. - } - } -
-
-
-
- - @Html.ActionLink("Отмена", "Courses", "Home", null, new { @class = "btn btn-danger" }) -
-
-
diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Courses.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Courses.cshtml deleted file mode 100644 index f2656b6..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Courses.cshtml +++ /dev/null @@ -1,47 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Courses; -} -
- - - - - - - - - - - - - @{ - int count = 20; - for (int i = 0; i < count; i++) - { - - - - - - - - } - } - -
НомерКоличество днейКоличество препаратов в деньКомментарий
@i123Очень хороший курс приема - - - - - - - - - - -
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Diagnose.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Diagnose.cshtml deleted file mode 100644 index 7a78422..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Diagnose.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Diagnose; -} -

Новая болезнь

-
-
-
Название:
-
-
-
-
Коментарий:
-
-
-
-
Начало:
-
-
-
-
Конец:
-
-
-
-
- - @Html.ActionLink("Отмена", "Diagnoses", "Home", null, new { @class = "btn btn-danger" }) -
-
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Diagnoses.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Diagnoses.cshtml deleted file mode 100644 index b72fdad..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Diagnoses.cshtml +++ /dev/null @@ -1,49 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Diagnoses; -} -
- - - - - - - - - - - - - - @{ - int count = 10; - for (int i = 0; i < count; i++) - { - - - - - - - - - } - } - -
НомерНазваниеНачалоКонецКомментарий
@iсиндром Мюнхгаузена12.04.202417.05.2024заболевание, при котором человек постоянно симулирует или преувеличивает симптомы болезней, чтобы привлечь внимание окружающих. - - - - - - - - - - -
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/DiagnosesReport.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/DiagnosesReport.cshtml deleted file mode 100644 index 707a733..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/DiagnosesReport.cshtml +++ /dev/null @@ -1,113 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.DiagnosesReport; -} -
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
- -
- @if (ViewData.ContainsKey("ShowReport")) - { - - - - - - - - - - - - - - @{ - for (int i = 0; i < 5; i++) - { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - } - } - -
Отчет по болезням с 01.01.2023 по 31.12.2023
- # - - Болезнь - - Дата начала - - Дата завершения - - Курсы - - Симптомы -
- @(i + 1) - - Лихорадка Эбола - - 16.03.2023 - - 20.10.2023 - - Курс приема топорина® - - Лихорадка -
Курс приема четвертина®Покрасения
Курс приема колесовина®Головокружение
Курс электрофореза
- } -
diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/MedicamentsByDiagnoses.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/MedicamentsByDiagnoses.cshtml deleted file mode 100644 index 5c5b465..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/MedicamentsByDiagnoses.cshtml +++ /dev/null @@ -1,40 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.MedicamentsByDiagnoses; -} -

Список лекарств по болезням

-
-
Выберите болезни
-
-
    - @{ - for(int i = 0; i < 10; i++) - { -
  • - - -
  • - } - } -
-
-
-
Укажите формат файла
-
-
- - -
-
- - -
-
-
-
-
Укажите название файла
- -
- -
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Privacy.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Privacy.cshtml deleted file mode 100644 index ce65fcc..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Privacy.cshtml +++ /dev/null @@ -1,6 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Privacy; -} -

Политика приватности

- -

Здесь нет никакой приватности

diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Symptom.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Symptom.cshtml deleted file mode 100644 index 52689f3..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Symptom.cshtml +++ /dev/null @@ -1,58 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Symptom; -} -

Новый симптом

-
-
-
Название:
-
-
-
-
Коментарий:
-
-
-
-
-
Болезни
- - -
-
-
-
    - @{ - count = 7; - for (int i = 0; i < count; i++) - { -
  1. - - - - - - Выбранная болезнь -
  2. - } - } -
-
-
-
- - @Html.ActionLink("Отмена", "Courses", "Home", null, new { @class = "btn btn-danger" }) -
-
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Symptomes.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Symptomes.cshtml deleted file mode 100644 index d899370..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Symptomes.cshtml +++ /dev/null @@ -1,45 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.Symptomes; -} -
- - - - - - - - - - - - @{ - int count = 10; - for (int i = 0; i < count; i++) - { - - - - - - - } - } - -
НомерНазваниеКомментарий
@iвраньепациент постоянно врёт о своих приключениях - - - - - - - - - - -
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Recipe/LinkCourse.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Recipe/LinkCourse.cshtml new file mode 100644 index 0000000..ccfbe9a --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Recipe/LinkCourse.cshtml @@ -0,0 +1,67 @@ +@model RecipeLinkCourseModel +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.AddRecipeToCourse; +} +

Привязка рецепта к курсу

+
+
+
+
+
Рецепт
+ +
+
+
+
+
Курс
+ +
+
+
+
+ +
+
+
+
+

Привязанные рецепты

+ + + + + + + @foreach (var item in Model.LinkedRecipes) + { + + + + + + } +
РецептКурс
#@item.Recipe.Id @item.Recipe.Comment#@item.Course.Id @item.Course.Comment +
+ +
+
+
+
diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml new file mode 100644 index 0000000..24b9e10 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/DiagnosesByPeriod.cshtml @@ -0,0 +1,123 @@ +@using PolyclinicBusinessLogic.OfficePackage.HelperEnums +@model DiagnosesByPeriodFormModel +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.DiagnosesReport; +} +
+ @if (Model.Error != null) + { + + } + @if (Model.Message != null) + { + + } +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ +
+ @if (Model.Report != null) + { + + @if (@Model.DateStart != null || @Model.DateEnd != null) + { + @if (Model.DateStart == null) + { + + } + else if (Model.DateEnd == null) + { + + } + else + { + + } + } + else + { + + } + + + + + + + + + + + + @{ + int i = 0; + } + @foreach (var item in Model.Report.DiagnosesData) + { + i++; + + + + + + + + + } + +
Отчет по болезням по @Model.DateEnd?.ToShortDateString()Отчет по болезням с @Model.DateStart?.ToShortDateString()Отчет по болезням с @Model.DateStart?.ToShortDateString() по @Model.DateEnd?.ToShortDateString()Отчет по болезням за весь период
+ # + + Болезнь + + Дата начала + + Дата завершения + + Симптомы + + Курсы +
+ @i + + @item.Diagnose.Name + + @item.Diagnose.DateStartDiagnose.ToShortDateString() + + @item.Diagnose.DateStopDiagnose?.ToShortDateString() + + @foreach (var symptom in item.Symptomes) + { +

@symptom.Name

+ } +
+ @foreach (var course in item.Courses) + { +

курс #@course.Id @course.Comment

+ } +
+ } +
diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml new file mode 100644 index 0000000..b98b9cb --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Reports/MedicamentsByDiagnoses.cshtml @@ -0,0 +1,47 @@ +@using PolyclinicBusinessLogic.OfficePackage.HelperEnums +@model MedicamentsByDiagnosesFormModel +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.MedicamentsByDiagnoses; +} +

Список лекарств по болезням

+
+
Выберите болезни
+
+
    + @foreach (var item in Model.Diagnoses) + { +
  • + @if (item.IsChecked) + { + + } + else + { + + } + +
  • + } +
+
+
+
Укажите формат файла
+
+
+ + +
+
+ + +
+
+
+
+
Укажите название файла
+ +
+ +
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Shared/_Layout.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Shared/_Layout.cshtml index 8a92d6d..77254d4 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Shared/_Layout.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Shared/_Layout.cshtml @@ -3,16 +3,16 @@ - - @if (ViewData.ContainsKey("SelectedSiteMenuItem")) - { - @ViewBag.SelectedSiteMenuItem.Item2 - } - else if (ViewData.ContainsKey("Title")) - { + @if (ViewData.ContainsKey("Title")) + { + <title> @ViewData["Title"] - } - + + } + else + { + Кабинет исполнителя + } @@ -32,19 +32,33 @@ + @if (LoginManager.LogginedUser != null) + { +
+ @Html.RouteLink(LoginManager.LogginedUser.FIO, new { controller = "User", action = "Privacy" }, new { @title = "Личный кабинет" }) +
+ +
+
+ } @@ -57,8 +71,7 @@ diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml new file mode 100644 index 0000000..7a2d556 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml @@ -0,0 +1,51 @@ +@model SymptomFormModel + +

@ViewData["Title"]

+
+
+
Название:
+
+
+
+
Коментарий:
+
+
+
+
    + @foreach (var item in Model.Diagnoses) + { + @if (LoginManager.LogginedUser.Id != item.Diagnose.UserId) + { + @if (item.IsChecked) + { + + } + else + { + + } + continue; + } +
  1. + @if (item.IsChecked) + { + + } + else + { + + } + +
  2. + } +
+
+
+
+ + @Html.ActionLink("Отмена", "", "Symptomes", null, new { @class = "btn btn-danger" }) +
+
+
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomesList.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomesList.cshtml new file mode 100644 index 0000000..a6614cf --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomesList.cshtml @@ -0,0 +1,46 @@ +@using PolyclinicContracts.ViewModels +@model List +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.Symptomes; +} +
+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
НомерНазваниеКомментарий
@item.Id@item.Name@item.Comment +
+ +
+ + + + + +
+
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Login.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/User/Login.cshtml similarity index 61% rename from Polyclinic/PolyclinicWebAppImplementer/Views/Home/Login.cshtml rename to Polyclinic/PolyclinicWebAppImplementer/Views/User/Login.cshtml index 4855fc6..a61a489 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Login.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/User/Login.cshtml @@ -1,20 +1,27 @@ -@{ +@model LoginModel +@{ ViewBag.SelectedSiteMenuItem = SiteMenuItems.Login; }

Вход

+ @foreach (var item in Model.Errors) + { + + }
- +
- +
+
+ diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Register.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/User/Register.cshtml similarity index 50% rename from Polyclinic/PolyclinicWebAppImplementer/Views/Home/Register.cshtml rename to Polyclinic/PolyclinicWebAppImplementer/Views/User/Register.cshtml index 0b15b41..8f7eed9 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/Register.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/User/Register.cshtml @@ -1,26 +1,39 @@ -@{ +@model RegisterModel +@{ ViewBag.SelectedSiteMenuItem = SiteMenuItems.Register; }
-

Регистрация

+

Регистрация исполнителя

+ @foreach (var item in Model.Errors) + { + + }
- +
- +
- + +
+
+ +
+ + + + + + } } diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Privacy.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Privacy.cshtml index af4fb19..f3c4049 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Privacy.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Privacy.cshtml @@ -1,6 +1,38 @@ -@{ - ViewData["Title"] = "Privacy Policy"; +@model UserPrivacyModel +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.Privacy; } -

@ViewData["Title"]

+

Личный кабинет

+@foreach (var item in Model.Errors) +{ + +} +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
-

Use this page to detail your site's privacy policy.

diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Procedures.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Procedures.cshtml index 31c7bb1..e21072c 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Procedures.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Procedures.cshtml @@ -7,72 +7,62 @@

Процедуры

-
+
@{ // if (Model == null) // { //

Авторизируйтесь

// return; // } -

- Создать процедуру -

+ - - - - - - - + + + + + + + - - - - - - - + @foreach (var item in Model) + { + + + + + + + + + + } +
- Номер - - Название процедуры - - Дата начала процедуры - - Дата окончания процедуры - - Комментарий - - Редактировать - - Удалить - НомерНазвание процедурыДата начала процедурыДата окончания процедурыКомментарийРедактироватьУдалить
- 1 - - Массаж пяточек - - 12.04.2024 - - 17.04.2024 - - ммммммм - - - - - - - - - - - - -
@item.Id@item.Name@item.DateStartProcedure.ToShortDateString()@item.DateStopProcedure?.ToShortDateString()@item.Comment + + + + + + +
+ + +
+ +
} diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ProceduresReport.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ProceduresReport.cshtml index edf4ce9..f1c29f1 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ProceduresReport.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ProceduresReport.cshtml @@ -1,19 +1,17 @@ @using PolyclinicContracts.ViewModels +@model List @{ - ViewData["Title"] = "ProceduresReport"; + ViewData["Title"] = "Отчет по процедурам"; } +
- +
- +
@@ -28,75 +26,43 @@
- + - @if (ViewData.ContainsKey("ShowReport")) + + @if (Model != null && Model.Any()) { - + - - - - - - + + + + + + - @{ - for (int i = 0; i < 5; i++) + @foreach (var item in Model) + { + + + + + + + + + @foreach (var ms in item.MedicamentSymptom) { - - - - - - - - - - - - - - - - - - + + } } diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Recipes.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Recipes.cshtml index 18e94d8..aa79c03 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Recipes.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Recipes.cshtml @@ -1,8 +1,5 @@ @using PolyclinicContracts.ViewModels @model List -@{ - ViewData["Title"] = "Recipes"; -}

Рецепты

@@ -33,6 +30,9 @@
+ @@ -42,29 +42,35 @@ - - - - - + @foreach (var item in Model) + { + + + + + + + + + } +
Отчет по лекарствам с 01.01.2023 по 31.12.2023Отчет по процедурам
- # - - Процедура - - Дата начала - - Дата завершения - - Лекарства - - Симптомы - НомерПроцедураДата началаДата завершенияЛекарствоСимптом
@item.Id@item.ProcedureName@item.DateStartProcedure.ToShortDateString()@item.DateStopProcedure?.ToShortDateString()
- @(i + 1) - - Процедура мытья спины - - 16.03.2023 - - 20.10.2023 - - Амоксициллин® - - Лихорадка -
Активированный уголь®Покрасения
Аскорбиновая кислота®Головокружение@ms.medicamentName@ms.symptomName
Количество процедур + Номер курса + Редактировать
- 1 - - Это процедура для вашей спины - - 4 - - - - - - - - - - - - -
@item.Id@item.Comment@item.ProceduresCount@item.CourseId + + + + + + +
+ +
+ +
} diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Register.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Register.cshtml index 21c8dbb..0cd7f63 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Register.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/Register.cshtml @@ -1,26 +1,39 @@ -@{ +@model RegisterModel +@{ ViewBag.SelectedSiteMenuItem = SiteMenuItems.Register; } -
-
-

Регистрация

-
-
-