reorganize packages, start converting overall app to react (very broken at the moment)
This commit is contained in:
1 parent
024fe1a448
commit
5f30f7bd35
479 files changed
+5364
-11611
No files matched your search
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Returns the specified element as a dicom attribute group/element.
|
||||
*
|
||||
* @param element - The group/element of the element (e.g. '00280009')
|
||||
* @param [defaultValue] - The value to return if the element is not present
|
||||
* @returns {*}
|
||||
*/
|
||||
export default function getAttribute(element, defaultValue) {
|
||||
if (!element) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Value is not present if the attribute has a zero length value
|
||||
if (!element.Value) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Sanity check to make sure we have at least one entry in the array.
|
||||
if (!element.Value.length) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return convertToInt(element.Value);
|
||||
};
|
||||
|
||||
function convertToInt(input) {
|
||||
function padFour(input) {
|
||||
var l = input.length;
|
||||
|
||||
if (l == 0) return '0000';
|
||||
if (l == 1) return '000' + input;
|
||||
if (l == 2) return '00' + input;
|
||||
if (l == 3) return '0' + input;
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
var output = '';
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
for (var j = 0; j < input[i].length; j++) {
|
||||
output += padFour(input[i].charCodeAt(j).toString(16));
|
||||
}
|
||||
}
|
||||
|
||||
return parseInt(output, 16);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { btoa } from 'isomorphic-base64';
|
||||
|
||||
/**
|
||||
* Returns the Authorization header as part of an Object.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
export default function getAuthorizationHeader() {
|
||||
const headers = {};
|
||||
|
||||
// Check for OHIF.user since this can also be run on the server
|
||||
const accessToken = OHIF.user && OHIF.user.getAccessToken && OHIF.user.getAccessToken();
|
||||
const server = OHIF.servers.getCurrentServer();
|
||||
|
||||
if (server &&
|
||||
server.requestOptions &&
|
||||
server.requestOptions.auth) {
|
||||
// HTTP Basic Auth (user:password)
|
||||
headers.Authorization = `Basic ${btoa(server.requestOptions.auth)}`;
|
||||
} else if (accessToken) {
|
||||
headers.Authorization = `Bearer ${accessToken}`;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
export default function getModalities(modality, modalitiesInStudy) {
|
||||
var modalities = {};
|
||||
if (modality) {
|
||||
modalities = modality;
|
||||
}
|
||||
|
||||
if (modalitiesInStudy) {
|
||||
// Find vr in modalities
|
||||
if (modalities.vr && modalities.vr === modalitiesInStudy.vr) {
|
||||
for (var i = 0; i < modalitiesInStudy.Value.length; i++) {
|
||||
var value = modalitiesInStudy.Value[i];
|
||||
if (modalities.Value.indexOf(value) === -1) {
|
||||
modalities.Value.push(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
modalities = modalitiesInStudy;
|
||||
}
|
||||
}
|
||||
return modalities;
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Returns the Alphabetic version of a PN
|
||||
*
|
||||
* @param element - The group/element of the element (e.g. '00200013')
|
||||
* @param [defaultValue] - The default value to return if the element is not found
|
||||
* @returns {*}
|
||||
*/
|
||||
export default function getName(element, defaultValue) {
|
||||
if (!element) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Value is not present if the attribute has a zero length value
|
||||
if (!element.Value) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Sanity check to make sure we have at least one entry in the array.
|
||||
if (!element.Value.length) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Return the Alphabetic component group
|
||||
if (element.Value[0].Alphabetic) {
|
||||
return element.Value[0].Alphabetic;
|
||||
}
|
||||
// Orthanc does not return PN properly so this is a temporary workaround
|
||||
return element.Value[0];
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Returns the first string value as a Javascript Number
|
||||
* @param element - The group/element of the element (e.g. '00200013')
|
||||
* @param [defaultValue] - The default value to return if the element does not exist
|
||||
* @returns {*}
|
||||
*/
|
||||
export default function getNumber(element, defaultValue) {
|
||||
if (!element) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Value is not present if the attribute has a zero length value
|
||||
if (!element.Value) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Sanity check to make sure we have at least one entry in the array.
|
||||
if (!element.Value.length) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return parseFloat(element.Value[0]);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Returns the specified element as a string. Multi-valued elements will be separated by a backslash
|
||||
*
|
||||
* @param element - The group/element of the element (e.g. '00200013')
|
||||
* @param [defaultValue] - The value to return if the element is not present
|
||||
* @returns {*}
|
||||
*/
|
||||
export default function getString(element, defaultValue) {
|
||||
if (!element) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Value is not present if the attribute has a zero length value
|
||||
if (!element.Value) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Sanity check to make sure we have at least one entry in the array.
|
||||
if (!element.Value.length) {
|
||||
return defaultValue;
|
||||
}
|
||||
// Join the array together separated by backslash
|
||||
// NOTE: Orthanc does not correctly split values into an array so the join is a no-op
|
||||
return element.Value.join('\\');
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
import getAttribute from './getAttribute.js';
|
||||
import getAuthorizationHeader from './getAuthorizationHeader.js';
|
||||
import getModalities from './getModalities.js';
|
||||
import getName from './getName.js';
|
||||
import getNumber from './getNumber.js';
|
||||
import getString from './getString.js';
|
||||
|
||||
const DICOMWeb = {
|
||||
getAttribute,
|
||||
getAuthorizationHeader,
|
||||
getModalities,
|
||||
getName,
|
||||
getNumber,
|
||||
getString,
|
||||
};
|
||||
|
||||
OHIF.DICOMWeb = DICOMWeb;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
export default function(path) {
|
||||
if (path) {
|
||||
// Remove the leading "/"
|
||||
path = path.replace(/^\//, '');
|
||||
}
|
||||
|
||||
return Meteor.absoluteUrl(path);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import _ from 'underscore';
|
||||
|
||||
OHIF.cornerstone = {};
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { Servers, CurrentServer } from '../collections';
|
||||
|
||||
/**
|
||||
* Retrieves the current server configuration used to retrieve studies
|
||||
*/
|
||||
OHIF.servers.getCurrentServer = () => {
|
||||
const currentServer = CurrentServer.findOne();
|
||||
|
||||
if (!currentServer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const serverConfiguration = Servers.findOne({ _id: currentServer.serverId });
|
||||
|
||||
return serverConfiguration;
|
||||
};
|
||||
@@ -5,3 +5,6 @@ import './ui.js';
|
||||
import './utils.js';
|
||||
import './viewer.js';
|
||||
import './user.js';
|
||||
import './object.js';
|
||||
import './DICOMWeb/';
|
||||
import './getCurrentServer.js';
|
||||
@@ -0,0 +1,52 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.object = {};
|
||||
|
||||
// Transforms a shallow object with keys separated by "." into a nested object
|
||||
OHIF.object.getNestedObject = shallowObject => {
|
||||
const nestedObject = {};
|
||||
for (let key in shallowObject) {
|
||||
if (!shallowObject.hasOwnProperty(key)) continue;
|
||||
const value = shallowObject[key];
|
||||
const propertyArray = key.split('.');
|
||||
let currentObject = nestedObject;
|
||||
while (propertyArray.length) {
|
||||
const currentProperty = propertyArray.shift();
|
||||
if (!propertyArray.length) {
|
||||
currentObject[currentProperty] = value;
|
||||
} else {
|
||||
if (!currentObject[currentProperty]) {
|
||||
currentObject[currentProperty] = {};
|
||||
}
|
||||
|
||||
currentObject = currentObject[currentProperty];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nestedObject;
|
||||
};
|
||||
|
||||
// Transforms a nested object into a shallowObject merging its keys with "." character
|
||||
OHIF.object.getShallowObject = nestedObject => {
|
||||
const shallowObject = {};
|
||||
const putValues = (baseKey, nestedObject, resultObject) => {
|
||||
for (let key in nestedObject) {
|
||||
if (!nestedObject.hasOwnProperty(key)) continue;
|
||||
let currentKey = baseKey ? `${baseKey}.${key}` : key;
|
||||
const currentValue = nestedObject[key];
|
||||
if (typeof currentValue === 'object') {
|
||||
if (currentValue instanceof Array) {
|
||||
currentKey += '[]';
|
||||
}
|
||||
|
||||
putValues(currentKey, currentValue, resultObject);
|
||||
} else {
|
||||
resultObject[currentKey] = currentValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
putValues('', nestedObject, shallowObject);
|
||||
return shallowObject;
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
import { dicomParser } from 'meteor/ohif:cornerstone';
|
||||
|
||||
/**
|
||||
* A small set of utilities to help parsing DICOM element values.
|
||||
* In the future the functionality provided by this library might
|
||||
* be incorporated into dicomParser library.
|
||||
*/
|
||||
|
||||
export const parsingUtils = {
|
||||
|
||||
/**
|
||||
* Check if supplied argument is a valid instance of the dicomParser.DataSet class.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @returns {Boolean} Returns true if data is a valid instance of the dicomParser.DataSet class.
|
||||
*/
|
||||
isValidDataSet: function(data) {
|
||||
return (data instanceof dicomParser.DataSet);
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses an element tag according to the 'AT' VR definition.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @param tag {String} A DICOM tag with in the format xGGGGEEEE.
|
||||
* @returns {String} A string representation of a data element tag or null if the field is not present or data is not long enough.
|
||||
*/
|
||||
attributeTag: function(data, tag) {
|
||||
if (this.isValidDataSet(data) && tag in data.elements) {
|
||||
let element = data.elements[tag];
|
||||
if (element && element.length === 4) {
|
||||
let parser = data.byteArrayParser.readUint16,
|
||||
bytes = data.byteArray,
|
||||
offset = element.dataOffset;
|
||||
return 'x' + ('00000000' + (parser(bytes, offset) * 256 * 256 + parser(bytes, offset + 2)).toString(16)).substr(-8);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses the string representation of a multi-valued element into an array of strings. If the parser
|
||||
* parameter is passed and is a function, it will be applied to each element of the resulting array.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @param tag {String} A DICOM tag with in the format xGGGGEEEE.
|
||||
* @param parser {Function} An optional parser function that can be applied to each element of the array.
|
||||
* @returns {Array} An array of floating point numbers or null if the field is not present or data is not long enough.
|
||||
*/
|
||||
multiValue: function(data, tag, parser) {
|
||||
if (this.isValidDataSet(data) && tag in data.elements) {
|
||||
let element = data.elements[tag];
|
||||
if (element && element.length > 0) {
|
||||
let string = dicomParser.readFixedString(data.byteArray, element.dataOffset, element.length);
|
||||
if (typeof string === 'string' && string.length > 0) {
|
||||
if (typeof parser !== 'function') {
|
||||
parser = null;
|
||||
}
|
||||
|
||||
return string.split('\\').map(function(value) {
|
||||
value = value.trim();
|
||||
return parser !== null ? parser(value) : value;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a string to an array of floats for a multi-valued element.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @param tag {String} A DICOM tag with in the format xGGGGEEEE.
|
||||
* @returns {Array} An array of floating point numbers or null if the field is not present or data is not long enough.
|
||||
*/
|
||||
floatArray: function(data, tag) {
|
||||
return this.multiValue(data, tag, parseFloat);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { _ } from 'meteor/underscore';
|
||||
import { $ } from 'meteor/jquery';
|
||||
import _ from 'underscore';
|
||||
import $ from 'jquery';
|
||||
|
||||
OHIF.string = {};
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/* jshint -W060 */
|
||||
import absoluteUrl from './absoluteUrl';
|
||||
|
||||
export default function(fileName, callback) {
|
||||
const script = document.createElement('script');
|
||||
script.src = absoluteUrl(`/packages/ohif_polyfill/public/js/${fileName}`);
|
||||
script.onload = () => {
|
||||
if (typeof callback === 'function') {
|
||||
callback(script);
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
Reference in new issue
Block a user