Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. using Softek.Cls.Impl.Kaiser.Util;
  5. using Softek.Nigiri;
  6. using Softek.Nigiri.Clinical.Processing.Model;
  7.  
  8. namespace Softek.Cls.Impl.Kaiser.Processors.RadiologyExam.ModelTransforms
  9. {
  10. public class ExtractRadAndDatesFromReport : IModelTransform
  11. {
  12. private static readonly Regex radRegex = new Regex(@"<br>\s*(?<name>.(?:(?<!(?: |: |\<br\>)).)+?)\u0020*(?:M\.?D\.?|D\.?O\.?)\<br\>(?:&nbsp;)?\<br\>DD:\s*(?<DictatedDate>\d{1,2}/\d{1,2}/\d{4})?\s*DT:\s*(?<Month>\d{1,2})/(?<Day>\d{1,2})/(?<Year>\d{4})",
  13. RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
  14.  
  15. private static readonly Regex newRadRegex = new Regex(@"Electronically Signed by:\s*(?<name>[A-Za-z]*\s*[A-Za-z]*\s*(?:(\(?(?:M\.?D\.?|D\.?O\.?)\)?))\s*[A-Za-z]*)\s*on\s*(?<Month>\d{1,2})/(?<Day>\d{1,2})/(?<Year>\d{2,4})(<br>)*\s*(?<Hour>\d{1,2}):(?<Minute>\d{1,2})[\\n\\r<br> ]*(?<TimePeriod>(AM|PM))",
  16. RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
  17.  
  18. private static readonly Regex addendumRegex = new Regex(@"<!--\s*IDXRADR:ADDEND:END\s*-->",
  19. RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
  20.  
  21. public void Transform(IDocument model)
  22. {
  23. string report = model["report_text"];
  24.  
  25. if (string.IsNullOrEmpty(report))
  26. return;
  27.  
  28. SigningInfo si = GetSigningInfo(report);
  29. if (si != null)
  30. {
  31. string currentStatus = model["status"];
  32.  
  33. if (currentStatus == "Dictated" || currentStatus == "Transcribed")
  34. {
  35. SetDictatedBy(model, si);
  36. model["dictateddate"] = si.Date.ToZuluString();
  37. model["transcribeddate"] = si.Date.ToZuluString();
  38. }
  39.  
  40. if (currentStatus == "Finalized")
  41. {
  42. if (model["addendumstatus"] == "addended")
  43. {
  44. string originalReport = GetOriginalReport(report);
  45. if (originalReport != null)
  46. {
  47. SigningInfo originalSigning = GetSigningInfo(originalReport);
  48. if (originalSigning != null)
  49. {
  50. SetDictatedBy(model, originalSigning);
  51. SetFinalizedBy(model, originalSigning);
  52.  
  53. model["dictateddate"] = originalSigning.Date.ToZuluString();
  54. model["transcribeddate"] = originalSigning.Date.ToZuluString();
  55. model["finalizeddate"] = originalSigning.Date.ToZuluString();
  56.  
  57. }
  58. }
  59. SetLastAddendedBy(model, si);
  60. model["addendeddate"] = si.Date.ToZuluString();
  61. }
  62. else
  63. {
  64. SetDictatedBy(model, si);
  65. SetFinalizedBy(model, si);
  66.  
  67. model["dictateddate"] = si.Date.ToZuluString();
  68. model["transcribeddate"] = si.Date.ToZuluString();
  69. model["finalizeddate"] = si.Date.ToZuluString();
  70. }
  71.  
  72. }
  73.  
  74. }
  75. }
  76.  
  77. private void SetDictatedBy(IDocument model, SigningInfo rad)
  78. {
  79. model["dictatedbyproviderid"] = rad.Id;
  80. model["dictatedby"] = rad.LastName.ToUpper() + ", " + rad.FirstName.ToUpper();
  81. model["dictatedbyfirstname"] = rad.FirstName.ToUpper();
  82. model["dictatedbylastname"] = rad.LastName.ToUpper();
  83. }
  84.  
  85. private void SetFinalizedBy(IDocument model, SigningInfo rad)
  86. {
  87. model["finalizedbyproviderid"] = rad.Id;
  88. model["finalizedby"] = rad.LastName.ToUpper() + ", " + rad.FirstName.ToUpper();
  89. model["finalizedbyfirstname"] = rad.FirstName.ToUpper();
  90. model["finalizedbylastname"] = rad.LastName.ToUpper();
  91. }
  92.  
  93. private void SetLastAddendedBy(IDocument model, SigningInfo rad)
  94. {
  95. model["lastaddendedbyid"] = rad.Id;
  96. model["lastaddendedby"] = rad.LastName.ToUpper() + ", " + rad.FirstName.ToUpper();
  97. }
  98.  
  99. private SigningInfo GetSigningInfo(string text)
  100. {
  101. SigningInfo retVal = null;
  102.  
  103. Match match = radRegex.Match(text);
  104.  
  105. if (match.Success)
  106. {
  107. retVal = GetSigningInfo(retVal, match);
  108. var month = match.Groups["Month"].Value.Trim();
  109. var day = match.Groups["Day"].Value.Trim();
  110. var year = match.Groups["Year"].Value.Trim();
  111. retVal.Date = new DateTimeOffset(
  112. new DateTime(int.Parse(year), int.Parse(month), int.Parse(day),
  113. 0, 0, 0, DateTimeKind.Local));
  114. }
  115. var newMatch = newRadRegex.Match(text);
  116. if (newMatch.Success)
  117. {
  118. retVal = GetSigningInfo(retVal, match);
  119. retVal.Date = new DateTimeOffset(DateTime.Parse(BuildDateTimeString(newMatch)));
  120. }
  121. return retVal;
  122. }
  123.  
  124. private static string BuildDateTimeString(Match match)
  125. {
  126. var builder = new StringBuilder();
  127. builder.Append(match.Groups["Month"].Value.Trim());
  128. builder.Append("/");
  129. builder.Append(match.Groups["Day"].Value.Trim());
  130. builder.Append("/");
  131. builder.Append(match.Groups["Year"].Value.Trim());
  132. builder.Append(" ");
  133. builder.Append(match.Groups["Hour"].Value.Trim());
  134. builder.Append(":");
  135. builder.Append(match.Groups["Minute"].Value.Trim());
  136. builder.Append(" ");
  137. builder.Append(match.Groups["TimePeriod"].Value.Trim());
  138. return builder.ToString();
  139. }
  140.  
  141. private static SigningInfo GetSigningInfo(SigningInfo retVal, Match match)
  142. {
  143. retVal = new SigningInfo();
  144. string rad = match.Groups["name"].Value.Trim();
  145.  
  146. string ln = string.Empty;
  147. string fn = string.Empty;
  148. int index = rad.IndexOf(',');
  149. if (index > -1)
  150. {
  151. ln = rad.Substring(0, index);
  152. fn = rad.Substring(index + 1);
  153. }
  154.  
  155. if (index < 0)
  156. {
  157. index = rad.LastIndexOf(" ");
  158. if (index < 0)
  159. {
  160. ln = rad;
  161. fn = "Unknown";
  162. }
  163. else
  164. {
  165. fn = rad.Substring(0, index);
  166. ln = rad.Substring(index + 1);
  167. }
  168. }
  169.  
  170. char[] trimmedChars = {',', ' '};
  171. retVal.FirstName = fn.Trim(trimmedChars);
  172. retVal.LastName = ln.Trim(trimmedChars);
  173.  
  174. // Find DT date
  175.  
  176. return retVal;
  177. }
  178.  
  179.  
  180. private string GetOriginalReport(string text)
  181. {
  182. Match match = addendumRegex.Match(text);
  183.  
  184. int index = -1;
  185. while (match.Success)
  186. {
  187. index = match.Index + match.Value.Length;
  188. match = match.NextMatch();
  189. }
  190.  
  191. if (index < 0)
  192. return null;
  193.  
  194. return text.Substring(index);
  195. }
  196.  
  197. private class SigningInfo
  198. {
  199. public string Id
  200. {
  201. get{ return (uint.MaxValue + (LastName + "|" + FirstName).GetHashCode()).ToString(); }
  202. }
  203. public string FirstName { get; set; }
  204. public string LastName { get; set; }
  205. public DateTimeOffset? Date { get; set; }
  206. }
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement