This commit is contained in:
Никита Потапов 2024-05-29 02:22:47 +04:00
commit a1bacf5b8f
12 changed files with 209 additions and 51 deletions

View File

@ -1,4 +1,6 @@
using PolyclinicContracts.BindingModels; using PolyclinicBusinessLogic.OfficePackage;
using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels; using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.StoragesContracts;
@ -15,35 +17,31 @@ namespace PolyclinicBusinessLogic.BusinessLogics
private readonly ICourseStorage courseStorage; private readonly ICourseStorage courseStorage;
private readonly ISymptomStorage symptomStorage; private readonly ISymptomStorage symptomStorage;
private readonly IRecipeStorage recipeStorage; private readonly IRecipeStorage recipeStorage;
private readonly AbstractSaveToWordCoursesByProcedures saveToWord;
public SuretorReportLogic(IProcedureStorage procedureStorage, IMedicamentStorage medicamentStorage, public SuretorReportLogic(IProcedureStorage procedureStorage, IMedicamentStorage medicamentStorage,
ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage) ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage, AbstractSaveToWordCoursesByProcedures saveToWord)
{ {
this.procedureStorage = procedureStorage; this.procedureStorage = procedureStorage;
this.medicamentStorage = medicamentStorage; this.medicamentStorage = medicamentStorage;
this.courseStorage = courseStorage; this.courseStorage = courseStorage;
this.symptomStorage = symptomStorage; this.symptomStorage = symptomStorage;
this.recipeStorage = recipeStorage; this.recipeStorage = recipeStorage;
this.saveToWord = saveToWord;
} }
public List<ReportCoursesByProcedureViewModel> GetProcedureCourses(ProcedureSearchModel model) public List<CourseViewModel> GetProcedureCourses(ProcedureSearchModel model)
{ {
var procedure = procedureStorage.GetElement(model); var procedure = procedureStorage.GetElement(model);
var courses = courseStorage.GetFullList(); var courses = courseStorage.GetFullList();
var recipes = recipeStorage.GetFullList(); var recipes = recipeStorage.GetFullList();
var list = new List<ReportCoursesByProcedureViewModel>(); var list = new List<CourseViewModel>();
var record = new ReportCoursesByProcedureViewModel
{
Name = procedure!.Name,
Courses = new List<(int countDays, int pillsPerDay, string comment)>()
};
using var context = new PolyclinicDatabase(); using var context = new PolyclinicDatabase();
var recipeProcedureId = context.RecipeProcedures var recipeProcedureId = context.RecipeProcedures
.Where(x => x.ProcedureId == model.Id).Select(x => x.RecipeId).ToList(); .Where(x => x.ProcedureId == model.Id).Select(x => x.RecipeId).ToList();
foreach (var recipe in recipes) foreach (var recipe in recipes)
{ {
foreach (var recipeId in recipeProcedureId) foreach (var recipeId in recipeProcedureId)
@ -54,13 +52,12 @@ namespace PolyclinicBusinessLogic.BusinessLogics
{ {
if(recipe.CourseId == course.Id) if(recipe.CourseId == course.Id)
{ {
record.Courses.Add((course.DaysCount, course.PillsPerDay, course.Comment)); list.Add(course);
} }
} }
} }
} }
} }
list.Add(record);
return list; return list;
} }
@ -103,9 +100,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void SaveCoursesByProcedureToWordFile(ReportBindingModel model) public void SaveCoursesByProcedureToWordFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode)
{ {
throw new NotImplementedException(); saveToWord.CreateDoc(new WordCoursesByProceduresInfo
{
FileName = model.FileName,
Title = "Курсы по процедурам",
Courses = GetProcedureCourses(procedureSearchMode)
});
} }
public void SaveProceduresToPdfFile(ReportBindingModel model) public void SaveProceduresToPdfFile(ReportBindingModel model)

View File

@ -6,6 +6,7 @@ namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Word
{ {
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public string ProcedureName { get; set; } = string.Empty;
public List<CourseViewModel> Courses { get; set; } = new(); public List<CourseViewModel> Courses { get; set; } = new();
} }
} }

View File

@ -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;
/// <summary>
/// Получение типа выравнивания
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
_ => JustificationValues.Left,
};
}
/// <summary>
/// Настройки страницы
/// </summary>
/// <returns></returns>
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
/// <summary>
/// Задание форматирования для абзаца
/// </summary>
/// <param name="paragraphProperties"></param>
/// <returns></returns>
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();
}
}
}

View File

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup> </ItemGroup>

View File

@ -15,7 +15,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts
/// Получение данных (списка) курсов по выбранным процедурам /// Получение данных (списка) курсов по выбранным процедурам
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
List<ReportCoursesByProcedureViewModel> GetProcedureCourses(ProcedureSearchModel model); List<CourseViewModel> GetProcedureCourses(ProcedureSearchModel model);
/// <summary> /// <summary>
/// Получение списка процедур /// Получение списка процедур
@ -28,7 +28,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts
/// Сохранение курсов по процедурам в файл-Word /// Сохранение курсов по процедурам в файл-Word
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
void SaveCoursesByProcedureToWordFile(ReportBindingModel model); void SaveCoursesByProcedureToWordFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode);
/// <summary> /// <summary>
/// Сохранение курсов по процедурам в файл-Excel /// Сохранение курсов по процедурам в файл-Excel

View File

@ -1,10 +1,4 @@
using System; namespace PolyclinicContracts.ViewModels
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PolyclinicContracts.ViewModels
{ {
public class ReportCoursesByProcedureViewModel public class ReportCoursesByProcedureViewModel
{ {

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PolyclinicBusinessLogic.BusinessLogics; using PolyclinicBusinessLogic.BusinessLogics;
using PolyclinicBusinessLogic.OfficePackage;
using PolyclinicContracts.BindingModels; using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels; using PolyclinicContracts.SearchModels;
@ -18,13 +19,15 @@ namespace PolyclinicWebAppSuretor.Controllers
private readonly IRecipeLogic _recipeLogic; private readonly IRecipeLogic _recipeLogic;
private readonly ISymptomLogic _symptomLogic; private readonly ISymptomLogic _symptomLogic;
private readonly ICourseLogic _courseLogic; private readonly ICourseLogic _courseLogic;
private readonly ISuretorReportLogic _suretorReportLogic;
public HomeController(ILogger<HomeController> logger, public HomeController(ILogger<HomeController> logger,
IProcedureLogic procedureLogic, IProcedureLogic procedureLogic,
IMedicamentLogic medicamentLogic, IMedicamentLogic medicamentLogic,
IRecipeLogic recipeLogic, IRecipeLogic recipeLogic,
ISymptomLogic symptomLogic, ISymptomLogic symptomLogic,
ICourseLogic courseLogic) ICourseLogic courseLogic,
ISuretorReportLogic suretorReportLogic)
{ {
_logger = logger; _logger = logger;
_procedureLogic = procedureLogic; _procedureLogic = procedureLogic;
@ -32,6 +35,7 @@ namespace PolyclinicWebAppSuretor.Controllers
_recipeLogic = recipeLogic; _recipeLogic = recipeLogic;
_symptomLogic = symptomLogic; _symptomLogic = symptomLogic;
_courseLogic = courseLogic; _courseLogic = courseLogic;
_suretorReportLogic = suretorReportLogic;
} }
public IActionResult Index() public IActionResult Index()
@ -276,11 +280,7 @@ namespace PolyclinicWebAppSuretor.Controllers
return RedirectToAction("Procedures"); return RedirectToAction("Procedures");
} }
public IActionResult ListCoursesByProcedures()
{
List<ProcedureViewModel> procedures = _procedureLogic.ReadList(null);
return View(procedures);
}
public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model) public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model)
{ {
@ -292,6 +292,43 @@ namespace PolyclinicWebAppSuretor.Controllers
return View(model); return View(model);
} }
public IActionResult ListCoursesByProcedures()
{
ViewBag.Procedures = _procedureLogic.ReadList(null);
return View();
}
[HttpPost]
public IActionResult CreateWordFile(int procedureId, string fileName, string fileFormat)
{
var procedure = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId});
ViewBag.Procedures = procedure;
fileName = fileName + $".{fileFormat}";
if(procedure == null)
{
return NotFound("Ïðîöåäóðà íå íàéäåíà");
}
var report = new ReportBindingModel
{
FileName = fileName,
};
var procedureSearch = new ProcedureSearchModel { Id = procedureId};
if (fileFormat == "docx")
{
_suretorReportLogic.SaveCoursesByProcedureToWordFile(report,procedureSearch);
}
var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
string mimeType = fileFormat.ToLower() == "docx" ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
return File(fileBytes, mimeType, fileName);
}
[HttpGet] [HttpGet]
[HttpPost] [HttpPost]
public IActionResult ProceduresReport() public IActionResult ProceduresReport()

View File

@ -1,4 +1,6 @@
using PolyclinicBusinessLogic.BusinessLogics; using PolyclinicBusinessLogic.BusinessLogics;
using PolyclinicBusinessLogic.OfficePackage;
using PolyclinicBusinessLogic.OfficePackage.Implements;
using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.StoragesContracts;
using PolyclinicDatabaseImplement.Implements; using PolyclinicDatabaseImplement.Implements;
@ -17,6 +19,9 @@ builder.Services.AddTransient<IProcedureStorage, ProcedureStorage>();
builder.Services.AddTransient<IMedicamentStorage, MedicamentStorage>(); builder.Services.AddTransient<IMedicamentStorage, MedicamentStorage>();
builder.Services.AddTransient<IRecipeStorage, RecipeStorage>(); builder.Services.AddTransient<IRecipeStorage, RecipeStorage>();
builder.Services.AddTransient<AbstractSaveToWordCoursesByProcedures, SaveToWordCoursesByProcedure>();
builder.Services.AddTransient<ISuretorReportLogic, SuretorReportLogic>();
builder.Services.AddTransient<IDiagnoseLogic, DiagnoseLogic>(); builder.Services.AddTransient<IDiagnoseLogic, DiagnoseLogic>();
builder.Services.AddTransient<ICourseLogic, CourseLogic>(); builder.Services.AddTransient<ICourseLogic, CourseLogic>();
builder.Services.AddTransient<ISymptomLogic, SymptomLogic>(); builder.Services.AddTransient<ISymptomLogic, SymptomLogic>();

View File

@ -1,5 +1,5 @@
@using PolyclinicContracts.ViewModels @using PolyclinicContracts.ViewModels
@model List<ProcedureViewModel> @model ProcedureViewModel
@{ @{
ViewData["Title"] = "ListCoursesByProcedures"; ViewData["Title"] = "ListCoursesByProcedures";
} }
@ -13,19 +13,15 @@
<p style="font-size: 3vh"> <p style="font-size: 3vh">
Выберите процедуру/ы из списка Выберите процедуру/ы из списка
</p> </p>
<div class="list-procedures list-group overflow-auto">
<ul> <select id="procedureId" name="procedureId" style="width: 45vh">
@{ <option value="">Выберите процедуру</option>
foreach (var item in Model) @foreach (var procedure in ViewBag.Procedures)
{ {
<li class="d-flex mb-2"> <option value="@procedure.Id">@procedure.Name</option>
<input class="me-2" name="procedure-@item.Id" type="checkbox" id="procedure-@item.Id" />
<label for="procedure-@item.Id">@item.Name</label>
</li>
} }
} </select>
</ul>
</div>
</div> </div>
<div class="d-flex flex-column mb-5 mt-5 justify-content-center align-items-center"> <div class="d-flex flex-column mb-5 mt-5 justify-content-center align-items-center">
@ -34,7 +30,7 @@
</p> </p>
<div class="d-flex flex-row align-content-center mb-3" style="font-size: 3vh"> <div class="d-flex flex-row align-content-center mb-3" style="font-size: 3vh">
<input type="radio" value="docx" class="radio-docx me-1" name="fileFormat" /> <input type="radio" value="docx" class="radio-docx me-1" name="fileFormat" checked/>
<label class="me-5">docx</label> <label class="me-5">docx</label>
<input type="radio" value="xlsx" class="radio-xlsx me-1" name="fileFormat" /> <input type="radio" value="xlsx" class="radio-xlsx me-1" name="fileFormat" />
<label>xlsx</label> <label>xlsx</label>
@ -44,10 +40,10 @@
Как назовем файл? Как назовем файл?
</p> </p>
<input type="text" placeholder="Отчет по курсам" /> <input type="text" name="fileName" placeholder="Отчет по курсам" required />
<div class="button-save-list-courses mt-5"> <div class="button-save-list-courses mt-5">
<input type="submit" value="Сохранить" class="button-save-list-courses btn" asp-action="Index" /> <input type="submit" value="Сохранить" class="button-save-list-courses btn" asp-action="CreateWordFile" />
</div> </div>
</div> </div>
</form> </form>

Binary file not shown.

Binary file not shown.

Binary file not shown.