ohif-viewer/Packages/ohif-study-list/client/lib/OHIFStudyMetadataSource.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

76 lines
2.7 KiB
JavaScript

import { OHIF } from 'meteor/ohif:core';
import 'meteor/ohif:viewerbase';
// Important metadata classes
const { OHIFError, metadata } = OHIF.viewerbase;
const { StudySummary, StudyMetadata } = metadata;
export class OHIFStudyMetadataSource extends OHIF.viewerbase.StudyMetadataSource {
/**
* Get study metadata for a study with given study InstanceUID
* @param {String} studyInstanceUID Study InstanceUID
* @return {Promise} A Promise object
*/
getByInstanceUID(studyInstanceUID) {
return OHIF.studylist.retrieveStudyMetadata(studyInstanceUID);
}
/**
* Load study info (OHIF.viewer.Studies) and study metadata (OHIF.viewer.StudyMetadataList) for a given study.
* @param {StudySummary|StudyMetadata} study of StudySummary or StudyMetadata object.
*/
loadStudy(study) {
if (!(study instanceof StudyMetadata) && !(study instanceof StudySummary)) {
throw new OHIFError('OHIFStudyMetadataSource::loadStudy study is not an instance of StudySummary or StudyMetadata');
}
return new Promise((resolve, reject) => {
const studyInstanceUID = study.getStudyInstanceUID();
if (study instanceof StudyMetadata) {
const alreadyLoaded = OHIF.viewer.Studies.findBy({
studyInstanceUid: studyInstanceUID
});
if (!alreadyLoaded) {
OHIFStudyMetadataSource._updateStudyCollections(study);
}
resolve(study);
return;
}
this.getByInstanceUID(studyInstanceUID).then(studyInfo => {
// Create study metadata object
const studyMetadata = new OHIF.metadata.StudyMetadata(studyInfo, studyInfo.studyInstanceUid);
// Get Study display sets
const displaySets = OHIF.viewerbase.sortingManager.getDisplaySets(studyMetadata);
// Set studyMetadata display sets
studyMetadata.setDisplaySets(displaySets);
OHIFStudyMetadataSource._updateStudyCollections(studyMetadata);
resolve(studyMetadata);
}).catch(reject);
});
}
// Static methods
static _updateStudyCollections(studyMetadata) {
const studyInfo = studyMetadata.getData();
// Set some studyInfo properties
studyInfo.selected = true;
studyInfo.displaySets = studyMetadata.getDisplaySets();
// Insert new study info object in Studies TypeSafeCollection
OHIF.viewer.Studies.insert(studyInfo);
// Insert new study metadata in StudyMetadataList TypeSafeCollection
OHIF.viewer.StudyMetadataList.insert(studyMetadata);
}
}