src/pacsfile.js
/** * Imports ***/
import Request from './request';
import RequestException from './exception';
import Collection from './cj';
import { ItemResource, ListResource } from './resource';
import { FileBrowserFolder } from './filebrowser';
/**
* PACS series item resource object representing a PACS series.
*/
export class PACSSeries extends ItemResource {
/**
* Constructor
*
* @param {string} url - url of the resource
* @param {Object} auth - authentication object
* @param {string} auth.token - authentication token
*/
constructor(url, auth) {
super(url, auth);
}
/**
* Fetch the folder associated with this PACS series from the REST API.
*
* @param {number} [timeout=30000] - request timeout
*
* @return {Promise<FileBrowserFolder>} - JS Promise, resolves to a ``FileBrowserFolder`` object
*/
getFolder(timeout = 30000) {
const linkRelation = 'folder';
const resourceClass = FileBrowserFolder;
return this._getResource(linkRelation, resourceClass, null, timeout);
}
}
/**
* PACS series list resource object representing a list of PACS series.
*/
export class PACSSeriesList extends ListResource {
/**
* Constructor
*
* @param {string} url - url of the resource
* @param {Object} auth - authentication object
* @param {string} auth.token - authentication token
*/
constructor(url, auth) {
super(url, auth);
/** @type {Object} */
this.itemClass = PACSSeries;
}
}
/**
* PACS file item resource object representing a PACS file.
*/
export class PACSFile extends ItemResource {
/**
* Constructor
*
* @param {string} url - url of the resource
* @param {Object} auth - authentication object
* @param {string} auth.token - authentication token
*/
constructor(url, auth) {
super(url, auth);
}
/**
* Fetch the file blob associated to this file item from the REST API.
*
* @param {number} [timeout=30000] - request timeout
*
* @return {Promise<Blob>} - JS Promise, resolves to a ``Blob`` object
*/
getFileBlob(timeout = 30000) {
if (this.isEmpty) {
throw new RequestException('Item object has not been set!');
}
const req = new Request(this.auth, 'application/octet-stream', timeout);
const item = this.collection.items[0];
const blobUrl = Collection.getLinkRelationUrls(item, 'file_resource')[0];
return req.get(blobUrl).then(resp => resp.data);
}
/**
* Fetch the parent folder of this file from the REST API.
*
* @param {number} [timeout=30000] - request timeout
*
* @return {Promise<FileBrowserFolder>} - JS Promise, resolves to a ``FileBrowserFolder`` object
*/
getParentFolder(timeout = 30000) {
const linkRelation = 'parent_folder';
const resourceClass = FileBrowserFolder;
return this._getResource(linkRelation, resourceClass, null, timeout);
}
}
/**
* PACS file list resource object representing a list of PACS files.
*/
export class PACSFileList extends ListResource {
/**
* Constructor
*
* @param {string} url - url of the resource
* @param {Object} auth - authentication object
* @param {string} auth.token - authentication token
*/
constructor(url, auth) {
super(url, auth);
/** @type {Object} */
this.itemClass = PACSFile;
}
}