123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using Dicom;
- using FISLib.Remedical;
- using System;
- using System.Text.RegularExpressions;
- using Vinno.IUS.Common.Log;
- namespace Vinno.FIS.Sonopost.Features.Dicom
- {
- internal class PatientScanInfoHelper
- {
- /// <summary>
- /// Create patient scan info
- /// </summary>
- /// <param name="dataset">Dicom dataset.</param>
- /// <returns>Patient scan info.</returns>
- public static FISPatientScanInfo CreatePatientScanInfo(DicomDataset dataset)
- {
- var patientScanInfo = new FISPatientScanInfo();
- try
- {
- var patientName = dataset.GetSingleValueOrDefault(DicomTag.PatientName, "Unknown");
- var patientGender = dataset.GetSingleValueOrDefault(DicomTag.PatientSex, "Unknown");
- var patientId = dataset.GetSingleValueOrDefault(DicomTag.PatientID, string.Empty);
- var patientBirthdayDate = GetPatientBirthDate(dataset);
- AssignPatientName(patientName, patientScanInfo);
- AssignPatientGender(patientGender, patientScanInfo);
- AssignPatientCommonInfo(patientId, patientBirthdayDate, patientScanInfo);
- }
- catch (Exception e)
- {
- Logger.WriteLineError($"CreatePatientScanInfo Error:{e}");
- }
- return patientScanInfo;
- }
- private static DateTime GetPatientBirthDate(DicomDataset dataset)
- {
- try
- {
- if (dataset.Contains(DicomTag.PatientBirthDate))
- {
- return dataset.GetSingleValueOrDefault(DicomTag.PatientBirthDate, DateTime.MinValue);
- }
- }
- catch (Exception e)
- {
- string result = "";
- dataset.TryGetString(DicomTag.PatientBirthDate, out result);
- Logger.WriteLineError($"Get Patient BirthData Error,{result}:{e}");
- }
- return DateTime.MinValue;
- }
- private static void AssignPatientCommonInfo(string patientId, DateTime birthdayDate, FISPatientScanInfo patientScanInfo)
- {
- if (birthdayDate != DateTime.MinValue && birthdayDate.ToString("yyyyMMdd") != DateTime.Now.ToString("yyyyMMdd"))
- {
- patientScanInfo.Birthday = birthdayDate;
- patientScanInfo.AgeUnit = FISAgeUnit.Year;
- patientScanInfo.AgeYears = (DateTime.Now - birthdayDate).Days / 365;
- }
- patientScanInfo.PatientId = patientId;
- }
- private static void AssignPatientGender(string gender, FISPatientScanInfo patientScanInfo)
- {
- if (gender == "M")
- {
- patientScanInfo.IsMale = true;
- }
- else if (gender == "F")
- {
- patientScanInfo.IsMale = false;
- }
- else
- {
- patientScanInfo.IsMale = null;
- }
- }
- private static void AssignPatientName(string name, FISPatientScanInfo patientScanInfo)
- {
- var tempName = name.Replace("^", " ");
- if (IsContainChinese(tempName))
- {
- patientScanInfo.LastName = tempName.Trim();
- return;
- }
- var chars = name.Split('^');
- if (chars.Length > 1)
- {
- patientScanInfo.FirstName = chars[0];
- if (chars.Length >= 3)
- {
- patientScanInfo.LastName = chars[1] + chars[2];
- }
- else
- {
- patientScanInfo.LastName = chars[1];
- }
- return;
- }
- patientScanInfo.LastName = chars[0];
- }
- private static bool IsContainChinese(string name)
- {
- var reg = new Regex(@"[\u4e00-\u9fa5]");
- return reg.IsMatch(name);
- }
- }
- }
|