From fe754d0a7d2303462783ab9a60a62358e68bc7bd Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 3 Aug 2023 11:11:13 +0700 Subject: [PATCH 1/8] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=88?= =?UTF-8?q?=E0=B8=B8=E0=B8=94=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=95=E0=B8=81?= =?UTF-8?q?=E0=B8=AB=E0=B8=A5=E0=B9=88=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Command.Service/Controllers/OrderController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 4525fb76..ea6f0e81 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -41,7 +41,7 @@ namespace BMA.EHR.Command.Service.Controllers ApplicationDBContext context, MinIOService documentService, IHttpContextAccessor httpContextAccessor, - GenericRepository prefixRepository) + PrefixRepository prefixRepository) { _repository = repository; _context = context; From 1a528e4a91a4c95d1648d6a30c514c45ef238b66 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 3 Aug 2023 11:52:11 +0700 Subject: [PATCH 2/8] =?UTF-8?q?Add=20-=20API=20=E0=B9=81=E0=B8=AA=E0=B8=94?= =?UTF-8?q?=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B9=80=E0=B8=A0=E0=B8=97=E0=B8=84?= =?UTF-8?q?=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=20Edit=20-=20API?= =?UTF-8?q?=20=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=9B=E0=B8=B5=20?= =?UTF-8?q?=E0=B8=96=E0=B9=89=E0=B8=B2=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=B5=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5?= =?UTF-8?q?=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=9B?= =?UTF-8?q?=E0=B8=B5=E0=B8=9B=E0=B8=B1=E0=B8=88=E0=B8=88=E0=B8=B8=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=99=E0=B9=83=E0=B8=AB=E0=B9=89=201=20=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/OrderController.cs | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index ea6f0e81..6e2ea314 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -31,6 +31,7 @@ namespace BMA.EHR.Command.Service.Controllers private readonly MinIOService _documentService; private readonly IHttpContextAccessor _httpContextAccessor; private readonly PrefixRepository _prefixRepository; + private readonly CommandTypeRepository _commandTypeRepository; #endregion @@ -41,7 +42,8 @@ namespace BMA.EHR.Command.Service.Controllers ApplicationDBContext context, MinIOService documentService, IHttpContextAccessor httpContextAccessor, - PrefixRepository prefixRepository) + PrefixRepository prefixRepository, + CommandTypeRepository commandTypeRepository) { _repository = repository; _context = context; @@ -49,6 +51,7 @@ namespace BMA.EHR.Command.Service.Controllers _httpContextAccessor = httpContextAccessor; _placementRepository = placementRepository; _prefixRepository = prefixRepository; + _commandTypeRepository = commandTypeRepository; } #endregion @@ -68,6 +71,9 @@ namespace BMA.EHR.Command.Service.Controllers /// /// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ /// + /// + /// ถ้าไม่มีข้อมูลเลยจะ default ปีปัจจุบันให้ 1 รายการ + /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ @@ -76,22 +82,57 @@ namespace BMA.EHR.Command.Service.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] - public async Task> GetFiscal() + public async Task> GetFiscalAsync() { var data = await _repository.GetAllAsync(); if (data != null) { var _data = data.GroupBy(x => x.CommandYear).Select(x => new { - Id = x.FirstOrDefault().CommandYear, - Name = x.FirstOrDefault().CommandYear + 543, + Id = x.FirstOrDefault().CommandYear.ToInteger().ToCeYear(), + Name = x.FirstOrDefault().CommandYear.ToInteger().ToThaiYear(), }).ToList(); + + if(_data == null || _data.Count == 0) + { + _data!.Add(new + { + Id = DateTime.Now.Year, + Name = DateTime.Now.Year.ToThaiYear() + }); + } + return Success(_data); } return Success(data); } + /// + /// แสดงประเภทคำสั่ง โดยดึงจากข้อมูลที่มีในระบบ + /// + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("order-type")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetCommandTypeAsync() + { + try + { + var data = (await _commandTypeRepository.GetAllAsync()).OrderBy(x => x.CommandCode); + + return Success(data); + } + catch + { + throw; + } + } + /// /// PM7-19 : หน้าจอรายการออกคำสั่ง /// From e8607f76faa087fadd66db413ad6acaf36ee56e0 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 4 Aug 2023 09:47:58 +0700 Subject: [PATCH 3/8] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B9=89=E0=B8=81=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B6=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=84=E0=B8=94=E0=B9=89?= =?UTF-8?q?=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B9=83=E0=B8=AA=E0=B9=88=E0=B8=84=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=97=E0=B8=B3=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=83=E0=B8=99?= =?UTF-8?q?=20GenericRepoository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfaces/IApplicationDBContext.cs | 2 ++ .../Commands/CommandRepository.cs | 9 +++++++ .../Repositories/GenericRepository.cs | 25 ++++++++++--------- .../Persistence/ApplicationDBContext.cs | 5 ++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/BMA.EHR.Application/Common/Interfaces/IApplicationDBContext.cs b/BMA.EHR.Application/Common/Interfaces/IApplicationDBContext.cs index 2422892b..ab32d1af 100644 --- a/BMA.EHR.Application/Common/Interfaces/IApplicationDBContext.cs +++ b/BMA.EHR.Application/Common/Interfaces/IApplicationDBContext.cs @@ -7,6 +7,8 @@ namespace BMA.EHR.Application.Common.Interfaces { DbSet Set() where T : class; + void Attatch(T entity) where T : class; + Task SaveChangesAsync(); } } diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index d8914f35..c8c9e2e5 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -42,6 +42,15 @@ namespace BMA.EHR.Application.Repositories.Commands .FirstOrDefaultAsync(x => x.Id == id); } + public override async Task AddAsync(Command command) + { + var status = await _dbContext.Set().FirstOrDefaultAsync(c => c.Sequence == 1); + command.CommandStatus = status!; + _dbContext.Attatch(status!); + + return await base.AddAsync(command); + } + #endregion public async Task> GetReceiverByCommmandIdAsync(Guid Id) diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index c196430c..f752c581 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -1,4 +1,5 @@ using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Domain.Models.Base; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using System.Security.Claims; @@ -49,12 +50,12 @@ namespace BMA.EHR.Application.Repositories public virtual async Task AddAsync(T entity) { - //if (entity is IAuditableEntity) - //{ - // (entity as IAuditableEntity).CreatedUserId = Guid.Parse(UserId); - // (entity as IAuditableEntity).CreatedUserFullName = FullName; - // (entity as IAuditableEntity).CreatedDate = DateTime.Now; - //} + if (entity is EntityBase) + { + (entity as EntityBase).CreatedUserId = UserId!; + (entity as EntityBase).CreatedFullName = FullName!; + (entity as EntityBase).CreatedAt = DateTime.Now; + } await _dbSet.AddAsync(entity); @@ -65,12 +66,12 @@ namespace BMA.EHR.Application.Repositories public virtual async Task UpdateAsync(T entity) { - //if (entity is IAuditableEntity) - //{ - // (entity as IAuditableEntity).ModifiedUserId = Guid.Parse(UserId); - // (entity as IAuditableEntity).ModifiedUserFullName = FullName; - // (entity as IAuditableEntity).ModifiedDate = DateTime.Now; - //} + if (entity is EntityBase) + { + (entity as EntityBase).LastUpdateUserId = UserId!; + (entity as EntityBase).LastUpdateFullName = FullName!; + (entity as EntityBase).LastUpdatedAt = DateTime.Now; + } _dbSet.Update(entity); await _dbContext.SaveChangesAsync(); diff --git a/BMA.EHR.Infrastructure/Persistence/ApplicationDBContext.cs b/BMA.EHR.Infrastructure/Persistence/ApplicationDBContext.cs index b41d8822..6b57e77d 100644 --- a/BMA.EHR.Infrastructure/Persistence/ApplicationDBContext.cs +++ b/BMA.EHR.Infrastructure/Persistence/ApplicationDBContext.cs @@ -313,5 +313,10 @@ namespace BMA.EHR.Infrastructure.Persistence { return base.SaveChangesAsync(); } + + public void Attatch(T entity) where T : class + { + Attach(entity); + } } } From ab7135fcbf99b84bb623d1a2cd02f21fc8f3ee7c Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 4 Aug 2023 10:40:09 +0700 Subject: [PATCH 4/8] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20api=201.=20=E0=B8=95=E0=B8=A3=E0=B8=A7=E0=B8=88?= =?UTF-8?q?=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B8=AA=E0=B8=96=E0=B8=B2=E0=B8=99?= =?UTF-8?q?=E0=B8=B0=E0=B8=84=E0=B8=A7=E0=B8=B2=E0=B8=A1=E0=B8=9E=E0=B8=A3?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B9=83=E0=B8=99=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA?= =?UTF-8?q?=E0=B8=B1=E0=B9=88=E0=B8=87=202.=20=E0=B9=80=E0=B8=9B=E0=B8=A5?= =?UTF-8?q?=E0=B8=B5=E0=B9=88=E0=B8=A2=E0=B8=99=E0=B8=AA=E0=B8=96=E0=B8=B2?= =?UTF-8?q?=E0=B8=99=E0=B8=B0=E0=B9=84=E0=B8=9B=20state=20=E0=B8=96?= =?UTF-8?q?=E0=B8=B1=E0=B8=94=E0=B9=84=E0=B8=9B=203.=20=E0=B9=80=E0=B8=9B?= =?UTF-8?q?=E0=B8=A5=E0=B8=B5=E0=B9=88=E0=B8=A2=E0=B8=99=E0=B8=AA=E0=B8=96?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B8=B0=E0=B9=84=E0=B8=9B=20state=20?= =?UTF-8?q?=E0=B8=81=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B8=AB=E0=B8=99=E0=B9=89?= =?UTF-8?q?=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 72 ++++++++++- .../BMA.EHR.Command.Service.csproj | 12 ++ .../Controllers/OrderController.cs | 113 ++++++++++++++++-- BMA.EHR.Domain/Shared/GlobalConstants.cs | 8 ++ 4 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 BMA.EHR.Domain/Shared/GlobalConstants.cs diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index c8c9e2e5..b69f52db 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1,5 +1,4 @@ -using Amazon.S3.Model.Internal.MarshallTransformations; -using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Placement; @@ -39,6 +38,9 @@ namespace BMA.EHR.Application.Repositories.Commands return await _dbContext.Set() .Include(x => x.Placement) .Include(x => x.CommandType) + .Include(x => x.Documents) + .Include(x => x.Receivers) + .Include(x => x.CommandStatus) .FirstOrDefaultAsync(x => x.Id == id); } @@ -47,10 +49,20 @@ namespace BMA.EHR.Application.Repositories.Commands var status = await _dbContext.Set().FirstOrDefaultAsync(c => c.Sequence == 1); command.CommandStatus = status!; _dbContext.Attatch(status!); - + return await base.AddAsync(command); } + public override async Task UpdateAsync(Command entity) + { + // attatch + _dbContext.Attatch(entity.CommandStatus); + _dbContext.Attatch(entity.CommandType); + _dbContext.Attatch(entity.Placement); + + return await base.UpdateAsync(entity); + } + #endregion public async Task> GetReceiverByCommmandIdAsync(Guid Id) @@ -343,12 +355,64 @@ namespace BMA.EHR.Application.Repositories.Commands #endregion + #region " Change Command Status " + + public async Task GotoNextStateAsync(Guid id) + { + try + { + var command = await _dbContext.Set().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var notProcess = new int[] { 4, 5 }; + + if (!notProcess.Contains(command.CommandStatus.Sequence)) + { + var nextStatus = await _dbContext.Set().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence + 1); + command.CommandStatus = nextStatus!; + _dbContext.Attatch(nextStatus!); + await _dbContext.SaveChangesAsync(); + } + } + catch + { + throw; + } + } + + public async Task GotoPrevStateAsync(Guid id) + { + try + { + var command = await _dbContext.Set().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var notProcess = new int[] { 1, 5 }; + + if (!notProcess.Contains(command.CommandStatus.Sequence)) + { + var nextStatus = await _dbContext.Set().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence - 1); + command.CommandStatus = nextStatus!; + _dbContext.Attatch(nextStatus!); + await _dbContext.SaveChangesAsync(); + } + } + 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) + if (command == null) throw new Exception(GlobalMessages.CommandNotFound); command.CommandExcecuteDate = signDate; diff --git a/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj b/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj index 2a444d61..96d01d2d 100644 --- a/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj +++ b/BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj @@ -39,6 +39,18 @@ + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 6e2ea314..1d19f681 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -1,4 +1,5 @@ -using BMA.EHR.Application.Repositories; +using Amazon.S3.Model.Internal.MarshallTransformations; +using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Command.Service.Requests; using BMA.EHR.Domain.Common; @@ -33,6 +34,8 @@ namespace BMA.EHR.Command.Service.Controllers private readonly PrefixRepository _prefixRepository; private readonly CommandTypeRepository _commandTypeRepository; + + #endregion #region " Constuctor and Destructor " @@ -93,7 +96,7 @@ namespace BMA.EHR.Command.Service.Controllers Name = x.FirstOrDefault().CommandYear.ToInteger().ToThaiYear(), }).ToList(); - if(_data == null || _data.Count == 0) + if (_data == null || _data.Count == 0) { _data!.Add(new { @@ -133,6 +136,102 @@ namespace BMA.EHR.Command.Service.Controllers } } + /// + /// ตรวจสอบความพร้อมในการออกคำสั่ง + /// + /// Record Id ของคำสั่ง + /// + /// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("ready/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> CheckReadyToExcecuteAsync(Guid orderId) + { + try + { + var command = await _repository.GetByIdAsync(orderId); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var cover = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_COVER); + var attatchment = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_ATTATCHMENT); + + if (command.CommandNo != "" && + command.CommandYear != null && + command.CommandExcecuteDate != null && + cover != null && + attatchment != null) + { + return Success(new { result = "Y" }); + } + else + return Success(new { result = "N" }); + } + catch + { + throw; + } + } + + /// + /// เปลี่ยน status ของคำสั่งไปขั้นตอนถัดไป + /// + /// Record Id ของคำสั่ง + /// + /// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("next/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GoToNextState(Guid orderId) + { + try + { + await _repository.GotoNextStateAsync(orderId); + return Success(); + } + catch + { + throw; + } + } + + /// + /// เปลี่ยน status ของคำสั่งไปขั้นตอนก่อนหน้า + /// + /// Record Id ของคำสั่ง + /// + /// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("prev/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GoToPrevState(Guid orderId) + { + try + { + await _repository.GotoPrevStateAsync(orderId); + return Success(); + } + catch + { + throw; + } + } + /// /// PM7-19 : หน้าจอรายการออกคำสั่ง /// @@ -584,17 +683,17 @@ namespace BMA.EHR.Command.Service.Controllers try { var command = await _repository.GetByIdAsync(orderId); - if(command == null) + 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 cover = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_COVER).FirstOrDefault(); + var attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTATCHMENT).FirstOrDefault(); var result = new { - orderNo=command.CommandNo, - orderYear=command.CommandYear, + 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), diff --git a/BMA.EHR.Domain/Shared/GlobalConstants.cs b/BMA.EHR.Domain/Shared/GlobalConstants.cs new file mode 100644 index 00000000..d89f50ec --- /dev/null +++ b/BMA.EHR.Domain/Shared/GlobalConstants.cs @@ -0,0 +1,8 @@ +namespace BMA.EHR.Domain.Shared +{ + public class GlobalConstants + { + public static readonly string TYPE_ATTATCHMENT = "attachment"; + public static readonly string TYPE_COVER = "cover"; + } +} From 680bfba81edfc720161b3681cc99d289a5ef75c6 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 4 Aug 2023 11:59:02 +0700 Subject: [PATCH 5/8] =?UTF-8?q?fix=20bug=20GetList=20=E0=B8=84=E0=B8=B3?= =?UTF-8?q?=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=20=E0=B9=80=E0=B8=9E?= =?UTF-8?q?=E0=B8=B4=E0=B9=88=E0=B8=A1=20api=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B9=84=E0=B8=82=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 89 +++++++++ .../Controllers/OrderController.cs | 171 +++++++++++++++++- BMA.EHR.Domain/Shared/GlobalConstants.cs | 2 +- BMA.EHR.Domain/Shared/GlobalMessages.cs | 2 + 4 files changed, 255 insertions(+), 9 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index b69f52db..4a8718c8 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1,8 +1,10 @@ using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Domain.Models.Commands.Core; +using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Command = BMA.EHR.Domain.Models.Commands.Core.Command; @@ -44,6 +46,15 @@ namespace BMA.EHR.Application.Repositories.Commands .FirstOrDefaultAsync(x => x.Id == id); } + public override async Task> GetAllAsync() + { + return await _dbContext.Set() + .Include(x => x.Placement) + .Include(x => x.CommandType) + .Include(x => x.CommandStatus) + .ToListAsync(); + } + public override async Task AddAsync(Command command) { var status = await _dbContext.Set().FirstOrDefaultAsync(c => c.Sequence == 1); @@ -335,6 +346,54 @@ namespace BMA.EHR.Application.Repositories.Commands #region " Documents " + public async Task> GetExistDocument(Guid id, string category) + { + try + { + var command = await _dbContext.Set() + .Include(x => x.Documents) + .ThenInclude(x => x.Document) + .FirstOrDefaultAsync(c => c.Id == id); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + // insert new record to comand Document + var exist = command.Documents.Where(x => x.Category == category).ToList(); + + return exist; + } + catch + { + throw; + } + } + + public async Task UploadDocument(Guid id, string category, CommandDocument document) + { + try + { + var command = await _dbContext.Set().Include(x => x.Documents).FirstOrDefaultAsync(c => c.Id == id); + if (command == null) + throw new Exception(GlobalMessages.CommandNotFound); + + // insert new record to comand Document + var exist = command.Documents.Where(x => x.Category == category).ToList(); + if (exist.Any()) + { + _dbContext.Set().RemoveRange(exist); + await _dbContext.SaveChangesAsync(); + } + + // insert new Record + command.Documents.Add(document); + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + public async Task> GetCommandDocumentAsync(Guid id) { try @@ -407,6 +466,36 @@ namespace BMA.EHR.Application.Repositories.Commands #endregion + #region " Change Detail Sequence " + + + #endregion + + #region " Placement " + + public async Task> GetPlacementPositionPath(Guid id) + { + try + { + var data = await _dbContext.Set() + .Include(x => x.PositionPath) + .Include(x => x.Placement) + .Where(x => x.Placement!.Id == id) + .Where(x => x.PositionPath != null) + .Select(x => x.PositionPath) + .Distinct() + .ToListAsync(); + + return data!; + } + catch + { + throw; + } + } + + #endregion + public async Task UpdateCommandInfo(Guid id, string orderNo, string orderYear, DateTime signDate) { try diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 1d19f681..66aa17f9 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -33,8 +33,7 @@ namespace BMA.EHR.Command.Service.Controllers private readonly IHttpContextAccessor _httpContextAccessor; private readonly PrefixRepository _prefixRepository; private readonly CommandTypeRepository _commandTypeRepository; - - + private readonly CommandStatusRepository _commandStatusRepository; #endregion @@ -46,7 +45,8 @@ namespace BMA.EHR.Command.Service.Controllers MinIOService documentService, IHttpContextAccessor httpContextAccessor, PrefixRepository prefixRepository, - CommandTypeRepository commandTypeRepository) + CommandTypeRepository commandTypeRepository, + CommandStatusRepository commandStatusRepository) { _repository = repository; _context = context; @@ -55,6 +55,7 @@ namespace BMA.EHR.Command.Service.Controllers _placementRepository = placementRepository; _prefixRepository = prefixRepository; _commandTypeRepository = commandTypeRepository; + _commandStatusRepository = commandStatusRepository; } #endregion @@ -159,7 +160,7 @@ namespace BMA.EHR.Command.Service.Controllers throw new Exception(GlobalMessages.CommandNotFound); var cover = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_COVER); - var attatchment = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_ATTATCHMENT); + var attatchment = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_ATTACHMENT); if (command.CommandNo != "" && command.CommandYear != null && @@ -250,6 +251,7 @@ namespace BMA.EHR.Command.Service.Controllers var data = (await _repository.GetAllAsync()) .Select(d => new { + OrderId = d.Id, OrderName = d.CommandSubject, OrderNo = d.CommandNo, FiscalYear = d.CommandYear, @@ -310,7 +312,7 @@ namespace BMA.EHR.Command.Service.Controllers /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpGet("{orderId}")] + [HttpGet("detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] @@ -333,7 +335,7 @@ namespace BMA.EHR.Command.Service.Controllers orderBy = data.IssuerOrganizationId, signatoryBy = data.AuthorizedUserFullName, signatoryPosition = data.AuthorizedPosition, - examRound = data.Placement.Round, + examRound = data.Placement.Id, registerPosition = "", conclusionRegisterNo = data.ConclusionRegisterNo, conclusionRegisterDate = data.ConclusionRegisterDate, @@ -357,7 +359,7 @@ namespace BMA.EHR.Command.Service.Controllers /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน - [HttpPost] + [HttpPost("detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] @@ -392,6 +394,56 @@ namespace BMA.EHR.Command.Service.Controllers } } + /// + /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง + /// + /// Record Id ของคำสั่ง + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("detail/{orderId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PutAsync(Guid orderId, [FromBody] CreateCommandRequest req) + { + try + { + var order = await _repository.GetByIdAsync(orderId); + if (order == null) + throw new Exception(GlobalMessages.CommandNotFound); + + var placement = await _placementRepository.GetByIdAsync(req.examRound); + var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); + var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); + + order.CommandNo = req.orderNo.ToString(); + order.CommandYear = req.orderYear.ToString(); + order.CommandSubject = req.orderTitle; + order.PositionName = req.registerPosition; + order.CommandType = commandType!; + order.IssuerOrganizationId = req.orderBy; + order.AuthorizedUserFullName = req.signatoryBy; + order.AuthorizedPosition = req.signatoryPosition; + order.Placement = placement!; + order.ConclusionRegisterNo = req.conclusionRegisterNo; + order.ConclusionRegisterDate = req.conclusionRegisterDate; + order.ConclusionResultNo = req.conclusionResultNo; + order.ConclusionResultDate = req.conclusionResultDate; + order.CommandStatus = status!; + + var result = await _repository.UpdateAsync(order); + + return Success(result); + } + catch + { + throw; + } + } + + /// /// PM7-24 : dropdown รอบการสอบ หน้ารายละเอียดการออกคำสั่ง /// @@ -688,7 +740,7 @@ namespace BMA.EHR.Command.Service.Controllers var documents = await _repository.GetCommandDocumentAsync(orderId); var cover = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_COVER).FirstOrDefault(); - var attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTATCHMENT).FirstOrDefault(); + var attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTACHMENT).FirstOrDefault(); var result = new { @@ -707,6 +759,109 @@ namespace BMA.EHR.Command.Service.Controllers } } + + /// + /// PM7-35 : อัปโหลดไฟล์คำสั่ง + /// + /// Record Id ของคำสั่ง + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("attachment/order-file/{orderId}"), DisableRequestSizeLimit] + public async Task> UploadCommandCoverAsync(Guid orderId) + { + try + { + // check upload file + if (Request.Form.Files == null || Request.Form.Files.Count == 0) + { + return Error(GlobalMessages.NoFileToUpload); + } + + var file = Request.Form.Files[0]; + + // get exit file + var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_COVER); + + // delete exist document from s3 + foreach (var doc in docs) + { + await _documentService.DeleteFileAsync(doc.Document.ObjectRefId); + } + + // upload new document to s3 + var cover = await _documentService.UploadFileAsync(file); + + // create new CommandDocumentEntity + var commandDoc = new CommandDocument + { + Category = GlobalConstants.TYPE_COVER, + Document = cover, + }; + + // send to repo to save in database + await _repository.UploadDocument(orderId, GlobalConstants.TYPE_COVER, commandDoc); + + return Success(); + } + catch + { + throw; + } + } + + /// + /// PM7-36 : อัปโหลดไฟล์เอกสารแนบท้าย + /// + /// Record Id ของคำสั่ง + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("attachment/file/{orderId}"), DisableRequestSizeLimit] + public async Task> UploadCommandAttachmentAsync(Guid orderId) + { + try + { + // check upload file + if (Request.Form.Files == null || Request.Form.Files.Count == 0) + { + return Error(GlobalMessages.NoFileToUpload); + } + + var file = Request.Form.Files[0]; + + // get exit file + var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_ATTACHMENT); + + // delete exist document from s3 + foreach (var doc in docs) + { + await _documentService.DeleteFileAsync(doc.Document.ObjectRefId); + } + + // upload new document to s3 + var cover = await _documentService.UploadFileAsync(file); + + // create new CommandDocumentEntity + var commandDoc = new CommandDocument + { + Category = GlobalConstants.TYPE_ATTACHMENT, + Document = cover, + }; + + // send to repo to save in database + await _repository.UploadDocument(orderId, GlobalConstants.TYPE_ATTACHMENT, commandDoc); + + return Success(); + } + catch + { + throw; + } + } + #endregion /// diff --git a/BMA.EHR.Domain/Shared/GlobalConstants.cs b/BMA.EHR.Domain/Shared/GlobalConstants.cs index d89f50ec..22ed9b28 100644 --- a/BMA.EHR.Domain/Shared/GlobalConstants.cs +++ b/BMA.EHR.Domain/Shared/GlobalConstants.cs @@ -2,7 +2,7 @@ { public class GlobalConstants { - public static readonly string TYPE_ATTATCHMENT = "attachment"; + public static readonly string TYPE_ATTACHMENT = "attachment"; public static readonly string TYPE_COVER = "cover"; } } diff --git a/BMA.EHR.Domain/Shared/GlobalMessages.cs b/BMA.EHR.Domain/Shared/GlobalMessages.cs index 0c5c2e77..81bdf617 100644 --- a/BMA.EHR.Domain/Shared/GlobalMessages.cs +++ b/BMA.EHR.Domain/Shared/GlobalMessages.cs @@ -16,6 +16,8 @@ public static readonly string FileNotFoundOnServer = "ไม่พบไฟล์ในระบบ!!"; + public static readonly string NoFileToUpload = "ไม่พบไฟล์ที่ทำการอัพโหลด!"; + #region " Meta Data " public static readonly string DataExist5 = "เนื่องจากมีการกำหนดวันหยุดในการทำงาน 5 วันอยู่"; From a4e8b50d456c9162fba1bba5ea0428293ebc23c1 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 4 Aug 2023 14:30:10 +0700 Subject: [PATCH 6/8] Add new API Update Salary Swap Sequence --- .../Commands/CommandRepository.cs | 109 ++++++++++++++++++ .../Commands/UpdatePlacementSalaryRequest.cs | 11 ++ .../Controllers/OrderController.cs | 76 ++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 BMA.EHR.Application/Requests/Commands/UpdatePlacementSalaryRequest.cs diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 4a8718c8..2be308d1 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1,4 +1,5 @@ using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Organizations; @@ -7,6 +8,7 @@ using BMA.EHR.Domain.Shared; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; +using System.Transactions; using Command = BMA.EHR.Domain.Models.Commands.Core.Command; namespace BMA.EHR.Application.Repositories.Commands @@ -76,6 +78,8 @@ namespace BMA.EHR.Application.Repositories.Commands #endregion + #region " Command Receiver " + public async Task> GetReceiverByCommmandIdAsync(Guid Id) { try @@ -167,6 +171,89 @@ namespace BMA.EHR.Application.Repositories.Commands } } + public async Task GetCommandReceiverAsync(Guid personalId) + { + try + { + var receiver = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == personalId); + + if (receiver == null) + throw new Exception(GlobalMessages.DataNotFound); + + return receiver; + } + catch + { + throw; + } + + + } + + public async Task SwapReceiverOrderAsync(Guid personalId, string direction) + { + try + { + var current = await _dbContext.Set() + .FirstOrDefaultAsync(x => x.Id == personalId); + + if (current == null) + throw new Exception(GlobalMessages.DataNotFound); + + var currentSeq = current.Sequence; + + switch (direction.Trim().ToLower()) + { + case "up": + { + // get prev record + var prev = await _dbContext.Set() + .OrderByDescending(x => x.Sequence) + .Where(x => x.Sequence < currentSeq) + .Take(1) + .FirstOrDefaultAsync(); + + if (prev != null) + { + var prevSeq = prev.Sequence; + + current.Sequence = prevSeq; + prev.Sequence = currentSeq; + await _dbContext.SaveChangesAsync(); + } + break; + } + case "down": + { + // get next record + var next = await _dbContext.Set() + .OrderBy(x => x.Sequence) + .Where(x => x.Sequence > currentSeq) + .Take(1) + .FirstOrDefaultAsync(); + + if (next != null) + { + var nextSeq = next.Sequence; + + current.Sequence = nextSeq; + next.Sequence = currentSeq; + await _dbContext.SaveChangesAsync(); + } + break; + } + default: throw new Exception("Invalid swap direction!"); + } + } + catch + { + throw; + } + } + + #endregion + public async Task> GetDeploymentByCommandIdAsync(Guid id) { try @@ -473,6 +560,28 @@ namespace BMA.EHR.Application.Repositories.Commands #region " Placement " + public async Task UpdatePlacementSalaryAsync(Guid placementProfileId, UpdatePlacementSalaryRequest req) + { + try + { + var placementProfile = await _dbContext.Set() + .FirstOrDefaultAsync(p => p.Id == placementProfileId); + + if (placementProfile == null) + throw new Exception($"Invalid placement profile: {placementProfileId}"); + + placementProfile.Amount = req.SalaryAmount; + placementProfile.PositionSalaryAmount = req.PositionSalaryAmount; + placementProfile.MouthSalaryAmount = req.MonthSalaryAmount; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + public async Task> GetPlacementPositionPath(Guid id) { try diff --git a/BMA.EHR.Application/Requests/Commands/UpdatePlacementSalaryRequest.cs b/BMA.EHR.Application/Requests/Commands/UpdatePlacementSalaryRequest.cs new file mode 100644 index 00000000..2aefb92f --- /dev/null +++ b/BMA.EHR.Application/Requests/Commands/UpdatePlacementSalaryRequest.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Requests.Commands +{ + public class UpdatePlacementSalaryRequest + { + public double SalaryAmount { get; set; } = 0; + + public double PositionSalaryAmount { get; set; } = 0; + + public double MonthSalaryAmount { get; set; } = 0; + } +} diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 66aa17f9..d89d1b8c 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -1,6 +1,7 @@ using Amazon.S3.Model.Internal.MarshallTransformations; using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; +using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Command.Service.Requests; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; @@ -889,6 +890,81 @@ namespace BMA.EHR.Command.Service.Controllers } } + /// + /// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ + /// + /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("salary/{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> UpdatePlacementSalaryAsync(Guid personalId, [FromBody] UpdatePlacementSalaryRequest req) + { + try + { + var receiver = await _repository.GetCommandReceiverAsync(personalId); + + if (receiver == null) + throw new Exception(GlobalMessages.DataNotFound); + + await _repository.UpdatePlacementSalaryAsync(personalId, req); + + return Success(); + } + catch + { + throw; + } + } + + /// + /// สลับลำดับข้อมูลในบัญชีแนบท้ายขึ้น + /// + /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("swap/up/{personalId}")] + public async Task> SwapUpReceiverOrderAsync(Guid personalId) + { + try + { + await _repository.SwapReceiverOrderAsync(personalId, "up"); + return Success(); + } + catch + { + throw; + } + } + + /// + /// สลับลำดับข้อมูลในบัญชีแนบท้ายลง + /// + /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("swap/down/{personalId}")] + public async Task> SwapDownReceiverOrderAsync(Guid personalId) + { + try + { + await _repository.SwapReceiverOrderAsync(personalId, "down"); + return Success(); + } + catch + { + throw; + } + } + #endregion } } From 353eeada7767c1c1054b7268b03372f049b3dac2 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 4 Aug 2023 15:05:43 +0700 Subject: [PATCH 7/8] Add Github Action for build docker image --- .github/workflows/build-local.yaml | 46 ++++++++++++++ .github/workflows/release_command.yaml | 87 ++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 .github/workflows/build-local.yaml create mode 100644 .github/workflows/release_command.yaml diff --git a/.github/workflows/build-local.yaml b/.github/workflows/build-local.yaml new file mode 100644 index 00000000..3a06de72 --- /dev/null +++ b/.github/workflows/build-local.yaml @@ -0,0 +1,46 @@ +# use for local build with act +name: build-local +run-name: build-local ${{ github.actor }} +on: + workflow_dispatch: +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: demo/bma-ehr-metadata-service +jobs: + # act workflow_dispatch -W .github/workflows/build-local.yaml --input IMAGE_VER=test-v6.1 + build-local: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + - name: Gen Version + id: gen_ver + run: | + if [[ $GITHUB_REF == 'refs/tags/'* ]]; then + IMAGE_VER='${GITHUB_REF/refs\/tags\//}' + else + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + fi + if [[ $IMAGE_VER == '' ]]; then + IMAGE_VER='test-vBeta' + fi + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Test Version + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + # - name: Login in to registry + # uses: docker/login-action@v2 + # with: + # registry: ${{env.REGISTRY}} + # username: ${{secrets.DOCKER_USER}} + # password: ${{secrets.DOCKER_PASS}} + - name: Build and load local docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + load: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest diff --git a/.github/workflows/release_command.yaml b/.github/workflows/release_command.yaml new file mode 100644 index 00000000..37301964 --- /dev/null +++ b/.github/workflows/release_command.yaml @@ -0,0 +1,87 @@ +name: release-dev +run-name: release-dev ${{ github.actor }} +on: + # push: + # tags: + # - 'v[0-9]+.[0-9]+.[0-9]+' + # tags-ignore: + # - '2.*' + # Allow run workflow manually from Action tab + workflow_dispatch: +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: ehr/bma-ehr-command-service + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma-ehr-command + TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0 + +jobs: + # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd + release-dev: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + - name: Gen Version + id: gen_ver + run: | + if [[ $GITHUB_REF == 'refs/tags/'* ]]; then + IMAGE_VER='${GITHUB_REF/refs\/tags\//}' + else + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + fi + if [[ $IMAGE_VER == '' ]]; then + IMAGE_VER='test-vBeta' + fi + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Test Version + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login in to registry + uses: docker/login-action@v2 + with: + registry: ${{env.REGISTRY}} + username: ${{secrets.DOCKER_USER}} + password: ${{secrets.DOCKER_PASS}} + - name: Build and load local docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + file: BMA.EHR.Command.Service/Dockerfile + push: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest + + - name: Reload docker compose + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{env.DEPLOY_HOST}} + username: frappet + password: ${{ secrets.SSH_PASSWORD }} + port: 22 + script: | + cd "${{env.COMPOSE_PATH}}" + docker-compose pull + docker-compose up -d + echo "${{ steps.gen_ver.outputs.image_ver }}"> success + - uses: snow-actions/line-notify@v1.1.0 + if: success() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Success✅✅✅ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} + - uses: snow-actions/line-notify@v1.1.0 + if: failure() + with: + access_token: ${{ env.TOKEN_LINE }} + message: | + -Failure❌❌❌ + Image: ${{env.IMAGE_NAME}} + Version: ${{ github.event.inputs.IMAGE_VER }} + By: ${{secrets.DOCKER_USER}} From f07b4037f6edf7135e5647cb5924d040d7fa55c3 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 4 Aug 2023 15:17:17 +0700 Subject: [PATCH 8/8] fix bugs create and update command - :Add OrderDate Parameter --- BMA.EHR.Command.Service/Controllers/OrderController.cs | 4 +++- BMA.EHR.Command.Service/Requests/CreateCommandRequest.cs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index d89d1b8c..264926fa 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -382,7 +382,8 @@ namespace BMA.EHR.Command.Service.Controllers ConclusionRegisterNo = req.conclusionRegisterNo, ConclusionRegisterDate = req.conclusionRegisterDate, ConclusionResultNo = req.conclusionResultNo, - ConclusionResultDate = req.conclusionResultDate + ConclusionResultDate = req.conclusionResultDate, + CommandAffectDate = req.orderDate }; var result = await _repository.AddAsync(inserted); @@ -433,6 +434,7 @@ namespace BMA.EHR.Command.Service.Controllers order.ConclusionResultNo = req.conclusionResultNo; order.ConclusionResultDate = req.conclusionResultDate; order.CommandStatus = status!; + order.CommandAffectDate = req.orderDate; var result = await _repository.UpdateAsync(order); diff --git a/BMA.EHR.Command.Service/Requests/CreateCommandRequest.cs b/BMA.EHR.Command.Service/Requests/CreateCommandRequest.cs index 336cd3c4..c14accfd 100644 --- a/BMA.EHR.Command.Service/Requests/CreateCommandRequest.cs +++ b/BMA.EHR.Command.Service/Requests/CreateCommandRequest.cs @@ -10,6 +10,8 @@ public int orderYear { get; set; } + public DateTime orderDate { get; set; } + public Guid orderBy { get; set; } public string signatoryBy { get; set; }