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);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user