DicomUploadQueue.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using Dicom;
  2. using System;
  3. using Vinno.FIS.Sonopost.Common;
  4. using Vinno.FIS.Sonopost.Managers;
  5. using Vinno.FIS.Sonopost.Managers.Interfaces;
  6. using Vinno.IUS.Common.Log;
  7. namespace Vinno.FIS.Sonopost.Features.Dicom
  8. {
  9. internal class DicomUploadQueue : DicomOperateQueue
  10. {
  11. private static volatile DicomUploadQueue _instance;
  12. private IRemedicalManager _remedicalManager;
  13. public static DicomUploadQueue Instance => _instance ?? (_instance = new DicomUploadQueue());
  14. private DicomUploadQueue() : base("DicomUploadQueue")
  15. {
  16. _remedicalManager = AppManager.Instance.GetManager<IRemedicalManager>();
  17. }
  18. protected override bool DoWork(DicomFile dicomFile)
  19. {
  20. var patientId = string.Empty;
  21. var patientName = string.Empty;
  22. try
  23. {
  24. patientId = dicomFile.GetPatientId();
  25. patientName = dicomFile.GetPatientName();
  26. //Single picture, almost use 1 second to finish below steps.
  27. var newGuid = Guid.NewGuid().ToString("N").ToUpper();
  28. var currentDate = DateTime.Now.Date.ToString("yyyyMMdd");
  29. Logger.WriteLineInfo($"Save to original dicom,PatientId:{patientId},PatientName:{patientName}");
  30. var dicomFilePath = Save(SonopostConstants.OriginalDicomFolder, dicomFile, newGuid, currentDate);
  31. var cache = new DicomUploadContext(newGuid, dicomFilePath, patientId, patientName);
  32. DicomUploadContextOperator.Instance.Create(cache);
  33. Logger.WriteLineInfo($"Convert to vinno dicom,PatientId:{patientId}");
  34. var convertVinnoFileResult = VinnoStorage.Store(newGuid, currentDate, dicomFilePath);
  35. DicomUploadContextOperator.Instance.UpdateVidPath(newGuid, convertVinnoFileResult.VidFilePath);
  36. Logger.WriteLineInfo($"Convert Vid Status:{convertVinnoFileResult.IsSuccess}");
  37. if (convertVinnoFileResult.IsSuccess)
  38. {
  39. _remedicalManager.UploadWorkFlow(convertVinnoFileResult.VidFilePath, patientId);
  40. }
  41. else
  42. {
  43. DicomUploadContextOperator.Instance.UpdateStatus(newGuid, DicomUploadStatus.ConvertFail);
  44. }
  45. }
  46. catch (Exception e)
  47. {
  48. Logger.WriteLineInfo($"Upload dicom file error ,PatientId:{patientId},PatientName:{patientName},{e}");
  49. }
  50. return true;
  51. }
  52. protected override bool DoWork(VidInfo vidInfo)
  53. {
  54. var patientId = string.Empty;
  55. var patientName = string.Empty;
  56. try
  57. {
  58. patientId = vidInfo.PatientInfo?.PatientId;
  59. patientName = vidInfo.PatientInfo?.LastName;
  60. //Single picture, almost use 1 second to finish below steps.
  61. var newGuid = Guid.NewGuid().ToString("N").ToUpper();
  62. var currentDate = DateTime.Now.Date.ToString("yyyyMMdd");
  63. Logger.WriteLineInfo($"Save to original vid,PatientId:{patientId},PatientName:{patientName}");
  64. var vidFilePath = Save(SonopostConstants.OriginalVidFolder, vidInfo.VidFilePath, newGuid, currentDate);
  65. if (string.IsNullOrEmpty(vidFilePath))
  66. {
  67. return false;
  68. }
  69. vidInfo.VidFilePath = vidFilePath;
  70. var cache = new DicomUploadContext(newGuid, vidFilePath, patientId, patientName);
  71. DicomUploadContextOperator.Instance.Create(cache);
  72. var convertVinnoFileResult = VinnoStorage.Store(newGuid, currentDate, vidInfo);
  73. DicomUploadContextOperator.Instance.UpdateVidPath(newGuid, convertVinnoFileResult.VidFilePath);
  74. Logger.WriteLineInfo($"Convert Vid Status:{convertVinnoFileResult.IsSuccess}");
  75. if (convertVinnoFileResult.IsSuccess)
  76. {
  77. _remedicalManager.UploadWorkFlow(convertVinnoFileResult.VidFilePath, patientId);
  78. }
  79. else
  80. {
  81. DicomUploadContextOperator.Instance.UpdateStatus(newGuid, DicomUploadStatus.ConvertFail);
  82. }
  83. }
  84. catch (Exception e)
  85. {
  86. Logger.WriteLineInfo($"Upload dicom file error ,PatientId:{patientId},PatientName:{patientName},{e}");
  87. }
  88. return true;
  89. }
  90. }
  91. }