reportreire

This commit is contained in:
moss 2025-04-04 10:55:16 +07:00
parent d0a6f21e05
commit a830b7d016

View file

@ -157,10 +157,76 @@ namespace BMA.EHR.Application.Repositories.Reports
profiles = profiles.OrderBy(x => x.order).ToList(); profiles = profiles.OrderBy(x => x.order).ToList();
} }
var mapProfiles = new List<ProfileRetireJsonRequest>(); var mapProfiles = new List<ProfileRetireJsonRequest>();
// string previousRoot = null; string previousRoot = null;
// string previousPosTypeName = null; string previousChild1 = null;
// string previousPosLevelName = null; string previousPosTypeName = null;
string previousPosLevelName = null;
if (profiles.Count > 0) if (profiles.Count > 0)
{
if (retireHistorys.TypeReport == null)
{
profiles = profiles.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();
mapProfiles = profiles.Select((profile, index) =>
{
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;
if (isDuplicateHospital == false)
{
previousPosTypeName = null;
previousPosLevelName = null;
}
bool isDuplicatePosType = profile.posTypeName == previousPosTypeName;
previousPosTypeName = profile.posTypeName;
bool isDuplicatePosLevel = profile.posLevelName == previousPosLevelName;
previousPosLevelName = profile.posLevelName;
return new ProfileRetireJsonRequest
{
order = retireHistorys.TypeReport == null
? (index + 1).ToString().ToThaiNumber()
: $"{(index + 1).ToString().ToThaiNumber()}. ลำดับที่ {(profile.order).ToString().ToThaiNumber()}",
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = (isDuplicateRoot ? "" : profile.root + "\n") +
(isDuplicateHospital || !hospital.ToObject<List<string>>()
.Contains(profile.child1)
? ""
: profile.child1 + "\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 || hospital.ToObject<List<string>>()
.Contains(profile.child1)
? ""
: profile.child1 + "\n") +
(profile.reason == null ? "" : profile.reason),
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 : "-",
};
}).ToList();
}else
{ {
mapProfiles = profiles mapProfiles = profiles
// .OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root)) // .OrderBy(x => rootOrder.ToObject<List<string>>().IndexOf(x.root))
@ -176,21 +242,29 @@ namespace BMA.EHR.Application.Repositories.Reports
// previousPosLevelName = profile.posLevelName; // previousPosLevelName = profile.posLevelName;
return new ProfileRetireJsonRequest return new ProfileRetireJsonRequest
{ {
order = retireHistorys.TypeReport == null ? (index + 1).ToString().ToThaiNumber() : $"{(index + 1).ToString().ToThaiNumber()}. ลำดับที่ {(profile.order).ToString().ToThaiNumber()}", order = retireHistorys.TypeReport == null
? (index + 1).ToString().ToThaiNumber()
: $"{(index + 1).ToString().ToThaiNumber()}. ลำดับที่ {(profile.order).ToString().ToThaiNumber()}",
fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}", fullName = $"{profile.prefix}{profile.firstName} {profile.lastName}",
root = "", root = "",
child = (profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") + child =
(profile.posExecutiveName == null ? "" : profile.posExecutiveName + "\n") +
(profile.child4 == null ? "" : profile.child4 + "\n") + (profile.child4 == null ? "" : profile.child4 + "\n") +
(profile.child3 == null ? "" : profile.child3 + "\n") + (profile.child3 == null ? "" : profile.child3 + "\n") +
(profile.child2 == null ? "" : profile.child2 + "\n") + (profile.child2 == null ? "" : profile.child2 + "\n") +
(profile.child1 == null ? "" : profile.child1 + "\n") + (profile.child1 == null ? "" : profile.child1 + "\n") +
(profile.reason == null ? "" : profile.reason), (profile.reason == null ? "" : profile.reason),
position = profile.position != "" && profile.position != null ? profile.position : "-", position = profile.position != "" && profile.position != null
posNo = profile.posNo != "" && profile.posNo != null ? profile.posNo?.ToThaiNumber() : "-", ? profile.position
: "-",
posNo = profile.posNo != "" && profile.posNo != null
? profile.posNo?.ToThaiNumber()
: "-",
reason = profile.reason != "" && profile.reason != null ? profile.reason : "-", reason = profile.reason != "" && profile.reason != null ? profile.reason : "-",
}; };
}).ToList(); }).ToList();
} }
}
string SignDate = retireHistorys.SignDate != null ? DateTime.Parse(retireHistorys.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-"; string SignDate = retireHistorys.SignDate != null ? DateTime.Parse(retireHistorys.SignDate.ToString()).ToThaiFullDate().ToString().ToThaiNumber() : "-";
return new { SignDate, retireHistorys.Detail, retireHistorys.Id, retireHistorys.CreatedAt, Year = retireHistorys.Year.ToThaiYear().ToString().ToThaiNumber(), retireHistorys.Round, retireHistorys.Type, retireHistorys.TypeReport, Total = retireHistorys.Total.ToString().ToThaiNumber(), profiles = mapProfiles }; return new { SignDate, retireHistorys.Detail, retireHistorys.Id, retireHistorys.CreatedAt, Year = retireHistorys.Year.ToThaiYear().ToString().ToThaiNumber(), retireHistorys.Round, retireHistorys.Type, retireHistorys.TypeReport, Total = retireHistorys.Total.ToString().ToThaiNumber(), profiles = mapProfiles };
} }