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:
parent
0e31eff332
commit
55fbf3f1da
@ -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,39 +69,52 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
numberOfFilesExported++;
|
var blobFile = new Blob([xhr.response], {type: 'application/dicom'});
|
||||||
|
|
||||||
if (numberOfFilesExported === numberOfFilesToExport) {
|
var fileReader = new FileReader();
|
||||||
var zipContent = zip.generate({ type: "blob" });
|
|
||||||
saveAs(zipContent, "studies.zip");
|
|
||||||
}
|
|
||||||
|
|
||||||
progressDialog.update(numberOfFilesExported);
|
fileReader.onload = function() {
|
||||||
|
try {
|
||||||
|
seriesFolder.file(instance.sopInstanceUid + ".dcm", fileReader.result, { binary: true });
|
||||||
|
} catch(err) {
|
||||||
|
onExportFailed(err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
numberOfFilesExported++;
|
||||||
|
|
||||||
|
if (numberOfFilesExported === numberOfFilesToExport) {
|
||||||
|
var zipContent = zip.generate({ type: "blob" });
|
||||||
|
saveAs(zipContent, "studies.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
progressDialog.update(numberOfFilesExported);
|
||||||
|
};
|
||||||
|
|
||||||
|
fileReader.readAsArrayBuffer(blobFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Failed to download the dicom file
|
// Failed to download the dicom file
|
||||||
xhr.onerror = function() {
|
xhr.onerror = function() {
|
||||||
exportFailed = true;
|
onExportFailed("File not downloaded: " + instance.wadouri);
|
||||||
|
|
||||||
progressDialog.close();
|
|
||||||
console.error("Failed to export studies!");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.send(null);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user