From b5025c382f48ba664cbce3c979f31187696174b0 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 30 Apr 2026 14:24:42 +0700 Subject: [PATCH] =?UTF-8?q?fix=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=93=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=83=E0=B8=AB=E0=B9=89?= =?UTF-8?q?=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=AA=E0=B8=B3=E0=B8=99?= =?UTF-8?q?=E0=B8=B1=E0=B8=81=20#2261?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/RetirementReportService.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/BMA.EHR.Retirement.Service/Services/RetirementReportService.cs b/BMA.EHR.Retirement.Service/Services/RetirementReportService.cs index 82bf2b27..48e301be 100644 --- a/BMA.EHR.Retirement.Service/Services/RetirementReportService.cs +++ b/BMA.EHR.Retirement.Service/Services/RetirementReportService.cs @@ -126,6 +126,10 @@ namespace BMA.EHR.Retirement.Service.Services if (IsSingleParagraphFormat(rows)) return new SingleParagraphTableStrategy(); + // retire-1 format: 2 rows, 3 columns (root row + data row per profile) + if (IsTwoRowPerProfileFormat(rows)) + return new TwoRowPerProfileTableStrategy(); + // retire-3 format: 2+ rows (header + template) return new MultiRowTableStrategy(); } @@ -135,6 +139,11 @@ namespace BMA.EHR.Retirement.Service.Services rows[0].Elements().Count() == 1 && rows[0].Elements().First().Elements().Count() == 1; + private static bool IsTwoRowPerProfileFormat(List rows) => + rows.Count == 2 && + rows[0].Elements().Count() == 3 && + rows[1].Elements().Count() == 3; + #endregion #region PDF Conversion @@ -634,5 +643,56 @@ namespace BMA.EHR.Retirement.Service.Services } } + internal class TwoRowPerProfileTableStrategy : ITableStrategy + { + public void Process(Table table, List rows, System.Collections.IEnumerable profiles) + { + // retire-1 format: 2 rows per profile (root row + data row) + var rootRow = rows[0]; + var dataRow = rows[1]; + + // Remove template rows from table + rootRow.Remove(); + dataRow.Remove(); + + var profileList = profiles.Cast().ToList(); + + foreach (var profile in profileList) + { + var props = profile.GetType() + .GetProperties() + .Where(p => p.GetIndexParameters().Length == 0) + .ToList(); + + // Check root value - skip root row if empty or null + var rootValue = props.FirstOrDefault(p => p.Name.Equals("root", StringComparison.OrdinalIgnoreCase)) + ?.GetValue(profile)?.ToString() ?? string.Empty; + + // Clone root row and fill with placeholders (only if root has value) + if (!string.IsNullOrWhiteSpace(rootValue)) + { + var newRootRow = (TableRow)rootRow.CloneNode(true); + foreach (var prop in props) + { + var value = prop.GetValue(profile)?.ToString() ?? string.Empty; + var placeholder = $"{{{{{prop.Name}}}}}"; + TextReplacer.ReplaceInRow(newRootRow, placeholder, value); + } + table.AppendChild(newRootRow); + } + + // Clone data row and fill with placeholders (always show) + var newDataRow = (TableRow)dataRow.CloneNode(true); + foreach (var prop in props) + { + var value = prop.GetValue(profile)?.ToString() ?? string.Empty; + var placeholder = $"{{{{{prop.Name}}}}}"; + TextReplacer.ReplaceInRow(newDataRow, placeholder, value); + } + table.AppendChild(newDataRow); + } + } + } + #endregion }