LT-212 Fix the bug caused by exporting large studies

- Use blob instead of arraybuffer as xhr response type to download dicom files
- Convert blob to arraybuffer after blob downloaded via xhr
This commit is contained in:
Evren Ozkan 2016-04-01 22:43:48 -04:00
parent 0e31eff332
commit 55fbf3f1da

View File

@ -1,3 +1,5 @@
var exportFailed;
/** /**
* Exports requested studies * Exports requested studies
* @param studiesToExport Studies to export * @param studiesToExport Studies to export
@ -43,7 +45,7 @@ function exportQueriedStudies(studiesToExport) {
function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) { function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
var zip = new JSZip(); var zip = new JSZip();
var exportFailed = false; exportFailed = false;
var numberOfFilesExported = 0; var numberOfFilesExported = 0;
studiesToExport.forEach(function(study) { studiesToExport.forEach(function(study) {
@ -67,18 +69,31 @@ function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
// Download and Zip the dicom file // Download and Zip the dicom file
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("GET", instance.wadouri, true); xhr.open("GET", instance.wadouri, true);
xhr.responseType = "arraybuffer"; xhr.responseType = "blob";
// Downloaded the dicom file completely // Downloaded the dicom file completely
xhr.onload = function() { xhr.onload = function(e) {
// If failed to download a dicom file, skip others // If failed to download a dicom file, skip others
if (exportFailed) { if (exportFailed) {
return; return;
} }
var responseArrayBuffer = xhr.response; // Failed to export a file
if (responseArrayBuffer) { if (xhr.readyState === 4 && xhr.status !== 200) {
seriesFolder.file(instance.sopInstanceUid + ".dcm", responseArrayBuffer, { binary: true }); onExportFailed("File not downloaded: " + instance.wadouri);
return;
}
var blobFile = new Blob([xhr.response], {type: 'application/dicom'});
var fileReader = new FileReader();
fileReader.onload = function() {
try {
seriesFolder.file(instance.sopInstanceUid + ".dcm", fileReader.result, { binary: true });
} catch(err) {
onExportFailed(err.message);
return;
} }
numberOfFilesExported++; numberOfFilesExported++;
@ -91,15 +106,15 @@ function exportQueriedStudiesInternal(studiesToExport, numberOfFilesToExport) {
progressDialog.update(numberOfFilesExported); progressDialog.update(numberOfFilesExported);
}; };
// Failed to download the dicom file fileReader.readAsArrayBuffer(blobFile);
xhr.onerror = function() {
exportFailed = true;
progressDialog.close();
console.error("Failed to export studies!");
}; };
xhr.send(null); // Failed to download the dicom file
xhr.onerror = function() {
onExportFailed("File not downloaded: " + instance.wadouri);
};
xhr.send();
}); });
}); });
}); });
@ -120,3 +135,11 @@ function getNumberOfFilesToExport(studiesToExport) {
return numberOFFilesToExport; return numberOFFilesToExport;
} }
function onExportFailed(err) {
exportFailed = true;
progressDialog.close();
//TODO: Export failed and dialog closed, so let user know
console.error("Failed to export studies!", err);
}