- API แสดงรายการประเภทคำสั่ง
Edit
- API แสดงปี ถ้าไม่มีข้อมูล เพิ่มการแสดงปีปัจจุบันให้ 1 รายการ
This commit is contained in:
Suphonchai Phoonsawat 2023-08-03 11:52:11 +07:00
parent fe754d0a7d
commit 1a528e4a91

View file

@ -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
/// <summary>
/// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ
/// </summary>
/// <remarks>
/// ถ้าไม่มีข้อมูลเลยจะ default ปีปัจจุบันให้ 1 รายการ
/// </remarks>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
@ -76,22 +82,57 @@ namespace BMA.EHR.Command.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetFiscal()
public async Task<ActionResult<ResponseObject>> 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);
}
/// <summary>
/// แสดงประเภทคำสั่ง โดยดึงจากข้อมูลที่มีในระบบ
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("order-type")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetCommandTypeAsync()
{
try
{
var data = (await _commandTypeRepository.GetAllAsync()).OrderBy(x => x.CommandCode);
return Success(data);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-19 : หน้าจอรายการออกคำสั่ง
/// </summary>