PatientScanInfoHelper.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Dicom;
  2. using FISLib.Remedical;
  3. using System;
  4. using System.Text.RegularExpressions;
  5. using Vinno.IUS.Common.Log;
  6. namespace Vinno.FIS.Sonopost.Features.Dicom
  7. {
  8. internal class PatientScanInfoHelper
  9. {
  10. /// <summary>
  11. /// Create patient scan info
  12. /// </summary>
  13. /// <param name="dataset">Dicom dataset.</param>
  14. /// <returns>Patient scan info.</returns>
  15. public static FISPatientScanInfo CreatePatientScanInfo(DicomDataset dataset)
  16. {
  17. var patientScanInfo = new FISPatientScanInfo();
  18. try
  19. {
  20. var patientName = dataset.GetSingleValueOrDefault(DicomTag.PatientName, "Unknown");
  21. var patientGender = dataset.GetSingleValueOrDefault(DicomTag.PatientSex, "Unknown");
  22. var patientId = dataset.GetSingleValueOrDefault(DicomTag.PatientID, string.Empty);
  23. var patientBirthdayDate = GetPatientBirthDate(dataset);
  24. AssignPatientName(patientName, patientScanInfo);
  25. AssignPatientGender(patientGender, patientScanInfo);
  26. AssignPatientCommonInfo(patientId, patientBirthdayDate, patientScanInfo);
  27. }
  28. catch (Exception e)
  29. {
  30. Logger.WriteLineError($"CreatePatientScanInfo Error:{e}");
  31. }
  32. return patientScanInfo;
  33. }
  34. private static DateTime GetPatientBirthDate(DicomDataset dataset)
  35. {
  36. try
  37. {
  38. if (dataset.Contains(DicomTag.PatientBirthDate))
  39. {
  40. return dataset.GetSingleValueOrDefault(DicomTag.PatientBirthDate, DateTime.MinValue);
  41. }
  42. }
  43. catch (Exception e)
  44. {
  45. string result = "";
  46. dataset.TryGetString(DicomTag.PatientBirthDate, out result);
  47. Logger.WriteLineError($"Get Patient BirthData Error,{result}:{e}");
  48. }
  49. return DateTime.MinValue;
  50. }
  51. private static void AssignPatientCommonInfo(string patientId, DateTime birthdayDate, FISPatientScanInfo patientScanInfo)
  52. {
  53. if (birthdayDate != DateTime.MinValue && birthdayDate.ToString("yyyyMMdd") != DateTime.Now.ToString("yyyyMMdd"))
  54. {
  55. patientScanInfo.Birthday = birthdayDate;
  56. patientScanInfo.AgeUnit = FISAgeUnit.Year;
  57. patientScanInfo.AgeYears = (DateTime.Now - birthdayDate).Days / 365;
  58. }
  59. patientScanInfo.PatientId = patientId;
  60. }
  61. private static void AssignPatientGender(string gender, FISPatientScanInfo patientScanInfo)
  62. {
  63. if (gender == "M")
  64. {
  65. patientScanInfo.IsMale = true;
  66. }
  67. else if (gender == "F")
  68. {
  69. patientScanInfo.IsMale = false;
  70. }
  71. else
  72. {
  73. patientScanInfo.IsMale = null;
  74. }
  75. }
  76. private static void AssignPatientName(string name, FISPatientScanInfo patientScanInfo)
  77. {
  78. var tempName = name.Replace("^", " ");
  79. if (IsContainChinese(tempName))
  80. {
  81. patientScanInfo.LastName = tempName.Trim();
  82. return;
  83. }
  84. var chars = name.Split('^');
  85. if (chars.Length > 1)
  86. {
  87. patientScanInfo.FirstName = chars[0];
  88. if (chars.Length >= 3)
  89. {
  90. patientScanInfo.LastName = chars[1] + chars[2];
  91. }
  92. else
  93. {
  94. patientScanInfo.LastName = chars[1];
  95. }
  96. return;
  97. }
  98. patientScanInfo.LastName = chars[0];
  99. }
  100. private static bool IsContainChinese(string name)
  101. {
  102. var reg = new Regex(@"[\u4e00-\u9fa5]");
  103. return reg.IsMatch(name);
  104. }
  105. }
  106. }