wwu
This commit is contained in:
parent
ffe8f8cf99
commit
ae0d6f3310
@ -15,6 +15,7 @@ Package.onUse(function(api) {
|
||||
api.addFiles('server/Data.js', 'server');
|
||||
api.addFiles('server/Message.js', 'server');
|
||||
api.addFiles('server/PDU.js', 'server');
|
||||
api.addFiles('server/CSocket.js', 'server');
|
||||
api.addFiles('server/Connection.js', 'server');
|
||||
api.addFiles('server/DIMSE.js', 'server');
|
||||
|
||||
|
||||
587
Packages/dimseservice/server/CSocket.js
Executable file
587
Packages/dimseservice/server/CSocket.js
Executable file
@ -0,0 +1,587 @@
|
||||
var EventEmitter = Npm.require('events').EventEmitter;
|
||||
|
||||
function time() {
|
||||
return Math.floor(Date.now() / 1000);
|
||||
}
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
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) {
|
||||
EventEmitter.call(this);
|
||||
this.socket = socket;
|
||||
this.negotiatedContexts = {};
|
||||
this.receiving = null;
|
||||
this.receiveLength = null;
|
||||
this.minRecv = null;
|
||||
this.lastReceived = null;
|
||||
this.presentationContexts = [];
|
||||
this.associated = false;
|
||||
this.pendingPDVs = null;
|
||||
this.connected = false;
|
||||
this.started = null;
|
||||
this.intervalId = null;
|
||||
this.lastCommand = null;
|
||||
this.lastSent = null;
|
||||
this.messages = {};
|
||||
this.messageIdCounter = 0;
|
||||
this.callingAe = null;
|
||||
this.calledAe = null;
|
||||
this.id = getRandomInt(1000, 9999);
|
||||
this.options = options;
|
||||
|
||||
var o = this;
|
||||
this.socket.on("connect", function(){
|
||||
o.ready();
|
||||
});
|
||||
this.socket.on("data", function(data) {
|
||||
o.received(data);
|
||||
});
|
||||
this.socket.on("error", function(he) {
|
||||
console.log("Error: ", 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() {
|
||||
this.released();
|
||||
});
|
||||
this.on('aborted', function() {
|
||||
this.released();
|
||||
})
|
||||
this.on('message', function(pdvs) {
|
||||
this.receivedMessage(pdvs);
|
||||
});
|
||||
};
|
||||
util.inherits(CSocket, EventEmitter);
|
||||
|
||||
CSocket.prototype.setCallingAE = function(ae) {
|
||||
this.callingAe = ae;
|
||||
};
|
||||
|
||||
CSocket.prototype.setCalledAe = function(ae) {
|
||||
this.calledAe = ae;
|
||||
};
|
||||
|
||||
CSocket.prototype.associate = function() {
|
||||
var associateRQ = new AssociateRQ();
|
||||
associateRQ.setCalledAETitle(this.calledAe);
|
||||
associateRQ.setCallingAETitle(this.callingAe);
|
||||
associateRQ.setApplicationContextItem(new ApplicationContextItem());
|
||||
|
||||
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 abstractItem = new AbstractSyntaxItem();
|
||||
abstractItem.setAbstractSyntaxName(context.abstractSyntax);
|
||||
contextItem.setAbstractSyntaxItem(abstractItem);
|
||||
contextItems.push(contextItem);
|
||||
});
|
||||
associateRQ.setPresentationContextItems(contextItems);
|
||||
|
||||
var maxLengthItem = new MaximumLengthItem(),
|
||||
classUIDItem = new ImplementationClassUIDItem(),
|
||||
versionItem = new ImplementationVersionNameItem();
|
||||
|
||||
classUIDItem.setImplementationClassUID(C.IMPLEM_UID);
|
||||
versionItem.setImplementationVersionName(C.IMPLEM_VERSION);
|
||||
var packageSize = this.options.maxPackageSize ? this.options.maxPackageSize : C.DEFAULT_MAX_PACKAGE_SIZE;
|
||||
maxLengthItem.setMaximumLengthReceived(packageSize);
|
||||
|
||||
var userInfo = new UserInformationItem();
|
||||
userInfo.setUserDataItems([maxLengthItem, classUIDItem, versionItem]);
|
||||
|
||||
associateRQ.setUserInformationItem(userInfo);
|
||||
|
||||
this.send(associateRQ);
|
||||
};
|
||||
|
||||
CSocket.prototype.getContext = function(id) {
|
||||
for (var k in this.presentationContexts) {
|
||||
var ctx = this.presentationContexts[k];
|
||||
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) {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
CSocket.prototype.getContextId = function(contextId) {
|
||||
if (!this.negotiatedContexts[contextId]) return null;
|
||||
|
||||
return this.negotiatedContexts[contextId].id;
|
||||
}
|
||||
|
||||
CSocket.prototype.setPresentationContexts = function(uids) {
|
||||
var contexts = [],
|
||||
id = 0;
|
||||
uids.forEach(function(uid) {
|
||||
contexts.push({
|
||||
id: ++id,
|
||||
abstractSyntax: uid,
|
||||
transferSyntaxes: [C.IMPLICIT_LITTLE_ENDIAN, C.EXPLICIT_LITTLE_ENDIAN, C.EXPLICIT_BIG_ENDIAN]
|
||||
});
|
||||
});
|
||||
this.presentationContexts = contexts;
|
||||
};
|
||||
|
||||
CSocket.prototype.newMessageId = function() {
|
||||
return (++this.messageIdCounter) % 65536;
|
||||
}
|
||||
|
||||
CSocket.prototype.resetReceive = function() {
|
||||
this.receiving = this.receiveLength = null;
|
||||
};
|
||||
|
||||
CSocket.prototype.send = function(pdu, afterCbk) {
|
||||
//console.log('SEND PDU-TYPE: ', pdu.type);
|
||||
var toSend = pdu.buffer();
|
||||
//console.log('send buffer', toSend.toString('hex'));
|
||||
this.socket.write(toSend, afterCbk ? afterCbk : function() {
|
||||
//console.log('Data written');
|
||||
});
|
||||
};
|
||||
|
||||
CSocket.prototype.release = function() {
|
||||
var releaseRQ = new ReleaseRQ();
|
||||
this.send(releaseRQ);
|
||||
};
|
||||
|
||||
CSocket.prototype.released = function() {
|
||||
this.socket.end();
|
||||
};
|
||||
|
||||
CSocket.prototype.ready = function() {
|
||||
console.log("Connection established");
|
||||
this.connected = true;
|
||||
this.started = time();
|
||||
|
||||
var o = this;
|
||||
if (this.options.idle) {
|
||||
this.intervalId = setInterval(function() {
|
||||
o.checkIdle();
|
||||
}, 3000);
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.checkIdle = function() {
|
||||
var current = time(),
|
||||
idl = this.options.idle;
|
||||
|
||||
if (!this.lastReceived && (current - this.started >= idl)) {
|
||||
this.idleClose();
|
||||
} else if (this.lastReceived && (current - this.lastReceived >= idl)) {
|
||||
this.idleClose();
|
||||
} else {
|
||||
//console.log('keep idling')
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.idleClose = function() {
|
||||
console.log('Exceed idle time, closing connection');
|
||||
this.release();
|
||||
};
|
||||
|
||||
CSocket.prototype.received = function(data) {
|
||||
var i = 0;
|
||||
do {
|
||||
data = this.process(data);
|
||||
} while (data !== null);
|
||||
this.lastReceived = time();
|
||||
};
|
||||
|
||||
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);
|
||||
this.minRecv = null;
|
||||
}
|
||||
|
||||
if (data.length < 6) {
|
||||
this.minRecv = data;
|
||||
return null;
|
||||
}
|
||||
|
||||
var stream = new ReadStream(data);
|
||||
var type = stream.read(C.TYPE_UINT8);
|
||||
stream.increment(1);
|
||||
var len = stream.read(C.TYPE_UINT32),
|
||||
cmp = data.length - 6;
|
||||
if (len > cmp) {
|
||||
this.receiving = data;
|
||||
this.receiveLength = len;
|
||||
} else {
|
||||
var process = data,
|
||||
remaining = null;
|
||||
if (len < cmp) {
|
||||
process = data.slice(0, len + 6);
|
||||
remaining = data.slice(len + 6, cmp + 6);
|
||||
}
|
||||
this.resetReceive();
|
||||
this.interpret(new ReadStream(process), this);
|
||||
if (remaining) {
|
||||
return remaining;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var newData = Buffer.concat([this.receiving, data], this.receiving.length + data.length),
|
||||
pduLength = newData.length - 6;
|
||||
|
||||
if (pduLength < this.receiveLength) {
|
||||
this.receiving = newData;
|
||||
} else {
|
||||
var remaining = null;
|
||||
if (pduLength > this.receiveLength) {
|
||||
remaining = newData.slice(this.receiveLength + 6, pduLength + 6);
|
||||
newData = newData.slice(0, this.receiveLength + 6);
|
||||
}
|
||||
this.resetReceive();
|
||||
this.interpret(new ReadStream(newData));
|
||||
if (remaining) {
|
||||
return remaining;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
CSocket.prototype.interpret = function(stream) {
|
||||
var pdatas = [],
|
||||
size = stream.size(),
|
||||
o = this;
|
||||
while (stream.offset < size) {
|
||||
var pdu = PDU.createByStream(stream);
|
||||
//console.log("Received PDU-TYPE " + PDU.typeToString(pdu.type));
|
||||
if (pdu.is(C.ITEM_TYPE_PDU_ASSOCIATE_AC)) {
|
||||
pdu.presentationContextItems.forEach(function(ctx) {
|
||||
var requested = o.getContext(ctx.presentationContextID);
|
||||
if (!requested) {
|
||||
throw "Accepted presentation context not found";
|
||||
}
|
||||
o.negotiatedContexts[ctx.presentationContextID] = {
|
||||
id: ctx.presentationContextID,
|
||||
transferSyntax: ctx.transferSyntaxesItems[0].transferSyntaxName,
|
||||
abstractSyntax: requested.abstractSyntax
|
||||
};
|
||||
});
|
||||
|
||||
//console.log('Accepted');
|
||||
this.associated = true;
|
||||
this.emit('associated', pdu);
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_ASSOCIATE_RQ)) {
|
||||
var accepd = new AssociateAC();
|
||||
|
||||
pdu.presentationContextItems.forEach(function(ctx) {
|
||||
|
||||
});
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_RELEASE_RP)) {
|
||||
//console.log('Released');
|
||||
this.associated = false;
|
||||
this.emit('released');
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_AABORT)) {
|
||||
//console.log('Aborted');
|
||||
this.emit('aborted');
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_PDATA)) {
|
||||
pdatas.push(pdu);
|
||||
}
|
||||
}
|
||||
|
||||
if (pdatas) {
|
||||
var pdvs = this.pendingPDVs ? this.pendingPDVs : [];
|
||||
pdatas.forEach(function(pdata) {
|
||||
pdvs = pdvs.concat(pdata.presentationDataValueItems);
|
||||
});
|
||||
this.pendingPDVs = null;
|
||||
var i = 0,
|
||||
count = pdvs.length;
|
||||
while (i < count) {
|
||||
if (!pdvs[i].isLast) {
|
||||
var j = i + 1;
|
||||
while (j < count) {
|
||||
pdvs[i].messageStream.concat(pdvs[j].messageStream);
|
||||
if (pdvs[j++].isLast) {
|
||||
pdvs[i].isLast = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pdvs[i].isLast) {
|
||||
this.emit('message', pdvs[i]);
|
||||
} else {
|
||||
this.pendingPDVs = [pdvs[i]];
|
||||
}
|
||||
i = j;
|
||||
} else {
|
||||
this.emit('message', pdvs[i++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.receivedMessage = function(pdv) {
|
||||
var syntax = this.getSyntax(pdv.contextId),
|
||||
msg = DicomMessage.read(pdv.messageStream, pdv.type, syntax, this.options.vr);
|
||||
|
||||
if (msg.isCommand()) {
|
||||
this.lastCommand = msg;
|
||||
|
||||
if (msg.isResponse()) {
|
||||
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));
|
||||
}
|
||||
if (msg.isFinal()) {
|
||||
var replyId = msg.respondedTo();
|
||||
if (this.messages[replyId].listener) {
|
||||
this.messages[replyId].listener.emit('end', msg);
|
||||
|
||||
if (!msg.haveData())
|
||||
delete this.messages[replyId];
|
||||
}
|
||||
|
||||
if (msg.is(C.COMMAND_C_GET_RSP)) {
|
||||
if (!msg.getNumOfRemainingSubOperations()) {
|
||||
if (this.lastGets && this.lastGets.length > 0) this.lastGets.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*if (msg.is(0x01)) {
|
||||
console.log('ae title ', msg.getValue(0x00001031))
|
||||
}*/
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!this.lastCommand) {
|
||||
throw "Only dataset?";
|
||||
} else if (!this.lastCommand.haveData()) {
|
||||
throw "Last command didn't indicate presence of data";
|
||||
}
|
||||
|
||||
if (this.lastCommand.isResponse()) {
|
||||
var replyId = this.lastCommand.respondedTo();
|
||||
if (this.messages[replyId].listener) {
|
||||
var flag = this.lastCommand.failure() ? true : false;
|
||||
|
||||
this.messages[replyId].listener.emit("result", msg, flag);
|
||||
|
||||
if (this.lastCommand.failure()) {
|
||||
delete this.messages[replyId];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.lastCommand.is(C.COMMAND_C_STORE_RQ)) {
|
||||
var moveMessageId = this.lastCommand.getMoveMessageId(),
|
||||
useId = moveMessageId;
|
||||
if (!moveMessageId) {
|
||||
//!! Going to deprecate now
|
||||
//kinda hacky but we know this c-store is came from a c-get
|
||||
if (this.lastGets.length > 0) {
|
||||
useId = this.lastGets[0];
|
||||
} else {
|
||||
throw "Where does this c-store came from?";
|
||||
}
|
||||
} else console.log('move ', moveMessageId);
|
||||
//this.storeResponse(useId, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CSocket.prototype.wrapToPData = function(message, context) {
|
||||
var useContext = message.contextUID ? message.contextUID : context;
|
||||
var ctx = this.getContextByUID(useContext);
|
||||
|
||||
var pdata = new PDataTF(),
|
||||
pdv = new PresentationDataValueItem(ctx.id);
|
||||
pdv.setMessage(message);
|
||||
pdata.setPresentationDataValueItems([pdv]);
|
||||
return pdata;
|
||||
}
|
||||
|
||||
CSocket.prototype.sendMessage = function(context, command, dataset) {
|
||||
var nContext = this.getContextByUID(context),
|
||||
syntax = nContext.transferSyntax,
|
||||
cid = nContext.id,
|
||||
messageId = this.newMessageId(),
|
||||
msgData = {};
|
||||
|
||||
msgData.listener = new Envelope(command);
|
||||
|
||||
var o = this;
|
||||
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();
|
||||
|
||||
cancelMessage.setReplyMessageId(this.command.messageId);
|
||||
cancelMessage.setSyntax(C.IMPLICIT_LITTLE_ENDIAN);
|
||||
|
||||
o.send(o.wrapToPData(cancelMessage, this.command.contextUID));
|
||||
}
|
||||
});
|
||||
|
||||
command.setSyntax(C.IMPLICIT_LITTLE_ENDIAN);
|
||||
command.setContextId(context);
|
||||
command.setMessageId(messageId);
|
||||
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;
|
||||
|
||||
this.send(pdata);
|
||||
if (dataset) {
|
||||
dataset.setSyntax(syntax);
|
||||
var dsData = new PDataTF(),
|
||||
dPdv = new PresentationDataValueItem(cid);
|
||||
|
||||
dPdv.setMessage(dataset);
|
||||
dsData.setPresentationDataValueItems([dPdv]);
|
||||
this.send(dsData);
|
||||
}
|
||||
return msgData.listener;
|
||||
};
|
||||
|
||||
CSocket.prototype.verify = function() {
|
||||
this.setPresentationContexts([C.SOP_VERIFICATION]);
|
||||
this.startAssociationRequest(function() {
|
||||
//associated, we can release now
|
||||
this.release();
|
||||
});
|
||||
};
|
||||
|
||||
CSocket.prototype.wrapMessage = function(data) {
|
||||
if (data) {
|
||||
var datasetMessage = new DataSetMessage();
|
||||
datasetMessage.setElements(data);
|
||||
return datasetMessage;
|
||||
} else return data;
|
||||
};
|
||||
|
||||
CSocket.prototype.find = function(params, options) {
|
||||
return this.sendMessage(options.context, new CFindRQ(), this.wrapMessage(params));
|
||||
};
|
||||
|
||||
CSocket.prototype.move = function(destination, params, options) {
|
||||
var moveMessage = new CMoveRQ();
|
||||
moveMessage.setDestination(destination);
|
||||
|
||||
return this.sendMessage(options.context, moveMessage, this.wrapMessage(params));
|
||||
};
|
||||
|
||||
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
|
||||
}, options);
|
||||
|
||||
return this.move(destination, sendParams, options);
|
||||
};
|
||||
|
||||
CSocket.prototype.findPatients = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_PATIENT,
|
||||
0x00100010: "",
|
||||
0x00100020: "",
|
||||
0x00100030: "",
|
||||
0x00100040: "",
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_PATIENT_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
};
|
||||
|
||||
CSocket.prototype.findStudies = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_STUDY,
|
||||
0x00080020: "",
|
||||
0x00100010: "",
|
||||
0x00080061: "",
|
||||
0x0020000D: ""
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
};
|
||||
|
||||
CSocket.prototype.findSeries = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_SERIES,
|
||||
0x00080020: "",
|
||||
0x0020000E: "",
|
||||
0x0008103E: "",
|
||||
0x0020000D: ""
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
};
|
||||
|
||||
CSocket.prototype.findInstances = function(params, options) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_IMAGE,
|
||||
0x00080020: "",
|
||||
0x0020000E: "",
|
||||
0x0008103E: "",
|
||||
0x0020000D: ""
|
||||
}, params);
|
||||
options = Object.assign({
|
||||
context : C.SOP_STUDY_ROOT_FIND
|
||||
}, options);
|
||||
|
||||
return this.find(sendParams, options);
|
||||
};
|
||||
@ -1,461 +1,69 @@
|
||||
var EventEmitter = Npm.require('events').EventEmitter;
|
||||
|
||||
function time() {
|
||||
return Math.floor(Date.now() / 1000);
|
||||
}
|
||||
var EventEmitter = Npm.require('events').EventEmitter, net = Npm.require('net'), Socket = net.Socket;
|
||||
|
||||
var DEFAULT_MAX_PACKAGE_SIZE = 32768;
|
||||
var DEFAULT_SOURCE_AE = 'OHIFDCM';
|
||||
|
||||
var Envelope = function(conn, command, dataset) {
|
||||
Connection = function(options) {
|
||||
EventEmitter.call(this);
|
||||
this.command = command;
|
||||
this.dataset = dataset;
|
||||
this.conn = conn;
|
||||
};
|
||||
|
||||
util.inherits(Envelope, EventEmitter);
|
||||
|
||||
Envelope.prototype.send = function() {
|
||||
return this;
|
||||
};
|
||||
|
||||
Connection = function(socket, options) {
|
||||
EventEmitter.call(this);
|
||||
this.socket = socket;
|
||||
this.options = Object.assign({
|
||||
hostAE: '',
|
||||
sourceAE: 'OHIFDCM',
|
||||
maxPackageSize: 32768,
|
||||
idle: 60,
|
||||
maxPackageSize: C.DEFAULT_MAX_PACKAGE_SIZE,
|
||||
idle: false,
|
||||
reconnect: true,
|
||||
vr: {
|
||||
split: true
|
||||
}
|
||||
}, options);
|
||||
|
||||
this.connected = false;
|
||||
this.started = null;
|
||||
this.lastReceived = null;
|
||||
this.associated = false;
|
||||
this.receiving = null;
|
||||
this.receiveLength = null;
|
||||
this.minRecv = null;
|
||||
this.pendingPDVs = null;
|
||||
this.server = null;
|
||||
//this.retrieveModel = RETRIEVE_MODEL_STUDY_ROOT;
|
||||
this.presentationContexts = [];
|
||||
this.transferSyntaxes = [];
|
||||
this.negotiatedContexts = {};
|
||||
this.messages = {};
|
||||
this.messageIdCounter = 0;
|
||||
this.services = [];
|
||||
this.lastCommand = null;
|
||||
this.lastSent = null;
|
||||
this.lastGets = [];
|
||||
this.findContext = C.SOP_STUDY_ROOT_FIND;
|
||||
|
||||
//register hooks
|
||||
var o = this;
|
||||
this.socket.on('data', function(data) {
|
||||
o.received(data);
|
||||
});
|
||||
this.socket.on('close', function(he) {
|
||||
o.closed(he);
|
||||
o.emit('close', he);
|
||||
});
|
||||
this.socket.on('error', function(he) {
|
||||
o.error(he);
|
||||
});
|
||||
this.socket.on('end', function() {
|
||||
if (o.intervalId) {
|
||||
clearInterval(o.intervalId);
|
||||
}
|
||||
|
||||
if (o.server) {
|
||||
console.log('Closing server');
|
||||
o.server.close();
|
||||
}
|
||||
|
||||
console.log('ended');
|
||||
});
|
||||
this.on('released', function() {
|
||||
this.released();
|
||||
});
|
||||
this.on('aborted', function() {
|
||||
this.released();
|
||||
});
|
||||
this.on('message', function(pdvs) {
|
||||
this.receivedMessage(pdvs);
|
||||
});
|
||||
this.on('init', this.ready);
|
||||
|
||||
//this.pause();
|
||||
if (this.options.listenHost && this.options.listenPort) {
|
||||
this.server = net.createServer();
|
||||
this.server.listen(this.options.listenPort, this.options.listenHost);
|
||||
this.server.on('listening', function() {
|
||||
console.log('listening on %j', this.address());
|
||||
});
|
||||
this.server.on('connection', function(socket) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
this.emit('init');
|
||||
};
|
||||
this.peers = {};
|
||||
this.peerSockets = {};
|
||||
this.defaultPeer = null;
|
||||
this.defaultServer = null;
|
||||
}
|
||||
|
||||
util.inherits(Connection, EventEmitter);
|
||||
|
||||
Connection.prototype.checkIdle = function() {
|
||||
var current = time(),
|
||||
idl = this.options.idle;
|
||||
if (!this.lastReceived && (current - this.started >= idl)) {
|
||||
this.idleClose();
|
||||
} else if (this.lastReceived && (current - this.lastReceived >= idl)) {
|
||||
this.idleClose();
|
||||
Connection.prototype.addPeer = function(options) {
|
||||
if (!options.aeTitle || !options.host || !options.port) {
|
||||
return false;
|
||||
}
|
||||
this.peers[options.aeTitle] = {
|
||||
host : options.host, port : options.port
|
||||
};
|
||||
if (options.default) {
|
||||
if (options.server) {
|
||||
this.defaultServer = options.aeTitle;
|
||||
} else {
|
||||
//console.log('keep idling')
|
||||
this.defaultPeer = options.aeTitle;
|
||||
}
|
||||
};
|
||||
|
||||
Connection.prototype.released = function() {
|
||||
this.socket.end();
|
||||
};
|
||||
|
||||
Connection.prototype.idleClose = function() {
|
||||
console.log('Exceed idle time, closing connection');
|
||||
this.release();
|
||||
};
|
||||
|
||||
Connection.prototype.getSoureceAE = function() {
|
||||
return this.options.sourceAE;
|
||||
};
|
||||
|
||||
Connection.prototype.ready = function() {
|
||||
console.log('Connection established');
|
||||
this.connected = true;
|
||||
this.started = time();
|
||||
|
||||
}
|
||||
if (options.server) {
|
||||
//start listening
|
||||
var server = net.createServer();
|
||||
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);
|
||||
});
|
||||
var o = this;
|
||||
this.intervalId = setInterval(function() {
|
||||
o.checkIdle();
|
||||
}, 3000);
|
||||
server.on('connection', function(nativeSocket) {
|
||||
//incoming connections
|
||||
var socket = new CSocket(nativeSocket, o.options);
|
||||
o.addSocket(options.aeTitle, socket);
|
||||
|
||||
//this.emit("init");
|
||||
//this.startAssociationRequest();
|
||||
};
|
||||
|
||||
Connection.prototype.resetReceive = function() {
|
||||
this.receiving = this.receiveLength = null;
|
||||
};
|
||||
|
||||
Connection.prototype.received = function(data) {
|
||||
var i = 0;
|
||||
do {
|
||||
data = this.process(data);
|
||||
} while (data !== null);
|
||||
this.lastReceived = time();
|
||||
};
|
||||
|
||||
Connection.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);
|
||||
this.minRecv = null;
|
||||
}
|
||||
|
||||
if (data.length < 6) {
|
||||
this.minRecv = data;
|
||||
return null;
|
||||
}
|
||||
|
||||
var stream = new ReadStream(data);
|
||||
var type = stream.read(C.TYPE_UINT8);
|
||||
stream.increment(1);
|
||||
var len = stream.read(C.TYPE_UINT32),
|
||||
cmp = data.length - 6;
|
||||
if (len > cmp) {
|
||||
this.receiving = data;
|
||||
this.receiveLength = len;
|
||||
} else {
|
||||
var process = data,
|
||||
remaining = null;
|
||||
if (len < cmp) {
|
||||
process = data.slice(0, len + 6);
|
||||
remaining = data.slice(len + 6, cmp + 6);
|
||||
}
|
||||
|
||||
this.resetReceive();
|
||||
this.interpret(new ReadStream(process));
|
||||
if (remaining) {
|
||||
return remaining;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var newData = Buffer.concat([ this.receiving, data ], this.receiving.length + data.length),
|
||||
pduLength = newData.length - 6;
|
||||
|
||||
if (pduLength < this.receiveLength) {
|
||||
this.receiving = newData;
|
||||
} else {
|
||||
var remaining = null;
|
||||
if (pduLength > this.receiveLength) {
|
||||
remaining = newData.slice(this.receiveLength + 6, pduLength + 6);
|
||||
newData = newData.slice(0, this.receiveLength + 6);
|
||||
}
|
||||
|
||||
this.resetReceive();
|
||||
this.interpret(new ReadStream(newData));
|
||||
if (remaining) {
|
||||
return remaining;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Connection.prototype.interpret = function(stream) {
|
||||
var pdatas = [],
|
||||
size = stream.size(),
|
||||
o = this;
|
||||
while (stream.offset < size) {
|
||||
var pdu = pduByStream(stream);
|
||||
//console.log("Received PDU-TYPE " + pdu.type);
|
||||
if (pdu.is(C.ITEM_TYPE_PDU_ASSOCIATE_AC)) {
|
||||
pdu.presentationContextItems.forEach(function(ctx) {
|
||||
var requested = o.getContext(ctx.presentationContextID);
|
||||
if (!requested) {
|
||||
throw 'Accepted presentation context not found';
|
||||
}
|
||||
|
||||
o.negotiatedContexts[ctx.presentationContextID] = {
|
||||
id: ctx.presentationContextID,
|
||||
transferSyntax: ctx.transferSyntaxesItems[0].transferSyntaxName,
|
||||
abstractSyntax: requested.abstractSyntax
|
||||
};
|
||||
|
||||
var notfound = false;
|
||||
o.services.forEach(function(service) {
|
||||
if (service.contextUID == requested.abstractSyntax) {
|
||||
service.contextID = ctx.presentationContextID;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//console.log('Accepted');
|
||||
this.associated = true;
|
||||
this.emit('associated', pdu);
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_RELEASE_RP)) {
|
||||
//console.log('Released');
|
||||
this.associated = false;
|
||||
this.emit('released');
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_AABORT)) {
|
||||
//console.log('Aborted');
|
||||
this.emit('aborted');
|
||||
} else if (pdu.is(C.ITEM_TYPE_PDU_PDATA)) {
|
||||
pdatas.push(pdu);
|
||||
}
|
||||
}
|
||||
|
||||
if (pdatas) {
|
||||
var pdvs = this.pendingPDVs ? this.pendingPDVs : [];
|
||||
pdatas.forEach(function(pdata) {
|
||||
pdvs = pdvs.concat(pdata.presentationDataValueItems);
|
||||
});
|
||||
this.pendingPDVs = null;
|
||||
var i = 0,
|
||||
count = pdvs.length;
|
||||
while (i < count) {
|
||||
if (!pdvs[i].isLast) {
|
||||
var j = i + 1;
|
||||
while (j < count) {
|
||||
pdvs[i].messageStream.concat(pdvs[j].messageStream);
|
||||
if (pdvs[j++].isLast) {
|
||||
pdvs[i].isLast = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pdvs[i].isLast) {
|
||||
this.emit('message', pdvs[i]);
|
||||
} else {
|
||||
this.pendingPDVs = [ pdvs[i] ];
|
||||
}
|
||||
|
||||
i = j;
|
||||
} else {
|
||||
this.emit('message', pdvs[i++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//this.release();
|
||||
};
|
||||
|
||||
Connection.prototype.newMessageId = function() {
|
||||
return (++this.messageIdCounter) % 255;
|
||||
};
|
||||
|
||||
Connection.prototype.closed = function(had_error) {
|
||||
this.connected = false;
|
||||
console.log('Connection closed', had_error);
|
||||
//this.destroy();
|
||||
};
|
||||
|
||||
Connection.prototype.error = function(err) {
|
||||
console.log('Error: ', err);
|
||||
};
|
||||
|
||||
Connection.prototype.send = function(pdu, afterCbk) {
|
||||
//console.log('SEND PDU-TYPE: ', pdu.type);
|
||||
var toSend = pdu.buffer();
|
||||
//console.log('send buffer', toSend.toString('hex'));
|
||||
this.socket.write(toSend, afterCbk ? afterCbk : function() {
|
||||
//console.log('Data written');
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.getSyntax = function(contextId) {
|
||||
if (!this.negotiatedContexts[contextId]) return null;
|
||||
|
||||
return this.negotiatedContexts[contextId].transferSyntax;
|
||||
};
|
||||
|
||||
Connection.prototype.getContextByUID = function(uid) {
|
||||
for (var k in this.negotiatedContexts) {
|
||||
var ctx = this.negotiatedContexts[k];
|
||||
if (ctx.abstractSyntax == uid) {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Connection.prototype.getContextId = function(contextId) {
|
||||
if (!this.negotiatedContexts[contextId]) return null;
|
||||
|
||||
return this.negotiatedContexts[contextId].id;
|
||||
};
|
||||
|
||||
Connection.prototype.getContext = function(id) {
|
||||
for (var k in this.presentationContexts) {
|
||||
var ctx = this.presentationContexts[k];
|
||||
if (id == ctx.id) return ctx;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Connection.prototype.setPresentationContexts = function(uids) {
|
||||
var contexts = [],
|
||||
id = 0;
|
||||
uids.forEach(function(uid) {
|
||||
contexts.push({
|
||||
id: ++id,
|
||||
abstractSyntax: uid,
|
||||
transferSyntaxes: [ C.IMPLICIT_LITTLE_ENDIAN, C.EXPLICIT_LITTLE_ENDIAN, C.EXPLICIT_BIG_ENDIAN ]
|
||||
//close server on close socket
|
||||
socket.on('close', function(){
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
this.presentationContexts = contexts;
|
||||
}
|
||||
};
|
||||
|
||||
Connection.prototype.verify = function() {
|
||||
this.setPresentationContexts([ C.SOP_VERIFICATION ]);
|
||||
this.startAssociationRequest(function() {
|
||||
//associated, we can release now
|
||||
this.release();
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.release = function() {
|
||||
var releaseRQ = new ReleaseRQ();
|
||||
this.send(releaseRQ);
|
||||
};
|
||||
|
||||
Connection.prototype.addService = function(service) {
|
||||
service.setConnection(this);
|
||||
this.services.push(service);
|
||||
};
|
||||
|
||||
Connection.prototype.receivedMessage = function(pdv) {
|
||||
var syntax = this.getSyntax(pdv.contextId),
|
||||
msg = readMessage(pdv.messageStream, pdv.type, syntax, this.options.vr);
|
||||
|
||||
if (msg.isCommand()) {
|
||||
this.lastCommand = msg;
|
||||
|
||||
if (msg.isResponse()) {
|
||||
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));
|
||||
}
|
||||
|
||||
if (msg.isFinal()) {
|
||||
var replyId = msg.respondedTo();
|
||||
if (this.messages[replyId].listener) {
|
||||
this.messages[replyId].listener.emit('end', msg);
|
||||
/*if (this.messages[replyId].listener[1]) {
|
||||
this.messages[replyId].listener[1].call(this, msg);
|
||||
}*/
|
||||
if (!msg.haveData())
|
||||
delete this.messages[replyId];
|
||||
}
|
||||
|
||||
if (msg.is(C.COMMAND_C_GET_RSP)) {
|
||||
if (!msg.getNumOfRemainingSubOperations()) {
|
||||
if (this.lastGets && this.lastGets.length > 0) this.lastGets.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*if (msg.is(0x01)) {
|
||||
console.log('ae title ', msg.getValue(0x00001031))
|
||||
}*/
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!this.lastCommand) {
|
||||
throw 'Only dataset?';
|
||||
} else if (!this.lastCommand.haveData()) {
|
||||
throw "Last command didn't indicate presence of data";
|
||||
}
|
||||
|
||||
if (this.lastCommand.isResponse()) {
|
||||
var replyId = this.lastCommand.respondedTo();
|
||||
if (this.messages[replyId].listener) {
|
||||
var flag = this.lastCommand.failure() ? true : false;
|
||||
|
||||
this.messages[replyId].listener.emit('result', msg, flag);
|
||||
|
||||
if (this.lastCommand.failure()) {
|
||||
delete this.messages[replyId];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.lastCommand.is(C.COMMAND_C_STORE_RQ)) {
|
||||
var moveMessageId = this.lastCommand.getMoveMessageId(),
|
||||
useId = moveMessageId;
|
||||
if (!moveMessageId) {
|
||||
//!! Going to deprecate now
|
||||
//kinda hacky but we know this c-store is came from a c-get
|
||||
if (this.lastGets.length > 0) {
|
||||
useId = this.lastGets[0];
|
||||
} else {
|
||||
throw 'Where does this c-store came from?';
|
||||
}
|
||||
} else console.log('move ', moveMessageId);
|
||||
//this.storeResponse(useId, msg);
|
||||
}
|
||||
}
|
||||
Connection.prototype.selectPeer = function(aeTitle) {
|
||||
if (!aeTitle || !this.peers[aeTitle]) {
|
||||
throw "No such peer";
|
||||
}
|
||||
};
|
||||
return this.peers[aeTitle];
|
||||
}
|
||||
|
||||
Connection.prototype.storeResponse = function(messageId, msg) {
|
||||
var rq = this.messages[messageId];
|
||||
@ -470,183 +78,62 @@ 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.sendMessage = function(context, command, dataset, listener) {
|
||||
var nContext = this.getContextByUID(context),
|
||||
syntax = nContext.transferSyntax,
|
||||
cid = nContext.id,
|
||||
messageId = this.newMessageId(),
|
||||
msgData = {};
|
||||
|
||||
/*if (listener) {
|
||||
if (typeof listener != 'object') {
|
||||
listener = [listener, null];
|
||||
Connection.prototype.allClosed = function() {
|
||||
var allClosed = true;
|
||||
for (var i in o.peerSockets) {
|
||||
if (Object.keys(o.peerSockets[ae]).length > 0) {
|
||||
allClosed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
msgData.listener = listener;
|
||||
}*/
|
||||
msgData.listener = new Envelope();
|
||||
return allClosed;
|
||||
};
|
||||
|
||||
var pdata = new PDataTF(),
|
||||
pdv = new PresentationDataValueItem(cid);
|
||||
|
||||
command.setSyntax(C.IMPLICIT_LITTLE_ENDIAN);
|
||||
command.setContextId(context);
|
||||
command.setMessageId(messageId);
|
||||
if (dataset)
|
||||
command.setDataSetPresent(C.DATA_SET_PRESENT);
|
||||
|
||||
this.lastSent = command;
|
||||
if (command.is(C.COMMAND_C_GET_RQ)) {
|
||||
this.lastGets.push(messageId);
|
||||
Connection.prototype.addSocket = function(ae, socket) {
|
||||
if (!this.peerSockets[ae]) {
|
||||
this.peerSockets[ae] = {};
|
||||
}
|
||||
this.peerSockets[ae][socket.id] = socket;
|
||||
|
||||
pdv.setMessage(command);
|
||||
pdata.setPresentationDataValueItems([ pdv ]);
|
||||
|
||||
msgData.command = command;
|
||||
this.messages[messageId] = msgData;
|
||||
|
||||
/*var stream = new ReadStream(pdata.buffer()), np = pduByStream(stream), pdv = np.presentationDataValueItems[0];
|
||||
var msg = readMessage(pdv.messageStream, pdv.type, C.IMPLICIT_LITTLE_ENDIAN);
|
||||
console.log(msg.isCommand());
|
||||
return;*/
|
||||
|
||||
this.send(pdata);
|
||||
if (dataset) {
|
||||
dataset.setSyntax(syntax);
|
||||
var dsData = new PDataTF(),
|
||||
dPdv = new PresentationDataValueItem(cid);
|
||||
|
||||
dPdv.setMessage(dataset);
|
||||
dsData.setPresentationDataValueItems([ dPdv ]);
|
||||
this.send(dsData);
|
||||
}
|
||||
|
||||
return msgData.listener;
|
||||
var o = this;
|
||||
socket.on("close", function() {
|
||||
if (o.peerSockets[ae][this.id]) {
|
||||
delete o.peerSockets[ae][this.id];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Connection.prototype.associate = function(options, callback) {
|
||||
var hostAE = options.hostAE ? options.hostAE : this.defaultPeer,
|
||||
sourceAE = options.sourceAE ? options.sourceAE : this.defaultServer;
|
||||
peerInfo = this.selectPeer(hostAE), nativeSocket = new Socket();
|
||||
|
||||
var socket = new CSocket(nativeSocket, this.options), o = this;
|
||||
if (callback) {
|
||||
this.once('associated', callback);
|
||||
socket.once('associated', callback);
|
||||
}
|
||||
socket.setCalledAe(hostAE);
|
||||
socket.setCallingAE(sourceAE);
|
||||
|
||||
if (this.associated) {
|
||||
this.emit('associated');
|
||||
return;
|
||||
}
|
||||
nativeSocket.connect({
|
||||
host : peerInfo.host, port : peerInfo.port
|
||||
}, function(){
|
||||
//connected
|
||||
o.addSocket(hostAE, socket);
|
||||
|
||||
if (options.contexts) {
|
||||
this.setPresentationContexts(options.contexts);
|
||||
} else {
|
||||
throw 'No services attached';
|
||||
}
|
||||
if (options.contexts) {
|
||||
socket.setPresentationContexts(options.contexts);
|
||||
} else {
|
||||
throw "Contexts must be specified";
|
||||
}
|
||||
|
||||
var associateRQ = new AssociateRQ();
|
||||
associateRQ.setCalledAETitle(options.hostAE);
|
||||
var sourceAE = options.sourceAE ? options.sourceAE : DEFAULT_SOURCE_AE;
|
||||
associateRQ.setCallingAETitle(sourceAE);
|
||||
associateRQ.setApplicationContextItem(new ApplicationContextItem());
|
||||
|
||||
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 abstractItem = new AbstractSyntaxItem();
|
||||
abstractItem.setAbstractSyntaxName(context.abstractSyntax);
|
||||
contextItem.setAbstractSyntaxItem(abstractItem);
|
||||
contextItems.push(contextItem);
|
||||
socket.associate();
|
||||
});
|
||||
associateRQ.setPresentationContextItems(contextItems);
|
||||
|
||||
var maxLengthItem = new MaximumLengthItem(),
|
||||
classUIDItem = new ImplementationClassUIDItem(),
|
||||
versionItem = new ImplementationVersionNameItem();
|
||||
|
||||
classUIDItem.setImplementationClassUID(C.IMPLEM_UID);
|
||||
versionItem.setImplementationVersionName(C.IMPLEM_VERSION);
|
||||
var packageSize = options.maxPackageSize ? options.maxPackageSize : DEFAULT_MAX_PACKAGE_SIZE;
|
||||
maxLengthItem.setMaximumLengthReceived(packageSize);
|
||||
|
||||
var userInfo = new UserInformationItem();
|
||||
userInfo.setUserDataItems([ maxLengthItem, classUIDItem, versionItem ]);
|
||||
|
||||
associateRQ.setUserInformationItem(userInfo);
|
||||
|
||||
this.send(associateRQ);
|
||||
};
|
||||
|
||||
Connection.prototype.wrapMessage = function(data) {
|
||||
if (data) {
|
||||
var datasetMessage = new DataSetMessage();
|
||||
datasetMessage.setElements(data);
|
||||
return datasetMessage;
|
||||
} else return data;
|
||||
};
|
||||
|
||||
Connection.prototype.setFindContext = function(ctx) {
|
||||
this.findContext = ctx;
|
||||
};
|
||||
|
||||
Connection.prototype.find = function(params, callback) {
|
||||
return this.sendMessage(this.findContext, new CFindRQ(), this.wrapMessage(params), callback);
|
||||
};
|
||||
|
||||
Connection.prototype.findPatients = function(params, callback) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_PATIENT,
|
||||
0x00100010: '',
|
||||
0x00100020: '',
|
||||
0x00100030: '',
|
||||
0x00100040: '',
|
||||
}, params);
|
||||
|
||||
return this.find(sendParams, callback);
|
||||
};
|
||||
|
||||
Connection.prototype.findStudies = function(params, callback) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_STUDY,
|
||||
0x00080020: '',
|
||||
0x00100010: '',
|
||||
0x00080061: '',
|
||||
0x0020000D: ''
|
||||
}, params);
|
||||
|
||||
return this.find(sendParams, callback);
|
||||
};
|
||||
|
||||
Connection.prototype.findSeries = function(params, callback) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_SERIES,
|
||||
0x00080020: '',
|
||||
0x0020000E: '',
|
||||
0x0008103E: '',
|
||||
0x0020000D: ''
|
||||
}, params);
|
||||
|
||||
return this.find(sendParams, callback);
|
||||
};
|
||||
|
||||
Connection.prototype.findInstances = function(params, callback) {
|
||||
var sendParams = Object.assign({
|
||||
0x00080052: C.QUERY_RETRIEVE_LEVEL_IMAGE,
|
||||
0x00080020: '',
|
||||
0x0020000E: '',
|
||||
0x0008103E: '',
|
||||
0x0020000D: ''
|
||||
}, params);
|
||||
|
||||
return this.find(sendParams, callback);
|
||||
};
|
||||
return socket;
|
||||
};
|
||||
@ -1,61 +1,43 @@
|
||||
var net = Npm.require('net'),
|
||||
Future = Npm.require('fibers/future');
|
||||
var Future = Npm.require('fibers/future');
|
||||
|
||||
DIMSE = {};
|
||||
|
||||
var conn = new Connection({
|
||||
vr: {
|
||||
split: false
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.startup(function(){
|
||||
var peers = Meteor.settings.dimse;
|
||||
peers.forEach(function(peer){
|
||||
conn.addPeer(peer);
|
||||
});
|
||||
});
|
||||
|
||||
DIMSE.associate = function(contexts, callback) {
|
||||
var host = Meteor.settings.dimse.host,
|
||||
port = Meteor.settings.dimse.port,
|
||||
ae = Meteor.settings.dimse.hostAE;
|
||||
|
||||
console.log("Associating via DIMSE");
|
||||
console.log(Meteor.settings.dimse);
|
||||
|
||||
var client = net.connect({
|
||||
host: host,
|
||||
port: port
|
||||
});
|
||||
|
||||
client.on('connect', function() {
|
||||
//'connect' listener
|
||||
console.log('==Connected');
|
||||
|
||||
var conn = new Connection(client, {
|
||||
vr: {
|
||||
split: false
|
||||
}
|
||||
});
|
||||
|
||||
conn.associate({
|
||||
contexts: contexts,
|
||||
hostAE: ae
|
||||
}, function(pdu) {
|
||||
// associated
|
||||
console.log('==Associated');
|
||||
|
||||
callback.call(conn, pdu);
|
||||
});
|
||||
});
|
||||
|
||||
client.on('error', function(error) {
|
||||
throw error;
|
||||
conn.associate({
|
||||
contexts: contexts
|
||||
}, function(pdu) {
|
||||
// associated
|
||||
console.log('==Associated');
|
||||
callback.call(this, pdu);
|
||||
});
|
||||
};
|
||||
|
||||
DIMSE.retrievePatients = function(params) {
|
||||
//var start = new Date();
|
||||
var future = new Future;
|
||||
DIMSE.associate([ C.SOP_PATIENT_ROOT_FIND ], function(pdu) {
|
||||
DIMSE.associate([C.SOP_PATIENT_ROOT_FIND], function(pdu) {
|
||||
var defaultParams = {
|
||||
0x00100010: '',
|
||||
0x00100020: '',
|
||||
0x00100030: '',
|
||||
0x00100040: '',
|
||||
0x00101010: '',
|
||||
0x00101040: ''
|
||||
0x00100010: "",
|
||||
0x00100020: "",
|
||||
0x00100030: "",
|
||||
0x00100040: "",
|
||||
0x00101010: "",
|
||||
0x00101040: ""
|
||||
};
|
||||
|
||||
this.setFindContext(C.SOP_PATIENT_ROOT_FIND);
|
||||
var result = this.findPatients(Object.assign(defaultParams, params)),
|
||||
o = this;
|
||||
|
||||
@ -76,30 +58,32 @@ DIMSE.retrievePatients = function(params) {
|
||||
return future.wait();
|
||||
};
|
||||
|
||||
DIMSE.retrieveStudies = function(params) {
|
||||
DIMSE.retrieveStudies = function(params, options) {
|
||||
//var start = new Date();
|
||||
var future = new Future;
|
||||
DIMSE.associate([ C.SOP_STUDY_ROOT_FIND ], function(pdu) {
|
||||
var future = new Future, options = Object.assign({limit : 100}, options);
|
||||
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
||||
var defaultParams = {
|
||||
0x0020000D: '',
|
||||
0x00080060: '',
|
||||
0x00080005: '',
|
||||
0x00080020: '',
|
||||
0x00080030: '',
|
||||
0x00080090: '',
|
||||
0x00100010: '',
|
||||
0x00100020: '',
|
||||
0x00200010: '',
|
||||
0x00100030: ''
|
||||
0x0020000D: "",
|
||||
0x00080060: "",
|
||||
0x00080005: "",
|
||||
0x00080020: "",
|
||||
0x00080030: "",
|
||||
0x00080090: "",
|
||||
0x00100010: "",
|
||||
0x00100020: "",
|
||||
0x00200010: "",
|
||||
0x00100030: ""
|
||||
};
|
||||
|
||||
this.setFindContext(C.SOP_STUDY_ROOT_FIND);
|
||||
var result = this.findStudies(Object.assign(defaultParams, params)),
|
||||
o = this;
|
||||
|
||||
var studies = [];
|
||||
result.on('result', function(msg) {
|
||||
studies.push(msg);
|
||||
if (options.limit && options.limit == studies.length) {
|
||||
result.emit('cancel');
|
||||
}
|
||||
});
|
||||
|
||||
result.on('end', function() {
|
||||
@ -116,22 +100,21 @@ DIMSE.retrieveStudies = function(params) {
|
||||
|
||||
DIMSE.retrieveSeries = function(studyInstanceUID, params) {
|
||||
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 ? studyInstanceUID : '',
|
||||
0x00080005: '',
|
||||
0x00080020: '',
|
||||
0x00080030: '',
|
||||
0x00080090: '',
|
||||
0x00100010: '',
|
||||
0x00100020: '',
|
||||
0x00200010: '',
|
||||
0x0008103E: '',
|
||||
0x0020000E: '',
|
||||
0x00200011: ''
|
||||
0x0020000D: studyInstanceUID ? studyInstanceUID : "",
|
||||
0x00080005: "",
|
||||
0x00080020: "",
|
||||
0x00080030: "",
|
||||
0x00080090: "",
|
||||
0x00100010: "",
|
||||
0x00100020: "",
|
||||
0x00200010: "",
|
||||
0x0008103E: "",
|
||||
0x0020000E: "",
|
||||
0x00200011: ""
|
||||
};
|
||||
|
||||
this.setFindContext(C.SOP_STUDY_ROOT_FIND);
|
||||
var result = this.findSeries(Object.assign(defaultParams, params)),
|
||||
o = this;
|
||||
|
||||
@ -151,37 +134,34 @@ DIMSE.retrieveSeries = function(studyInstanceUID, params) {
|
||||
return future.wait();
|
||||
};
|
||||
|
||||
DIMSE.retrieveInstances = function(studyInstanceUID, seriesInstanceUID, params) {
|
||||
DIMSE.retrieveInstances = function(studyInstanceUID, seriesInstanceUID, 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 ? studyInstanceUID : '',
|
||||
0x0020000E: (studyInstanceUID && seriesInstanceUID) ? seriesInstanceUID : '',
|
||||
0x00080005: '',
|
||||
0x00080020: '',
|
||||
0x00080030: '',
|
||||
0x00080090: '',
|
||||
0x00100010: '',
|
||||
0x00100020: '',
|
||||
0x00200010: '',
|
||||
0x0008103E: '',
|
||||
0x00200011: '',
|
||||
0x00080016: '',
|
||||
0x00080018: '', // sopInstanceUid. This is missing from the results?
|
||||
0x00200013: '',
|
||||
0x00280010: '',
|
||||
0x00280011: '',
|
||||
0x00280100: '',
|
||||
0x00280103: ''
|
||||
0x0020000D: studyInstanceUID ? studyInstanceUID : "",
|
||||
0x0020000E: (studyInstanceUID && seriesInstanceUID) ? seriesInstanceUID : "",
|
||||
0x00080005: "",
|
||||
0x00080020: "",
|
||||
0x00080030: "",
|
||||
0x00080090: "",
|
||||
0x00100010: "",
|
||||
0x00100020: "",
|
||||
0x00200010: "",
|
||||
0x0008103E: "",
|
||||
0x00200011: "",
|
||||
0x00080016: "",
|
||||
0x00080018: "",
|
||||
0x00200013: "",
|
||||
0x00280010: "",
|
||||
0x00280011: "",
|
||||
0x00280100: "",
|
||||
0x00280103: ""
|
||||
};
|
||||
|
||||
this.setFindContext(C.SOP_STUDY_ROOT_FIND);
|
||||
var result = this.findInstances(Object.assign(defaultParams, params)),
|
||||
var result = this.findInstances(Object.assign(defaultParams, params), options),
|
||||
o = this;
|
||||
|
||||
var instances = [];
|
||||
result.on('result', function(msg) {
|
||||
console.log(msg);
|
||||
instances.push(msg);
|
||||
});
|
||||
|
||||
@ -195,3 +175,14 @@ DIMSE.retrieveInstances = function(studyInstanceUID, seriesInstanceUID, params)
|
||||
});
|
||||
return future.wait();
|
||||
};
|
||||
|
||||
DIMSE.moveInstances = function(studyInstanceUID, seriesInstanceUID, sopInstanceUID, sopClassUID, params) {
|
||||
DIMSE.associate([C.SOP_STUDY_ROOT_MOVE, sopClassUID], function() {
|
||||
var defaultParams = {
|
||||
0x0020000D: studyInstanceUID ? studyInstanceUID : "",
|
||||
0x0020000E: seriesInstanceUID ? seriesInstanceUID : "",
|
||||
0x00080018: sopInstanceUID ? sopInstanceUID : ""
|
||||
}
|
||||
this.moveInstances("OHIFDCM", Object.assign(defaultParams, params));
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,141 +1,128 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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,463 +1,459 @@
|
||||
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));
|
||||
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));
|
||||
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());
|
||||
});
|
||||
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.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)) + ']';
|
||||
} else {
|
||||
typeName += '[' + p + ']';
|
||||
}
|
||||
});
|
||||
if (typeName[typeName.length - 1] != '\n') {
|
||||
typeName += '\n';
|
||||
}
|
||||
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 += value + '\n';
|
||||
typeName += "[" + p + "]";
|
||||
}
|
||||
});
|
||||
if (typeName[typeName.length-1] != "\n") {
|
||||
typeName += "\n";
|
||||
}
|
||||
} else {
|
||||
typeName += value + "\n";
|
||||
}
|
||||
|
||||
return typeName;
|
||||
};
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
DicomMessage.prototype.toString = 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;
|
||||
}
|
||||
}
|
||||
|
||||
typeName += ' [\n';
|
||||
typeName += this.printElements(this.elementPairs, 0);
|
||||
typeName += ']';
|
||||
return typeName;
|
||||
};
|
||||
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;
|
||||
}
|
||||
}
|
||||
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);
|
||||
});
|
||||
}
|
||||
obj[tag] = u;
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
return obj;
|
||||
}
|
||||
|
||||
DicomMessage.prototype.toObject = function() {
|
||||
return this.walkObject(this.elementPairs);
|
||||
};
|
||||
return this.walkObject(this.elementPairs);
|
||||
}
|
||||
|
||||
readMessage = 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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
elem.setSyntax(useSyntax);
|
||||
elem.readBytes(stream);//return;
|
||||
pairs[elem.tag.value] = elem;
|
||||
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;
|
||||
default : throw "Unrecognized command type " + cmdType.toString(16); break;
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
message.setElementPairs(pairs);
|
||||
message.setDataSetPresent(message.getValue(0x00000800));
|
||||
message.setContextId(message.getValue(0x00000002));
|
||||
if (!message.isResponse()) {
|
||||
message.setMessageId(message.getValue(0x00000110));
|
||||
} else {
|
||||
throw 'Unrecognized message type';
|
||||
message.setReplyMessageId(message.getValue(0x00000120));
|
||||
}
|
||||
} else if (type == C.DATA_TYPE_DATA) {
|
||||
message = new DataSetMessage(useSyntax);
|
||||
message.setElementPairs(pairs);
|
||||
} else {
|
||||
throw "Unrecognized message type";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
return message;
|
||||
DataSetMessage = function(syntax){
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_DATA;
|
||||
};
|
||||
|
||||
DataSetMessage = function(syntax) {
|
||||
DicomMessage.call(this, syntax);
|
||||
this.type = C.DATA_TYPE_DATA;
|
||||
};
|
||||
|
||||
util.inherits(DataSetMessage, DicomMessage);
|
||||
|
||||
DataSetMessage.prototype.is = function(type) {
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
CMoveRQ = function(syntax, destination) {
|
||||
CommandMessage.call(this, syntax);
|
||||
this.commandType = 0x21;
|
||||
this.contextUID = C.SOP_STUDY_ROOT_MOVE;
|
||||
this.setDestination(destination || '');
|
||||
CCancelRQ = function(syntax) {
|
||||
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;
|
||||
};
|
||||
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 || "");
|
||||
};
|
||||
util.inherits(CMoveRQ, CommandMessage);
|
||||
|
||||
CMoveRQ.prototype.setStore = function(cstr) {
|
||||
this.store = cstr;
|
||||
};
|
||||
this.store = cstr;
|
||||
}
|
||||
|
||||
CMoveRQ.prototype.setDestination = function(dest) {
|
||||
this.setElements({
|
||||
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.getSOPInstanceUID = function() {
|
||||
return this.getValue(0x00001000);
|
||||
};
|
||||
return this.getValue(0x00001000);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,229 +1,229 @@
|
||||
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;
|
||||
case C.TYPE_UINT16 : size = 2; break;
|
||||
case C.TYPE_UINT32 : 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;
|
||||
default :break;
|
||||
}
|
||||
return size;
|
||||
};
|
||||
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_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;
|
||||
default :break;
|
||||
}
|
||||
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.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,98 +1,99 @@
|
||||
C = {
|
||||
IMPLEM_UID: '1.2.840.0.1.3680045.8.641',
|
||||
IMPLEM_VERSION: 'OHIF-DCM-0.1',
|
||||
APPLICATION_CONTEXT_NAME: '1.2.840.10008.3.1.1.1',
|
||||
PROTOCOL_VERSION: '0001',
|
||||
ITEM_TYPE_RESERVED: '00',
|
||||
ITEM_TYPE_APPLICATION_CONTEXT: '10',
|
||||
ITEM_TYPE_PDU_ASSOCIATE_RQ: '01',
|
||||
ITEM_TYPE_PDU_ASSOCIATE_AC: '02',
|
||||
ITEM_TYPE_PDU_PDATA: '04',
|
||||
ITEM_TYPE_PDU_RELEASE_RQ: '05',
|
||||
ITEM_TYPE_PDU_RELEASE_RP: '06',
|
||||
ITEM_TYPE_PDU_AABORT: '07',
|
||||
ITEM_TYPE_PRESENTATION_CONTEXT: '20',
|
||||
ITEM_TYPE_PRESENTATION_CONTEXT_AC: '21',
|
||||
ITEM_TYPE_ABSTRACT_CONTEXT: '30',
|
||||
ITEM_TYPE_TRANSFER_CONTEXT: '40',
|
||||
ITEM_TYPE_USER_INFORMATION: '50',
|
||||
ITEM_TYPE_MAXIMUM_LENGTH: '51',
|
||||
ITEM_TYPE_IMPLEMENTATION_UID: '52',
|
||||
ITEM_TYPE_IMPLEMENTATION_VERSION: '55',
|
||||
IMPLICIT_LITTLE_ENDIAN: '1.2.840.10008.1.2',
|
||||
EXPLICIT_LITTLE_ENDIAN: '1.2.840.10008.1.2.1',
|
||||
EXPLICIT_BIG_ENDIAN: '1.2.840.10008.1.2.2',
|
||||
SOP_PATIENT_ROOT_FIND: '1.2.840.10008.5.1.4.1.2.1.1',
|
||||
SOP_PATIENT_ROOT_MOVE: '1.2.840.10008.5.1.4.1.2.1.2',
|
||||
SOP_PATIENT_ROOT_GET: '1.2.840.10008.5.1.4.1.2.1.3',
|
||||
SOP_STUDY_ROOT_FIND: '1.2.840.10008.5.1.4.1.2.2.1',
|
||||
SOP_STUDY_ROOT_MOVE: '1.2.840.10008.5.1.4.1.2.2.2',
|
||||
SOP_STUDY_ROOT_GET: '1.2.840.10008.5.1.4.1.2.2.3',
|
||||
SOP_VERIFICATION: '1.2.840.10008.1.1',
|
||||
SOP_HANGING_PROTOCOL_FIND: '1.2.840.10008.5.1.4.38.2',
|
||||
SOP_MR_IMAGE_STORAGE: '1.2.840.10008.5.1.4.1.1.4',
|
||||
TYPE_ASCII: 1,
|
||||
TYPE_HEX: 2,
|
||||
TYPE_UINT8: 3,
|
||||
TYPE_UINT16: 4,
|
||||
TYPE_UINT32: 5,
|
||||
TYPE_COMPOSITE: 6,
|
||||
TYPE_FLOAT: 7,
|
||||
TYPE_DOUBLE: 8,
|
||||
TYPE_INT8: 9,
|
||||
TYPE_INT16: 10,
|
||||
TYPE_INT32: 11,
|
||||
RESULT_REASON_ACCEPTANCE: 0,
|
||||
RESULT_REASON_USER_REJECTION: 1,
|
||||
RESULT_REASON_NO_REASON: 2,
|
||||
RESULT_REASON_ABSTRACT_NOT_SUPPORTED: 3,
|
||||
RESULT_REASON_TRANSFER_NOT_SUPPORTED: 4,
|
||||
DEFAULT_MESSAGE_ID: 1,
|
||||
LITTLE_ENDIAN: 1,
|
||||
BIG_ENDIAN: 2,
|
||||
VM_SINGLE: 1,
|
||||
VM_TWO: 3,
|
||||
VM_THREE: 4,
|
||||
VM_FOUR: 5,
|
||||
VM_1N: 6,
|
||||
VM_2N: 7,
|
||||
VM_3N: 8,
|
||||
VM_6N: 9,
|
||||
VM_3_3N: 10,
|
||||
VM_2_2N: 11,
|
||||
VM_16: 12,
|
||||
VM_1_2: 13,
|
||||
VM_1_3: 18,
|
||||
VM_SIX: 14,
|
||||
VM_NINE: 15,
|
||||
VM_1_32: 16,
|
||||
VM_1_99: 17,
|
||||
PRIORITY_LOW: 0x2,
|
||||
PRIORITY_MEDIUM: 0x0,
|
||||
PRIORITY_HIGH: 0x1,
|
||||
DATA_SET_PRESENT: 1,
|
||||
DATE_SET_ABSENCE: 0x0101,
|
||||
DATA_TYPE_COMMAND: 1,
|
||||
DATA_TYPE_DATA: 0,
|
||||
DATA_IS_LAST: 1,
|
||||
DATA_NOT_LAST: 0,
|
||||
SOURCE_SERVICE_USER: 0,
|
||||
SOURCE_SERVICE_PROVIDER: 2,
|
||||
QUERY_RETRIEVE_LEVEL_PATIENT: 'PATIENT',
|
||||
QUERY_RETRIEVE_LEVEL_STUDY: 'STUDY',
|
||||
QUERY_RETRIEVE_LEVEL_SERIES: 'SERIES',
|
||||
QUERY_RETRIEVE_LEVEL_IMAGE: 'IMAGE',
|
||||
VALUE_LENGTH_UNDEFINED: 0xffffffff,
|
||||
STATUS_SUCCESS: 0x0000,
|
||||
STATUS_CANCEL: 0xfe00,
|
||||
STATUS_CFIND_CONT_OK: 0xff00,
|
||||
STATUS_CFIND_CONT_WARN: 0xff01,
|
||||
COMMAND_C_GET_RSP: 0x8010,
|
||||
COMMAND_C_MOVE_RSP: 0x8021,
|
||||
COMMAND_C_GET_RQ: 0x10,
|
||||
COMMAND_C_STORE_RQ: 0x01,
|
||||
COMMAND_C_FIND_RSP: 0x8020,
|
||||
COMMAND_C_MOVE_RQ: 0x21,
|
||||
COMMAND_C_FIND_RQ: 0x20,
|
||||
COMMAND_C_STORE_RSP: 0x8001
|
||||
};
|
||||
IMPLEM_UID : "1.2.840.0.1.3680045.8.641",
|
||||
IMPLEM_VERSION : "OHIF-DCM-0.1",
|
||||
DEFAULT_MAX_PACKAGE_SIZE : 32768,
|
||||
APPLICATION_CONTEXT_NAME : "1.2.840.10008.3.1.1.1",
|
||||
PROTOCOL_VERSION : "0001",
|
||||
ITEM_TYPE_RESERVED : "00",
|
||||
ITEM_TYPE_APPLICATION_CONTEXT : "10",
|
||||
ITEM_TYPE_PDU_ASSOCIATE_RQ : "01",
|
||||
ITEM_TYPE_PDU_ASSOCIATE_AC : "02",
|
||||
ITEM_TYPE_PDU_PDATA : "04",
|
||||
ITEM_TYPE_PDU_RELEASE_RQ : "05",
|
||||
ITEM_TYPE_PDU_RELEASE_RP : "06",
|
||||
ITEM_TYPE_PDU_AABORT : "07",
|
||||
ITEM_TYPE_PRESENTATION_CONTEXT : "20",
|
||||
ITEM_TYPE_PRESENTATION_CONTEXT_AC : "21",
|
||||
ITEM_TYPE_ABSTRACT_CONTEXT : "30",
|
||||
ITEM_TYPE_TRANSFER_CONTEXT : "40",
|
||||
ITEM_TYPE_USER_INFORMATION : "50",
|
||||
ITEM_TYPE_MAXIMUM_LENGTH : "51",
|
||||
ITEM_TYPE_IMPLEMENTATION_UID : "52",
|
||||
ITEM_TYPE_IMPLEMENTATION_VERSION : "55",
|
||||
IMPLICIT_LITTLE_ENDIAN : "1.2.840.10008.1.2",
|
||||
EXPLICIT_LITTLE_ENDIAN : "1.2.840.10008.1.2.1",
|
||||
EXPLICIT_BIG_ENDIAN : "1.2.840.10008.1.2.2",
|
||||
SOP_PATIENT_ROOT_FIND : "1.2.840.10008.5.1.4.1.2.1.1",
|
||||
SOP_PATIENT_ROOT_MOVE : "1.2.840.10008.5.1.4.1.2.1.2",
|
||||
SOP_PATIENT_ROOT_GET : "1.2.840.10008.5.1.4.1.2.1.3",
|
||||
SOP_STUDY_ROOT_FIND : "1.2.840.10008.5.1.4.1.2.2.1",
|
||||
SOP_STUDY_ROOT_MOVE : "1.2.840.10008.5.1.4.1.2.2.2",
|
||||
SOP_STUDY_ROOT_GET : "1.2.840.10008.5.1.4.1.2.2.3",
|
||||
SOP_VERIFICATION : "1.2.840.10008.1.1",
|
||||
SOP_HANGING_PROTOCOL_FIND : "1.2.840.10008.5.1.4.38.2",
|
||||
SOP_MR_IMAGE_STORAGE : "1.2.840.10008.5.1.4.1.1.4",
|
||||
TYPE_ASCII : 1,
|
||||
TYPE_HEX : 2,
|
||||
TYPE_UINT8 : 3,
|
||||
TYPE_UINT16 : 4,
|
||||
TYPE_UINT32 : 5,
|
||||
TYPE_COMPOSITE : 6,
|
||||
TYPE_FLOAT : 7,
|
||||
TYPE_DOUBLE : 8,
|
||||
TYPE_INT8 : 9,
|
||||
TYPE_INT16 : 10,
|
||||
TYPE_INT32 : 11,
|
||||
RESULT_REASON_ACCEPTANCE : 0,
|
||||
RESULT_REASON_USER_REJECTION : 1,
|
||||
RESULT_REASON_NO_REASON :2,
|
||||
RESULT_REASON_ABSTRACT_NOT_SUPPORTED : 3,
|
||||
RESULT_REASON_TRANSFER_NOT_SUPPORTED : 4,
|
||||
DEFAULT_MESSAGE_ID : 1,
|
||||
LITTLE_ENDIAN : 1,
|
||||
BIG_ENDIAN : 2,
|
||||
VM_SINGLE :1,
|
||||
VM_TWO : 3,
|
||||
VM_THREE : 4,
|
||||
VM_FOUR : 5,
|
||||
VM_1N : 6,
|
||||
VM_2N :7,
|
||||
VM_3N :8,
|
||||
VM_6N :9,
|
||||
VM_3_3N : 10,
|
||||
VM_2_2N : 11,
|
||||
VM_16 : 12,
|
||||
VM_1_2 : 13,
|
||||
VM_1_3 : 18,
|
||||
VM_SIX : 14,
|
||||
VM_NINE : 15,
|
||||
VM_1_32 : 16,
|
||||
VM_1_99 : 17,
|
||||
PRIORITY_LOW : 0x2,
|
||||
PRIORITY_MEDIUM : 0x0,
|
||||
PRIORITY_HIGH : 0x1,
|
||||
DATA_SET_PRESENT : 1,
|
||||
DATE_SET_ABSENCE : 0x0101,
|
||||
DATA_TYPE_COMMAND : 1,
|
||||
DATA_TYPE_DATA : 0,
|
||||
DATA_IS_LAST : 1,
|
||||
DATA_NOT_LAST : 0,
|
||||
SOURCE_SERVICE_USER : 0,
|
||||
SOURCE_SERVICE_PROVIDER : 2,
|
||||
QUERY_RETRIEVE_LEVEL_PATIENT : "PATIENT",
|
||||
QUERY_RETRIEVE_LEVEL_STUDY : "STUDY",
|
||||
QUERY_RETRIEVE_LEVEL_SERIES : "SERIES",
|
||||
QUERY_RETRIEVE_LEVEL_IMAGE : "IMAGE",
|
||||
VALUE_LENGTH_UNDEFINED : 0xffffffff,
|
||||
STATUS_SUCCESS : 0x0000,
|
||||
STATUS_CANCEL : 0xfe00,
|
||||
STATUS_CFIND_CONT_OK : 0xff00,
|
||||
STATUS_CFIND_CONT_WARN : 0xff01,
|
||||
COMMAND_C_GET_RSP : 0x8010,
|
||||
COMMAND_C_MOVE_RSP : 0x8021,
|
||||
COMMAND_C_GET_RQ : 0x10,
|
||||
COMMAND_C_STORE_RQ : 0x01,
|
||||
COMMAND_C_FIND_RSP : 0x8020,
|
||||
COMMAND_C_MOVE_RQ : 0x21,
|
||||
COMMAND_C_FIND_RQ : 0x20,
|
||||
COMMAND_C_STORE_RSP : 0x8001
|
||||
};
|
||||
@ -1,3 +1,3 @@
|
||||
Meteor.methods({
|
||||
|
||||
});
|
||||
});
|
||||
@ -1 +1 @@
|
||||
util = Npm.require('util');
|
||||
util = Npm.require("util");
|
||||
@ -18,10 +18,10 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"dimse" : {
|
||||
"dimse" : [{
|
||||
"host" : "localhost",
|
||||
"port" : 4242,
|
||||
"hostAE" : "ORTHANC"
|
||||
},
|
||||
"aeTitle" : "ORTHANCLOCAL"
|
||||
}],
|
||||
"defaultServiceType": "dimse"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user