Add ServerConfiguration schema to validate Meteor settings, removed defaultSettings, ran JSCS for DIMSEService package
This commit is contained in:
parent
356abd0978
commit
d4b014847a
@ -1,54 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
Meteor.startup(function() {
|
||||
if (Object.keys(Meteor.settings).length > 1) {
|
||||
console.log('Using custom LesionTracker settings');
|
||||
console.log(Meteor.settings);
|
||||
return;
|
||||
}
|
||||
|
||||
Meteor.settings = {
|
||||
servers: {
|
||||
dicomWeb: [{
|
||||
name: 'Orthanc',
|
||||
wadoUriRootNOTE: 'either this uri is not correct for wado-uri or wado-uri is not configured on orthanc currently',
|
||||
wadoUriRoot: 'http://localhost:8043/wado',
|
||||
qidoRoot: 'http://localhost:8042/dicom-web',
|
||||
wadoRoot: 'http://localhost:8042/dicom-web',
|
||||
qidoSupportsIncludeField: false,
|
||||
imageRendering: 'wadouri',
|
||||
requestOptions: {
|
||||
auth: 'orthanc:orthanc',
|
||||
logRequests: true,
|
||||
logResponses: false,
|
||||
logTiming: true
|
||||
}
|
||||
}],
|
||||
dimse: [{
|
||||
name: "ORTHANC_DIMSE",
|
||||
peers: [{
|
||||
host: 'localhost',
|
||||
port: 4242,
|
||||
aeTitle: 'ORTHANC',
|
||||
default: true
|
||||
}]
|
||||
}]
|
||||
},
|
||||
"defaultServiceType": 'dicomWeb',
|
||||
"public": {
|
||||
"verifyEmail": false,
|
||||
"ui": {
|
||||
"studyListFunctionsEnabled": true
|
||||
}
|
||||
}
|
||||
//defaultServiceType: 'dimse'
|
||||
};
|
||||
|
||||
console.log('Using default LesionTracker settings with service: ' + Meteor.settings.defaultServiceType);
|
||||
|
||||
// Bind events if window is closed
|
||||
$(window).bind('beforeunload', function (e) {
|
||||
// have to return null, unless you want a chrome popup alert
|
||||
// return 'If you leave this page then any unsaved changes will be lost.';
|
||||
});
|
||||
});
|
||||
@ -39,3 +39,4 @@ clinical:router
|
||||
fastclick@1.0.12
|
||||
standard-minifier-css@1.1.8
|
||||
standard-minifier-js@1.1.8
|
||||
aldeed:simple-schema
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
aldeed:simple-schema@1.5.3
|
||||
allow-deny@1.0.5
|
||||
arsnebula:reactive-promise@0.9.1
|
||||
autoupdate@1.3.11
|
||||
@ -49,6 +50,7 @@ jquery@1.11.9
|
||||
launch-screen@1.0.12
|
||||
livedata@1.0.18
|
||||
logging@1.1.14
|
||||
mdg:validation-error@0.2.0
|
||||
meteor@1.2.16
|
||||
meteor-base@1.0.4
|
||||
meteor-platform@1.2.6
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
Meteor.startup(function() {
|
||||
if (Object.keys(Meteor.settings).length > 1) {
|
||||
console.log('Using custom LesionTracker settings: ');
|
||||
console.log(Meteor.settings);
|
||||
return;
|
||||
}
|
||||
|
||||
Meteor.settings = {
|
||||
servers: {
|
||||
dicomWeb: [{
|
||||
name: 'Orthanc',
|
||||
wadoUriRootNOTE: 'either this uri is not correct for wado-uri or wado-uri is not configured on orthanc currently',
|
||||
wadoUriRoot: 'http://localhost:8043/wado',
|
||||
qidoRoot: 'http://localhost:8042/dicom-web',
|
||||
wadoRoot: 'http://localhost:8042/dicom-web',
|
||||
qidoSupportsIncludeField: false,
|
||||
imageRendering: 'wadouri',
|
||||
requestOptions: {
|
||||
auth: 'orthanc:orthanc',
|
||||
logRequests: true,
|
||||
logResponses: false,
|
||||
logTiming: true
|
||||
}
|
||||
}],
|
||||
dimse: [{
|
||||
name: "ORTHANC_DIMSE",
|
||||
peers: [{
|
||||
host: 'localhost',
|
||||
port: 4242,
|
||||
hostAE: 'ORTHANC'
|
||||
}]
|
||||
}]
|
||||
},
|
||||
defaultServiceType: 'dicomWeb',
|
||||
//defaultServiceType: 'dimse'
|
||||
public: {
|
||||
ui: {
|
||||
studyListFunctionsEnabled: true
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -5,8 +5,9 @@ Package.describe({
|
||||
});
|
||||
|
||||
Package.onUse(function(api) {
|
||||
//api.use("weiwei:dicomservices");
|
||||
api.versionsFrom('1.4');
|
||||
|
||||
api.use('ecmascript');
|
||||
api.addFiles('server/require.js', 'server');
|
||||
api.addFiles('server/constants.js', 'server');
|
||||
api.addFiles('server/elements_data.js', 'server');
|
||||
|
||||
@ -5,14 +5,15 @@ function time() {
|
||||
}
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
return Math.floor(Math.random() * (max - min)) + min;
|
||||
}
|
||||
|
||||
var Envelope = function(command, dataset) {
|
||||
EventEmitter.call(this);
|
||||
this.command = command;
|
||||
this.dataset = dataset;
|
||||
}
|
||||
};
|
||||
|
||||
util.inherits(Envelope, EventEmitter);
|
||||
|
||||
CSocket = function(socket, options) {
|
||||
@ -39,35 +40,43 @@ CSocket = function(socket, options) {
|
||||
this.options = options;
|
||||
|
||||
var o = this;
|
||||
this.socket.on("connect", function(){
|
||||
this.socket.on('connect', function() {
|
||||
console.log('Connect');
|
||||
o.ready();
|
||||
});
|
||||
this.socket.on("data", function(data) {
|
||||
this.socket.on('data', function(data) {
|
||||
o.received(data);
|
||||
});
|
||||
this.socket.on("error", function(he) {
|
||||
console.log("Error: ", he);
|
||||
this.socket.on('error', function(he) {
|
||||
console.log('Error: ', he);
|
||||
throw 'Error: ' + he;
|
||||
});
|
||||
this.socket.on("close", function() {
|
||||
this.socket.on('timeout', function(he) {
|
||||
console.log('Timeout: ', he);
|
||||
throw 'Timeout: ' + he;
|
||||
});
|
||||
this.socket.on('close', function() {
|
||||
if (o.intervalId) {
|
||||
clearInterval(o.intervalId);
|
||||
}
|
||||
o.connected = false;
|
||||
console.log("Connection closed");
|
||||
o.emit('close');
|
||||
})
|
||||
|
||||
this.on("released", function() {
|
||||
o.connected = false;
|
||||
console.log('Connection closed');
|
||||
o.emit('close');
|
||||
});
|
||||
|
||||
this.on('released', function() {
|
||||
this.released();
|
||||
});
|
||||
this.on('aborted', function(pdu) {
|
||||
console.log('Assocation aborted with reason ' + pdu.reason);
|
||||
console.warn('Association aborted with reason ' + pdu.reason);
|
||||
this.released();
|
||||
})
|
||||
});
|
||||
this.on('message', function(pdvs) {
|
||||
this.receivedMessage(pdvs);
|
||||
});
|
||||
};
|
||||
|
||||
util.inherits(CSocket, EventEmitter);
|
||||
|
||||
CSocket.prototype.setCallingAE = function(ae) {
|
||||
@ -84,22 +93,23 @@ CSocket.prototype.associate = function() {
|
||||
associateRQ.setCallingAETitle(this.callingAe);
|
||||
associateRQ.setApplicationContextItem(new ApplicationContextItem());
|
||||
|
||||
var contextItems = []
|
||||
var contextItems = [];
|
||||
this.presentationContexts.forEach(function(context) {
|
||||
var contextItem = new PresentationContextItem(),
|
||||
syntaxes = [];
|
||||
context.transferSyntaxes.forEach(function(transferSyntax) {
|
||||
var transfer = new TransferSyntaxItem();
|
||||
transfer.setTransferSyntaxName(transferSyntax);
|
||||
syntaxes.push(transfer);
|
||||
});
|
||||
contextItem.setTransferSyntaxesItems(syntaxes);
|
||||
contextItem.setPresentationContextID(context.id);
|
||||
var contextItem = new PresentationContextItem(),
|
||||
syntaxes = [];
|
||||
|
||||
var abstractItem = new AbstractSyntaxItem();
|
||||
abstractItem.setAbstractSyntaxName(context.abstractSyntax);
|
||||
contextItem.setAbstractSyntaxItem(abstractItem);
|
||||
contextItems.push(contextItem);
|
||||
context.transferSyntaxes.forEach(function(transferSyntax) {
|
||||
var transfer = new TransferSyntaxItem();
|
||||
transfer.setTransferSyntaxName(transferSyntax);
|
||||
syntaxes.push(transfer);
|
||||
});
|
||||
contextItem.setTransferSyntaxesItems(syntaxes);
|
||||
contextItem.setPresentationContextID(context.id);
|
||||
|
||||
var abstractItem = new AbstractSyntaxItem();
|
||||
abstractItem.setAbstractSyntaxName(context.abstractSyntax);
|
||||
contextItem.setAbstractSyntaxItem(abstractItem);
|
||||
contextItems.push(contextItem);
|
||||
});
|
||||
associateRQ.setPresentationContextItems(contextItems);
|
||||
|
||||
@ -123,39 +133,45 @@ CSocket.prototype.associate = function() {
|
||||
CSocket.prototype.getContext = function(id) {
|
||||
for (var k in this.presentationContexts) {
|
||||
var ctx = this.presentationContexts[k];
|
||||
if (id == ctx.id) return ctx;
|
||||
if (id === ctx.id) {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.getSyntax = function(contextId) {
|
||||
if (!this.negotiatedContexts[contextId]) return null;
|
||||
|
||||
return this.negotiatedContexts[contextId].transferSyntax;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.getContextByUID = function(uid) {
|
||||
for (var k in this.negotiatedContexts) {
|
||||
var ctx = this.negotiatedContexts[k];
|
||||
if (ctx.abstractSyntax == uid) {
|
||||
if (ctx.abstractSyntax === uid) {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.getContextId = function(contextId) {
|
||||
if (!this.negotiatedContexts[contextId]) return null;
|
||||
if (!this.negotiatedContexts[contextId]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.negotiatedContexts[contextId].id;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.setPresentationContexts = function(uids) {
|
||||
var contexts = [],
|
||||
id = 0;
|
||||
uids.forEach(function(uid) {
|
||||
id++;
|
||||
if (typeof uid == 'string') {
|
||||
if (typeof uid === 'string') {
|
||||
contexts.push({
|
||||
id: id,
|
||||
abstractSyntax: uid,
|
||||
@ -174,7 +190,7 @@ CSocket.prototype.setPresentationContexts = function(uids) {
|
||||
|
||||
CSocket.prototype.newMessageId = function() {
|
||||
return (++this.messageIdCounter) % 65536;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.resetReceive = function() {
|
||||
this.receiving = this.receiveLength = null;
|
||||
@ -197,7 +213,7 @@ CSocket.prototype.released = function() {
|
||||
};
|
||||
|
||||
CSocket.prototype.ready = function() {
|
||||
console.log("Connection established");
|
||||
console.log('Connection established');
|
||||
this.connected = true;
|
||||
this.started = time();
|
||||
|
||||
@ -217,8 +233,6 @@ CSocket.prototype.checkIdle = function() {
|
||||
this.idleClose();
|
||||
} else if (this.lastReceived && (current - this.lastReceived >= idl)) {
|
||||
this.idleClose();
|
||||
} else {
|
||||
//console.log('keep idling')
|
||||
}
|
||||
};
|
||||
|
||||
@ -228,7 +242,6 @@ CSocket.prototype.idleClose = function() {
|
||||
};
|
||||
|
||||
CSocket.prototype.received = function(data) {
|
||||
var i = 0;
|
||||
do {
|
||||
data = this.process(data);
|
||||
} while (data !== null);
|
||||
@ -236,7 +249,6 @@ CSocket.prototype.received = function(data) {
|
||||
};
|
||||
|
||||
CSocket.prototype.process = function(data) {
|
||||
//console.log("Data received");
|
||||
if (this.receiving === null) {
|
||||
if (this.minRecv) {
|
||||
data = Buffer.concat([this.minRecv, data], this.minRecv.length + data.length);
|
||||
@ -263,6 +275,7 @@ CSocket.prototype.process = function(data) {
|
||||
process = data.slice(0, len + 6);
|
||||
remaining = data.slice(len + 6, cmp + 6);
|
||||
}
|
||||
|
||||
this.resetReceive();
|
||||
this.interpret(new ReadStream(process), this);
|
||||
if (remaining) {
|
||||
@ -270,6 +283,7 @@ CSocket.prototype.process = function(data) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('Data received');
|
||||
var newData = Buffer.concat([this.receiving, data], this.receiving.length + data.length),
|
||||
pduLength = newData.length - 6;
|
||||
|
||||
@ -281,6 +295,7 @@ CSocket.prototype.process = function(data) {
|
||||
remaining = newData.slice(this.receiveLength + 6, pduLength + 6);
|
||||
newData = newData.slice(0, this.receiveLength + 6);
|
||||
}
|
||||
|
||||
this.resetReceive();
|
||||
this.interpret(new ReadStream(newData));
|
||||
if (remaining) {
|
||||
@ -288,6 +303,7 @@ CSocket.prototype.process = function(data) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -302,8 +318,9 @@ CSocket.prototype.interpret = function(stream) {
|
||||
pdu.presentationContextItems.forEach(function(ctx) {
|
||||
var requested = o.getContext(ctx.presentationContextID);
|
||||
if (!requested) {
|
||||
throw "Accepted presentation context not found";
|
||||
throw 'Accepted presentation context not found';
|
||||
}
|
||||
|
||||
o.negotiatedContexts[ctx.presentationContextID] = {
|
||||
id: ctx.presentationContextID,
|
||||
transferSyntax: ctx.transferSyntaxesItems[0].transferSyntaxName,
|
||||
@ -350,11 +367,13 @@ CSocket.prototype.interpret = function(stream) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pdvs[i].isLast) {
|
||||
this.emit('message', pdvs[i]);
|
||||
} else {
|
||||
this.pendingPDVs = [pdvs[i]];
|
||||
}
|
||||
|
||||
i = j;
|
||||
} else {
|
||||
this.emit('message', pdvs[i++]);
|
||||
@ -377,9 +396,11 @@ CSocket.prototype.receivedMessage = function(pdv) {
|
||||
if (msg.is(C.COMMAND_C_GET_RSP) || msg.is(C.COMMAND_C_MOVE_RSP)) {
|
||||
//console.log('remaining', msg.getNumOfRemainingSubOperations(), msg.getNumOfCompletedSubOperations());
|
||||
}
|
||||
|
||||
if (msg.failure()) {
|
||||
console.log("message failed with status ", msg.getStatus().toString(16));
|
||||
console.log('message failed with status ', msg.getStatus().toString(16));
|
||||
}
|
||||
|
||||
listener.emit('response', msg);
|
||||
if (msg.isFinal()) {
|
||||
if (listener) {
|
||||
@ -403,7 +424,7 @@ CSocket.prototype.receivedMessage = function(pdv) {
|
||||
|
||||
} else {
|
||||
if (!this.lastCommand) {
|
||||
throw "Only dataset?";
|
||||
throw 'Only dataset?';
|
||||
} else if (!this.lastCommand.haveData()) {
|
||||
throw "Last command didn't indicate presence of data";
|
||||
}
|
||||
@ -413,7 +434,7 @@ CSocket.prototype.receivedMessage = function(pdv) {
|
||||
if (this.messages[replyId].listener) {
|
||||
var flag = this.lastCommand.failure() ? true : false;
|
||||
|
||||
this.messages[replyId].listener.emit("result", msg, flag);
|
||||
this.messages[replyId].listener.emit('result', msg, flag);
|
||||
|
||||
if (this.lastCommand.failure()) {
|
||||
delete this.messages[replyId];
|
||||
@ -429,7 +450,7 @@ CSocket.prototype.receivedMessage = function(pdv) {
|
||||
if (this.lastGets.length > 0) {
|
||||
useId = this.lastGets[0];
|
||||
} else {
|
||||
throw "Where does this c-store came from?";
|
||||
throw 'Where does this c-store came from?';
|
||||
}
|
||||
} else console.log('move ', moveMessageId);
|
||||
//this.storeResponse(useId, msg);
|
||||
@ -447,7 +468,7 @@ CSocket.prototype.wrapToPData = function(message, context) {
|
||||
pdv.setMessage(message);
|
||||
pdata.setPresentationDataValueItems([pdv]);
|
||||
return pdata;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.sendMessage = function(context, command, dataset) {
|
||||
var nContext = this.getContextByUID(context),
|
||||
@ -459,7 +480,7 @@ CSocket.prototype.sendMessage = function(context, command, dataset) {
|
||||
msgData.listener = new Envelope(command);
|
||||
|
||||
var o = this;
|
||||
msgData.listener.on('cancel', function(){
|
||||
msgData.listener.on('cancel', function() {
|
||||
var cancelMessage = null;
|
||||
if (this.command.is(C.COMMAND_C_FIND_RQ) || this.command.is(C.COMMAND_C_MOVE_RQ)) {
|
||||
cancelMessage = new CCancelRQ();
|
||||
@ -474,20 +495,22 @@ CSocket.prototype.sendMessage = function(context, command, dataset) {
|
||||
command.setSyntax(C.IMPLICIT_LITTLE_ENDIAN);
|
||||
command.setContextId(context);
|
||||
command.setMessageId(messageId);
|
||||
if (dataset)
|
||||
if (dataset) {
|
||||
command.setDataSetPresent(C.DATA_SET_PRESENT);
|
||||
}
|
||||
|
||||
this.lastSent = command;
|
||||
if (command.is(C.COMMAND_C_GET_RQ)) {
|
||||
this.lastGets.push(messageId);
|
||||
}
|
||||
|
||||
var pdata = this.wrapToPData(command);
|
||||
|
||||
msgData.command = command;
|
||||
this.messages[messageId] = msgData;
|
||||
console.log('Sending command ' + command.typeString());
|
||||
this.send(pdata);
|
||||
if (dataset && typeof dataset == 'object') {
|
||||
if (dataset && typeof dataset === 'object') {
|
||||
dataset.setSyntax(syntax);
|
||||
var dsData = new PDataTF(),
|
||||
dPdv = new PresentationDataValueItem(cid);
|
||||
@ -496,6 +519,7 @@ CSocket.prototype.sendMessage = function(context, command, dataset) {
|
||||
dsData.setPresentationDataValueItems([dPdv]);
|
||||
this.send(dsData);
|
||||
}
|
||||
|
||||
return msgData.listener;
|
||||
};
|
||||
|
||||
@ -520,7 +544,9 @@ CSocket.prototype.wrapMessage = function(data) {
|
||||
var datasetMessage = new DataSetMessage();
|
||||
datasetMessage.setElements(data);
|
||||
return datasetMessage;
|
||||
} else return data;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.find = function(params, options) {
|
||||
@ -540,14 +566,14 @@ CSocket.prototype.storeInstance = function(sopClassUID, sopInstanceUID, options)
|
||||
storeMessage.setAffectedSOPClassUID(sopClassUID);
|
||||
|
||||
return this.sendMessage(sopClassUID, storeMessage, true);
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.moveInstances = function(destination, params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_IMAGE,
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_MOVE
|
||||
context: C.SOP_STUDY_ROOT_MOVE
|
||||
}, options);
|
||||
|
||||
return this.move(destination, sendParams, options);
|
||||
@ -556,13 +582,13 @@ CSocket.prototype.moveInstances = function(destination, params, options) {
|
||||
CSocket.prototype.findPatients = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_PATIENT,
|
||||
0x00100010: "",
|
||||
0x00100020: "",
|
||||
0x00100030: "",
|
||||
0x00100040: "",
|
||||
0x00100010: '',
|
||||
0x00100020: '',
|
||||
0x00100030: '',
|
||||
0x00100040: '',
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_PATIENT_ROOT_FIND
|
||||
context: C.SOP_PATIENT_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
@ -571,13 +597,13 @@ CSocket.prototype.findPatients = function(params, options) {
|
||||
CSocket.prototype.findStudies = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_STUDY,
|
||||
0x00080020: "",
|
||||
0x00100010: "",
|
||||
0x00080061: "",
|
||||
0x0020000D: ""
|
||||
0x00080020: '',
|
||||
0x00100010: '',
|
||||
0x00080061: '',
|
||||
0x0020000D: ''
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_FIND
|
||||
context: C.SOP_STUDY_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
@ -586,13 +612,13 @@ CSocket.prototype.findStudies = function(params, options) {
|
||||
CSocket.prototype.findSeries = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_SERIES,
|
||||
0x00080020: "",
|
||||
0x0020000E: "",
|
||||
0x0008103E: "",
|
||||
0x0020000D: ""
|
||||
0x00080020: '',
|
||||
0x0020000E: '',
|
||||
0x0008103E: '',
|
||||
0x0020000D: ''
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_FIND
|
||||
context: C.SOP_STUDY_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
@ -601,14 +627,14 @@ CSocket.prototype.findSeries = function(params, options) {
|
||||
CSocket.prototype.findInstances = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_IMAGE,
|
||||
0x00080020: "",
|
||||
0x0020000E: "",
|
||||
0x0008103E: "",
|
||||
0x0020000D: ""
|
||||
0x00080020: '',
|
||||
0x0020000E: '',
|
||||
0x0008103E: '',
|
||||
0x0020000D: ''
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_FIND
|
||||
context: C.SOP_STUDY_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
// Uses NodeJS 'net'
|
||||
// https://nodejs.org/api/net.html
|
||||
var net = Npm.require('net'),
|
||||
Socket = net.Socket;
|
||||
|
||||
var DEFAULT_MAX_PACKAGE_SIZE = 32768;
|
||||
|
||||
Connection = function (options) {
|
||||
Connection = function(options) {
|
||||
EventEmitter.call(this);
|
||||
this.options = Object.assign({
|
||||
maxPackageSize: C.DEFAULT_MAX_PACKAGE_SIZE,
|
||||
@ -18,21 +20,24 @@ Connection = function (options) {
|
||||
this.peerSockets = {};
|
||||
this.defaultPeer = null;
|
||||
this.defaultServer = null;
|
||||
}
|
||||
};
|
||||
|
||||
util.inherits(Connection, EventEmitter);
|
||||
|
||||
var StoreHandle = function () {
|
||||
var StoreHandle = function() {
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
util.inherits(StoreHandle, EventEmitter);
|
||||
|
||||
Connection.prototype.addPeer = function (options) {
|
||||
Connection.prototype.addPeer = function(options) {
|
||||
if (!options.aeTitle || !options.host || !options.port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.peers[options.aeTitle] = {
|
||||
host: options.host, port: options.port
|
||||
host: options.host,
|
||||
port: options.port
|
||||
};
|
||||
if (options.default) {
|
||||
if (options.server) {
|
||||
@ -41,90 +46,103 @@ Connection.prototype.addPeer = function (options) {
|
||||
this.defaultPeer = options.aeTitle;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.server) {
|
||||
//start listening
|
||||
var server = net.createServer();
|
||||
server.listen(options.port, options.host, function () {
|
||||
console.log("listening on %j", this.address());
|
||||
server.listen(options.port, options.host, function() {
|
||||
console.log('listening on %j', this.address());
|
||||
});
|
||||
server.on('error', function (err) {
|
||||
console.log("server error %j", err);
|
||||
server.on('error', function(err) {
|
||||
console.log('server error %j', err);
|
||||
});
|
||||
var o = this;
|
||||
server.on('connection', function (nativeSocket) {
|
||||
server.on('connection', function(nativeSocket) {
|
||||
//incoming connections
|
||||
var socket = new CSocket(nativeSocket, o.options);
|
||||
o.addSocket(options.aeTitle, socket);
|
||||
|
||||
//close server on close socket
|
||||
socket.on('close', function () {
|
||||
socket.on('close', function() {
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Connection.prototype.selectPeer = function (aeTitle) {
|
||||
Connection.prototype.selectPeer = function(aeTitle) {
|
||||
if (!aeTitle || !this.peers[aeTitle]) {
|
||||
throw "No such peer";
|
||||
throw 'No such peer';
|
||||
}
|
||||
|
||||
return this.peers[aeTitle];
|
||||
};
|
||||
|
||||
Connection.prototype._sendFile = function (socket, sHandle, file, maxSend, metaLength, list) {
|
||||
var fileNameText = typeof file.file == 'string' ? file.file : 'buffer';
|
||||
console.log("Sending file " + fileNameText);
|
||||
var useContext = socket.getContextByUID(file.context), self = this;
|
||||
Connection.prototype._sendFile = function(socket, sHandle, file, maxSend, metaLength, list) {
|
||||
var fileNameText = typeof file.file === 'string' ? file.file : 'buffer';
|
||||
console.log('Sending file ' + fileNameText);
|
||||
var useContext = socket.getContextByUID(file.context),
|
||||
self = this;
|
||||
|
||||
PDU.generatePDatas(useContext.id, file.file, maxSend, null, metaLength, function (err, handle) {
|
||||
PDU.generatePDatas(useContext.id, file.file, maxSend, null, metaLength, function(err, handle) {
|
||||
if (err) {
|
||||
console.log('Error while sending file');
|
||||
return;
|
||||
}
|
||||
var processNext = function () {
|
||||
|
||||
var processNext = function() {
|
||||
var next = list.shift();
|
||||
if (next)
|
||||
if (next) {
|
||||
self._sendFile(socket, sHandle, next, maxSend, metaLength, list);
|
||||
else
|
||||
} else {
|
||||
socket.release();
|
||||
}
|
||||
};
|
||||
|
||||
var store = socket.storeInstance(useContext.abstractSyntax, file.uid);
|
||||
handle.on('pdv', function (pdv) {
|
||||
handle.on('pdv', function(pdv) {
|
||||
socket.sendPData(pdv);
|
||||
});
|
||||
handle.on('error', function (err) {
|
||||
handle.on('error', function(err) {
|
||||
sHandle.emit('file', err, fileNameText);
|
||||
processNext();
|
||||
});
|
||||
store.on('response', function (msg) {
|
||||
store.on('response', function(msg) {
|
||||
var statusText = msg.getStatus().toString(16);
|
||||
console.log('STORE reponse with status', statusText);
|
||||
var error = null;
|
||||
if (msg.failure()) {
|
||||
error = new Error(statusText);
|
||||
}
|
||||
|
||||
sHandle.emit('file', error, fileNameText);
|
||||
processNext();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.storeInstances = function (fileList) {
|
||||
var contexts = {}, read = 0, length = fileList.length, toSend = [], self = this, handle = new StoreHandle();
|
||||
Connection.prototype.storeInstances = function(fileList) {
|
||||
var contexts = {},
|
||||
read = 0,
|
||||
length = fileList.length,
|
||||
toSend = [],
|
||||
self = this,
|
||||
handle = new StoreHandle();
|
||||
var lastProcessedMetaLength;
|
||||
fileList.forEach(function (bufferOrFile) {
|
||||
var fileNameText = typeof bufferOrFile == 'string' ? bufferOrFile : 'buffer';
|
||||
DicomMessage.readMetaHeader(bufferOrFile, function (err, metaMessage, metaLength) {
|
||||
fileList.forEach(function(bufferOrFile) {
|
||||
var fileNameText = typeof bufferOrFile === 'string' ? bufferOrFile : 'buffer';
|
||||
DicomMessage.readMetaHeader(bufferOrFile, function(err, metaMessage, metaLength) {
|
||||
read++;
|
||||
if (err) {
|
||||
handle.emit('file', err, fileNameText);
|
||||
if (read == length && toSend.length > 0 && lastProcessedMetaLength) {
|
||||
if (read === length && toSend.length > 0 && lastProcessedMetaLength) {
|
||||
sendProcessedFiles(self, contexts, toSend, handle, lastProcessedMetaLength);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
console.log('Dicom file ' + (typeof bufferOrFile == 'string' ? bufferOrFile : 'buffer') + ' found');
|
||||
|
||||
console.log('Dicom file ' + (typeof bufferOrFile === 'string' ? bufferOrFile : 'buffer') + ' found');
|
||||
lastProcessedMetaLength = metaLength;
|
||||
var syntax = metaMessage.getValue(0x00020010),
|
||||
sopClassUID = metaMessage.getValue(0x00020002),
|
||||
@ -133,12 +151,18 @@ Connection.prototype.storeInstances = function (fileList) {
|
||||
if (!contexts[sopClassUID]) {
|
||||
contexts[sopClassUID] = [];
|
||||
}
|
||||
if (syntax && contexts[sopClassUID].indexOf(syntax) == -1) {
|
||||
|
||||
if (syntax && contexts[sopClassUID].indexOf(syntax) === -1) {
|
||||
contexts[sopClassUID].push(syntax);
|
||||
}
|
||||
toSend.push({file: bufferOrFile, context: sopClassUID, uid: instanceUID});
|
||||
|
||||
if (read == length) {
|
||||
toSend.push({
|
||||
file: bufferOrFile,
|
||||
context: sopClassUID,
|
||||
uid: instanceUID
|
||||
});
|
||||
|
||||
if (read === length) {
|
||||
sendProcessedFiles(self, contexts, toSend, handle, metaLength);
|
||||
}
|
||||
});
|
||||
@ -147,27 +171,31 @@ Connection.prototype.storeInstances = function (fileList) {
|
||||
};
|
||||
|
||||
// Starts to send dcm files
|
||||
sendProcessedFiles = function (self, contexts, toSend, handle, metaLength) {
|
||||
sendProcessedFiles = function(self, contexts, toSend, handle, metaLength) {
|
||||
var useContexts = [];
|
||||
for (var context in contexts) {
|
||||
var useSyntaxes = contexts[context];
|
||||
if (useSyntaxes.length > 0) {
|
||||
useContexts.push({context: context, syntaxes: contexts[context]});
|
||||
useContexts.push({
|
||||
context: context,
|
||||
syntaxes: contexts[context]
|
||||
});
|
||||
} else {
|
||||
throw "No syntax specified for context " + context;
|
||||
throw 'No syntax specified for context ' + context;
|
||||
}
|
||||
}
|
||||
|
||||
self.associate({
|
||||
contexts: useContexts
|
||||
}, function (ac) {
|
||||
var maxSend = ac.getMaxSize(), next = toSend.shift();
|
||||
}, function(ac) {
|
||||
var maxSend = ac.getMaxSize(),
|
||||
next = toSend.shift();
|
||||
self._sendFile(this, handle, next, maxSend, metaLength, toSend);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.storeResponse = function (messageId, msg) {
|
||||
Connection.prototype.storeResponse = function(messageId, msg) {
|
||||
var rq = this.messages[messageId];
|
||||
|
||||
if (rq.listener[2]) {
|
||||
@ -180,12 +208,12 @@ Connection.prototype.storeResponse = function (messageId, msg) {
|
||||
replyMessage.setReplyMessageId(this.lastCommand.messageId);
|
||||
this.sendMessage(replyMessage, null, null, storeSr);
|
||||
} else {
|
||||
throw "Missing store status";
|
||||
throw 'Missing store status';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Connection.prototype.allClosed = function () {
|
||||
Connection.prototype.allClosed = function() {
|
||||
var allClosed = true;
|
||||
for (var i in o.peerSockets) {
|
||||
if (Object.keys(o.peerSockets[ae]).length > 0) {
|
||||
@ -193,48 +221,61 @@ Connection.prototype.allClosed = function () {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return allClosed;
|
||||
};
|
||||
|
||||
Connection.prototype.addSocket = function (ae, socket) {
|
||||
Connection.prototype.addSocket = function(ae, socket) {
|
||||
if (!this.peerSockets[ae]) {
|
||||
this.peerSockets[ae] = {};
|
||||
}
|
||||
|
||||
this.peerSockets[ae][socket.id] = socket;
|
||||
|
||||
var o = this;
|
||||
socket.on("close", function () {
|
||||
socket.on('close', function() {
|
||||
if (o.peerSockets[ae][this.id]) {
|
||||
delete o.peerSockets[ae][this.id];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.associate = function (options, callback) {
|
||||
Connection.prototype.associate = function(options, callback) {
|
||||
var hostAE = options.hostAE ? options.hostAE : this.defaultPeer,
|
||||
sourceAE = options.sourceAE ? options.sourceAE : this.defaultServer;
|
||||
|
||||
if (!hostAE || !sourceAE) {
|
||||
throw "Peers not provided or no defaults in settings";
|
||||
throw 'Peers not provided or no defaults in settings';
|
||||
}
|
||||
|
||||
var peerInfo = this.selectPeer(hostAE), nativeSocket = new Socket();
|
||||
var socket = new CSocket(nativeSocket, this.options), o = this;
|
||||
var peerInfo = this.selectPeer(hostAE),
|
||||
nativeSocket = new Socket();
|
||||
|
||||
var socket = new CSocket(nativeSocket, this.options),
|
||||
o = this;
|
||||
|
||||
if (callback) {
|
||||
socket.once('associated', callback);
|
||||
}
|
||||
|
||||
console.log('Starting Connection...');
|
||||
|
||||
socket.setCalledAe(hostAE);
|
||||
socket.setCallingAE(sourceAE);
|
||||
|
||||
console.log(peerInfo);
|
||||
|
||||
nativeSocket.connect({
|
||||
host: peerInfo.host, port: peerInfo.port
|
||||
}, function () {
|
||||
host: peerInfo.host,
|
||||
port: peerInfo.port
|
||||
}, function() {
|
||||
//connected
|
||||
o.addSocket(hostAE, socket);
|
||||
|
||||
if (options.contexts) {
|
||||
socket.setPresentationContexts(options.contexts);
|
||||
} else {
|
||||
throw "Contexts must be specified";
|
||||
throw 'Contexts must be specified';
|
||||
}
|
||||
|
||||
socket.associate();
|
||||
|
||||
@ -56,12 +56,14 @@ var getInstanceRetrievalParams = function(studyInstanceUID, seriesInstanceUID) {
|
||||
|
||||
Meteor.startup(function() {
|
||||
if (!Meteor.settings.servers.dimse || !Meteor.settings.servers.dimse.length) {
|
||||
return;
|
||||
console.error('dimse-config: ' + 'No DIMSE Servers provided.');
|
||||
throw new Meteor.Error('dimse-config', 'No DIMSE Servers provided.');
|
||||
}
|
||||
|
||||
// TODO: [custom-servers] use active server and check if type is DIMSE
|
||||
var peers = Meteor.settings.servers.dimse[0].peers;
|
||||
if (!peers || !peers.length) {
|
||||
console.error('dimse-config: ' + 'No DIMSE Peers provided.');
|
||||
throw new Meteor.Error('dimse-config', 'No DIMSE Peers provided.');
|
||||
}
|
||||
|
||||
@ -71,7 +73,7 @@ Meteor.startup(function() {
|
||||
conn.addPeer(peer);
|
||||
});
|
||||
} catch(error) {
|
||||
console.warn('dimse-addPeers: ' + error);
|
||||
console.error('dimse-addPeers: ' + error);
|
||||
throw new Meteor.Error('dimse-addPeers', error);
|
||||
}
|
||||
});
|
||||
@ -82,6 +84,7 @@ DIMSE.associate = function(contexts, callback, options) {
|
||||
};
|
||||
options = Object.assign(defaults, options);
|
||||
|
||||
console.log('Associating...');
|
||||
try {
|
||||
conn.associate(options, function(pdu) {
|
||||
// associated
|
||||
@ -89,7 +92,7 @@ DIMSE.associate = function(contexts, callback, options) {
|
||||
callback.call(this, pdu);
|
||||
});
|
||||
} catch(error) {
|
||||
console.warn('dimse-associate: ' + error);
|
||||
console.error('dimse-associate: ' + error);
|
||||
throw new Meteor.Error('dimse-associate', error);
|
||||
}
|
||||
};
|
||||
@ -165,7 +168,8 @@ DIMSE.retrieveStudies = function(params, options) {
|
||||
};
|
||||
|
||||
DIMSE._retrieveInstancesBySeries = function(conn, series, studyInstanceUID, callback, params) {
|
||||
var aSeries = series.shift(), seriesInstanceUID = aSeries.getValue(0x0020000E),
|
||||
var aSeries = series.shift(),
|
||||
seriesInstanceUID = aSeries.getValue(0x0020000E),
|
||||
defaultParams = getInstanceRetrievalParams(studyInstanceUID, seriesInstanceUID);
|
||||
|
||||
var result = conn.findInstances(Object.assign(defaultParams, params)),
|
||||
@ -189,8 +193,9 @@ DIMSE.retrieveInstancesByStudyOnlyMulti = function(studyInstanceUID, params, opt
|
||||
return [];
|
||||
}
|
||||
|
||||
var series = DIMSE.retrieveSeries(studyInstanceUID, params, options), instances = [];
|
||||
series.forEach(function(seriesData){
|
||||
var series = DIMSE.retrieveSeries(studyInstanceUID, params, options),
|
||||
instances = [];
|
||||
series.forEach(function(seriesData) {
|
||||
var seriesInstanceUID = seriesData.getValue(0x0020000E);
|
||||
|
||||
var relatedInstances = DIMSE.retrieveInstances(studyInstanceUID, seriesInstanceUID, params, options);
|
||||
@ -205,7 +210,7 @@ DIMSE.retrieveInstancesByStudyOnly = function(studyInstanceUID, params, options)
|
||||
}
|
||||
|
||||
var future = new Future;
|
||||
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu){
|
||||
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
||||
var defaultParams = {
|
||||
0x0020000D: studyInstanceUID,
|
||||
0x00080005: '',
|
||||
@ -220,14 +225,16 @@ DIMSE.retrieveInstancesByStudyOnly = function(studyInstanceUID, params, options)
|
||||
0x00200011: ''
|
||||
};
|
||||
var result = this.findSeries(Object.assign(defaultParams, params)),
|
||||
series = [], conn = this, allInstances = [];
|
||||
series = [],
|
||||
conn = this,
|
||||
allInstances = [];
|
||||
|
||||
result.on('result', function(msg) {
|
||||
series.push(msg);
|
||||
});
|
||||
result.on('end', function(){
|
||||
result.on('end', function() {
|
||||
if (series.length > 0) {
|
||||
DIMSE._retrieveInstancesBySeries(conn, series, studyInstanceUID, function(relatedInstances, isEnd){
|
||||
DIMSE._retrieveInstancesBySeries(conn, series, studyInstanceUID, function(relatedInstances, isEnd) {
|
||||
allInstances = allInstances.concat(relatedInstances);
|
||||
if (isEnd) {
|
||||
conn.release();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,143 +1,156 @@
|
||||
Field = function(type, value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
Field.prototype.length = function() {
|
||||
return calcLength(this.type, this.value);
|
||||
}
|
||||
return calcLength(this.type, this.value);
|
||||
};
|
||||
|
||||
Field.prototype.write = function(stream) {
|
||||
stream.write(this.type, this.value);
|
||||
}
|
||||
stream.write(this.type, this.value);
|
||||
};
|
||||
|
||||
Field.prototype.isNumeric = function() {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
BufferField = function(buffer, start, length) {
|
||||
Field.call(this, C.TYPE_BUFFER, buffer);
|
||||
this.bufferLength = length;
|
||||
this.bufferStart = start;
|
||||
}
|
||||
Field.call(this, C.TYPE_BUFFER, buffer);
|
||||
this.bufferLength = length;
|
||||
this.bufferStart = start;
|
||||
};
|
||||
|
||||
util.inherits(BufferField, Field);
|
||||
|
||||
BufferField.prototype.length = function() {
|
||||
return this.bufferLength;
|
||||
}
|
||||
return this.bufferLength;
|
||||
};
|
||||
|
||||
BufferField.prototype.write = function(stream) {
|
||||
stream.writeRawBuffer(this.value, this.bufferStart, this.bufferLength);
|
||||
}
|
||||
stream.writeRawBuffer(this.value, this.bufferStart, this.bufferLength);
|
||||
};
|
||||
|
||||
StringField = function(str) {
|
||||
Field.call(this, C.TYPE_ASCII, typeof str == 'string' ? str : "");
|
||||
}
|
||||
Field.call(this, C.TYPE_ASCII, typeof str == 'string' ? str : '');
|
||||
};
|
||||
|
||||
util.inherits(StringField, Field);
|
||||
|
||||
FilledField = function(value, length) {
|
||||
Field.call(this, C.TYPE_COMPOSITE, value);
|
||||
this.fillLength = length;
|
||||
}
|
||||
Field.call(this, C.TYPE_COMPOSITE, value);
|
||||
this.fillLength = length;
|
||||
};
|
||||
|
||||
util.inherits(FilledField, Field);
|
||||
|
||||
FilledField.prototype.length = function() {
|
||||
return this.fillLength;
|
||||
}
|
||||
return this.fillLength;
|
||||
};
|
||||
|
||||
FilledField.prototype.write = function(stream) {
|
||||
var len = this.value.length;
|
||||
if (len < this.fillLength && len >= 0) {
|
||||
if (len > 0)
|
||||
stream.write(C.TYPE_ASCII, this.value);
|
||||
var zeroLength = this.fillLength - len;
|
||||
stream.write(C.TYPE_HEX, "20".repeat(zeroLength));
|
||||
} else if (len == this.fillLength) {
|
||||
stream.write(C.TYPE_ASCII, this.value);
|
||||
} else {
|
||||
throw "Length mismatch";
|
||||
}
|
||||
}
|
||||
var len = this.value.length;
|
||||
if (len < this.fillLength && len >= 0) {
|
||||
if (len > 0)
|
||||
stream.write(C.TYPE_ASCII, this.value);
|
||||
var zeroLength = this.fillLength - len;
|
||||
stream.write(C.TYPE_HEX, '20'.repeat(zeroLength));
|
||||
} else if (len == this.fillLength) {
|
||||
stream.write(C.TYPE_ASCII, this.value);
|
||||
} else {
|
||||
throw 'Length mismatch';
|
||||
}
|
||||
};
|
||||
|
||||
HexField = function(hex) {
|
||||
Field.call(this, C.TYPE_HEX, hex);
|
||||
}
|
||||
Field.call(this, C.TYPE_HEX, hex);
|
||||
};
|
||||
|
||||
util.inherits(HexField, Field);
|
||||
|
||||
ReservedField = function(length) {
|
||||
length = length || 1;
|
||||
Field.call(this, C.TYPE_HEX, "00".repeat(length));
|
||||
}
|
||||
length = length || 1;
|
||||
Field.call(this, C.TYPE_HEX, '00'.repeat(length));
|
||||
};
|
||||
|
||||
util.inherits(ReservedField, Field);
|
||||
|
||||
UInt8Field = function(value) {
|
||||
Field.call(this, C.TYPE_UINT8, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_UINT8, value);
|
||||
};
|
||||
|
||||
util.inherits(UInt8Field, Field);
|
||||
|
||||
UInt8Field.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
UInt16Field = function(value) {
|
||||
Field.call(this, C.TYPE_UINT16, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_UINT16, value);
|
||||
};
|
||||
|
||||
util.inherits(UInt16Field, Field);
|
||||
|
||||
UInt16Field.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
UInt32Field = function(value) {
|
||||
Field.call(this, C.TYPE_UINT32, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_UINT32, value);
|
||||
};
|
||||
|
||||
util.inherits(UInt32Field, Field);
|
||||
|
||||
UInt32Field.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Int8Field = function(value) {
|
||||
Field.call(this, C.TYPE_INT8, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_INT8, value);
|
||||
};
|
||||
|
||||
util.inherits(Int8Field, Field);
|
||||
|
||||
Int8Field.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Int16Field = function(value) {
|
||||
Field.call(this, C.TYPE_INT16, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_INT16, value);
|
||||
};
|
||||
|
||||
util.inherits(Int16Field, Field);
|
||||
|
||||
Int16Field.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Int32Field = function(value) {
|
||||
Field.call(this, C.TYPE_INT32, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_INT32, value);
|
||||
};
|
||||
|
||||
util.inherits(Int32Field, Field);
|
||||
|
||||
Int32Field.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
FloatField = function(value) {
|
||||
Field.call(this, C.TYPE_FLOAT, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_FLOAT, value);
|
||||
};
|
||||
|
||||
util.inherits(FloatField, Field);
|
||||
|
||||
FloatField.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
DoubleField = function(value) {
|
||||
Field.call(this, C.TYPE_DOUBLE, value);
|
||||
}
|
||||
Field.call(this, C.TYPE_DOUBLE, value);
|
||||
};
|
||||
|
||||
util.inherits(DoubleField, Field);
|
||||
|
||||
DoubleField.prototype.isNumeric = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
@ -1,556 +1,590 @@
|
||||
DicomMessage = function(syntax) {
|
||||
this.syntax = syntax ? syntax : null;
|
||||
this.type = C.DATA_TYPE_COMMAND;
|
||||
this.messageId = C.DEFAULT_MESSAGE_ID;
|
||||
this.elementPairs = {};
|
||||
this.syntax = syntax ? syntax : null;
|
||||
this.type = C.DATA_TYPE_COMMAND;
|
||||
this.messageId = C.DEFAULT_MESSAGE_ID;
|
||||
this.elementPairs = {};
|
||||
};
|
||||
|
||||
DicomMessage.prototype.isCommand = function() {
|
||||
return this.type == C.DATA_TYPE_COMMAND;
|
||||
}
|
||||
return this.type == C.DATA_TYPE_COMMAND;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setSyntax = function(syntax) {
|
||||
this.syntax = syntax;
|
||||
this.syntax = syntax;
|
||||
|
||||
for (var tag in this.elementPairs) {
|
||||
this.elementPairs[tag].setSyntax(this.syntax);
|
||||
}
|
||||
}
|
||||
for (var tag in this.elementPairs) {
|
||||
this.elementPairs[tag].setSyntax(this.syntax);
|
||||
}
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setMessageId = function(id) {
|
||||
this.messageId = id;
|
||||
}
|
||||
this.messageId = id;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setReplyMessageId = function(id) {
|
||||
this.replyMessageId = id;
|
||||
}
|
||||
this.replyMessageId = id;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.command = function(cmds) {
|
||||
cmds.unshift(this.newElement(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
||||
cmds.unshift(this.newElement(0x00000700, this.priority));
|
||||
cmds.unshift(this.newElement(0x00000110, this.messageId));
|
||||
cmds.unshift(this.newElement(0x00000100, this.commandType));
|
||||
cmds.unshift(this.newElement(0x00000002, this.contextUID));
|
||||
|
||||
var length = 0;
|
||||
cmds.forEach(function(cmd) {
|
||||
length += cmd.length(cmd.getFields());
|
||||
});
|
||||
|
||||
cmds.unshift(this.newElement(0x00000000, length));
|
||||
return cmds;
|
||||
}
|
||||
|
||||
DicomMessage.prototype.response = function(cmds) {
|
||||
cmds.unshift(this.newElement(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
||||
cmds.unshift(this.newElement(0x00000120, this.replyMessageId));
|
||||
cmds.unshift(this.newElement(0x00000100, this.commandType));
|
||||
if (this.contextUID)
|
||||
cmds.unshift(this.newElement(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
||||
cmds.unshift(this.newElement(0x00000700, this.priority));
|
||||
cmds.unshift(this.newElement(0x00000110, this.messageId));
|
||||
cmds.unshift(this.newElement(0x00000100, this.commandType));
|
||||
cmds.unshift(this.newElement(0x00000002, this.contextUID));
|
||||
|
||||
var length = 0;
|
||||
cmds.forEach(function(cmd) {
|
||||
length += cmd.length(cmd.getFields());
|
||||
});
|
||||
var length = 0;
|
||||
cmds.forEach(function(cmd) {
|
||||
length += cmd.length(cmd.getFields());
|
||||
});
|
||||
|
||||
cmds.unshift(this.newElement(0x00000000, length));
|
||||
return cmds;
|
||||
}
|
||||
cmds.unshift(this.newElement(0x00000000, length));
|
||||
return cmds;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.response = function(cmds) {
|
||||
cmds.unshift(this.newElement(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
||||
cmds.unshift(this.newElement(0x00000120, this.replyMessageId));
|
||||
cmds.unshift(this.newElement(0x00000100, this.commandType));
|
||||
if (this.contextUID)
|
||||
cmds.unshift(this.newElement(0x00000002, this.contextUID));
|
||||
|
||||
var length = 0;
|
||||
cmds.forEach(function(cmd) {
|
||||
length += cmd.length(cmd.getFields());
|
||||
});
|
||||
|
||||
cmds.unshift(this.newElement(0x00000000, length));
|
||||
return cmds;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setElements = function(pairs) {
|
||||
var p = {};
|
||||
for (var tag in pairs) {
|
||||
p[tag] = this.newElement(tag, pairs[tag]);
|
||||
}
|
||||
this.elementPairs = p;
|
||||
}
|
||||
var p = {};
|
||||
for (var tag in pairs) {
|
||||
p[tag] = this.newElement(tag, pairs[tag]);
|
||||
}
|
||||
|
||||
this.elementPairs = p;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.newElement = function(tag, value) {
|
||||
return elementByType(tag, value, this.syntax);
|
||||
}
|
||||
return elementByType(tag, value, this.syntax);
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setElement = function(key, value) {
|
||||
this.elementPairs[key] = elementByType(key, value);
|
||||
}
|
||||
this.elementPairs[key] = elementByType(key, value);
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setElementPairs = function(pairs) {
|
||||
this.elementPairs = pairs;
|
||||
}
|
||||
this.elementPairs = pairs;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setContextId = function(context) {
|
||||
this.contextUID = context;
|
||||
}
|
||||
this.contextUID = context;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setPriority = function(pri) {
|
||||
this.priority = pri;
|
||||
}
|
||||
this.priority = pri;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setType = function(type) {
|
||||
this.type = type;
|
||||
}
|
||||
this.type = type;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.setDataSetPresent = function(present) {
|
||||
this.dataSetPresent = present == 0x0101 ? false : true;
|
||||
}
|
||||
this.dataSetPresent = present == 0x0101 ? false : true;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.haveData = function() {
|
||||
return this.dataSetPresent;
|
||||
}
|
||||
return this.dataSetPresent;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.tags = function() {
|
||||
return Object.keys(this.elementPairs);
|
||||
}
|
||||
return Object.keys(this.elementPairs);
|
||||
};
|
||||
|
||||
DicomMessage.prototype.key = function(tag) {
|
||||
return elementKeywordByTag(tag);
|
||||
}
|
||||
return elementKeywordByTag(tag);
|
||||
};
|
||||
|
||||
DicomMessage.prototype.getValue = function(tag) {
|
||||
return this.elementPairs[tag] ? this.elementPairs[tag].getValue() : null;
|
||||
}
|
||||
return this.elementPairs[tag] ? this.elementPairs[tag].getValue() : null;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.affectedSOPClassUID = function() {
|
||||
return this.getValue(0x00000002);
|
||||
}
|
||||
return this.getValue(0x00000002);
|
||||
};
|
||||
|
||||
DicomMessage.prototype.getMessageId = function() {
|
||||
return this.getValue(0x00000110);
|
||||
}
|
||||
return this.getValue(0x00000110);
|
||||
};
|
||||
|
||||
DicomMessage.prototype.getFields = function() {
|
||||
var eles = [];
|
||||
for (var tag in this.elementPairs) {
|
||||
eles.push(this.elementPairs[tag]);
|
||||
}
|
||||
return eles;
|
||||
}
|
||||
var eles = [];
|
||||
for (var tag in this.elementPairs) {
|
||||
eles.push(this.elementPairs[tag]);
|
||||
}
|
||||
|
||||
return eles;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.length = function(elems) {
|
||||
var len = 0;
|
||||
elems.forEach(function(elem){
|
||||
len += elem.length(elem.getFields());
|
||||
});
|
||||
return len;
|
||||
}
|
||||
var len = 0;
|
||||
elems.forEach(function(elem) {
|
||||
len += elem.length(elem.getFields());
|
||||
});
|
||||
return len;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.isResponse = function() {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.is = function(type) {
|
||||
return this.commandType == type;
|
||||
}
|
||||
return this.commandType == type;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.write = function(stream) {
|
||||
var fields = this.getFields(), o = this;
|
||||
fields.forEach(function(field){
|
||||
field.setSyntax(o.syntax);
|
||||
field.write(stream);
|
||||
});
|
||||
}
|
||||
var fields = this.getFields(),
|
||||
o = this;
|
||||
fields.forEach(function(field) {
|
||||
field.setSyntax(o.syntax);
|
||||
field.write(stream);
|
||||
});
|
||||
};
|
||||
|
||||
DicomMessage.prototype.printElements = function(pairs, indent) {
|
||||
var typeName = "";
|
||||
for (var tag in pairs) {
|
||||
var value = pairs[tag].getValue();
|
||||
typeName += (" ".repeat(indent)) + this.key(tag) + " : ";
|
||||
if (value instanceof Array) {
|
||||
var o = this;
|
||||
value.forEach(function(p) {
|
||||
if (typeof p == "object") {
|
||||
typeName += "[\n" + o.printElements(p, indent + 2) + (" ".repeat(indent)) + "]";
|
||||
var typeName = '';
|
||||
for (var tag in pairs) {
|
||||
var value = pairs[tag].getValue();
|
||||
typeName += (' '.repeat(indent)) + this.key(tag) + ' : ';
|
||||
if (value instanceof Array) {
|
||||
var o = this;
|
||||
value.forEach(function(p) {
|
||||
if (typeof p == 'object') {
|
||||
typeName += '[\n' + o.printElements(p, indent + 2) + (' '.repeat(indent)) + ']';
|
||||
} else {
|
||||
typeName += '[' + p + ']';
|
||||
}
|
||||
});
|
||||
if (typeName[typeName.length - 1] != '\n') {
|
||||
typeName += '\n';
|
||||
}
|
||||
} else {
|
||||
typeName += "[" + p + "]";
|
||||
typeName += value + '\n';
|
||||
}
|
||||
});
|
||||
if (typeName[typeName.length-1] != "\n") {
|
||||
typeName += "\n";
|
||||
}
|
||||
} else {
|
||||
typeName += value + "\n";
|
||||
}
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
return typeName;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.typeString = function() {
|
||||
var typeName = "";
|
||||
if (!this.isCommand()) {
|
||||
typeName = "DateSet Message";
|
||||
} else {
|
||||
switch (this.commandType) {
|
||||
case C.COMMAND_C_GET_RSP : typeName = "C-GET-RSP"; break;
|
||||
case C.COMMAND_C_MOVE_RSP : typeName = "C-MOVE-RSP"; break;
|
||||
case C.COMMAND_C_GET_RQ : typeName = "C-GET-RQ"; break;
|
||||
case C.COMMAND_C_STORE_RQ : typeName = "C-STORE-RQ"; break;
|
||||
case C.COMMAND_C_FIND_RSP : typeName = "C-FIND-RSP"; break;
|
||||
case C.COMMAND_C_MOVE_RQ : typeName = "C-MOVE-RQ"; break;
|
||||
case C.COMMAND_C_FIND_RQ : typeName = "C-FIND-RQ"; break;
|
||||
case C.COMMAND_C_STORE_RSP : typeName = "C-STORE-RSP"; break;
|
||||
var typeName = '';
|
||||
if (!this.isCommand()) {
|
||||
typeName = 'DateSet Message';
|
||||
} else {
|
||||
switch (this.commandType) {
|
||||
case C.COMMAND_C_GET_RSP : typeName = 'C-GET-RSP'; break;
|
||||
case C.COMMAND_C_MOVE_RSP : typeName = 'C-MOVE-RSP'; break;
|
||||
case C.COMMAND_C_GET_RQ : typeName = 'C-GET-RQ'; break;
|
||||
case C.COMMAND_C_STORE_RQ : typeName = 'C-STORE-RQ'; break;
|
||||
case C.COMMAND_C_FIND_RSP : typeName = 'C-FIND-RSP'; break;
|
||||
case C.COMMAND_C_MOVE_RQ : typeName = 'C-MOVE-RQ'; break;
|
||||
case C.COMMAND_C_FIND_RQ : typeName = 'C-FIND-RQ'; break;
|
||||
case C.COMMAND_C_STORE_RSP : typeName = 'C-STORE-RSP'; break;
|
||||
}
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
|
||||
return typeName;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.toString = function() {
|
||||
var typeName = this.typeString();
|
||||
typeName += " [\n";
|
||||
typeName += this.printElements(this.elementPairs, 0);
|
||||
typeName += "]";
|
||||
return typeName;
|
||||
}
|
||||
var typeName = this.typeString();
|
||||
typeName += ' [\n';
|
||||
typeName += this.printElements(this.elementPairs, 0);
|
||||
typeName += ']';
|
||||
return typeName;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.walkObject = function(pairs) {
|
||||
var obj = {}, o = this;
|
||||
for (var tag in pairs) {
|
||||
var v = pairs[tag].getValue(), u = v;
|
||||
if (v instanceof Array) {
|
||||
u = [];
|
||||
v.forEach(function(a) {
|
||||
if (typeof a == 'object') {
|
||||
u.push(o.walkObject(a));
|
||||
} else u.push(a);
|
||||
});
|
||||
}
|
||||
obj[tag] = u;
|
||||
}
|
||||
var obj = {},
|
||||
o = this;
|
||||
for (var tag in pairs) {
|
||||
var v = pairs[tag].getValue(),
|
||||
u = v;
|
||||
if (v instanceof Array) {
|
||||
u = [];
|
||||
v.forEach(function(a) {
|
||||
if (typeof a == 'object') {
|
||||
u.push(o.walkObject(a));
|
||||
} else u.push(a);
|
||||
});
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
obj[tag] = u;
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
DicomMessage.prototype.toObject = function() {
|
||||
return this.walkObject(this.elementPairs);
|
||||
}
|
||||
return this.walkObject(this.elementPairs);
|
||||
};
|
||||
|
||||
DicomMessage.readToPairs = function(stream, syntax, options) {
|
||||
var pairs = {};
|
||||
while (!stream.end()) {
|
||||
var elem = new DataElement();
|
||||
if (options) {
|
||||
elem.setOptions(options);
|
||||
var pairs = {};
|
||||
while (!stream.end()) {
|
||||
var elem = new DataElement();
|
||||
if (options) {
|
||||
elem.setOptions(options);
|
||||
}
|
||||
|
||||
elem.setSyntax(syntax);
|
||||
elem.readBytes(stream);
|
||||
pairs[elem.tag.value] = elem;
|
||||
}
|
||||
elem.setSyntax(syntax);
|
||||
elem.readBytes(stream);
|
||||
pairs[elem.tag.value] = elem;
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
return pairs;
|
||||
};
|
||||
|
||||
var fileValid = function(stream) {
|
||||
return stream.readString(4, C.TYPE_ASCII) == 'DICM';
|
||||
}
|
||||
return stream.readString(4, C.TYPE_ASCII) == 'DICM';
|
||||
};
|
||||
|
||||
var readMetaStream = function(stream, useSyntax, length, callback) {
|
||||
var message = new FileMetaMessage();
|
||||
message.setElementPairs(DicomMessage.readToPairs(stream, useSyntax));
|
||||
if (callback) {
|
||||
callback(null, message, length);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
var message = new FileMetaMessage();
|
||||
message.setElementPairs(DicomMessage.readToPairs(stream, useSyntax));
|
||||
if (callback) {
|
||||
callback(null, message, length);
|
||||
}
|
||||
|
||||
return message;
|
||||
};
|
||||
|
||||
DicomMessage.readMetaHeader = function(bufferOrFile, callback) {
|
||||
var useSyntax = C.EXPLICIT_LITTLE_ENDIAN;
|
||||
if (bufferOrFile instanceof Buffer) {
|
||||
var stream = new ReadStream(bufferOrFile);
|
||||
stream.reset();
|
||||
stream.increment(128);
|
||||
if (!fileValid(stream)) {
|
||||
return quitWithError('Invalid a dicom file ', callback);
|
||||
}
|
||||
var el = readAElement(stream, useSyntax),
|
||||
metaLength = el.value,
|
||||
metaStream = stream.more(metaLength);
|
||||
|
||||
return readMetaStream(metaStream, useSyntax, metaLength, callback);
|
||||
} else if (typeof bufferOrFile == 'string') {
|
||||
fs.open(bufferOrFile, 'r', function(err, fd) {
|
||||
if (err) {
|
||||
//fs.closeSync(fd);
|
||||
return quitWithError('Cannot open file', callback);
|
||||
}
|
||||
var buffer = new Buffer(16);
|
||||
fs.read(fd, buffer, 0, 16, 128, function(err, bytesRead) {
|
||||
if (err || bytesRead != 16) {
|
||||
fs.closeSync(fd);
|
||||
return quitWithError('Cannot read file', callback);
|
||||
}
|
||||
var stream = new ReadStream(buffer);
|
||||
var useSyntax = C.EXPLICIT_LITTLE_ENDIAN;
|
||||
if (bufferOrFile instanceof Buffer) {
|
||||
var stream = new ReadStream(bufferOrFile);
|
||||
stream.reset();
|
||||
stream.increment(128);
|
||||
if (!fileValid(stream)) {
|
||||
fs.closeSync(fd);
|
||||
return quitWithError('Not a dicom file ' + bufferOrFile, callback);
|
||||
}
|
||||
var el = readAElement(stream, useSyntax),
|
||||
return quitWithError('Invalid a dicom file ', callback);
|
||||
}
|
||||
|
||||
var el = readAElement(stream, useSyntax),
|
||||
metaLength = el.value,
|
||||
metaBuffer = new Buffer(metaLength);
|
||||
metaStream = stream.more(metaLength);
|
||||
|
||||
fs.read(fd, metaBuffer, 0, metaLength, 144, function(err, bytesRead) {
|
||||
fs.closeSync(fd);
|
||||
if (err || bytesRead != metaLength) {
|
||||
return quitWithError('Invalid a dicom file ' + bufferOrFile, callback);
|
||||
}
|
||||
var metaStream = new ReadStream(metaBuffer);
|
||||
return readMetaStream(metaStream, useSyntax, metaLength, callback);
|
||||
return readMetaStream(metaStream, useSyntax, metaLength, callback);
|
||||
} else if (typeof bufferOrFile == 'string') {
|
||||
fs.open(bufferOrFile, 'r', function(err, fd) {
|
||||
if (err) {
|
||||
//fs.closeSync(fd);
|
||||
return quitWithError('Cannot open file', callback);
|
||||
}
|
||||
|
||||
var buffer = new Buffer(16);
|
||||
fs.read(fd, buffer, 0, 16, 128, function(err, bytesRead) {
|
||||
if (err || bytesRead != 16) {
|
||||
fs.closeSync(fd);
|
||||
return quitWithError('Cannot read file', callback);
|
||||
}
|
||||
|
||||
var stream = new ReadStream(buffer);
|
||||
if (!fileValid(stream)) {
|
||||
fs.closeSync(fd);
|
||||
return quitWithError('Not a dicom file ' + bufferOrFile, callback);
|
||||
}
|
||||
|
||||
var el = readAElement(stream, useSyntax),
|
||||
metaLength = el.value,
|
||||
metaBuffer = new Buffer(metaLength);
|
||||
|
||||
fs.read(fd, metaBuffer, 0, metaLength, 144, function(err, bytesRead) {
|
||||
fs.closeSync(fd);
|
||||
if (err || bytesRead != metaLength) {
|
||||
return quitWithError('Invalid a dicom file ' + bufferOrFile, callback);
|
||||
}
|
||||
|
||||
var metaStream = new ReadStream(metaBuffer);
|
||||
return readMetaStream(metaStream, useSyntax, metaLength, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
DicomMessage.read = function(stream, type, syntax, options) {
|
||||
var elements = [], pairs = {}, useSyntax = type == C.DATA_TYPE_COMMAND ? C.IMPLICIT_LITTLE_ENDIAN : syntax;
|
||||
stream.reset();
|
||||
while (!stream.end()) {
|
||||
var elem = new DataElement();
|
||||
if (options) {
|
||||
elem.setOptions(options);
|
||||
}
|
||||
elem.setSyntax(useSyntax);
|
||||
elem.readBytes(stream);//return;
|
||||
pairs[elem.tag.value] = elem;
|
||||
}
|
||||
var elements = [],
|
||||
pairs = {},
|
||||
useSyntax = type == C.DATA_TYPE_COMMAND ? C.IMPLICIT_LITTLE_ENDIAN : syntax;
|
||||
stream.reset();
|
||||
while (!stream.end()) {
|
||||
var elem = new DataElement();
|
||||
if (options) {
|
||||
elem.setOptions(options);
|
||||
}
|
||||
|
||||
var message = null;
|
||||
if (type == C.DATA_TYPE_COMMAND) {
|
||||
var cmdType = pairs[0x00000100].value;
|
||||
|
||||
switch (cmdType) {
|
||||
case 0x8020 : message = new CFindRSP(useSyntax); break;
|
||||
case 0x8021 : message = new CMoveRSP(useSyntax); break;
|
||||
case 0x8010 : message = new CGetRSP(useSyntax); break;
|
||||
case 0x0001 : message = new CStoreRQ(useSyntax); break;
|
||||
case 0x0020 : message = new CFindRQ(useSyntax); break;
|
||||
case 0x8001 : message = new CStoreRSP(useSyntax); break;
|
||||
default : throw "Unrecognized command type " + cmdType.toString(16); break;
|
||||
elem.setSyntax(useSyntax);
|
||||
elem.readBytes(stream);//return;
|
||||
pairs[elem.tag.value] = elem;
|
||||
}
|
||||
|
||||
message.setElementPairs(pairs);
|
||||
message.setDataSetPresent(message.getValue(0x00000800));
|
||||
message.setContextId(message.getValue(0x00000002));
|
||||
if (!message.isResponse()) {
|
||||
message.setMessageId(message.getValue(0x00000110));
|
||||
var message = null;
|
||||
if (type == C.DATA_TYPE_COMMAND) {
|
||||
var cmdType = pairs[0x00000100].value;
|
||||
|
||||
switch (cmdType) {
|
||||
case 0x8020 : message = new CFindRSP(useSyntax); break;
|
||||
case 0x8021 : message = new CMoveRSP(useSyntax); break;
|
||||
case 0x8010 : message = new CGetRSP(useSyntax); break;
|
||||
case 0x0001 : message = new CStoreRQ(useSyntax); break;
|
||||
case 0x0020 : message = new CFindRQ(useSyntax); break;
|
||||
case 0x8001 : message = new CStoreRSP(useSyntax); break;
|
||||
default : throw 'Unrecognized command type ' + cmdType.toString(16); break;
|
||||
}
|
||||
|
||||
message.setElementPairs(pairs);
|
||||
message.setDataSetPresent(message.getValue(0x00000800));
|
||||
message.setContextId(message.getValue(0x00000002));
|
||||
if (!message.isResponse()) {
|
||||
message.setMessageId(message.getValue(0x00000110));
|
||||
} else {
|
||||
message.setReplyMessageId(message.getValue(0x00000120));
|
||||
}
|
||||
} else if (type == C.DATA_TYPE_DATA) {
|
||||
message = new DataSetMessage(useSyntax);
|
||||
message.setElementPairs(pairs);
|
||||
} else {
|
||||
message.setReplyMessageId(message.getValue(0x00000120));
|
||||
throw 'Unrecognized message type';
|
||||
}
|
||||
} else if (type == C.DATA_TYPE_DATA) {
|
||||
message = new DataSetMessage(useSyntax);
|
||||
message.setElementPairs(pairs);
|
||||
} else {
|
||||
throw "Unrecognized message type";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
DataSetMessage = function(syntax){
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_DATA;
|
||||
return message;
|
||||
};
|
||||
|
||||
DataSetMessage = function(syntax) {
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_DATA;
|
||||
};
|
||||
|
||||
util.inherits(DataSetMessage, DicomMessage);
|
||||
|
||||
DataSetMessage.prototype.is = function(type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FileMetaMessage = function(syntax){
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = null
|
||||
return false;
|
||||
};
|
||||
|
||||
FileMetaMessage = function(syntax) {
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = null;
|
||||
};
|
||||
|
||||
util.inherits(FileMetaMessage, DicomMessage);
|
||||
|
||||
CommandMessage = function(syntax) {
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_COMMAND;
|
||||
this.priority = C.PRIORITY_MEDIUM;
|
||||
this.dataSetPresent = true;
|
||||
}
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_COMMAND;
|
||||
this.priority = C.PRIORITY_MEDIUM;
|
||||
this.dataSetPresent = true;
|
||||
};
|
||||
|
||||
util.inherits(CommandMessage, DicomMessage);
|
||||
|
||||
CommandMessage.prototype.getFields = function() {
|
||||
return this.command(CommandMessage.super_.prototype.getFields.call(this));
|
||||
}
|
||||
return this.command(CommandMessage.super_.prototype.getFields.call(this));
|
||||
};
|
||||
|
||||
CommandResponse = function(syntax) {
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_COMMAND;
|
||||
this.dataSetPresent = true;
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_COMMAND;
|
||||
this.dataSetPresent = true;
|
||||
};
|
||||
|
||||
util.inherits(CommandResponse, DicomMessage);
|
||||
|
||||
CommandResponse.prototype.isResponse = function() {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
CommandResponse.prototype.respondedTo = function() {
|
||||
return this.getValue(0x00000120);
|
||||
}
|
||||
return this.getValue(0x00000120);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.isFinal = function() {
|
||||
return this.success() || this.failure() || this.cancel();
|
||||
}
|
||||
return this.success() || this.failure() || this.cancel();
|
||||
};
|
||||
|
||||
CommandResponse.prototype.warning = function() {
|
||||
var status = this.getStatus();
|
||||
return (status == 0x0001) || (status >> 12 == 0xb);
|
||||
}
|
||||
var status = this.getStatus();
|
||||
return (status == 0x0001) || (status >> 12 == 0xb);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.success = function() {
|
||||
return this.getStatus() == 0x0000;
|
||||
}
|
||||
return this.getStatus() == 0x0000;
|
||||
};
|
||||
|
||||
CommandResponse.prototype.failure = function() {
|
||||
var status = this.getStatus();
|
||||
return (status >> 12 == 0xa) || (status >> 12 == 0xc) || (status >> 8 == 0x1)
|
||||
}
|
||||
var status = this.getStatus();
|
||||
return (status >> 12 == 0xa) || (status >> 12 == 0xc) || (status >> 8 == 0x1);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.cancel = function() {
|
||||
return this.getStatus() == C.STATUS_CANCEL;
|
||||
}
|
||||
return this.getStatus() == C.STATUS_CANCEL;
|
||||
};
|
||||
|
||||
CommandResponse.prototype.pending = function() {
|
||||
var status = this.getStatus();
|
||||
return (status == 0xff00) || (status == 0xff01);
|
||||
}
|
||||
var status = this.getStatus();
|
||||
return (status == 0xff00) || (status == 0xff01);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.getStatus = function() {
|
||||
return this.getValue(0x00000900);
|
||||
}
|
||||
return this.getValue(0x00000900);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.setStatus = function(status) {
|
||||
this.setElement(0x00000900, status);
|
||||
}
|
||||
this.setElement(0x00000900, status);
|
||||
};
|
||||
|
||||
// following four methods only available to C-GET-RSP and C-MOVE-RSP
|
||||
CommandResponse.prototype.getNumOfRemainingSubOperations = function() {
|
||||
return this.getValue(0x00001020);
|
||||
}
|
||||
return this.getValue(0x00001020);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.getNumOfCompletedSubOperations = function() {
|
||||
return this.getValue(0x00001021);
|
||||
}
|
||||
return this.getValue(0x00001021);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.getNumOfFailedSubOperations = function() {
|
||||
return this.getValue(0x00001022);
|
||||
}
|
||||
return this.getValue(0x00001022);
|
||||
};
|
||||
|
||||
CommandResponse.prototype.getNumOfWarningSubOperations = function() {
|
||||
return this.getValue(0x00001023);
|
||||
}
|
||||
return this.getValue(0x00001023);
|
||||
};
|
||||
//end
|
||||
|
||||
CommandResponse.prototype.getFields = function() {
|
||||
return this.response(CommandResponse.super_.prototype.getFields.call(this));
|
||||
}
|
||||
return this.response(CommandResponse.super_.prototype.getFields.call(this));
|
||||
};
|
||||
|
||||
CFindRSP = function(syntax) {
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8020;
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8020;
|
||||
};
|
||||
|
||||
util.inherits(CFindRSP, CommandResponse);
|
||||
|
||||
CGetRSP = function(syntax) {
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8010;
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8010;
|
||||
};
|
||||
|
||||
util.inherits(CGetRSP, CommandResponse);
|
||||
|
||||
CMoveRSP = function(syntax) {
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8021;
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8021;
|
||||
};
|
||||
|
||||
util.inherits(CMoveRSP, CommandResponse);
|
||||
|
||||
CFindRQ = function(syntax) {
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x20;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_FIND;
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x20;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_FIND;
|
||||
};
|
||||
|
||||
util.inherits(CFindRQ, CommandMessage);
|
||||
|
||||
CCancelRQ = function(syntax) {
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x0fff;
|
||||
this.contextUID = null;
|
||||
this.dataSetPresent = false;
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x0fff;
|
||||
this.contextUID = null;
|
||||
this.dataSetPresent = false;
|
||||
};
|
||||
|
||||
util.inherits(CCancelRQ, CommandResponse);
|
||||
|
||||
CCancelMoveRQ = function(syntax) {
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x0fff;
|
||||
this.contextUID = null;
|
||||
this.dataSetPresent = false;
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x0fff;
|
||||
this.contextUID = null;
|
||||
this.dataSetPresent = false;
|
||||
};
|
||||
|
||||
util.inherits(CCancelMoveRQ, CommandResponse);
|
||||
|
||||
CMoveRQ = function(syntax, destination) {
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x21;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_MOVE;
|
||||
this.setDestination(destination || "");
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x21;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_MOVE;
|
||||
this.setDestination(destination || '');
|
||||
};
|
||||
|
||||
util.inherits(CMoveRQ, CommandMessage);
|
||||
|
||||
CMoveRQ.prototype.setStore = function(cstr) {
|
||||
this.store = cstr;
|
||||
}
|
||||
this.store = cstr;
|
||||
};
|
||||
|
||||
CMoveRQ.prototype.setDestination = function(dest) {
|
||||
this.setElement(0x00000600, dest);
|
||||
}
|
||||
this.setElement(0x00000600, dest);
|
||||
};
|
||||
|
||||
CGetRQ = function(syntax) {
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x10;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||
this.store = null;
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x10;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||
this.store = null;
|
||||
};
|
||||
|
||||
util.inherits(CGetRQ, CommandMessage);
|
||||
|
||||
CGetRQ.prototype.setStore = function(cstr) {
|
||||
this.store = cstr;
|
||||
}
|
||||
this.store = cstr;
|
||||
};
|
||||
|
||||
CStoreRQ = function(syntax) {
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x01;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x01;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||
};
|
||||
|
||||
util.inherits(CStoreRQ, CommandMessage);
|
||||
|
||||
CStoreRQ.prototype.getOriginAETitle = function() {
|
||||
return this.getValue(0x00001030);
|
||||
}
|
||||
return this.getValue(0x00001030);
|
||||
};
|
||||
|
||||
CStoreRQ.prototype.getMoveMessageId = function() {
|
||||
return this.getValue(0x00001031);
|
||||
}
|
||||
return this.getValue(0x00001031);
|
||||
};
|
||||
|
||||
CStoreRQ.prototype.getAffectedSOPInstanceUID = function() {
|
||||
return this.getValue(0x00001000);
|
||||
}
|
||||
return this.getValue(0x00001000);
|
||||
};
|
||||
|
||||
CStoreRQ.prototype.setAffectedSOPInstanceUID = function(uid) {
|
||||
this.setElement(0x00001000, uid);
|
||||
}
|
||||
this.setElement(0x00001000, uid);
|
||||
};
|
||||
|
||||
CStoreRQ.prototype.setAffectedSOPClassUID = function(uid) {
|
||||
this.setElement(0x00000002, uid);
|
||||
}
|
||||
this.setElement(0x00000002, uid);
|
||||
};
|
||||
|
||||
CStoreRSP = function(syntax) {
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8001;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||
this.dataSetPresent = false;
|
||||
CommandResponse.call(this, syntax);
|
||||
this.commandType = 0x8001;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||
this.dataSetPresent = false;
|
||||
};
|
||||
|
||||
util.inherits(CStoreRSP, CommandResponse);
|
||||
|
||||
CStoreRSP.prototype.setAffectedSOPInstanceUID = function(uid) {
|
||||
this.setElement(0x00001000, uid);
|
||||
}
|
||||
this.setElement(0x00001000, uid);
|
||||
};
|
||||
|
||||
CStoreRSP.prototype.getAffectedSOPInstanceUID = function(uid) {
|
||||
return this.getValue(0x00001000);
|
||||
}
|
||||
return this.getValue(0x00001000);
|
||||
};
|
||||
|
||||
@ -1,236 +1,239 @@
|
||||
var isString = function(type) {
|
||||
if (type == C.TYPE_ASCII || type == C.TYPE_HEX) {
|
||||
return true;
|
||||
} else return false;
|
||||
if (type === C.TYPE_ASCII || type === C.TYPE_HEX) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
calcLength = function(type, value) {
|
||||
var size = NaN;
|
||||
switch (type) {
|
||||
case C.TYPE_HEX : size = Buffer.byteLength(value, 'hex'); break;
|
||||
case C.TYPE_ASCII : size = Buffer.byteLength(value, 'ascii'); break;
|
||||
case C.TYPE_UINT8 : size = 1; break;
|
||||
var size = NaN;
|
||||
switch (type) {
|
||||
case C.TYPE_HEX : size = Buffer.byteLength(value, 'hex'); break;
|
||||
case C.TYPE_ASCII : size = Buffer.byteLength(value, 'ascii'); break;
|
||||
case C.TYPE_UINT8 : size = 1; break;
|
||||
case C.TYPE_UINT16 : size = 2; break;
|
||||
case C.TYPE_UINT32 : size = 4; break;
|
||||
case C.TYPE_FLOAT : size = 4; break;
|
||||
case C.TYPE_FLOAT : size = 4; break;
|
||||
case C.TYPE_DOUBLE : size = 8; break;
|
||||
case C.TYPE_INT8 : size = 1; break;
|
||||
case C.TYPE_INT16 : size = 2; break;
|
||||
case C.TYPE_INT32 : size = 4; break;
|
||||
case C.TYPE_INT8 : size = 1; break;
|
||||
case C.TYPE_INT16 : size = 2; break;
|
||||
case C.TYPE_INT32 : size = 4; break;
|
||||
default :break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
return size;
|
||||
};
|
||||
|
||||
var RWStream = function() {
|
||||
this.endian = C.BIG_ENDIAN;
|
||||
this.endian = C.BIG_ENDIAN;
|
||||
};
|
||||
|
||||
RWStream.prototype.setEndian = function(endian) {
|
||||
this.endian = endian;
|
||||
}
|
||||
this.endian = endian;
|
||||
};
|
||||
|
||||
RWStream.prototype.getEncoding = function(type) {
|
||||
return RWStream.encodings[type];
|
||||
}
|
||||
return RWStream.encodings[type];
|
||||
};
|
||||
|
||||
RWStream.prototype.getWriteType = function(type) {
|
||||
return RWStream.writes[this.endian][type];
|
||||
}
|
||||
return RWStream.writes[this.endian][type];
|
||||
};
|
||||
|
||||
RWStream.prototype.getReadType = function(type) {
|
||||
return RWStream.reads[this.endian][type];
|
||||
}
|
||||
return RWStream.reads[this.endian][type];
|
||||
};
|
||||
|
||||
WriteStream = function() {
|
||||
RWStream.call(this);
|
||||
this.defaultBufferSize = 512; //512 bytes
|
||||
this.rawBuffer = new Buffer(this.defaultBufferSize);
|
||||
this.offset = 0;
|
||||
this.contentSize = 0;
|
||||
}
|
||||
RWStream.call(this);
|
||||
this.defaultBufferSize = 512; //512 bytes
|
||||
this.rawBuffer = new Buffer(this.defaultBufferSize);
|
||||
this.offset = 0;
|
||||
this.contentSize = 0;
|
||||
};
|
||||
|
||||
util.inherits(WriteStream, RWStream);
|
||||
|
||||
WriteStream.prototype.increment = function(add) {
|
||||
this.offset += add;
|
||||
if (this.offset > this.contentSize) {
|
||||
this.contentSize = this.offset;
|
||||
}
|
||||
}
|
||||
this.offset += add;
|
||||
if (this.offset > this.contentSize) {
|
||||
this.contentSize = this.offset;
|
||||
}
|
||||
};
|
||||
|
||||
WriteStream.prototype.size = function() {
|
||||
return this.contentSize;
|
||||
}
|
||||
return this.contentSize;
|
||||
};
|
||||
|
||||
WriteStream.prototype.skip = function(amount) {
|
||||
this.increment(amount);
|
||||
}
|
||||
this.increment(amount);
|
||||
};
|
||||
|
||||
WriteStream.prototype.checkSize = function(length) {
|
||||
if (this.offset + length > this.rawBuffer.length) {
|
||||
// we need more size, copying old one to new buffer
|
||||
var oldLength = this.rawBuffer.length,
|
||||
newBuffer = new Buffer(oldLength + length + (oldLength / 2));
|
||||
this.rawBuffer.copy(newBuffer, 0, 0, this.contentSize);
|
||||
this.rawBuffer = newBuffer;
|
||||
}
|
||||
}
|
||||
if (this.offset + length > this.rawBuffer.length) {
|
||||
// we need more size, copying old one to new buffer
|
||||
var oldLength = this.rawBuffer.length,
|
||||
newBuffer = new Buffer(oldLength + length + (oldLength / 2));
|
||||
this.rawBuffer.copy(newBuffer, 0, 0, this.contentSize);
|
||||
this.rawBuffer = newBuffer;
|
||||
}
|
||||
};
|
||||
|
||||
WriteStream.prototype.writeToBuffer = function(type, value, length) {
|
||||
if (value === "" || value === null) return;
|
||||
if (value === '' || value === null) return;
|
||||
|
||||
this.checkSize(length);
|
||||
this.rawBuffer[this.getWriteType(type)](value, this.offset);
|
||||
this.increment(length);
|
||||
}
|
||||
this.checkSize(length);
|
||||
this.rawBuffer[this.getWriteType(type)](value, this.offset);
|
||||
this.increment(length);
|
||||
};
|
||||
|
||||
WriteStream.prototype.writeRawBuffer = function(source, start, length) {
|
||||
if (!source) return;
|
||||
this.checkSize(length);
|
||||
source.copy(this.rawBuffer, this.offset, start, length);
|
||||
this.increment(length);
|
||||
}
|
||||
if (!source) return;
|
||||
this.checkSize(length);
|
||||
source.copy(this.rawBuffer, this.offset, start, length);
|
||||
this.increment(length);
|
||||
};
|
||||
|
||||
WriteStream.prototype.write = function(type, value) {
|
||||
if (isString(type)) {
|
||||
this.writeString(value, type);
|
||||
} else {
|
||||
this.writeToBuffer(type, value, calcLength(type));
|
||||
}
|
||||
}
|
||||
if (isString(type)) {
|
||||
this.writeString(value, type);
|
||||
} else {
|
||||
this.writeToBuffer(type, value, calcLength(type));
|
||||
}
|
||||
};
|
||||
|
||||
WriteStream.prototype.writeString = function(string, type) {
|
||||
var encoding = this.getEncoding(type), length = Buffer.byteLength(string, encoding);
|
||||
this.rawBuffer.write(string, this.offset, length, encoding);
|
||||
this.increment(length);
|
||||
}
|
||||
var encoding = this.getEncoding(type),
|
||||
length = Buffer.byteLength(string, encoding);
|
||||
this.rawBuffer.write(string, this.offset, length, encoding);
|
||||
this.increment(length);
|
||||
};
|
||||
|
||||
WriteStream.prototype.buffer = function() {
|
||||
return this.rawBuffer.slice(0, this.contentSize);
|
||||
}
|
||||
return this.rawBuffer.slice(0, this.contentSize);
|
||||
};
|
||||
|
||||
WriteStream.prototype.toReadBuffer = function() {
|
||||
return new ReadStream(this.buffer());
|
||||
}
|
||||
return new ReadStream(this.buffer());
|
||||
};
|
||||
|
||||
WriteStream.prototype.concat = function(newStream) {
|
||||
var newSize = this.size() + newStream.size();
|
||||
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
||||
this.contentSize = newSize;
|
||||
this.offset = newSize;
|
||||
}
|
||||
var newSize = this.size() + newStream.size();
|
||||
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
||||
this.contentSize = newSize;
|
||||
this.offset = newSize;
|
||||
};
|
||||
|
||||
ReadStream = function(buffer) {
|
||||
RWStream.call(this);
|
||||
this.rawBuffer = buffer;
|
||||
this.offset = 0;
|
||||
RWStream.call(this);
|
||||
this.rawBuffer = buffer;
|
||||
this.offset = 0;
|
||||
};
|
||||
|
||||
util.inherits(ReadStream, RWStream);
|
||||
|
||||
ReadStream.prototype.size = function() {
|
||||
return this.rawBuffer.length;
|
||||
}
|
||||
return this.rawBuffer.length;
|
||||
};
|
||||
|
||||
ReadStream.prototype.increment = function(add) {
|
||||
this.offset += add;
|
||||
}
|
||||
this.offset += add;
|
||||
};
|
||||
|
||||
ReadStream.prototype.more = function(length) {
|
||||
var newBuf = this.rawBuffer.slice(this.offset, this.offset + length);
|
||||
this.increment(length);
|
||||
return new ReadStream(newBuf);
|
||||
}
|
||||
var newBuf = this.rawBuffer.slice(this.offset, this.offset + length);
|
||||
this.increment(length);
|
||||
return new ReadStream(newBuf);
|
||||
};
|
||||
|
||||
ReadStream.prototype.reset = function() {
|
||||
this.offset = 0;
|
||||
return this;
|
||||
}
|
||||
this.offset = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
ReadStream.prototype.end = function() {
|
||||
return this.offset >= this.size();
|
||||
}
|
||||
return this.offset >= this.size();
|
||||
};
|
||||
|
||||
ReadStream.prototype.readFromBuffer = function(type, length) {
|
||||
//this.checkSize(length);
|
||||
//if (this.offset + length > this.rawBuffer.length) throw ("out of bound " + this.offset + "," + length + "," + this.rawBuffer.length);
|
||||
var value = this.rawBuffer[this.getReadType(type)](this.offset);
|
||||
this.increment(length);
|
||||
return value;
|
||||
}
|
||||
//this.checkSize(length);
|
||||
//if (this.offset + length > this.rawBuffer.length) throw ("out of bound " + this.offset + "," + length + "," + this.rawBuffer.length);
|
||||
var value = this.rawBuffer[this.getReadType(type)](this.offset);
|
||||
this.increment(length);
|
||||
return value;
|
||||
};
|
||||
|
||||
ReadStream.prototype.read = function(type, length) {
|
||||
var value = null;
|
||||
if (isString(type)) {
|
||||
value = this.readString(length, type);
|
||||
} else {
|
||||
value = this.readFromBuffer(type, calcLength(type));
|
||||
}
|
||||
var value = null;
|
||||
if (isString(type)) {
|
||||
value = this.readString(length, type);
|
||||
} else {
|
||||
value = this.readFromBuffer(type, calcLength(type));
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
ReadStream.prototype.readString = function(length, type) {
|
||||
var encoding = this.getEncoding(type),
|
||||
str = this.rawBuffer.toString(encoding, this.offset, this.offset + length);
|
||||
this.increment(length);
|
||||
return str;
|
||||
}
|
||||
var encoding = this.getEncoding(type),
|
||||
str = this.rawBuffer.toString(encoding, this.offset, this.offset + length);
|
||||
this.increment(length);
|
||||
return str;
|
||||
};
|
||||
|
||||
ReadStream.prototype.buffer = function() {
|
||||
return this.rawBuffer;
|
||||
}
|
||||
return this.rawBuffer;
|
||||
};
|
||||
|
||||
ReadStream.prototype.concat = function(newStream) {
|
||||
var newSize = this.size() + newStream.size();
|
||||
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
||||
this.contentSize = newSize;
|
||||
this.offset = newSize;
|
||||
}
|
||||
var newSize = this.size() + newStream.size();
|
||||
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
||||
this.contentSize = newSize;
|
||||
this.offset = newSize;
|
||||
};
|
||||
|
||||
RWStream.writes = {};
|
||||
RWStream.writes[C.BIG_ENDIAN] = {};
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT8] = "writeUInt8";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT16] = "writeUInt16BE";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT32] = "writeUInt32BE";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT8] = "writeInt8";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT16] = "writeInt16BE";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT32] = "writeInt32BE";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_FLOAT] = "writeFloatBE";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_DOUBLE] = "writeDoubleBE";
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT8] = 'writeUInt8';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT16] = 'writeUInt16BE';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT32] = 'writeUInt32BE';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT8] = 'writeInt8';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT16] = 'writeInt16BE';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT32] = 'writeInt32BE';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_FLOAT] = 'writeFloatBE';
|
||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_DOUBLE] = 'writeDoubleBE';
|
||||
|
||||
RWStream.writes[C.LITTLE_ENDIAN] = {};
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT8] = "writeUInt8";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT16] = "writeUInt16LE";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT32] = "writeUInt32LE";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT8] = "writeInt8";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT16] = "writeInt16LE";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT32] = "writeInt32LE";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_FLOAT] = "writeFloatLE";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_DOUBLE] = "writeDoubleLE";
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT8] = 'writeUInt8';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT16] = 'writeUInt16LE';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT32] = 'writeUInt32LE';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT8] = 'writeInt8';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT16] = 'writeInt16LE';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT32] = 'writeInt32LE';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_FLOAT] = 'writeFloatLE';
|
||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_DOUBLE] = 'writeDoubleLE';
|
||||
|
||||
RWStream.reads = {};
|
||||
RWStream.reads[C.BIG_ENDIAN] = {};
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT8] = "readUInt8";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT16] = "readUInt16BE";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT32] = "readUInt32BE";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT8] = "readInt8";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT16] = "readInt16BE";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT32] = "readInt32BE";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_FLOAT] = "readFloatBE";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_DOUBLE] = "readDoubleBE";
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT8] = 'readUInt8';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT16] = 'readUInt16BE';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT32] = 'readUInt32BE';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT8] = 'readInt8';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT16] = 'readInt16BE';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT32] = 'readInt32BE';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_FLOAT] = 'readFloatBE';
|
||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_DOUBLE] = 'readDoubleBE';
|
||||
|
||||
RWStream.reads[C.LITTLE_ENDIAN] = {};
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT8] = "readUInt8";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT16] = "readUInt16LE";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT32] = "readUInt32LE";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT8] = "readInt8";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT16] = "readInt16LE";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT32] = "readInt32LE";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_FLOAT] = "readFloatLE";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_DOUBLE] = "readDoubleLE";
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT8] = 'readUInt8';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT16] = 'readUInt16LE';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT32] = 'readUInt32LE';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT8] = 'readInt8';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT16] = 'readInt16LE';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT32] = 'readInt32LE';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_FLOAT] = 'readFloatLE';
|
||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_DOUBLE] = 'readDoubleLE';
|
||||
|
||||
RWStream.encodings = {};
|
||||
RWStream.encodings[C.TYPE_HEX] = "hex";
|
||||
RWStream.encodings[C.TYPE_ASCII] = "ascii";
|
||||
RWStream.encodings[C.TYPE_HEX] = 'hex';
|
||||
RWStream.encodings[C.TYPE_ASCII] = 'ascii';
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
Meteor.methods({
|
||||
|
||||
});
|
||||
160
Packages/worklist/both/schema.js
Normal file
160
Packages/worklist/both/schema.js
Normal file
@ -0,0 +1,160 @@
|
||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||
|
||||
export const DICOMWebRequestOptions = new SimpleSchema({
|
||||
auth: {
|
||||
type: String,
|
||||
label: 'Username:Password Authentication String',
|
||||
},
|
||||
logRequests: {
|
||||
type: Boolean,
|
||||
defaultValue: true,
|
||||
label: 'Log Requests?',
|
||||
},
|
||||
logResponses: {
|
||||
type: Boolean,
|
||||
defaultValue: false,
|
||||
label: 'Log Responses?',
|
||||
},
|
||||
logTiming: {
|
||||
type: Boolean,
|
||||
defaultValue: true,
|
||||
label: 'Log Timing?',
|
||||
},
|
||||
});
|
||||
|
||||
export const DICOMWebServer = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
label: 'Name',
|
||||
max: 100
|
||||
},
|
||||
wadoUriRoot: {
|
||||
type: String,
|
||||
label: 'WADO URI Root',
|
||||
max: 1000
|
||||
},
|
||||
qidoRoot: {
|
||||
type: String,
|
||||
label: 'QIDO Root',
|
||||
max: 1000
|
||||
},
|
||||
// TODO: Remove this
|
||||
wadoUriRootNOTE: {
|
||||
type: String,
|
||||
label: 'WADO URI Root Note',
|
||||
optional: true
|
||||
},
|
||||
wadoRoot: {
|
||||
type: String,
|
||||
label: 'WADO Root',
|
||||
max: 1000
|
||||
},
|
||||
qidoSupportsIncludeField: {
|
||||
type: Boolean,
|
||||
label: 'QIDO Supports Include Field?',
|
||||
defaultValue: false
|
||||
},
|
||||
imageRendering: {
|
||||
type: String,
|
||||
label: 'Image Rendering',
|
||||
defaultValue: 'wadouri'
|
||||
},
|
||||
requestOptions: {
|
||||
type: DICOMWebRequestOptions,
|
||||
label: 'Request Options'
|
||||
}
|
||||
});
|
||||
|
||||
export const DIMSEPeer = new SimpleSchema({
|
||||
host: {
|
||||
type: String,
|
||||
label: 'Host URL',
|
||||
},
|
||||
port: {
|
||||
type: Number,
|
||||
label: 'Port',
|
||||
min: 1,
|
||||
defaultValue: 11112,
|
||||
max: 65535
|
||||
},
|
||||
aeTitle: {
|
||||
type: String,
|
||||
label: 'Application Entity (AE) Title',
|
||||
},
|
||||
default: {
|
||||
type: Boolean,
|
||||
label: 'Default?',
|
||||
defaultValue: false
|
||||
},
|
||||
server: {
|
||||
type: Boolean,
|
||||
label: 'Server?',
|
||||
defaultValue: false
|
||||
},
|
||||
supportsInstanceRetrievalByStudyUid: {
|
||||
type: Boolean,
|
||||
label: 'Supports instance retrieval by StudyUid?',
|
||||
defaultValue: true
|
||||
}
|
||||
});
|
||||
|
||||
export const DIMSEServer = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
label: 'Name',
|
||||
max: 100
|
||||
},
|
||||
peers: {
|
||||
type: [ DIMSEPeer ],
|
||||
label: 'DIMSE Peers',
|
||||
}
|
||||
});
|
||||
|
||||
export const UISettings = new SimpleSchema({
|
||||
studyListFunctionsEnabled: {
|
||||
type: Boolean,
|
||||
label: 'Study List Functions Enabled?',
|
||||
defaultValue: true
|
||||
}
|
||||
});
|
||||
|
||||
export const PublicServerConfig = new SimpleSchema({
|
||||
verifyEmail: {
|
||||
type: Boolean,
|
||||
label: 'Verify Email',
|
||||
defaultValue: false
|
||||
},
|
||||
ui: {
|
||||
type: UISettings,
|
||||
label: 'UI Settings'
|
||||
}
|
||||
});
|
||||
|
||||
export const Servers = new SimpleSchema({
|
||||
dicomWeb: {
|
||||
type: [ DICOMWebServer ],
|
||||
label: 'DICOMWeb Servers',
|
||||
optional: true
|
||||
},
|
||||
dimse: {
|
||||
type: [ DIMSEServer ],
|
||||
label: 'DIMSE Servers',
|
||||
optional: true
|
||||
}
|
||||
});
|
||||
|
||||
export const ServerConfiguration = new SimpleSchema({
|
||||
servers: {
|
||||
type: Servers,
|
||||
label: 'Servers'
|
||||
},
|
||||
defaultServiceType: {
|
||||
type: String,
|
||||
label: 'Default Service Type',
|
||||
defaultValue: 'dicomWeb'
|
||||
},
|
||||
public: {
|
||||
type: PublicServerConfig,
|
||||
label: 'Public Server Configuration',
|
||||
}
|
||||
});
|
||||
@ -5,7 +5,7 @@ Package.describe({
|
||||
});
|
||||
|
||||
Package.onUse(function (api) {
|
||||
api.versionsFrom('1.3.5.1');
|
||||
api.versionsFrom('1.4');
|
||||
|
||||
api.use('ecmascript');
|
||||
api.use('standard-app-packages');
|
||||
@ -15,6 +15,7 @@ Package.onUse(function (api) {
|
||||
api.use('practicalmeteor:loglevel');
|
||||
api.use('rwatts:uuid');
|
||||
api.use('silentcicero:jszip');
|
||||
api.use('aldeed:simple-schema');
|
||||
|
||||
// Note: MomentJS appears to be required for Bootstrap3 Datepicker, but not a dependency for some reason
|
||||
api.use('momentjs:moment');
|
||||
@ -37,6 +38,9 @@ Package.onUse(function (api) {
|
||||
// console for debugging purposes
|
||||
api.addFiles('log.js');
|
||||
|
||||
api.addFiles('both/collections.js', [ 'client', 'server' ]);
|
||||
api.addFiles('both/schema.js', [ 'client', 'server' ]);
|
||||
|
||||
// Components
|
||||
api.addFiles('client/components/worklist.html', 'client');
|
||||
api.addFiles('client/components/worklist.js', 'client');
|
||||
@ -78,6 +82,7 @@ Package.onUse(function (api) {
|
||||
|
||||
// Server-side functions
|
||||
api.addFiles('server/collections.js', 'server');
|
||||
api.addFiles('server/validateServerConfiguration.js', 'server');
|
||||
api.addFiles('server/lib/namespace.js', 'server');
|
||||
api.addFiles('server/lib/encodeQueryData.js', 'server');
|
||||
api.addFiles('server/methods/getStudyMetadata.js', 'server');
|
||||
@ -99,16 +104,12 @@ Package.onUse(function (api) {
|
||||
api.addFiles('server/services/remote/studies.js', 'server');
|
||||
api.addFiles('server/services/remote/retrieveMetadata.js', 'server');
|
||||
|
||||
api.addFiles('both/collections.js', [ 'client', 'server' ]);
|
||||
|
||||
api.export('Services', 'server');
|
||||
|
||||
// Export Worklist helper functions for usage in Routes
|
||||
api.export('getTimepointName', 'client');
|
||||
api.export('getStudyMetadata', 'client');
|
||||
api.export('getStudiesMetadata', 'client');
|
||||
api.export('openNewTab', 'client');
|
||||
api.export('setWorklistSubscriptions', 'client');
|
||||
api.export('switchToTab', 'client');
|
||||
api.export('progressDialog', 'client');
|
||||
api.export('Worklist');
|
||||
|
||||
12
Packages/worklist/server/validateServerConfiguration.js
Normal file
12
Packages/worklist/server/validateServerConfiguration.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import { ServerConfiguration } from '../both/schema.js';
|
||||
|
||||
Meteor.startup(() => {
|
||||
console.log('------ Testing Meteor Settings ------');
|
||||
let config = ServerConfiguration.clean(Meteor.settings);
|
||||
console.log(JSON.stringify(config, null, 2));
|
||||
|
||||
Meteor.settings = config;
|
||||
check(config, ServerConfiguration);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user