Browse Source

魔盒截图分时会诊当无名氏的记录已被结束扫查,则会自动创建一个新的记录并上传。

felix 1 year ago
parent
commit
1471870da4

+ 3 - 3
FISSDK/FISIMPL/RemedicalService.cs

@@ -90,7 +90,7 @@ namespace FISIMPL
         /// <param name="fisMeasuredResults">Measure result</param>
         /// <param name="fisCommentResult">Comment result</param>
         /// <returns>scan Data Id</returns>
-        public string UploadScanData(string examId, string workOrderId, string filePath, FISVidType fisVidType, string description, FISPatientScanInfo fisPatientInfo, string examRecordId = null, FISMeasuredResults fisMeasuredResults = null, FISCommentResults fisCommentResult = null)
+        public string UploadScanData(string examId, string workOrderId, string filePath, FISVidType fisVidType, string description, FISPatientScanInfo fisPatientInfo, string examRecordId = null, FISMeasuredResults fisMeasuredResults = null, FISCommentResults fisCommentResult = null, bool canRecreateExamRecord = false)
         {
             try
             {
@@ -134,7 +134,7 @@ namespace FISIMPL
                     var commentResults = FISConverter.ConvertFISCommentResultsToScanImageDTO(fisCommentResult);
                     if (string.IsNullOrWhiteSpace(examRecordId))
                     {
-                        var scanData = _remedicalV2.CreateScanData(examId, workOrderId, filePath, (VidType)fisVidType, description, patientScanInfo, UploadStatus.Idle, measureResults, commentResults);
+                        var scanData = _remedicalV2.CreateScanData(examId, workOrderId, filePath, (VidType)fisVidType, description, patientScanInfo, UploadStatus.Idle, measureResults, commentResults, canRecreateExamRecord);
                         if (scanData == null)
                         {
                             Logger.WriteLineError("Remedical create scan data is null when upload scan data");
@@ -157,7 +157,7 @@ namespace FISIMPL
                     else
                     {
                         var vCloudExamRecord = new vCloudExamRecord(examRecordId, examId, workOrderId);
-                        var scanData = _remedicalV2.CreateScanData(vCloudExamRecord, filePath, (VidType)fisVidType, description, patientScanInfo, UploadStatus.Idle, measureResults, commentResults);
+                        var scanData = _remedicalV2.CreateScanData(vCloudExamRecord, filePath, (VidType)fisVidType, description, patientScanInfo, UploadStatus.Idle, measureResults, commentResults, canRecreateExamRecord);
                         if (scanData == null)
                         {
                             Logger.WriteLineError("Remedical create scan data is null when upload scan data");

+ 1 - 1
FISSDK/FISSDK/Remedical/IRemedicalService.cs

@@ -24,7 +24,7 @@ namespace FISLib.Remedical
         /// <param name="fisMeasuredResults">Measure result</param>
         /// <param name="fisCommentResult">Comment result</param>
         /// <returns>scan Data Id</returns>
-        string UploadScanData(string examId, string workOrderId, string filePath, FISVidType fisVidType, string description, FISPatientScanInfo fisPatientInfo, string examRecordId = null, FISMeasuredResults fisMeasuredResults = null, FISCommentResults fisCommentResult = null);
+        string UploadScanData(string examId, string workOrderId, string filePath, FISVidType fisVidType, string description, FISPatientScanInfo fisPatientInfo, string examRecordId = null, FISMeasuredResults fisMeasuredResults = null, FISCommentResults fisCommentResult = null, bool canRecreateExam = false);
 
         /// <summary>
         /// Re upload scan data file.

+ 3 - 1
Vinno.FIS.Sonopost/Managers/LiveVideoManager.cs

@@ -218,10 +218,11 @@ namespace Vinno.FIS.Sonopost.Managers
                     var examRecordId = _remedicalManager.GetCollcetingRecordCode();
                     if (!string.IsNullOrEmpty(examRecordId))
                     {
+                        Logger.WriteLineInfo($"LiveVideoManager GetCollcetingRecordCode Result is {examRecordId}");
                         var detailInfo = _remedicalManager.GetvCloudExamDetailInfoByExamRecordId(examRecordId);
                         if (detailInfo == null)
                         {
-                            Logger.WriteLineError($"LiveVideoManager GetvCloudExamDetailInfoByExamRecordId Result is null");
+                            Logger.WriteLineError($"LiveVideoManager GetvCloudExamDetailInfoByExamRecordId {examRecordId} Result is null");
                         }
                         else
                         {
@@ -230,6 +231,7 @@ namespace Vinno.FIS.Sonopost.Managers
                                 vidInfo.ExamRecordId = examRecordId;
                                 vidInfo.PatientInfo = detailInfo.PatientScanInfo;
                             }
+                            Logger.WriteLineInfo($"{examRecordId} ExamStatus is {detailInfo.ExamStatus}");
                         }
                     }
                 }

+ 9 - 1
Vinno.FIS.Sonopost/Managers/RemedicalManager.cs

@@ -144,7 +144,15 @@ namespace Vinno.FIS.Sonopost.Managers
                             Logger.WriteLineError($"Upload vinno dicom file failed,Because the Remedical is null.PatientId:{patientId}");
                             return;
                         }
-                        var scanDataId = _fisRemedicalService.UploadScanData(string.Empty, string.Empty, content.UploadFilePath, content.VidType, "FromSonopost", new FISPatientScanInfo(), content.ExamRecordId);
+                        string scanDataId;
+                        if (string.IsNullOrEmpty(content.ExamRecordId))
+                        {
+                            scanDataId = _fisRemedicalService.UploadScanData(string.Empty, string.Empty, content.UploadFilePath, content.VidType, "FromSonopost", new FISPatientScanInfo(), content.ExamRecordId, null, null, true);
+                        }
+                        else
+                        {
+                            scanDataId = _fisRemedicalService.UploadScanData(string.Empty, string.Empty, content.UploadFilePath, content.VidType, "FromSonopost", new FISPatientScanInfo(), content.ExamRecordId, null, null, false);
+                        }
                         if (!string.IsNullOrEmpty(scanDataId))
                         {
                             DicomUploadContextOperator.Instance.UpdateScanId(content.Id, scanDataId);

+ 2 - 2
Vinno.vCloud.Common.FIS/Remedicals/IRemedicalV2.cs

@@ -39,7 +39,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// <param name="patientInfo">The patient info of this data.</param>
         /// <param name="status">Upload status</param>
         /// <returns><see cref="IvCloudScanData"/></returns>
-        IvCloudScanData CreateScanData(IvCloudExamRecord record, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null);
+        IvCloudScanData CreateScanData(IvCloudExamRecord record, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null, bool canRecreateExam = false);
 
         /// <summary>
         /// Create a scan data.
@@ -52,7 +52,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// <param name="examId"></param>
         /// <param name="status">Upload status</param>
         /// <returns><see cref="IvCloudScanData"/></returns>
-        IvCloudScanData CreateScanData(string examId, string workOrderId, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null);
+        IvCloudScanData CreateScanData(string examId, string workOrderId, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null, bool canRecreateExam = false);
 
         /// <summary>
         /// Upload the data to the vCloud server.

+ 17 - 5
Vinno.vCloud.Common.FIS/Remedicals/RemedicalV2.cs

@@ -124,12 +124,12 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// <param name="patientInfo">The patient info of this data.</param>
         /// <param name="status">Upload status</param>
         /// <returns><see cref="IvCloudScanData"/></returns>
-        public IvCloudScanData CreateScanData(IvCloudExamRecord record, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null)
+        public IvCloudScanData CreateScanData(IvCloudExamRecord record, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null, bool canRecreateExamRecord = false)
         {
             try
             {
                 var scanDataId = Guid.NewGuid().ToString("N").ToUpper();
-                var scanData = new vCloudScanDataV2(record, scanDataId, filePath, dataType, description, patientInfo, status, _remedicalService, _storageService, _token, measuredResults, commentResults);
+                var scanData = new vCloudScanDataV2(record, scanDataId, filePath, dataType, description, patientInfo, status, _remedicalService, _storageService, _token, UpdateExamRecordCache, measuredResults, commentResults, canRecreateExamRecord);
                 return scanData;
             }
             catch (Exception ex)
@@ -151,13 +151,13 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// <param name="examId"></param>
         /// <param name="status">Upload status</param>
         /// <returns><see cref="IvCloudScanData" /></returns>
-        public IvCloudScanData CreateScanData(string examId, string workOrderId, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null)
+        public IvCloudScanData CreateScanData(string examId, string workOrderId, string filePath, VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null, bool canRecreateExamRecord = false)
         {
             try
             {
                 var scanDataId = Guid.NewGuid().ToString("N").ToUpper();
                 var record = new vCloudExamRecord(string.Empty, examId, workOrderId);
-                var scanData = new vCloudScanDataV2(record, scanDataId, filePath, dataType, description, patientInfo, status, _remedicalService, _storageService, _token, measuredResults, commentResults);
+                var scanData = new vCloudScanDataV2(record, scanDataId, filePath, dataType, description, patientInfo, status, _remedicalService, _storageService, _token, UpdateExamRecordCache, measuredResults, commentResults, canRecreateExamRecord);
                 return scanData;
             }
             catch (Exception ex)
@@ -283,7 +283,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
                         {
                             continue;
                         }
-                        var scanData = vCloudScanData2Serializer.Deserialize(_remedicalService, _storageService, _token, storeFile);
+                        var scanData = vCloudScanData2Serializer.Deserialize(_remedicalService, _storageService, _token, storeFile, UpdateExamRecordCache);
                         if (scanData != null)
                         {
                             _uploadingScanDatas.AddOrUpdate(scanData.Id, s => scanData, (s, exist) =>
@@ -341,6 +341,18 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
             }
         }
 
+        private void UpdateExamRecordCache(ExamRecordCache examRecordCache)
+        {
+            lock (_examRecordCachesLocker)
+            {
+                var found = _examRecordCaches.FirstOrDefault(x => x.ExamId == examRecordCache.ExamId);
+                if (found != null)
+                {
+                    found.ExamRecordId = examRecordCache.ExamRecordId;
+                }
+            }
+        }
+
         public void Dispose()
         {
             DoDispose();

+ 14 - 5
Vinno.vCloud.Common.FIS/Remedicals/vCloudScanDataSerializerV2.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Text;
 using Vinno.IUS.Common.Configuration;
 using Vinno.IUS.Common.Log;
+using Vinno.vCloud.FIS.CrossPlatform.Common.SQLite;
 using Vinno.vCloud.Protocol.Infrastructures;
 using WingInterfaceLibrary.DTO.Comment;
 using WingInterfaceLibrary.DTO.Measure;
@@ -11,7 +12,7 @@ using WingInterfaceLibrary.Interface;
 
 namespace Vinno.vCloud.Common.FIS.Remedicals
 {
-    static class vCloudScanData2Serializer
+    internal static class vCloudScanData2Serializer
     {
         /// <summary>
         /// Serialize scan data content to a file.
@@ -45,10 +46,10 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
             stringBuilder.AppendLine($"Description = {data.Description}");
 
             //Application
-            stringBuilder.AppendLine($"Description = {data.Application}");
+            stringBuilder.AppendLine($"Application = {data.Application}");
 
             //ApplicationCategory
-            stringBuilder.AppendLine($"Description = {data.ApplicationCategory}");
+            stringBuilder.AppendLine($"ApplicationCategory = {data.ApplicationCategory}");
 
             //FilePath
             stringBuilder.AppendLine($"VidFilePath = {data.VidFilePath}");
@@ -56,6 +57,9 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
             //Status
             stringBuilder.AppendLine($"Status = {data.Status}");
 
+            //CanRecreateExam
+            stringBuilder.AppendLine($"CanRecreateExamRecord = {data.CanRecreateExamRecord}");
+
             //PatientInfo
             var patientInfo = data.PatientInfo;
             if (patientInfo != null)
@@ -85,7 +89,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// <param name="leaf">The leaf to create the scan data.</param>
         /// <param name="scanDataFilePath"></param>
         /// <returns><see cref="vCloudScanData"/></returns>
-        public static vCloudScanDataV2 Deserialize(IRemedicalService remedicalService, IStorageService storageService, string token, string scanDataFilePath)
+        public static vCloudScanDataV2 Deserialize(IRemedicalService remedicalService, IStorageService storageService, string token, string scanDataFilePath, Action<ExamRecordCache> updateExamRecordCache)
         {
             if (File.Exists(scanDataFilePath))
             {
@@ -104,6 +108,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
                     var application = string.Empty;
                     var applicationCategory = string.Empty;
                     var status = UploadStatus.Idle;
+                    bool canRecreateExam = false;
                     var patientInfo = new PatientScanInfo();
                     MeasuredResultsDTO measuredResults = null;
                     ScanImageDTO commentResults = null;
@@ -149,6 +154,10 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
                                                 Enum.TryParse(item.Value, out status);
                                                 break;
 
+                                            case "CanRecreateExamRecord":
+                                                bool.TryParse(item.Value, out canRecreateExam);
+                                                break;
+
                                             case "ExamRecordId":
                                                 examRecordId = item.Value;
                                                 break;
@@ -175,7 +184,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
                         }
                     }
                     var record = new vCloudExamRecord(examRecordId, examId, workOrderId);
-                    var scanData = new vCloudScanDataV2(record, id, filePath, dataType, description, patientInfo, status, remedicalService, storageService, token, measuredResults, commentResults);
+                    var scanData = new vCloudScanDataV2(record, id, filePath, dataType, description, patientInfo, status, remedicalService, storageService, token, updateExamRecordCache, measuredResults, commentResults, canRecreateExam);
                     return scanData;
                 }
                 catch (Exception ex)

+ 47 - 8
Vinno.vCloud.Common.FIS/Remedicals/vCloudScanDataV2.cs

@@ -7,6 +7,7 @@ using Vinno.IUS.Common.Log;
 using Vinno.vCloud.Common.FIS.Helper;
 using Vinno.vCloud.Common.Vid2;
 using Vinno.vCloud.FIS.CrossPlatform.Common.Helper;
+using Vinno.vCloud.FIS.CrossPlatform.Common.SQLite;
 using Vinno.vCloud.Protocol.Infrastructures;
 using WingInterfaceLibrary.DTO.Comment;
 using WingInterfaceLibrary.DTO.Measure;
@@ -29,6 +30,7 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         private const string BreastImageLocation = "BreastImageLocation";
         private const string LiverImageLocation = "LiverImageLocation";
         private const string ThyroidImageLocation = "ThyroidImageLocation";
+        private Action<ExamRecordCache> _updateExamRecordCache;
 
         /// <inheritdoc />
         /// <summary>
@@ -135,8 +137,10 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// </summary>
         public ScanImageDTO CommentResults { get; }
 
+        public bool CanRecreateExamRecord { get; }
+
         public vCloudScanDataV2(IvCloudExamRecord record, string id, string vidFilePath,
-            VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, IRemedicalService remedicalService, IStorageService storageService, string token, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null)
+            VidType dataType, string description, PatientScanInfo patientInfo, UploadStatus status, IRemedicalService remedicalService, IStorageService storageService, string token, Action<ExamRecordCache> updateExamRecordCache, MeasuredResultsDTO measuredResults = null, ScanImageDTO commentResults = null, bool canModifyExamRecordId = false)
         {
             _status = status;
             _token = token;
@@ -151,6 +155,8 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
             PatientInfo = patientInfo;
             MeasuredResults = measuredResults;
             CommentResults = commentResults;
+            CanRecreateExamRecord = canModifyExamRecordId;
+            _updateExamRecordCache = updateExamRecordCache;
             //Generate files.
             VidFilePath = GetVidFilePath(_status);
             if (string.Compare(VidFilePath, vidFilePath, StringComparison.OrdinalIgnoreCase) != 0)
@@ -401,13 +407,44 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
             {
                 if (result.ErrorCode == 4002)
                 {
-                    Status = UploadStatus.FailBecauseExamIsFinished;
-                    Save();
-                    return;
+                    if (!CanRecreateExamRecord)
+                    {
+                        Status = UploadStatus.FailBecauseExamIsFinished;
+                        Save();
+                        return;
+                    }
+                    else
+                    {
+                        if (CreateExamRecord(string.Empty, out var newExamRecordId))
+                        {
+                            ExamRecordId = newExamRecordId;
+                            uploadExamDataRequest.ExamCode = ExamRecordId;
+                            var examRecordCache = new ExamRecordCache(ExamId, newExamRecordId, WorkOrderId);
+                            _updateExamRecordCache(examRecordCache);
+                            result = JsonRpcHelper.UploadExamData(_remedicalService, uploadExamDataRequest);
+                            if (result == null)
+                            {
+                                throw new InvalidDataException($"JsonRPCHelper UploadExamData Result is null");
+                            }
+                            else if (result.IsSuccess)
+                            {
+                                Status = UploadStatus.Uploaded;
+                                return;
+                            }
+                            else
+                            {
+                                throw new InvalidDataException($"JsonRPCHelper UploadExamData Fail,Error Code is {result.ErrorCode}");
+                            }
+                        }
+                        else
+                        {
+                            throw new InvalidDataException($"JsonRPCHelper UploadExamData Fail:FailBecauseExamIsFinished and ReCreateExamRecord Result is false");
+                        }
+                    }
                 }
                 else if (result.ErrorCode == 4015)
                 {
-                    if (CreateExamRecord())
+                    if (CreateExamRecord(ExamRecordId, out var newExamRecordId) && ExamRecordId == newExamRecordId)
                     {
                         result = JsonRpcHelper.UploadExamData(_remedicalService, uploadExamDataRequest);
                         if (result == null)
@@ -498,23 +535,25 @@ namespace Vinno.vCloud.Common.FIS.Remedicals
         /// <param name="workOrderId">The workerId</param>
         /// <param name="patientInfo">The patient basic info for creating the exam record.</param>
         /// <returns><see cref="T:Vinno.vCloud.Terminal.Remedicals.IvCloudExamRecord" /></returns>
-        public bool CreateExamRecord()
+        public bool CreateExamRecord(string examRecordId, out string newExamRecordId)
         {
             var createExaminfoRequest = new CreateExaminfoRequest
             {
                 Token = _token,
                 PatientType = vCloudServerConfig.Instance.PatientType.ToString(),
-                ExamRecordCode = ExamRecordId,
+                ExamRecordCode = examRecordId,
                 PatientInfo = DTOConverter.RenderPatientInfo(PatientInfo),
                 PatientScanInfoList = DTOConverter.RenderPatientScanInfo(PatientInfo),
             };
             CreateExaminfoResult result = JsonRpcHelper.CreateExamInfo(_remedicalService, createExaminfoRequest);
-            if (result == null || result.ExamCode != ExamRecordId)
+            if (result == null || string.IsNullOrEmpty(result.ExamCode))
             {
+                newExamRecordId = string.Empty;
                 return false;
             }
             else
             {
+                newExamRecordId = result.ExamCode;
                 return true;
             }
         }