Merge branch 'develop' into working
All checks were successful
Build & Deploy Checkin Service / build (push) Successful in 20s
All checks were successful
Build & Deploy Checkin Service / build (push) Successful in 20s
This commit is contained in:
commit
aed1e8a58d
1 changed files with 60 additions and 0 deletions
|
|
@ -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<TableCell>().Count() == 1 &&
|
||||
rows[0].Elements<TableCell>().First().Elements<Paragraph>().Count() == 1;
|
||||
|
||||
private static bool IsTwoRowPerProfileFormat(List<TableRow> rows) =>
|
||||
rows.Count == 2 &&
|
||||
rows[0].Elements<TableCell>().Count() == 3 &&
|
||||
rows[1].Elements<TableCell>().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<TableRow> 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<object>().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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue