diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index ff725e06..22017275 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -8672,6 +8672,74 @@ namespace BMA.EHR.Command.Service.Controllers } } + /// + /// เอกสารแนบท้าย C-PM-40 + /// + /// Record Id ของคำสั่ง + /// pdf, docx หรือ xlsx + /// + /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("command40/report/attachment")] + [AllowAnonymous] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> PostReportCommand40Attachment([FromBody] ReportPersonRequest req_) + { + try + { + var raw_data = await _context.Set() + .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(); + 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(_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; + } + } + /// /// ออกคำสั่ง C-PM-40 ///