using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Shared; using BMA.EHR.Application.Repositories.Reports; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Swashbuckle.AspNetCore.Annotations; using DocumentFormat.OpenXml.Drawing; using Telerik.Reporting; using Telerik.Reporting.Processing; using System.IO; namespace BMA.EHR.Report.Service.Controllers { [Route("api/v{version:apiVersion}/report/deceased")] [ApiVersion("2.0")] [ApiController] [Produces("application/json")] [Authorize] [SwaggerTag("API รายงานบันทึกเวียนแจ้งการถึงแก่กรรม")] public class DeceasedReportController : BaseController { #region " Fields " private readonly IWebHostEnvironment _hostingEnvironment; private readonly IConfiguration _configuration; private readonly GenericReportGenerator _reportGenerator; #endregion #region " Constuctor and Destructor " public DeceasedReportController(IWebHostEnvironment hostingEnvironment, IConfiguration configuration, GenericReportGenerator reportGenerator) { _hostingEnvironment = hostingEnvironment; _configuration = configuration; _reportGenerator = reportGenerator; } #endregion #region " Methods " #region 36-บันทึกเวียนแจ้งการถึงแก่กรรม /// /// 36-บันทึกเวียนแจ้งการถึงแก่กรรม /// /// id /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("36/{exportType}/{id}")] public IActionResult GetDeceasedConvertReportAsync(Guid id, string exportType = "pdf") { try { var mimeType = ""; switch (exportType.Trim().ToLower()) { case "pdf": mimeType = "application/pdf"; break; case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; } var rptFile = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"36-บันทึกเวียนแจ้งการถึงแก่กรรม.trdp"); var contentData = _reportGenerator.GenerateReport(rptFile, exportType); return File(contentData, mimeType, $"deceased.{exportType.Trim().ToLower()}"); } catch { throw; } } #endregion #endregion } }