using Dicom; using System; using Vinno.FIS.Sonopost.Common; using Vinno.FIS.Sonopost.Managers; using Vinno.FIS.Sonopost.Managers.Interfaces; using Vinno.IUS.Common.Log; namespace Vinno.FIS.Sonopost.Features.Dicom { internal class DicomUploadQueue : DicomOperateQueue { private static volatile DicomUploadQueue _instance; private IRemedicalManager _remedicalManager; public static DicomUploadQueue Instance => _instance ?? (_instance = new DicomUploadQueue()); private DicomUploadQueue() : base("DicomUploadQueue") { _remedicalManager = AppManager.Instance.GetManager(); } protected override bool DoWork(DicomFile dicomFile) { var patientId = string.Empty; var patientName = string.Empty; try { patientId = dicomFile.GetPatientId(); patientName = dicomFile.GetPatientName(); //Single picture, almost use 1 second to finish below steps. var newGuid = Guid.NewGuid().ToString("N").ToUpper(); var currentDate = DateTime.Now.Date.ToString("yyyyMMdd"); Logger.WriteLineInfo($"Save to original dicom,PatientId:{patientId},PatientName:{patientName}"); var dicomFilePath = Save(SonopostConstants.OriginalDicomFolder, dicomFile, newGuid, currentDate); var cache = new DicomUploadContext(newGuid, dicomFilePath, patientId, patientName); DicomUploadContextOperator.Instance.Create(cache); Logger.WriteLineInfo($"Convert to vinno dicom,PatientId:{patientId}"); var convertVinnoFileResult = VinnoStorage.Store(newGuid, currentDate, dicomFilePath); DicomUploadContextOperator.Instance.UpdateVidPath(newGuid, convertVinnoFileResult.VidFilePath); Logger.WriteLineInfo($"Convert Vid Status:{convertVinnoFileResult.IsSuccess}"); if (convertVinnoFileResult.IsSuccess) { _remedicalManager.UploadWorkFlow(convertVinnoFileResult.VidFilePath, patientId); } else { DicomUploadContextOperator.Instance.UpdateStatus(newGuid, DicomUploadStatus.ConvertFail); } } catch (Exception e) { Logger.WriteLineInfo($"Upload dicom file error ,PatientId:{patientId},PatientName:{patientName},{e}"); } return true; } protected override bool DoWork(VidInfo vidInfo) { var patientId = string.Empty; var patientName = string.Empty; try { patientId = vidInfo.PatientInfo?.PatientId; patientName = vidInfo.PatientInfo?.LastName; //Single picture, almost use 1 second to finish below steps. var newGuid = Guid.NewGuid().ToString("N").ToUpper(); var currentDate = DateTime.Now.Date.ToString("yyyyMMdd"); Logger.WriteLineInfo($"Save to original vid,PatientId:{patientId},PatientName:{patientName}"); var vidFilePath = Save(SonopostConstants.OriginalVidFolder, vidInfo.VidFilePath, newGuid, currentDate); if (string.IsNullOrEmpty(vidFilePath)) { return false; } vidInfo.VidFilePath = vidFilePath; var cache = new DicomUploadContext(newGuid, vidFilePath, patientId, patientName); DicomUploadContextOperator.Instance.Create(cache); var convertVinnoFileResult = VinnoStorage.Store(newGuid, currentDate, vidInfo); DicomUploadContextOperator.Instance.UpdateVidPath(newGuid, convertVinnoFileResult.VidFilePath); Logger.WriteLineInfo($"Convert Vid Status:{convertVinnoFileResult.IsSuccess}"); if (convertVinnoFileResult.IsSuccess) { _remedicalManager.UploadWorkFlow(convertVinnoFileResult.VidFilePath, patientId); } else { DicomUploadContextOperator.Instance.UpdateStatus(newGuid, DicomUploadStatus.ConvertFail); } } catch (Exception e) { Logger.WriteLineInfo($"Upload dicom file error ,PatientId:{patientId},PatientName:{patientName},{e}"); } return true; } } }