123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System.Collections.Generic;
- using System.Linq;
- using Vinno.vCloud.Report.Interfaces;
- using Vinno.vCloud.Report.Models;
- namespace ReportConverter
- {
- class GenderTranslater
- {
- private readonly IEnumerable<string> _maleList = new List<string> { "男", "雄", "公", "雄性" };
- private readonly IEnumerable<string> _femaleList = new List<string> { "女", "雌", "母", "雌性" };
- private const string Female = "Female";
- private const string Male = "Male";
- /// <summary>
- /// translate gender
- /// </summary>
- /// <param name="reportInfo">report info entity</param>
- public void TranslateGender(ReportInfo reportInfo)
- {
- var genderElement = reportInfo.Template.Blocks.SelectMany(b => b.Elements)
- .FirstOrDefault(e => ElementTag.PatientGender.Equals(e.Tag));
- if (genderElement is SingleSelected singleSelected)
- {
- if (reportInfo.ElementValues.TryGetValue(ElementTag.PatientGender, out var genderValue))
- {
- if (genderValue is TextElementValue textElementValue)
- {
- textElementValue.Value =
- TranslateGenderValueToSelecteItem(textElementValue.Value, singleSelected.Items);
- }
- }
- }
- }
- private string TranslateGenderValueToSelecteItem(string value, List<string> items)
- {
- if (value == Male)
- {
- var matchedValue = items.FirstOrDefault(i => _maleList.Contains(i));
- if (!string.IsNullOrEmpty(matchedValue))
- {
- return matchedValue;
- }
- }
- else if (value == Female)
- {
- var matchedValue = items.FirstOrDefault(i => _femaleList.Contains(i));
- if (!string.IsNullOrEmpty(matchedValue))
- {
- return matchedValue;
- }
- }
- return value;
- }
- }
- }
|