Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop

This commit is contained in:
kittapath 2024-10-03 15:03:46 +07:00
commit 79ce6fc569

View file

@ -8672,6 +8672,74 @@ namespace BMA.EHR.Command.Service.Controllers
}
}
/// <summary>
/// เอกสารแนบท้าย C-PM-40
/// </summary>
/// <param name="id">Record Id ของคำสั่ง</param>
/// <param name="exportType">pdf, docx หรือ xlsx</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("command40/report/attachment")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> PostReportCommand40Attachment([FromBody] ReportPersonRequest req_)
{
try
{
var raw_data = await _context.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(c => req_.refIds.Contains(c.Id.ToString()))
.ToListAsync();
if (raw_data == null)
{
throw new Exception(GlobalMessages.CommandNotFound);
}
var data = new List<CommandType40Response>();
var no = 1;
foreach (var d in raw_data)
{
var apiUrl = $"{_configuration["API"]}/org/pos/act/{d.RefDisciplineId}/{d.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<dynamic>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandType40Response
{
no = no.ToString().ToThaiNumber(),
fullName = $"{org.result.prefix}{org.result.firstName} {org.result.lastName}",
organization = org.result.organization,
position = org.result.position,
postype = org.result.postype,
poslevel = org.result.poslevel,
organizationNew = org.result.organizationNew,
dateStart = d.Command.ActStartDate == null ? "-" : d.Command.ActStartDate.Value.ToThaiFullDate3().ToThaiNumber(),
dateEnd = d.Command.ActEndDate == null ? "-" : d.Command.ActEndDate.Value.ToThaiFullDate3().ToThaiNumber(),
order = org.result.order,
};
no = no + 1;
data.Add(receiver);
}
}
return Success(data);
}
catch
{
throw;
}
}
/// <summary>
/// ออกคำสั่ง C-PM-40
/// </summary>