PWV-1: Refactoring ohif:studylist package
This commit is contained in:
1 parent
984ef94403
commit
4d79bf84a8
79 files changed
+450
-551
No files matched your search
@@ -1,10 +1,13 @@
|
||||
var exportFailed;
|
||||
import { JSZip } from 'meteor/silentcicero:jszip';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
let exportFailed;
|
||||
|
||||
/**
|
||||
* Exports requested studies
|
||||
* @param studiesToExport Studies to export
|
||||
*/
|
||||
exportStudies = function(studiesToExport) {
|
||||
OHIF.studylist.exportStudies = studiesToExport => {
|
||||
if (studiesToExport.length < 1) {
|
||||
return;
|
||||
}
|
||||
@@ -12,37 +15,45 @@ exportStudies = function(studiesToExport) {
|
||||
queryStudies(studiesToExport, exportQueriedStudies);
|
||||
};
|
||||
|
||||
function exportQueriedStudies(studiesToExport) {
|
||||
var numberOfFilesToExport = 0;
|
||||
studiesToExport.forEach(function(study) {
|
||||
const exportQueriedStudies = studiesToExport => {
|
||||
let numberOfFilesToExport = 0;
|
||||
studiesToExport.forEach(study => {
|
||||
numberOfFilesToExport += getNumberOfFilesInStudy(study);
|
||||
});
|
||||
|
||||
progressDialog.show("Exporting Studies...", numberOfFilesToExport);
|
||||
OHIF.studylist.progressDialog.show('Exporting Studies...', numberOfFilesToExport);
|
||||
|
||||
try {
|
||||
exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport);
|
||||
} catch (err) {
|
||||
progressDialog.close();
|
||||
console.error("Failed to export studies: " + err.message);
|
||||
OHIF.studylist.progressDialog.close();
|
||||
OHIF.log.error(`Failed to export studies: ${err.message}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
|
||||
var zip = new JSZip();
|
||||
const exportQueriedStudiesInternal = (studiesToExport, numberOfFilesToExport) => {
|
||||
const zip = new JSZip();
|
||||
|
||||
exportFailed = false;
|
||||
var numberOfFilesExported = 0;
|
||||
let numberOfFilesExported = 0;
|
||||
|
||||
studiesToExport.forEach(function(study) {
|
||||
const onExportFailed = err => {
|
||||
exportFailed = true;
|
||||
OHIF.studylist.progressDialog.close();
|
||||
|
||||
//TODO: Export failed and dialog closed, so let user know
|
||||
OHIF.log.error('Failed to export studies!', err);
|
||||
};
|
||||
|
||||
studiesToExport.forEach(study => {
|
||||
sortStudy(study);
|
||||
|
||||
var studyFolder = zip.folder(study.studyInstanceUid);
|
||||
const studyFolder = zip.folder(study.studyInstanceUid);
|
||||
|
||||
study.seriesList.forEach(function(series) {
|
||||
var seriesFolder = studyFolder.folder(series.seriesInstanceUid);
|
||||
study.seriesList.forEach(series => {
|
||||
const seriesFolder = studyFolder.folder(series.seriesInstanceUid);
|
||||
|
||||
series.instances.forEach(function(instance) {
|
||||
series.instances.forEach(instance => {
|
||||
if (!instance.wadouri) {
|
||||
return;
|
||||
}
|
||||
@@ -53,12 +64,12 @@ function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
|
||||
}
|
||||
|
||||
// Download and Zip the dicom file
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", instance.wadouri, true);
|
||||
xhr.responseType = "blob";
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', instance.wadouri, true);
|
||||
xhr.responseType = 'blob';
|
||||
|
||||
// Downloaded the dicom file completely
|
||||
xhr.onload = function(e) {
|
||||
xhr.onload = () => {
|
||||
// If failed to download a dicom file, skip others
|
||||
if (exportFailed) {
|
||||
return;
|
||||
@@ -66,17 +77,17 @@ function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
|
||||
|
||||
// Failed to export a file
|
||||
if (xhr.readyState === 4 && xhr.status !== 200) {
|
||||
onExportFailed("File not downloaded: " + instance.wadouri);
|
||||
onExportFailed(`File not downloaded: ${instance.wadouri}`);
|
||||
return;
|
||||
}
|
||||
|
||||
var blobFile = new Blob([xhr.response], {type: 'application/dicom'});
|
||||
const blobFile = new Blob([xhr.response], { type: 'application/dicom' });
|
||||
|
||||
var fileReader = new FileReader();
|
||||
const fileReader = new FileReader();
|
||||
|
||||
fileReader.onload = function() {
|
||||
fileReader.onload = () => {
|
||||
try {
|
||||
seriesFolder.file(instance.sopInstanceUid + ".dcm", fileReader.result, { binary: true });
|
||||
seriesFolder.file(`${instance.sopInstanceUid}.dcm`, fileReader.result, { binary: true });
|
||||
} catch(err) {
|
||||
onExportFailed(err.message);
|
||||
return;
|
||||
@@ -85,31 +96,21 @@ function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
|
||||
numberOfFilesExported++;
|
||||
|
||||
if (numberOfFilesExported === numberOfFilesToExport) {
|
||||
var zipContent = zip.generate({ type: "blob" });
|
||||
saveAs(zipContent, "studies.zip");
|
||||
const zipContent = zip.generate({ type: 'blob' });
|
||||
saveAs(zipContent, 'studies.zip');
|
||||
}
|
||||
|
||||
progressDialog.update(numberOfFilesExported);
|
||||
OHIF.studylist.progressDialog.update(numberOfFilesExported);
|
||||
};
|
||||
|
||||
fileReader.readAsArrayBuffer(blobFile);
|
||||
};
|
||||
|
||||
// Failed to download the dicom file
|
||||
xhr.onerror = function() {
|
||||
onExportFailed("File not downloaded: " + instance.wadouri);
|
||||
};
|
||||
xhr.onerror = () => onExportFailed(`File not downloaded: ${instance.wadouri}`);
|
||||
|
||||
xhr.send();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onExportFailed(err) {
|
||||
exportFailed = true;
|
||||
progressDialog.close();
|
||||
|
||||
//TODO: Export failed and dialog closed, so let user know
|
||||
console.error("Failed to export studies!", err);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.studylist.getSelectedStudies = () => {
|
||||
return StudyListSelectedStudies.find({}, {
|
||||
sort: {
|
||||
studyDate: 1
|
||||
}
|
||||
}).fetch() || [];
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import { $ } from 'meteor/jquery';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
/**
|
||||
@@ -10,7 +11,7 @@ import { OHIF } from 'meteor/ohif:core';
|
||||
* @param doneCallback The callback function to be executed when the study retrieval has finished
|
||||
* @param failCallback The callback function to be executed when the study retrieval has failed
|
||||
*/
|
||||
getStudiesMetadata = function(studyInstanceUids, doneCallback, failCallback) {
|
||||
OHIF.studylist.getStudiesMetadata = (studyInstanceUids, doneCallback, failCallback) => {
|
||||
// Check to make sure studyInstanceUids were actually input
|
||||
if (!studyInstanceUids || !studyInstanceUids.length) {
|
||||
if (failCallback && typeof failCallback === 'function') {
|
||||
@@ -22,13 +23,13 @@ getStudiesMetadata = function(studyInstanceUids, doneCallback, failCallback) {
|
||||
|
||||
// Create an empty array to store the Promises for each metaData
|
||||
// retrieval call
|
||||
var promises = [];
|
||||
const promises = [];
|
||||
|
||||
// Loop through the array of studyInstanceUids
|
||||
studyInstanceUids.forEach(function(studyInstanceUid) {
|
||||
// Create a new Deferred to monitor the progress of the asynchronous
|
||||
// metaData retrieval
|
||||
var deferred = new $.Deferred();
|
||||
const deferred = new $.Deferred();
|
||||
|
||||
// Send the call, and attach doneCallbacks and failCallbacks
|
||||
// which can resolve or reject the related promise based on its outcome
|
||||
@@ -45,7 +46,7 @@ getStudiesMetadata = function(studyInstanceUids, doneCallback, failCallback) {
|
||||
// When all of the promises are complete, this callback runs
|
||||
$.when.apply($, promises).done(function() {
|
||||
// Convert the Arguments Array-like Object to an actual array
|
||||
var studies = $.makeArray(arguments);
|
||||
const studies = $.makeArray(arguments);
|
||||
|
||||
// Pass the studies array to the doneCallback, if one exists
|
||||
if (doneCallback && typeof doneCallback === 'function') {
|
||||
|
||||
@@ -14,7 +14,7 @@ importStudies = function(filesToImport, importCallback) {
|
||||
};
|
||||
var numberOfFilesToUpload = filesToImport.length;
|
||||
var studiesToImport = [];
|
||||
progressDialog.show({
|
||||
OHIF.studylist.progressDialog.show({
|
||||
title: "Uploading Files...",
|
||||
numberOfCompleted: 0,
|
||||
numberOfTotal: numberOfFilesToUpload
|
||||
@@ -38,7 +38,7 @@ importStudies = function(filesToImport, importCallback) {
|
||||
updateFileUploadStatus(fileUploadStatus, true);
|
||||
|
||||
var numberOfFilesProcessedToUpload = fileUploadStatus.numberOfFilesUploaded + fileUploadStatus.numberOfFilesFailed;
|
||||
progressDialog.update(numberOfFilesProcessedToUpload);
|
||||
OHIF.studylist.progressDialog.update(numberOfFilesProcessedToUpload);
|
||||
|
||||
if (numberOfFilesToUpload === numberOfFilesProcessedToUpload) {
|
||||
// The upload is completed, so import files
|
||||
@@ -74,7 +74,7 @@ function importStudiesInternal(studiesToImport, importCallback) {
|
||||
|
||||
var numberOfStudiesToImport = studiesToImport.length;
|
||||
|
||||
progressDialog.show({
|
||||
OHIF.studylist.progressDialog.show({
|
||||
title: "Importing Studies...",
|
||||
numberOfCompleted: 0,
|
||||
numberOfTotal: numberOfStudiesToImport
|
||||
@@ -84,13 +84,13 @@ function importStudiesInternal(studiesToImport, importCallback) {
|
||||
Meteor.call("createStudyImportStatus", function(err, studyImportStatusId) {
|
||||
if (err) {
|
||||
// Hide dialog
|
||||
progressDialog.close();
|
||||
OHIF.studylist.progressDialog.close();
|
||||
console.log(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle when StudyImportStatus collection is updated
|
||||
StudyImportStatus.find(studyImportStatusId).observe({
|
||||
OHIF.studylist.collections.StudyImportStatus.find(studyImportStatusId).observe({
|
||||
changed: function(studyImportStatus) {
|
||||
if (!studyImportStatus) {
|
||||
return;
|
||||
@@ -100,16 +100,16 @@ function importStudiesInternal(studiesToImport, importCallback) {
|
||||
|
||||
// Show number of imported files
|
||||
var successMessage = 'Imported '+studyImportStatus.numberOfStudiesImported+' of '+numberOfStudiesToImport;
|
||||
progressDialog.setMessage({
|
||||
OHIF.studylist.progressDialog.setMessage({
|
||||
message: successMessage,
|
||||
messageType: 'success'
|
||||
});
|
||||
progressDialog.update(numberOfStudiesProcessedToImport);
|
||||
OHIF.studylist.progressDialog.update(numberOfStudiesProcessedToImport);
|
||||
|
||||
// Show number of failed files if there is at least one failed file
|
||||
if (studyImportStatus.numberOfStudiesFailed > 0) {
|
||||
var successMessage = 'Failed '+studyImportStatus.numberOfStudiesFailed+' of '+numberOfStudiesToImport;
|
||||
progressDialog.setMessage({
|
||||
OHIF.studylist.progressDialog.setMessage({
|
||||
message: successMessage,
|
||||
messageType: 'warning'
|
||||
});
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import './third-party/jquery.twbsPagination.min.js';
|
||||
|
||||
import './exportStudies.js';
|
||||
import './getSelectedStudies.js';
|
||||
import './getStudyMetadata.js';
|
||||
import './getStudiesMetadata.js';
|
||||
import './importStudies.js';
|
||||
import './openNewTab.js';
|
||||
import './queryStudies.js';
|
||||
import './studylist.js';
|
||||
import './switchToTab.js';
|
||||
@@ -1,3 +1,5 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
/**
|
||||
* Queries requested studies to get their metadata from PACS
|
||||
* @param studiesToQuery Studies to query
|
||||
@@ -11,7 +13,7 @@ queryStudies = function(studiesToQuery, doneCallback) {
|
||||
var studiesQueried = [];
|
||||
var numberOfStudiesToQuery = studiesToQuery.length;
|
||||
|
||||
progressDialog.show("Querying Studies...", numberOfStudiesToQuery);
|
||||
OHIF.studylist.progressDialog.show("Querying Studies...", numberOfStudiesToQuery);
|
||||
|
||||
studiesToQuery.forEach(function(studyToQuery) {
|
||||
getStudyMetadata(studyToQuery.studyInstanceUid, function(study) {
|
||||
@@ -19,7 +21,7 @@ queryStudies = function(studiesToQuery, doneCallback) {
|
||||
|
||||
var numberOfStudiesQueried = studiesQueried.length;
|
||||
|
||||
progressDialog.update(numberOfStudiesQueried);
|
||||
OHIF.studylist.progressDialog.update(numberOfStudiesQueried);
|
||||
|
||||
if (numberOfStudiesQueried === numberOfStudiesToQuery) {
|
||||
doneCallback(studiesQueried);
|
||||
@@ -45,4 +47,4 @@ getNumberOfFilesInStudy = function(study) {
|
||||
});
|
||||
|
||||
return numberOFFilesToExport;
|
||||
};
|
||||
};
|
||||
@@ -13,9 +13,6 @@ switchToTab = function(contentId) {
|
||||
|
||||
OHIF.log.info('Switching to tab: ' + contentId);
|
||||
|
||||
$('.tabTitle').removeClass('active');
|
||||
$('.tabTitle a[data-target="#' + contentId + '"]').addClass('active');
|
||||
|
||||
$('.tab-content .tab-pane').removeClass('active');
|
||||
if (contentId !== 'studylistTab') {
|
||||
$('.tab-content .tab-pane#viewerTab').addClass('active');
|
||||
@@ -71,7 +68,7 @@ switchToTab = function(contentId) {
|
||||
var studyInstanceUids = ViewerData[contentId].studyInstanceUids;
|
||||
|
||||
// Attempt to retrieve the meta data (it might be cached)
|
||||
getStudiesMetadata(studyInstanceUids, function(studies) {
|
||||
OHIF.studylist.getStudiesMetadata(studyInstanceUids, function(studies) {
|
||||
viewStudiesInTab(contentId, studies);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user