เพิ่ม api
1. ตรวจสอบสถานะความพร้อมในการออกคำสั่ง 2. เปลี่ยนสถานะไป state ถัดไป 3. เปลี่ยนสถานะไป state ก่อนหน้า
This commit is contained in:
parent
e8607f76fa
commit
ab7135fcbf
4 changed files with 194 additions and 11 deletions
|
|
@ -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.Commands.Core;
|
||||||
using BMA.EHR.Domain.Models.Organizations;
|
using BMA.EHR.Domain.Models.Organizations;
|
||||||
using BMA.EHR.Domain.Models.Placement;
|
using BMA.EHR.Domain.Models.Placement;
|
||||||
|
|
@ -39,6 +38,9 @@ namespace BMA.EHR.Application.Repositories.Commands
|
||||||
return await _dbContext.Set<Command>()
|
return await _dbContext.Set<Command>()
|
||||||
.Include(x => x.Placement)
|
.Include(x => x.Placement)
|
||||||
.Include(x => x.CommandType)
|
.Include(x => x.CommandType)
|
||||||
|
.Include(x => x.Documents)
|
||||||
|
.Include(x => x.Receivers)
|
||||||
|
.Include(x => x.CommandStatus)
|
||||||
.FirstOrDefaultAsync(x => x.Id == id);
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,6 +53,16 @@ namespace BMA.EHR.Application.Repositories.Commands
|
||||||
return await base.AddAsync(command);
|
return await base.AddAsync(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<Command> UpdateAsync(Command entity)
|
||||||
|
{
|
||||||
|
// attatch
|
||||||
|
_dbContext.Attatch(entity.CommandStatus);
|
||||||
|
_dbContext.Attatch(entity.CommandType);
|
||||||
|
_dbContext.Attatch(entity.Placement);
|
||||||
|
|
||||||
|
return await base.UpdateAsync(entity);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
|
||||||
|
|
@ -343,12 +355,64 @@ namespace BMA.EHR.Application.Repositories.Commands
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region " Change Command Status "
|
||||||
|
|
||||||
|
public async Task GotoNextStateAsync(Guid id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var command = await _dbContext.Set<Command>().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<CommandStatus>().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<Command>().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<CommandStatus>().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)
|
public async Task UpdateCommandInfo(Guid id, string orderNo, string orderYear, DateTime signDate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
|
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
|
||||||
if(command == null)
|
if (command == null)
|
||||||
throw new Exception(GlobalMessages.CommandNotFound);
|
throw new Exception(GlobalMessages.CommandNotFound);
|
||||||
|
|
||||||
command.CommandExcecuteDate = signDate;
|
command.CommandExcecuteDate = signDate;
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,18 @@
|
||||||
<ProjectReference Include="..\BMA.EHR.Infrastructure\BMA.EHR.Infrastructure.csproj" />
|
<ProjectReference Include="..\BMA.EHR.Infrastructure\BMA.EHR.Infrastructure.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="wwwroot\index.html">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Update="wwwroot\keycloak.js">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Update="wwwroot\keycloak.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="SeedCommand.xlsx">
|
<None Update="SeedCommand.xlsx">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
|
|
||||||
|
|
@ -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.Application.Repositories.Commands;
|
||||||
using BMA.EHR.Command.Service.Requests;
|
using BMA.EHR.Command.Service.Requests;
|
||||||
using BMA.EHR.Domain.Common;
|
using BMA.EHR.Domain.Common;
|
||||||
|
|
@ -33,6 +34,8 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
private readonly PrefixRepository _prefixRepository;
|
private readonly PrefixRepository _prefixRepository;
|
||||||
private readonly CommandTypeRepository _commandTypeRepository;
|
private readonly CommandTypeRepository _commandTypeRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Constuctor and Destructor "
|
#region " Constuctor and Destructor "
|
||||||
|
|
@ -93,7 +96,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
Name = x.FirstOrDefault().CommandYear.ToInteger().ToThaiYear(),
|
Name = x.FirstOrDefault().CommandYear.ToInteger().ToThaiYear(),
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
if(_data == null || _data.Count == 0)
|
if (_data == null || _data.Count == 0)
|
||||||
{
|
{
|
||||||
_data!.Add(new
|
_data!.Add(new
|
||||||
{
|
{
|
||||||
|
|
@ -133,6 +136,102 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ตรวจสอบความพร้อมในการออกคำสั่ง
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
||||||
|
/// <returns>
|
||||||
|
/// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpGet("ready/{orderId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// เปลี่ยน status ของคำสั่งไปขั้นตอนถัดไป
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
||||||
|
/// <returns>
|
||||||
|
/// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPut("next/{orderId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GoToNextState(Guid orderId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _repository.GotoNextStateAsync(orderId);
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// เปลี่ยน status ของคำสั่งไปขั้นตอนก่อนหน้า
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orderId">Record Id ของคำสั่ง</param>
|
||||||
|
/// <returns>
|
||||||
|
/// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPut("prev/{orderId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> GoToPrevState(Guid orderId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _repository.GotoPrevStateAsync(orderId);
|
||||||
|
return Success();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// PM7-19 : หน้าจอรายการออกคำสั่ง
|
/// PM7-19 : หน้าจอรายการออกคำสั่ง
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -584,17 +683,17 @@ namespace BMA.EHR.Command.Service.Controllers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var command = await _repository.GetByIdAsync(orderId);
|
var command = await _repository.GetByIdAsync(orderId);
|
||||||
if(command == null)
|
if (command == null)
|
||||||
throw new Exception(GlobalMessages.CommandNotFound);
|
throw new Exception(GlobalMessages.CommandNotFound);
|
||||||
|
|
||||||
var documents = await _repository.GetCommandDocumentAsync(orderId);
|
var documents = await _repository.GetCommandDocumentAsync(orderId);
|
||||||
var cover = documents.Where(x => x.Category.Trim().ToLower() == "cover").FirstOrDefault();
|
var cover = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_COVER).FirstOrDefault();
|
||||||
var attach = documents.Where(x => x.Category.Trim().ToLower() == "attachment").FirstOrDefault();
|
var attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTATCHMENT).FirstOrDefault();
|
||||||
|
|
||||||
var result = new
|
var result = new
|
||||||
{
|
{
|
||||||
orderNo=command.CommandNo,
|
orderNo = command.CommandNo,
|
||||||
orderYear=command.CommandYear,
|
orderYear = command.CommandYear,
|
||||||
signDate = command.CommandExcecuteDate,
|
signDate = command.CommandExcecuteDate,
|
||||||
orderFileUrl = cover == null ? null : _documentService.ImagesPath(cover.Document.ObjectRefId),
|
orderFileUrl = cover == null ? null : _documentService.ImagesPath(cover.Document.ObjectRefId),
|
||||||
attachmentFileUrl = attach == null ? null : _documentService.ImagesPath(attach.Document.ObjectRefId),
|
attachmentFileUrl = attach == null ? null : _documentService.ImagesPath(attach.Document.ObjectRefId),
|
||||||
|
|
|
||||||
8
BMA.EHR.Domain/Shared/GlobalConstants.cs
Normal file
8
BMA.EHR.Domain/Shared/GlobalConstants.cs
Normal file
|
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue