report retirement

This commit is contained in:
moss 2025-03-27 15:58:22 +07:00
parent 94100e304e
commit 066f49cad7
2 changed files with 76 additions and 24 deletions

View file

@ -147,30 +147,28 @@ namespace BMA.EHR.Application.Repositories.Reports
profiles = profiles.OrderBy(x => x.order).ToList();
}
var mapProfiles = new List<ProfileRetireJsonRequest>();
string previousRoot = null;
string previousPosTypeName = null;
string previousPosLevelName = null;
// string previousRoot = null;
// string previousPosTypeName = null;
// string previousPosLevelName = null;
if (profiles.Count > 0)
{
mapProfiles = profiles
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? ""))
// .OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
// .ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
// .ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? ""))
.Select((profile, index) =>
{
bool isDuplicateRoot = profile.root == previousRoot;
previousRoot = profile.root;
bool isDuplicatePosType = profile.posTypeName == previousPosTypeName;
previousPosTypeName = profile.posTypeName;
bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
previousPosLevelName = profile.posLevelName;
// bool isDuplicateRoot = profile.root == previousRoot;
// previousRoot = profile.root;
// bool isDuplicatePosType = profile.posTypeName == previousPosTypeName;
// previousPosTypeName = profile.posTypeName;
// bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
// previousPosLevelName = profile.posLevelName;
return new ProfileRetireJsonRequest
{
order = (index + 1).ToString().ToThaiNumber(),
order = $"{ (index + 1).ToString().ToThaiNumber() }. ลำดับที่ { (profile.order).ToString().ToThaiNumber() }",
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = (isDuplicateRoot ? "" : profile.root + "\n") +
(isDuplicatePosType ? "" : profile.posTypeName + "\n") +
(isDuplicatePosLevel ? "" : profile.posLevelName),
root = "",
child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
(profile.child4 == null ? "" : profile.child4 + "\n") +
(profile.child3 == null ? "" : profile.child3 + "\n") +
@ -262,11 +260,13 @@ namespace BMA.EHR.Application.Repositories.Reports
string previousPosLevelName = null;
if (profile_retire.Count > 0)
{
mapProfiles = profile_retire
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? ""))
.Select((profile, index) =>
if (retire.TypeReport == null)
{
profile_retire = profile_retire.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")).ToList();
}
mapProfiles = profile_retire.Select((profile, index) =>
{
bool isDuplicateRoot = profile.root == previousRoot;
previousRoot = profile.root;

View file

@ -408,8 +408,32 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
}
// var retires = new List<dynamic>();
var _apiUrl = $"{_configuration["API"]}/org/root/search/sort";
dynamic rootOrder = new List<string>();
dynamic posTypeNameOrder = new List<string>();
dynamic posLevelNameOrder = new List<string>();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
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)
{
rootOrder = org.result.root;
posTypeNameOrder = org.result.posTypeNameOrder;
posLevelNameOrder = org.result.posLevelNameOrder;
}
}
var order = 1;
foreach (var profile in profiles)
foreach (var profile in profiles.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")))
{
var data = new RetirementProfile
{
@ -510,11 +534,39 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Error(GlobalMessages.RetirementNotCreated);
if (req.Option == null)
req.Option = "EDIT";
var apiUrl = $"{_configuration["API"]}/org/root/search/sort";
dynamic rootOrder = new List<string>();
dynamic posTypeNameOrder = new List<string>();
dynamic posLevelNameOrder = new List<string>();
if(retire.TypeReport == null)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
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)
{
rootOrder = org.result.root;
posTypeNameOrder = org.result.posTypeNameOrder;
posLevelNameOrder = org.result.posLevelNameOrder;
}
}
}
var profile_old = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire)
.Select(x => new
.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? ""))
.Select((x,index) => new
{
order = x.Order,
order = retire.TypeReport == null ? index + 1 : x.Order,
id = x.Id,
reason = x.Reason,
remove = x.Remove,