From 8081b33a97f3761caa528ea7a8f27f69aa9a5d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E9=A3=9E?= Date: Thu, 18 Jan 2024 11:17:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=B7=BB=E5=8A=A0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/oss.js | 23 +- .../components/uploadDicomFiles2.vue | 366 +++++++++--------- 2 files changed, 211 insertions(+), 178 deletions(-) diff --git a/src/utils/oss.js b/src/utils/oss.js index 4c88c6b4..569c41e1 100644 --- a/src/utils/oss.js +++ b/src/utils/oss.js @@ -24,7 +24,28 @@ async function ossGenerateSTS() { switch (res.Result.ObjectStoreUse) { case 'AliyunOSS': Vue.prototype.OSSclientConfig.bucket = Vue.prototype.OSSclientConfig.bucketName - Vue.prototype.OSSclient = new OSS(Vue.prototype.OSSclientConfig) + let OSSclient = new OSS(Vue.prototype.OSSclientConfig) + Vue.prototype.OSSclient = { + put: function (objectName, object) { + return new Promise(async (resolve, reject) => { + try { + objectName = objectName + '_' + new Date().getTime() + let res = await OSSclient.put(objectName, object) + if (res && res.url) { + resolve({ + name: objectName, + url: Vue.prototype.OSSclientConfig.viewEndpoint + objectName + }) + } else { + reject() + } + } catch (e) { + console.log(e) + reject() + } + }) + } + } break case 'MinIO': let minioClient = new Minio.Client(Vue.prototype.OSSclientConfig); diff --git a/src/views/trials/trials-panel/visit/crc-upload/components/uploadDicomFiles2.vue b/src/views/trials/trials-panel/visit/crc-upload/components/uploadDicomFiles2.vue index c0fcb514..fda34ed1 100644 --- a/src/views/trials/trials-panel/visit/crc-upload/components/uploadDicomFiles2.vue +++ b/src/views/trials/trials-panel/visit/crc-upload/components/uploadDicomFiles2.vue @@ -1021,195 +1021,207 @@ export default { archiveStudy(index, config) { var scope = this return new Promise(function(resolve, reject) { - preArchiveDicomStudy({ - trialId: scope.trialId, - siteId: scope.data.SiteId, - subjectId: scope.subjectId, - subjectVisitId: scope.subjectVisitId, - // failedFileCount: scope.uploadQueues[index].dicomInfo.failedFileCount, - fileSize: scope.uploadQueues[index].dicomInfo.fileSize, - fileCount: scope.uploadQueues[index].dicomInfo.fileCount, - IsDicomReUpload: scope.uploadQueues[index].uploadState.AllowReUpload - }).then(async res => { - let dicomInfo = scope.uploadQueues[index].dicomInfo - let seriesNum = scope.uploadQueues[index].seriesList.length - let fileNum = scope.uploadQueues[index].fileList.length - let seriesList = scope.uploadQueues[index].seriesList - let fileList = scope.uploadQueues[index].fileList - dicomInfo.seriesNum = seriesNum - dicomInfo.fileNum = fileNum - dicomInfo.siteId = scope.data.SiteId - dicomInfo.subjectId = scope.data.SubjectId - dicomInfo.subjectVisitId = scope.subjectVisitId - let t = setInterval(() => { - dicomUploadInProgress({ - trialId: scope.trialId, - studyInstanceUid: dicomInfo.studyUid - }).then(res => { - }) - }, 5000) - scope.myInterval.push(t) - let Record = { - Failed: [], - Existed: [], - Uploaded: [], - FileCount: 0 - } - let params = { + try { + preArchiveDicomStudy({ trialId: scope.trialId, siteId: scope.data.SiteId, subjectId: scope.subjectId, subjectVisitId: scope.subjectVisitId, - studyMonitorId: res.Result, - failedFileCount: 0, - RecordPath: null, - study: { - studyId: dicomInfo.studyId, - studyInstanceUid: dicomInfo.studyUid, - studyTime: dicomInfo.studyTime, - description: dicomInfo.description, - seriesCount: dicomInfo.seriesNum, - instanceCount: dicomInfo.fileNum, - institutionName: dicomInfo.institutionName, - patientId: config.DicomStoreInfo.SubjectCode, - patientName: '', - patientAge: '', - patientSex: config.DicomStoreInfo.SubjectSex, - accessionNumber: dicomInfo.accNumber, - patientBirthDate: '', - acquisitionTime: dicomInfo.acquisitionTime, - acquisitionNumber: dicomInfo.acquisitionNumber, - triggerTime: dicomInfo.triggerTime, - bodyPartExamined: '', - seriesList: [], + // failedFileCount: scope.uploadQueues[index].dicomInfo.failedFileCount, + fileSize: scope.uploadQueues[index].dicomInfo.fileSize, + fileCount: scope.uploadQueues[index].dicomInfo.fileCount, + IsDicomReUpload: scope.uploadQueues[index].uploadState.AllowReUpload + }).then(async res => { + let dicomInfo = scope.uploadQueues[index].dicomInfo + let seriesNum = scope.uploadQueues[index].seriesList.length + let fileNum = scope.uploadQueues[index].fileList.length + let seriesList = scope.uploadQueues[index].seriesList + let fileList = scope.uploadQueues[index].fileList + dicomInfo.seriesNum = seriesNum + dicomInfo.fileNum = fileNum + dicomInfo.siteId = scope.data.SiteId + dicomInfo.subjectId = scope.data.SubjectId + dicomInfo.subjectVisitId = scope.subjectVisitId + let t = setInterval(() => { + dicomUploadInProgress({ + trialId: scope.trialId, + studyInstanceUid: dicomInfo.studyUid + }).then(res => { + }) + }, 5000) + scope.myInterval.push(t) + let Record = { + Failed: [], + Existed: [], + Uploaded: [], + FileCount: 0 } - } - let arr = [] - for (let i = 0; i < seriesList.length; i++) { - let v = seriesList[i] - let instanceList = [] - let ImageResizePath - for (let ii = 0; ii < v.instanceList.length; ii++) { - arr.push((function (){ - return new Promise(async resolve1 => { - let o = v.instanceList[ii] - let name = `${v.instanceList[ii].instanceUid}_${v.instanceList[ii].file.webkitRelativePath}` - if (o.isReUpload) { - dicomInfo.failedFileCount++ - Record.Existed.push(name) - Record.FileCount++ - } else { - let path = `/${params.trialId}/Image/${params.siteId}/${params.subjectId}/${params.subjectVisitId}/${dicomInfo.studyUid}/${v.seriesUid}/${o.instanceUid}/${scope.getGuid(dicomInfo.studyUid + v.seriesUid + o.instanceUid + params.trialId)}` - let res = await dcmUpload(path, o.file, config) - if (!res) { - params.failedFileCount++ - } else { - dicomInfo.failedFileCount++ - if (ii === 0 && o.modality !== 'SR') { - let fileId = cornerstoneWADOImageLoader.wadouri.fileManager.add( - o.file - ) - let blob = await scope.dicomToPng(fileId, o.imageColumns, o.imageRows) - let thumbnailPath = `/${params.trialId}/Image/${params.siteId}/${params.subjectId}/${params.subjectVisitId}/${dicomInfo.studyUid}/${v.seriesUid}/${v.seriesUid}.png` - let OSSclient = scope.OSSclient - let seriesRes = await OSSclient.put(thumbnailPath, blob) - if (seriesRes && seriesRes.url) { - ImageResizePath = scope.$getObjectName(seriesRes.url) + let params = { + trialId: scope.trialId, + siteId: scope.data.SiteId, + subjectId: scope.subjectId, + subjectVisitId: scope.subjectVisitId, + studyMonitorId: res.Result, + failedFileCount: 0, + RecordPath: null, + study: { + studyId: dicomInfo.studyId, + studyInstanceUid: dicomInfo.studyUid, + studyTime: dicomInfo.studyTime, + description: dicomInfo.description, + seriesCount: dicomInfo.seriesNum, + instanceCount: dicomInfo.fileNum, + institutionName: dicomInfo.institutionName, + patientId: config.DicomStoreInfo.SubjectCode, + patientName: '', + patientAge: '', + patientSex: config.DicomStoreInfo.SubjectSex, + accessionNumber: dicomInfo.accNumber, + patientBirthDate: '', + acquisitionTime: dicomInfo.acquisitionTime, + acquisitionNumber: dicomInfo.acquisitionNumber, + triggerTime: dicomInfo.triggerTime, + bodyPartExamined: '', + seriesList: [], + } + } + let arr = [] + for (let i = 0; i < seriesList.length; i++) { + let v = seriesList[i] + let instanceList = [] + let ImageResizePath + for (let ii = 0; ii < v.instanceList.length; ii++) { + arr.push((function (){ + return new Promise(async resolve1 => { + try { + let o = v.instanceList[ii] + let name = `${v.instanceList[ii].instanceUid}_${v.instanceList[ii].file.webkitRelativePath}` + if (o.isReUpload) { + dicomInfo.failedFileCount++ + Record.Existed.push(name) + Record.FileCount++ + } else { + let path = `/${params.trialId}/Image/${params.siteId}/${params.subjectId}/${params.subjectVisitId}/${dicomInfo.studyUid}/${v.seriesUid}/${o.instanceUid}/${scope.getGuid(dicomInfo.studyUid + v.seriesUid + o.instanceUid + params.trialId)}` + let res = await dcmUpload(path, o.file, config) + console.log('imageRes', res) + if (!res || !res.url) { + params.failedFileCount++ + } else { + dicomInfo.failedFileCount++ + if (ii === 0 && o.modality !== 'SR') { + let fileId = cornerstoneWADOImageLoader.wadouri.fileManager.add( + o.file + ) + let blob = await scope.dicomToPng(fileId, o.imageColumns, o.imageRows) + let thumbnailPath = `/${params.trialId}/Image/${params.siteId}/${params.subjectId}/${params.subjectVisitId}/${dicomInfo.studyUid}/${v.seriesUid}/${v.seriesUid}.png` + let OSSclient = scope.OSSclient + let seriesRes = await OSSclient.put(thumbnailPath, blob) + console.log('seriesRes', seriesRes) + if (seriesRes && seriesRes.url) { + ImageResizePath = scope.$getObjectName(seriesRes.url) + } + } + } + if (res && res.url) { + instanceList.push({ + studyInstanceUid: dicomInfo.studyUid, + seriesInstanceUid: v.seriesUid, + sopInstanceUid: o.instanceUid, + instanceNumber: o.instanceNumber, + instanceTime: o.instanceTime, + imageRows: o.imageRows, + imageColumns: o.imageColumns, + sliceLocation: o.sliceLocation, + sliceThickness: o.sliceThickness, + numberOfFrames: o.numberOfFrames, + pixelSpacing: o.pixelSpacing, + imagerPixelSpacing: o.imagerPixelSpacing, + frameOfReferenceUID: o.frameOfReferenceUID, + windowCenter: o.windowCenter, + windowWidth: o.windowWidth, + path: scope.$getObjectName(res.url) + }) + Record.Uploaded.push(name) + Record.FileCount++ + } else { + Record.Failed.push(name) + Record.FileCount++ } } + resolve1() + } catch (e) { + console.log(e) + resolve1() } - if (res && res.url) { - instanceList.push({ - studyInstanceUid: dicomInfo.studyUid, - seriesInstanceUid: v.seriesUid, - sopInstanceUid: o.instanceUid, - instanceNumber: o.instanceNumber, - instanceTime: o.instanceTime, - imageRows: o.imageRows, - imageColumns: o.imageColumns, - sliceLocation: o.sliceLocation, - sliceThickness: o.sliceThickness, - numberOfFrames: o.numberOfFrames, - pixelSpacing: o.pixelSpacing, - imagerPixelSpacing: o.imagerPixelSpacing, - frameOfReferenceUID: o.frameOfReferenceUID, - windowCenter: o.windowCenter, - windowWidth: o.windowWidth, - path: scope.$getObjectName(res.url) - }) - Record.Uploaded.push(name) - Record.FileCount++ - } else { - Record.Failed.push(name) - Record.FileCount++ - } - } - resolve1() - }) - })()) - if (arr.length >= 66 || ii === v.instanceList.length - 1) { - await Promise.all(arr) - arr = [] + }) + })()) + if (arr.length >= 66 || ii === v.instanceList.length - 1) { + await Promise.all(arr) + arr = [] + } } + params.study.seriesList.push({ + studyInstanceUid: dicomInfo.studyUid, + seriesInstanceUid: v.seriesUid, + seriesNumber: v.seriesNumber, + seriesTime: v.seriesTime, + sliceThickness: v.sliceThickness, + imagePositionPatient: v.imagePositionPatient, + imageOrientationPatient: v.imageOrientationPatient, + sequenceName: v.sequenceName, + protocolName: v.protocolName, + imagerPixelSpacing: v.imagerPixelSpacing, + acquisitionTime: dicomInfo.acquisitionTime, + acquisitionNumber: dicomInfo.acquisitionNumber, + triggerTime: dicomInfo.triggerTime, + modality: v.modality, + description: v.description, + instanceCount: v.instanceList.length, + bodyPartExamined: dicomInfo.bodyPart, + instanceList: instanceList, + ImageResizePath: ImageResizePath, + }) } - params.study.seriesList.push({ - studyInstanceUid: dicomInfo.studyUid, - seriesInstanceUid: v.seriesUid, - seriesNumber: v.seriesNumber, - seriesTime: v.seriesTime, - sliceThickness: v.sliceThickness, - imagePositionPatient: v.imagePositionPatient, - imageOrientationPatient: v.imageOrientationPatient, - sequenceName: v.sequenceName, - protocolName: v.protocolName, - imagerPixelSpacing: v.imagerPixelSpacing, - acquisitionTime: dicomInfo.acquisitionTime, - acquisitionNumber: dicomInfo.acquisitionNumber, - triggerTime: dicomInfo.triggerTime, - modality: v.modality, - description: v.description, - instanceCount: v.instanceList.length, - bodyPartExamined: dicomInfo.bodyPart, - instanceList: instanceList, - ImageResizePath: ImageResizePath, - }) - } - console.log(Record) - let text = JSON.stringify(Record) - let logJsonBlob = scope.generateTxtFile(text) - console.log(logJsonBlob) - let logJsonObjectName = `/${params.trialId}/Image/${params.siteId}/${params.subjectId}/${params.subjectVisitId}/${dicomInfo.studyUid}/${params.studyMonitorId}.txt` - let logRes = await scope.OSSclient.put(logJsonObjectName, logJsonBlob) - if (logRes && logRes.url) { - params.study.instanceCount = dicomInfo.failedFileCount - params.RecordPath = logJsonObjectName - addOrUpdateArchiveStudy(params).then(res => { - if (dicomInfo.failedFileCount === dicomInfo.fileCount) { - scope.$message.success(scope.$t('trials:uploadDicomList:label:uploaded')) - } else { - scope.$alert(scope.$t('trials:uploadDicomList:label:uploadFailed')) - } - // scope.uploadQueues[index].uploadState.selected = true - scope.uploadQueues[index].uploadState.selected = true - scope.uploadQueues[index].uploadState.record = Record - // scope.$refs.dicomFilesTable.toggleRowSelection(scope.uploadQueues[index]) - scope.getStudyInfo() - if (scope.$route.path !== '/trials/trials-panel/visit/crc-question') { - scope.$emit('getList') - } - clearInterval(t) - resolve() - }).catch((res) => { - scope.uploadQueues[index].uploadState.record = Record + console.log(Record) + let text = JSON.stringify(Record) + let logJsonBlob = scope.generateTxtFile(text) + console.log(logJsonBlob) + let logJsonObjectName = `/${params.trialId}/Image/${params.siteId}/${params.subjectId}/${params.subjectVisitId}/${dicomInfo.studyUid}/${params.studyMonitorId}.txt` + let logRes = await scope.OSSclient.put(logJsonObjectName, logJsonBlob) + if (logRes && logRes.url) { + params.study.instanceCount = dicomInfo.failedFileCount + params.RecordPath = logJsonObjectName + addOrUpdateArchiveStudy(params).then(res => { + if (dicomInfo.failedFileCount === dicomInfo.fileCount) { + scope.$message.success(scope.$t('trials:uploadDicomList:label:uploaded')) + } else { + scope.$alert(scope.$t('trials:uploadDicomList:label:uploadFailed')) + } + // scope.uploadQueues[index].uploadState.selected = true + scope.uploadQueues[index].uploadState.selected = true + scope.uploadQueues[index].uploadState.record = Record + // scope.$refs.dicomFilesTable.toggleRowSelection(scope.uploadQueues[index]) + scope.getStudyInfo() + if (scope.$route.path !== '/trials/trials-panel/visit/crc-question') { + scope.$emit('getList') + } + clearInterval(t) + resolve() + }).catch((res) => { + scope.uploadQueues[index].uploadState.record = Record + reject() + clearInterval(t) + }) + } else { + scope.$alert(scope.$t('trials:uploadDicomList:label:generateLogFailed')) reject() clearInterval(t) - }) - } else { - scope.$alert(scope.$t('trials:uploadDicomList:label:generateLogFailed')) - reject() - clearInterval(t) - } - }) + } + }) + } catch (e) { + console.log(e) + reject() + } }) }, generateTxtFile(text) {