From f68eae81200587eadd8a4a3525371636d9f375a3 Mon Sep 17 00:00:00 2001 From: moss <> Date: Fri, 4 Apr 2025 10:55:16 +0700 Subject: [PATCH] reportreire --- .../Reports/RetireReportRepository.cs | 132 ++++++++++++++---- 1 file changed, 103 insertions(+), 29 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs index 48abbadd..900427cf 100644 --- a/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Reports/RetireReportRepository.cs @@ -157,39 +157,113 @@ namespace BMA.EHR.Application.Repositories.Reports profiles = profiles.OrderBy(x => x.order).ToList(); } var mapProfiles = new List(); - // string previousRoot = null; - // string previousPosTypeName = null; - // string previousPosLevelName = null; + string previousRoot = null; + string previousChild1 = null; + string previousPosTypeName = null; + string previousPosLevelName = null; if (profiles.Count > 0) { - mapProfiles = profiles - // .OrderBy(x => rootOrder.ToObject>().IndexOf(x.root)) - // .ThenBy(x => posTypeNameOrder.ToObject>().IndexOf(x.posTypeName ?? "")) - // .ThenBy(x => posLevelNameOrder.ToObject>().IndexOf(x.posLevelName ?? "")) - .Select((profile, index) => + if (retireHistorys.TypeReport == null) { - // 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 + profiles = profiles.OrderBy(x => rootOrder.ToObject>().IndexOf(x.root)) + .ThenBy(x => child1Order.ToObject>().IndexOf(x.child1 ?? "")) + .ThenBy(x => child2Order.ToObject>().IndexOf(x.child2 ?? "")) + .ThenBy(x => child3Order.ToObject>().IndexOf(x.child3 ?? "")) + .ThenBy(x => child4Order.ToObject>().IndexOf(x.child4 ?? "")) + .ThenBy(x => posTypeNameOrder.ToObject>().IndexOf(x.posTypeName ?? "")) + .ThenBy(x => posLevelNameOrder.ToObject>().IndexOf(x.posLevelName ?? "")).ToList(); + mapProfiles = profiles.Select((profile, index) => { - order = retireHistorys.TypeReport == null ? (index + 1).ToString().ToThaiNumber() : $"{(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 + "\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(); + 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>() + .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>() + .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 + // .OrderBy(x => rootOrder.ToObject>().IndexOf(x.root)) + // .ThenBy(x => posTypeNameOrder.ToObject>().IndexOf(x.posTypeName ?? "")) + // .ThenBy(x => posLevelNameOrder.ToObject>().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; + 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 = "", + 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), + 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(); + } } 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 };