diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index d3ccf953..d8914f35 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -312,6 +312,47 @@ namespace BMA.EHR.Application.Repositories.Commands } } + #region " Documents " + + public async Task> GetCommandDocumentAsync(Guid id) + { + try + { + var docs = await _dbContext.Set() + .Include(x => x.Command) + .Include(x => x.Document) + .Where(x => x.Command.Id == id) + .ToListAsync(); + + return docs; + } + catch + { + throw; + } + } + + #endregion + + public async Task UpdateCommandInfo(Guid id, string orderNo, string orderYear, DateTime signDate) + { + try + { + var command = await _dbContext.Set().FirstOrDefaultAsync(x => x.Id == id); + if(command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + command.CommandExcecuteDate = signDate; + command.CommandNo = orderNo; + command.CommandYear = orderYear; + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + #endregion } diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 50145276..d6ef6ed6 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -1,5 +1,4 @@ -using Amazon.S3.Model.Internal.MarshallTransformations; -using BMA.EHR.Application.Repositories; +using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Command.Service.Requests; using BMA.EHR.Domain.Common; @@ -9,9 +8,8 @@ using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore.Infrastructure; using Swashbuckle.AspNetCore.Annotations; using System.Security.Claims; @@ -469,7 +467,6 @@ namespace BMA.EHR.Command.Service.Controllers /// /// PM7-32 : บันทึกช่องทางการส่งสำเนาคำสั่ง /// - /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ @@ -484,7 +481,7 @@ namespace BMA.EHR.Command.Service.Controllers { // transform var deploys = new List(); - foreach(var p in req) + foreach (var p in req) { var updated = await _repository.GetCommandDeploymentById(p.PersonalId); updated!.IsSendInbox = p.InboxChannel; @@ -527,6 +524,75 @@ namespace BMA.EHR.Command.Service.Controllers } } + #region " Documents " + + /// + /// PM7-34 : ข้อมูลรายละเอียดคำสั่งและแนบท้าย + /// + /// Record Id ของคำสั่ง + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("attachment/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetCommandAttatchmentAsync(Guid orderId) + { + try + { + var command = await _repository.GetByIdAsync(orderId); + if(command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var documents = await _repository.GetCommandDocumentAsync(orderId); + var cover = documents.Where(x => x.Category.Trim().ToLower() == "cover").FirstOrDefault(); + var attach = documents.Where(x => x.Category.Trim().ToLower() == "attachment").FirstOrDefault(); + + var result = new + { + orderNo=command.CommandNo, + orderYear=command.CommandYear, + signDate = command.CommandExcecuteDate, + orderFileUrl = cover == null ? null : _documentService.ImagesPath(cover.Document.ObjectRefId), + attachmentFileUrl = attach == null ? null : _documentService.ImagesPath(attach.Document.ObjectRefId), + }; + + return Success(result); + } + catch + { + throw; + } + } + + #endregion + + /// + /// PM7-37 : บันทึกข้อมูลคำสั่งและแนบท้าย + /// + /// Record Id ของคำสั่ง + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("attachment/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> UpdateCommandExecuteAsync(Guid orderId, [FromBody] UpdateCommandExecuteRequest req) + { + try + { + await _repository.UpdateCommandInfo(orderId, req.OrderNo, req.OrderYear, req.SignDate); + return Success(); + } + catch + { + throw; + } + } #endregion } diff --git a/BMA.EHR.Command.Service/Requests/UpdateCommandExecuteRequest.cs b/BMA.EHR.Command.Service/Requests/UpdateCommandExecuteRequest.cs new file mode 100644 index 00000000..58ef4502 --- /dev/null +++ b/BMA.EHR.Command.Service/Requests/UpdateCommandExecuteRequest.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Command.Service.Requests +{ + public class UpdateCommandExecuteRequest + { + public string OrderNo { get; set; } = string.Empty; + + public string OrderYear { get; set; } = string.Empty; + + public DateTime SignDate { get; set; } = DateTime.Now.Date; + } +} diff --git a/BMA.EHR.Infrastructure/Storage/MinIOService.cs b/BMA.EHR.Infrastructure/Storage/MinIOService.cs index bd20816e..f7eb797c 100644 --- a/BMA.EHR.Infrastructure/Storage/MinIOService.cs +++ b/BMA.EHR.Infrastructure/Storage/MinIOService.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using System.Net.Http.Headers; -using Microsoft.AspNetCore.Hosting; namespace BMA.EHR.Application.Repositories { @@ -210,6 +209,7 @@ namespace BMA.EHR.Application.Repositories } #endregion + public List GetAllIdByRoot(Guid? id) { try