ohif-viewer/Packages/ohif-study-list/client/lib/queryStudies.js
André Botelho Almeida af4b8b45f5 Ohif 168 proper error handling (#111)
* Adding a better error handling for DICOMWeb getJson method

* Adding a better error handling for DICOMWeb getBulkData method

* Fixinf some typos. Using console.error to log errors

* Better error handling for DIMSE connections

* Using meteor error in StudyListSearch to better display same error in the client

* Using Meteor.Error for a better pattern. Added an error message in the study list. created connection error types to DICOMWeb connection errors

* Changing error types for server connection. Added better errors for DIMSE server on sockets

* Improving viewer response to error being throw when not finding server to display studies

* OHIF-168: adding catches clauses for retrieveStudyMetada method

* OHIF-168: fixing typo in DIMSE.js

* OHIF-168: setting the session variable  to false when starting a new studylist search

* OHIF-168: Using OHIF.log instead of console

* OHIF-168: removing parsing into string for OHIF.log in Connection.js

* OHIF-168: improving error message visibility in study viewer
2017-09-19 17:44:39 +02:00

75 lines
2.2 KiB
JavaScript

import { OHIF } from 'meteor/ohif:core';
/**
* Queries requested studies to get their metadata from PACS
* @param studiesToQuery Studies to query
*/
queryStudies = function(studiesToQuery, options) {
let studiesQueried = 0;
const numberOfStudiesToQuery = studiesToQuery.length;
const notify = (options || {}).notify || function() { /* noop */ };
const promises = [];
studiesToQuery.forEach(studyToQuery => {
const promise = OHIF.studylist.retrieveStudyMetadata(studyToQuery.studyInstanceUid);
promise.then(study => {
studiesQueried++;
notify({
total: numberOfStudiesToQuery,
processed: studiesQueried
});
});
promises.push(promise);
});
return Promise.all(promises);
};
queryStudiesWithProgress = function(studiesToQuery) {
return OHIF.ui.showDialog('dialogProgress', {
title: 'Querying Studies...',
message: `Queried: 0 / ${studiesToQuery.length}`,
total: studiesToQuery.length,
task: {
run: (dialog) => {
queryStudies(studiesToQuery, {
notify: stats => {
dialog.update(stats.processed);
dialog.setMessage(`Queried: ${stats.processed} / ${stats.total}`);
}
})
.then(studiesQueried => {
dialog.done(studiesQueried);
}, () => {
dialog.cancel();
}).catch(error => {
OHIF.log.error('There was an error retrieving all studies metadeta.');
OHIF.log.error(error.stack);
OHIF.log.trace();
});
}
}
});
};
/**
* Returns the total number of dicom files in a study
* @param study Queried study (includes metadata)
* @returns {number}
*/
getNumberOfFilesInStudy = function(study) {
let numberOFFilesToExport = 0;
study.seriesList.forEach(function(series) {
series.instances.forEach(function(instance) {
if (instance.wadouri) {
numberOFFilesToExport++;
}
});
});
return numberOFFilesToExport;
};