เพิ่ม api

1. ตรวจสอบสถานะความพร้อมในการออกคำสั่ง
2. เปลี่ยนสถานะไป state ถัดไป
3. เปลี่ยนสถานะไป state ก่อนหน้า
This commit is contained in:
Suphonchai Phoonsawat 2023-08-04 10:40:09 +07:00
parent e8607f76fa
commit ab7135fcbf
4 changed files with 194 additions and 11 deletions

View file

@ -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
}
}
/// <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>
/// PM7-19 : หน้าจอรายการออกคำสั่ง
/// </summary>
@ -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),