123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<IRemedicalManager>();
- }
- 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;
- }
- }
- }
|