123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using SQLite;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Vinno.FIS.Sonopost.Features.Dicom
- {
- public class DicomUploadContextOperator
- {
- public static DicomUploadContextOperator Instance = new DicomUploadContextOperator();
- private readonly object _locker = new object();
- private DicomUploadContextOperator()
- {
- }
- public DicomUploadContext GetCacheByScanId(string scanDataId)
- {
- lock (_locker)
- {
- return DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.ScanId == scanDataId);
- }
- }
- public DicomUploadContext GetCacheById(string id)
- {
- lock (_locker)
- {
- return DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.Id == id);
- }
- }
- public List<DicomUploadContext> GetAll()
- {
- List<DicomUploadContext> list;
- lock (_locker)
- {
- list = DicomCacheDB.Instance.GetAll<DicomUploadContext>().OrderBy(c => c.CreateTime).ToList();
- }
- list.ForEach(x => x.CreateTime = x.CreateTime.ToLocalTime());
- return list;
- }
- public void Create(DicomUploadContext cache)
- {
- lock (_locker)
- {
- DicomCacheDB.Instance.Create(cache);
- }
- }
- public void UpdateVidPath(string id, string path)
- {
- lock (_locker)
- {
- var existingItem = DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.Id == id);
- if (existingItem != null)
- {
- var tmpPath = existingItem.VidPath;
- existingItem.VidPath = path;
- var ret = DicomCacheDB.Instance.Update(existingItem);
- if (ret == false)
- {
- existingItem.VidPath = tmpPath;
- }
- }
- }
- }
- public void UpdateVidPathByScanId(string scanId, string path)
- {
- lock (_locker)
- {
- var existingItem = DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.ScanId == scanId);
- if (existingItem != null)
- {
- var tmpPath = existingItem.VidPath;
- existingItem.VidPath = path;
- var ret = DicomCacheDB.Instance.Update(existingItem);
- if (ret == false)
- {
- existingItem.VidPath = tmpPath;
- }
- }
- }
- }
- public void UpdateScanId(string id, string scanId)
- {
- lock (_locker)
- {
- var existingItem = DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.Id == id);
- if (existingItem != null)
- {
- var tmp = existingItem.ScanId;
- existingItem.ScanId = scanId;
- var ret = DicomCacheDB.Instance.Update(existingItem);
- if (ret == false)
- {
- existingItem.ScanId = tmp;
- }
- }
- }
- }
- public void UpdateStatus(string id, DicomUploadStatus status)
- {
- lock (_locker)
- {
- var existingItem = DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.Id == id);
- if (existingItem != null)
- {
- var tmp = existingItem.Status;
- existingItem.Status = status;
- var ret = DicomCacheDB.Instance.Update(existingItem);
- if (ret == false)
- {
- existingItem.Status = tmp;
- }
- }
- }
- }
- public void UpdateStatusByScanId(string scanId, DicomUploadStatus status)
- {
- lock (_locker)
- {
- var existingItem = DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.ScanId == scanId);
- if (existingItem != null)
- {
- var tmp = existingItem.Status;
- existingItem.Status = status;
- var ret = DicomCacheDB.Instance.Update(existingItem);
- if (ret == false)
- {
- existingItem.Status = tmp;
- }
- }
- }
- }
- internal void UpdateRetryCount(DicomUploadContext item, int count)
- {
- lock (_locker)
- {
- var existingItem = DicomCacheDB.Instance.Get<DicomUploadContext>(c => c.Id == item.Id);
- if (existingItem != null)
- {
- existingItem.Count = count;
- DicomCacheDB.Instance.Update(existingItem);
- }
- }
- }
- public bool DeleteById(string id)
- {
- lock (_locker)
- {
- var ret = DicomCacheDB.Instance.Delete<DicomUploadContext>(c => c.Id == id);
- return ret;
- }
- }
- public bool DeleteByScanId(string scanId)
- {
- lock (_locker)
- {
- var ret = DicomCacheDB.Instance.Delete<DicomUploadContext>(c => c.ScanId == scanId);
- return ret;
- }
- }
- }
- public enum DicomUploadStatus
- {
- Create,
- ConvertFail,
- CreateScanDataFail,
- UploadFail,
- UploadFailBecauseExamIsFinished,
- Unknown,
- Waiting,
- Uploading,
- Success
- }
- public class DicomUploadContext
- {
- [PrimaryKey]
- public string Id { get; set; }
- public string DicomPath { get; set; }
- public string PatientId { get; set; }
- public string PatientName { get; set; }
- public DateTime CreateTime { get; set; }
- public string VidPath { get; set; }
- public string ScanId { get; set; }
- public DicomUploadStatus Status { get; set; }
- [Ignore]
- public int Count { get; set; }
- public DicomUploadContext()
- {
- }
- public DicomUploadContext(string id, string path, string patientId, string patientName)
- {
- Id = id;
- DicomPath = path;
- PatientId = patientId;
- PatientName = patientName;
- CreateTime = DateTime.UtcNow;
- Status = DicomUploadStatus.Create;
- Count = 0;
- }
- }
- }
|