sort report retire
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
moss 2025-03-27 18:44:06 +07:00
parent 8d1b37aef7
commit ef9a42a97a

View file

@ -77,8 +77,13 @@ namespace BMA.EHR.Application.Repositories.Reports
// var retires = new List<dynamic>();
var apiUrl = $"{_configuration["API"]}/org/root/search/sort";
dynamic rootOrder = new List<string>();
dynamic child1Order = new List<string>();
dynamic child2Order = new List<string>();
dynamic child3Order = new List<string>();
dynamic child4Order = new List<string>();
dynamic posTypeNameOrder = new List<string>();
dynamic posLevelNameOrder = new List<string>();
dynamic hospital = new List<string>();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
@ -92,8 +97,13 @@ namespace BMA.EHR.Application.Repositories.Reports
if (org != null && org.result != null)
{
rootOrder = org.result.root;
child1Order = org.result.child1;
child2Order = org.result.child2;
child3Order = org.result.child3;
child4Order = org.result.child4;
posTypeNameOrder = org.result.posTypeNameOrder;
posLevelNameOrder = org.result.posLevelNameOrder;
hospital = org.result.hospital;
}
}
if (retire == null)
@ -164,16 +174,23 @@ namespace BMA.EHR.Application.Repositories.Reports
// previousPosTypeName = profile.posTypeName;
// bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
// previousPosLevelName = profile.posLevelName;
var _child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
(profile.child4 == null ? "" : profile.child4 + "\n") +
(profile.child3 == null ? "" : profile.child3 + "\n") +
(profile.child2 == null ? "" : profile.child2 + "\n") +
(profile.child1 == null ? "" : profile.child1 + "\n") +
(profile.reason == null ? "" : profile.reason);
int lastNewLinechild = _child.LastIndexOf('\n');
if (lastNewLinechild != -1)
{
_child = _child.Remove(lastNewLinechild, 1);
}
return new ProfileRetireJsonRequest
{
order = $"{ (index + 1).ToString().ToThaiNumber() }. ลำดับที่ { (profile.order).ToString().ToThaiNumber() }",
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = "",
child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
(profile.child4 == null ? "" : profile.child4 + "\n") +
(profile.child3 == null ? "" : profile.child3 + "\n") +
(profile.child2 == null ? "" : profile.child2 + "\n") +
(profile.child1 == null ? "" : profile.child1),
child = _child,
position = profile.position != "" && profile.position != null ? profile.position : "-",
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
@ -256,6 +273,7 @@ namespace BMA.EHR.Application.Repositories.Reports
// }
var mapProfiles = new List<ProfileRetireJsonRequest>();
string previousRoot = null;
string previousChild1 = null;
string previousPosTypeName = null;
string previousPosLevelName = null;
if (profile_retire.Count > 0)
@ -263,6 +281,10 @@ namespace BMA.EHR.Application.Repositories.Reports
if (retire.TypeReport == null)
{
profile_retire = profile_retire.OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
.ThenBy(x => child1Order.ToObject<List<string>>().IndexOf(x.child1 ?? ""))
.ThenBy(x => child2Order.ToObject<List<string>>().IndexOf(x.child2 ?? ""))
.ThenBy(x => child3Order.ToObject<List<string>>().IndexOf(x.child3 ?? ""))
.ThenBy(x => child4Order.ToObject<List<string>>().IndexOf(x.child4 ?? ""))
.ThenBy(x => posTypeNameOrder.ToObject<List<string>>().IndexOf(x.posTypeName ?? ""))
.ThenBy(x => posLevelNameOrder.ToObject<List<string>>().IndexOf(x.posLevelName ?? "")).ToList();
}
@ -270,22 +292,46 @@ namespace BMA.EHR.Application.Repositories.Reports
{
bool isDuplicateRoot = profile.root == previousRoot;
previousRoot = profile.root;
if (isDuplicateRoot == false)
{
previousChild1 = null;
previousPosTypeName = null;
previousPosLevelName = null;
}
bool isDuplicateHospital = profile.child1 == previousChild1;
previousChild1 = profile.child1;
bool isDuplicatePosType = profile.posTypeName == previousPosTypeName;
previousPosTypeName = profile.posTypeName;
bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
previousPosLevelName = profile.posLevelName;
var _root = (isDuplicateRoot ? "" : profile.root + "\n") +
(isDuplicateHospital || !hospital.ToObject<List<string>>().Contains(profile.child1)
? ""
: profile.child1 + "\n") +
(isDuplicatePosType ? "" : $"ตำแหน่งประเภท{profile.posTypeName}" + "\n") +
(isDuplicatePosLevel ? "" : $"ระดับ{profile.posLevelName}");
int lastNewLineroot = _root.LastIndexOf('\n');
if (lastNewLineroot != -1)
{
_root = _root.Remove(lastNewLineroot, 1);
}
var _child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
(profile.child4 == null ? "" : profile.child4 + "\n") +
(profile.child3 == null ? "" : profile.child3 + "\n") +
(profile.child2 == null ? "" : profile.child2 + "\n") +
(profile.child1 == null || hospital.ToObject<List<string>>().Contains(profile.child1) ? "" : profile.child1 + "\n") +
(profile.reason == null ? "" : profile.reason);
int lastNewLinechild = _child.LastIndexOf('\n');
if (lastNewLinechild != -1)
{
_child = _child.Remove(lastNewLinechild, 1);
}
return new ProfileRetireJsonRequest
{
order = (index + 1).ToString().ToThaiNumber(),
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = (isDuplicateRoot ? "" : profile.root + "\n") +
(isDuplicatePosType ? "" : profile.posTypeName + "\n") +
(isDuplicatePosLevel ? "" : profile.posLevelName),
child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
(profile.child4 == null ? "" : profile.child4 + "\n") +
(profile.child3 == null ? "" : profile.child3 + "\n") +
(profile.child2 == null ? "" : profile.child2 + "\n") +
(profile.child1 == null ? "" : profile.child1),
root = _root,
child = _child,
position = profile.position != "" && profile.position != null ? profile.position : "-",
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-",
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",