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/Data.js', 'server');
|
||||||
api.addFiles('server/Message.js', 'server');
|
api.addFiles('server/Message.js', 'server');
|
||||||
api.addFiles('server/PDU.js', 'server');
|
api.addFiles('server/PDU.js', 'server');
|
||||||
|
api.addFiles('server/CSocket.js', 'server');
|
||||||
api.addFiles('server/Connection.js', 'server');
|
api.addFiles('server/Connection.js', 'server');
|
||||||
api.addFiles('server/DIMSE.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,462 +1,70 @@
|
|||||||
var EventEmitter = Npm.require('events').EventEmitter;
|
var EventEmitter = Npm.require('events').EventEmitter, net = Npm.require('net'), Socket = net.Socket;
|
||||||
|
|
||||||
function time() {
|
|
||||||
return Math.floor(Date.now() / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
var DEFAULT_MAX_PACKAGE_SIZE = 32768;
|
var DEFAULT_MAX_PACKAGE_SIZE = 32768;
|
||||||
var DEFAULT_SOURCE_AE = 'OHIFDCM';
|
|
||||||
|
|
||||||
var Envelope = function(conn, command, dataset) {
|
Connection = function(options) {
|
||||||
EventEmitter.call(this);
|
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({
|
this.options = Object.assign({
|
||||||
hostAE: '',
|
maxPackageSize: C.DEFAULT_MAX_PACKAGE_SIZE,
|
||||||
sourceAE: 'OHIFDCM',
|
idle: false,
|
||||||
maxPackageSize: 32768,
|
|
||||||
idle: 60,
|
|
||||||
reconnect: true,
|
reconnect: true,
|
||||||
vr: {
|
vr: {
|
||||||
split: true
|
split: true
|
||||||
}
|
}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
this.connected = false;
|
this.peers = {};
|
||||||
this.started = null;
|
this.peerSockets = {};
|
||||||
this.lastReceived = null;
|
this.defaultPeer = null;
|
||||||
this.associated = false;
|
this.defaultServer = null;
|
||||||
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');
|
|
||||||
};
|
|
||||||
|
|
||||||
util.inherits(Connection, EventEmitter);
|
util.inherits(Connection, EventEmitter);
|
||||||
|
|
||||||
Connection.prototype.checkIdle = function() {
|
Connection.prototype.addPeer = function(options) {
|
||||||
var current = time(),
|
if (!options.aeTitle || !options.host || !options.port) {
|
||||||
idl = this.options.idle;
|
return false;
|
||||||
if (!this.lastReceived && (current - this.started >= idl)) {
|
|
||||||
this.idleClose();
|
|
||||||
} else if (this.lastReceived && (current - this.lastReceived >= idl)) {
|
|
||||||
this.idleClose();
|
|
||||||
} else {
|
|
||||||
//console.log('keep idling')
|
|
||||||
}
|
}
|
||||||
|
this.peers[options.aeTitle] = {
|
||||||
|
host : options.host, port : options.port
|
||||||
};
|
};
|
||||||
|
if (options.default) {
|
||||||
Connection.prototype.released = function() {
|
if (options.server) {
|
||||||
this.socket.end();
|
this.defaultServer = options.aeTitle;
|
||||||
};
|
} else {
|
||||||
|
this.defaultPeer = options.aeTitle;
|
||||||
Connection.prototype.idleClose = function() {
|
}
|
||||||
console.log('Exceed idle time, closing connection');
|
}
|
||||||
this.release();
|
if (options.server) {
|
||||||
};
|
//start listening
|
||||||
|
var server = net.createServer();
|
||||||
Connection.prototype.getSoureceAE = function() {
|
server.listen(options.port, options.host, function(){
|
||||||
return this.options.sourceAE;
|
console.log("listening on %j", this.address());
|
||||||
};
|
});
|
||||||
|
server.on('error', function(err){
|
||||||
Connection.prototype.ready = function() {
|
console.log("server error %j", err);
|
||||||
console.log('Connection established');
|
});
|
||||||
this.connected = true;
|
|
||||||
this.started = time();
|
|
||||||
|
|
||||||
var o = this;
|
var o = this;
|
||||||
this.intervalId = setInterval(function() {
|
server.on('connection', function(nativeSocket) {
|
||||||
o.checkIdle();
|
//incoming connections
|
||||||
}, 3000);
|
var socket = new CSocket(nativeSocket, o.options);
|
||||||
|
o.addSocket(options.aeTitle, socket);
|
||||||
|
|
||||||
//this.emit("init");
|
//close server on close socket
|
||||||
//this.startAssociationRequest();
|
socket.on('close', function(){
|
||||||
};
|
server.close();
|
||||||
|
|
||||||
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 ]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
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) {
|
Connection.prototype.storeResponse = function(messageId, msg) {
|
||||||
var rq = this.messages[messageId];
|
var rq = this.messages[messageId];
|
||||||
|
|
||||||
@ -470,183 +78,62 @@ Connection.prototype.storeResponse = function(messageId, msg) {
|
|||||||
replyMessage.setReplyMessageId(this.lastCommand.messageId);
|
replyMessage.setReplyMessageId(this.lastCommand.messageId);
|
||||||
this.sendMessage(replyMessage, null, null, storeSr);
|
this.sendMessage(replyMessage, null, null, storeSr);
|
||||||
} else {
|
} else {
|
||||||
throw 'Missing store status';
|
throw "Missing store status";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Connection.prototype.sendMessage = function(context, command, dataset, listener) {
|
Connection.prototype.allClosed = function() {
|
||||||
var nContext = this.getContextByUID(context),
|
var allClosed = true;
|
||||||
syntax = nContext.transferSyntax,
|
for (var i in o.peerSockets) {
|
||||||
cid = nContext.id,
|
if (Object.keys(o.peerSockets[ae]).length > 0) {
|
||||||
messageId = this.newMessageId(),
|
allClosed = false;
|
||||||
msgData = {};
|
break;
|
||||||
|
|
||||||
/*if (listener) {
|
|
||||||
if (typeof listener != 'object') {
|
|
||||||
listener = [listener, null];
|
|
||||||
}
|
}
|
||||||
msgData.listener = listener;
|
|
||||||
}*/
|
|
||||||
msgData.listener = new Envelope();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
return allClosed;
|
||||||
|
};
|
||||||
|
|
||||||
pdv.setMessage(command);
|
Connection.prototype.addSocket = function(ae, socket) {
|
||||||
pdata.setPresentationDataValueItems([ pdv ]);
|
if (!this.peerSockets[ae]) {
|
||||||
|
this.peerSockets[ae] = {};
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
this.peerSockets[ae][socket.id] = socket;
|
||||||
|
|
||||||
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) {
|
Connection.prototype.associate = function(options, callback) {
|
||||||
if (callback) {
|
var hostAE = options.hostAE ? options.hostAE : this.defaultPeer,
|
||||||
this.once('associated', callback);
|
sourceAE = options.sourceAE ? options.sourceAE : this.defaultServer;
|
||||||
}
|
peerInfo = this.selectPeer(hostAE), nativeSocket = new Socket();
|
||||||
|
|
||||||
if (this.associated) {
|
var socket = new CSocket(nativeSocket, this.options), o = this;
|
||||||
this.emit('associated');
|
if (callback) {
|
||||||
return;
|
socket.once('associated', callback);
|
||||||
}
|
}
|
||||||
|
socket.setCalledAe(hostAE);
|
||||||
|
socket.setCallingAE(sourceAE);
|
||||||
|
|
||||||
|
nativeSocket.connect({
|
||||||
|
host : peerInfo.host, port : peerInfo.port
|
||||||
|
}, function(){
|
||||||
|
//connected
|
||||||
|
o.addSocket(hostAE, socket);
|
||||||
|
|
||||||
if (options.contexts) {
|
if (options.contexts) {
|
||||||
this.setPresentationContexts(options.contexts);
|
socket.setPresentationContexts(options.contexts);
|
||||||
} else {
|
} else {
|
||||||
throw 'No services attached';
|
throw "Contexts must be specified";
|
||||||
}
|
}
|
||||||
|
|
||||||
var associateRQ = new AssociateRQ();
|
socket.associate();
|
||||||
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();
|
return socket;
|
||||||
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 = 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);
|
|
||||||
};
|
};
|
||||||
@ -1,44 +1,27 @@
|
|||||||
var net = Npm.require('net'),
|
var Future = Npm.require('fibers/future');
|
||||||
Future = Npm.require('fibers/future');
|
|
||||||
|
|
||||||
DIMSE = {};
|
DIMSE = {};
|
||||||
|
|
||||||
DIMSE.associate = function(contexts, callback) {
|
var conn = new Connection({
|
||||||
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: {
|
vr: {
|
||||||
split: false
|
split: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Meteor.startup(function(){
|
||||||
|
var peers = Meteor.settings.dimse;
|
||||||
|
peers.forEach(function(peer){
|
||||||
|
conn.addPeer(peer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
DIMSE.associate = function(contexts, callback) {
|
||||||
conn.associate({
|
conn.associate({
|
||||||
contexts: contexts,
|
contexts: contexts
|
||||||
hostAE: ae
|
|
||||||
}, function(pdu) {
|
}, function(pdu) {
|
||||||
// associated
|
// associated
|
||||||
console.log('==Associated');
|
console.log('==Associated');
|
||||||
|
callback.call(this, pdu);
|
||||||
callback.call(conn, pdu);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('error', function(error) {
|
|
||||||
throw error;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -47,15 +30,14 @@ DIMSE.retrievePatients = function(params) {
|
|||||||
var future = new Future;
|
var future = new Future;
|
||||||
DIMSE.associate([C.SOP_PATIENT_ROOT_FIND], function(pdu) {
|
DIMSE.associate([C.SOP_PATIENT_ROOT_FIND], function(pdu) {
|
||||||
var defaultParams = {
|
var defaultParams = {
|
||||||
0x00100010: '',
|
0x00100010: "",
|
||||||
0x00100020: '',
|
0x00100020: "",
|
||||||
0x00100030: '',
|
0x00100030: "",
|
||||||
0x00100040: '',
|
0x00100040: "",
|
||||||
0x00101010: '',
|
0x00101010: "",
|
||||||
0x00101040: ''
|
0x00101040: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setFindContext(C.SOP_PATIENT_ROOT_FIND);
|
|
||||||
var result = this.findPatients(Object.assign(defaultParams, params)),
|
var result = this.findPatients(Object.assign(defaultParams, params)),
|
||||||
o = this;
|
o = this;
|
||||||
|
|
||||||
@ -76,30 +58,32 @@ DIMSE.retrievePatients = function(params) {
|
|||||||
return future.wait();
|
return future.wait();
|
||||||
};
|
};
|
||||||
|
|
||||||
DIMSE.retrieveStudies = function(params) {
|
DIMSE.retrieveStudies = function(params, options) {
|
||||||
//var start = new Date();
|
//var start = new Date();
|
||||||
var future = new Future;
|
var future = new Future, options = Object.assign({limit : 100}, options);
|
||||||
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
||||||
var defaultParams = {
|
var defaultParams = {
|
||||||
0x0020000D: '',
|
0x0020000D: "",
|
||||||
0x00080060: '',
|
0x00080060: "",
|
||||||
0x00080005: '',
|
0x00080005: "",
|
||||||
0x00080020: '',
|
0x00080020: "",
|
||||||
0x00080030: '',
|
0x00080030: "",
|
||||||
0x00080090: '',
|
0x00080090: "",
|
||||||
0x00100010: '',
|
0x00100010: "",
|
||||||
0x00100020: '',
|
0x00100020: "",
|
||||||
0x00200010: '',
|
0x00200010: "",
|
||||||
0x00100030: ''
|
0x00100030: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setFindContext(C.SOP_STUDY_ROOT_FIND);
|
|
||||||
var result = this.findStudies(Object.assign(defaultParams, params)),
|
var result = this.findStudies(Object.assign(defaultParams, params)),
|
||||||
o = this;
|
o = this;
|
||||||
|
|
||||||
var studies = [];
|
var studies = [];
|
||||||
result.on('result', function(msg) {
|
result.on('result', function(msg) {
|
||||||
studies.push(msg);
|
studies.push(msg);
|
||||||
|
if (options.limit && options.limit == studies.length) {
|
||||||
|
result.emit('cancel');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
result.on('end', function() {
|
result.on('end', function() {
|
||||||
@ -118,20 +102,19 @@ DIMSE.retrieveSeries = function(studyInstanceUID, params) {
|
|||||||
var future = new Future;
|
var future = new Future;
|
||||||
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
||||||
var defaultParams = {
|
var defaultParams = {
|
||||||
0x0020000D: studyInstanceUID ? studyInstanceUID : '',
|
0x0020000D: studyInstanceUID ? studyInstanceUID : "",
|
||||||
0x00080005: '',
|
0x00080005: "",
|
||||||
0x00080020: '',
|
0x00080020: "",
|
||||||
0x00080030: '',
|
0x00080030: "",
|
||||||
0x00080090: '',
|
0x00080090: "",
|
||||||
0x00100010: '',
|
0x00100010: "",
|
||||||
0x00100020: '',
|
0x00100020: "",
|
||||||
0x00200010: '',
|
0x00200010: "",
|
||||||
0x0008103E: '',
|
0x0008103E: "",
|
||||||
0x0020000E: '',
|
0x0020000E: "",
|
||||||
0x00200011: ''
|
0x00200011: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setFindContext(C.SOP_STUDY_ROOT_FIND);
|
|
||||||
var result = this.findSeries(Object.assign(defaultParams, params)),
|
var result = this.findSeries(Object.assign(defaultParams, params)),
|
||||||
o = this;
|
o = this;
|
||||||
|
|
||||||
@ -151,37 +134,34 @@ DIMSE.retrieveSeries = function(studyInstanceUID, params) {
|
|||||||
return future.wait();
|
return future.wait();
|
||||||
};
|
};
|
||||||
|
|
||||||
DIMSE.retrieveInstances = function(studyInstanceUID, seriesInstanceUID, params) {
|
DIMSE.retrieveInstances = function(studyInstanceUID, seriesInstanceUID, params, options) {
|
||||||
var future = new Future;
|
var future = new Future;
|
||||||
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
DIMSE.associate([C.SOP_STUDY_ROOT_FIND], function(pdu) {
|
||||||
var defaultParams = {
|
var defaultParams = {
|
||||||
0x0020000D: studyInstanceUID ? studyInstanceUID : '',
|
0x0020000D: studyInstanceUID ? studyInstanceUID : "",
|
||||||
0x0020000E: (studyInstanceUID && seriesInstanceUID) ? seriesInstanceUID : '',
|
0x0020000E: (studyInstanceUID && seriesInstanceUID) ? seriesInstanceUID : "",
|
||||||
0x00080005: '',
|
0x00080005: "",
|
||||||
0x00080020: '',
|
0x00080020: "",
|
||||||
0x00080030: '',
|
0x00080030: "",
|
||||||
0x00080090: '',
|
0x00080090: "",
|
||||||
0x00100010: '',
|
0x00100010: "",
|
||||||
0x00100020: '',
|
0x00100020: "",
|
||||||
0x00200010: '',
|
0x00200010: "",
|
||||||
0x0008103E: '',
|
0x0008103E: "",
|
||||||
0x00200011: '',
|
0x00200011: "",
|
||||||
0x00080016: '',
|
0x00080016: "",
|
||||||
0x00080018: '', // sopInstanceUid. This is missing from the results?
|
0x00080018: "",
|
||||||
0x00200013: '',
|
0x00200013: "",
|
||||||
0x00280010: '',
|
0x00280010: "",
|
||||||
0x00280011: '',
|
0x00280011: "",
|
||||||
0x00280100: '',
|
0x00280100: "",
|
||||||
0x00280103: ''
|
0x00280103: ""
|
||||||
};
|
};
|
||||||
|
var result = this.findInstances(Object.assign(defaultParams, params), options),
|
||||||
this.setFindContext(C.SOP_STUDY_ROOT_FIND);
|
|
||||||
var result = this.findInstances(Object.assign(defaultParams, params)),
|
|
||||||
o = this;
|
o = this;
|
||||||
|
|
||||||
var instances = [];
|
var instances = [];
|
||||||
result.on('result', function(msg) {
|
result.on('result', function(msg) {
|
||||||
console.log(msg);
|
|
||||||
instances.push(msg);
|
instances.push(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -195,3 +175,14 @@ DIMSE.retrieveInstances = function(studyInstanceUID, seriesInstanceUID, params)
|
|||||||
});
|
});
|
||||||
return future.wait();
|
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));
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -23,25 +23,25 @@ Tag = function(value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Tag.prototype.toString = function() {
|
Tag.prototype.toString = function() {
|
||||||
return '(' + paddingLeft('0000', this.group().toString(16)) + ',' +
|
return "(" + paddingLeft("0000", this.group().toString(16)) + "," +
|
||||||
paddingLeft('0000', this.element().toString(16)) + ')';
|
paddingLeft("0000", this.element().toString(16)) + ")";
|
||||||
};
|
}
|
||||||
|
|
||||||
Tag.prototype.is = function(t) {
|
Tag.prototype.is = function(t) {
|
||||||
return this.value == t;
|
return this.value == t;
|
||||||
};
|
}
|
||||||
|
|
||||||
Tag.prototype.group = function() {
|
Tag.prototype.group = function() {
|
||||||
return this.value >>> 16;
|
return this.value >>> 16;
|
||||||
};
|
}
|
||||||
|
|
||||||
Tag.prototype.element = function() {
|
Tag.prototype.element = function() {
|
||||||
return this.value & 0xffff;
|
return this.value & 0xffff;
|
||||||
};
|
}
|
||||||
|
|
||||||
tagFromNumbers = function(group, element) {
|
tagFromNumbers = function(group, element) {
|
||||||
return new Tag(((group << 16) | element) >>> 0);
|
return new Tag(((group << 16) | element) >>> 0);
|
||||||
};
|
}
|
||||||
|
|
||||||
function readTag(stream) {
|
function readTag(stream) {
|
||||||
var group = stream.read(C.TYPE_UINT16),
|
var group = stream.read(C.TYPE_UINT16),
|
||||||
@ -60,41 +60,38 @@ parseElements = function(stream, syntax) {
|
|||||||
elem.readBytes(stream);
|
elem.readBytes(stream);
|
||||||
pairs[elem.tag.value] = elem;
|
pairs[elem.tag.value] = elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pairs;
|
return pairs;
|
||||||
};
|
}
|
||||||
|
|
||||||
ValueRepresentation = function(type) {
|
ValueRepresentation = function(type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.multi = false;
|
this.multi = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
ValueRepresentation.prototype.read = function(stream, length, syntax) {
|
ValueRepresentation.prototype.read = function(stream, length, syntax) {
|
||||||
if (this.fixed && this.maxLength) {
|
if (this.fixed && this.maxLength) {
|
||||||
if (!length)
|
if (!length)
|
||||||
return this.defaultValue;
|
return this.defaultValue;
|
||||||
if (this.maxLength != length)
|
if (this.maxLength != length)
|
||||||
throw 'Invalid length for fixed length tag, vr ' + this.type + ', length ' + this.maxLength + ' != ' + length;
|
throw "Invalid length for fixed length tag, vr " + this.type + ", length " + this.maxLength + " != " + length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.readBytes(stream, length, syntax);
|
return this.readBytes(stream, length, syntax);
|
||||||
};
|
}
|
||||||
|
|
||||||
ValueRepresentation.prototype.readBytes = function(stream, length) {
|
ValueRepresentation.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_ASCII, length);
|
return stream.read(C.TYPE_ASCII, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
ValueRepresentation.prototype.readNullPaddedString = function(stream, length) {
|
ValueRepresentation.prototype.readNullPaddedString = function(stream, length) {
|
||||||
if (!length) return '';
|
if (!length) return "";
|
||||||
|
|
||||||
var str = stream.read(C.TYPE_ASCII, length - 1);
|
var str = stream.read(C.TYPE_ASCII, length - 1);
|
||||||
if (stream.read(C.TYPE_UINT8) != 0) {
|
if (stream.read(C.TYPE_UINT8) != 0) {
|
||||||
stream.increment(-1);
|
stream.increment(-1);
|
||||||
str += stream.read(C.TYPE_ASCII, 1);
|
str += stream.read(C.TYPE_ASCII, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
};
|
}
|
||||||
|
|
||||||
ValueRepresentation.prototype.getFields = function(fields) {
|
ValueRepresentation.prototype.getFields = function(fields) {
|
||||||
var valid = true;
|
var valid = true;
|
||||||
@ -111,9 +108,8 @@ ValueRepresentation.prototype.getFields = function(fields) {
|
|||||||
var check = this.maxLength, length = fieldsLength(fields);
|
var check = this.maxLength, length = fieldsLength(fields);
|
||||||
valid = length <= check;
|
valid = length <= check;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid)
|
if (!valid)
|
||||||
throw 'Value exceeds max length';
|
throw "Value exceeds max length";
|
||||||
|
|
||||||
//check for odd
|
//check for odd
|
||||||
var length = fieldsLength(fields);
|
var length = fieldsLength(fields);
|
||||||
@ -122,102 +118,97 @@ ValueRepresentation.prototype.getFields = function(fields) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0;i < fields.length;i++) {
|
for (var i = 0;i < fields.length;i++) {
|
||||||
if (fields[i].isNumeric() && (fields[i].value === '' || fields[i].value === null)) {
|
if (fields[i].isNumeric() && (fields[i].value === "" || fields[i].value === null)) {
|
||||||
fields[i] = new StringField('');
|
fields[i] = new StringField("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
};
|
}
|
||||||
|
|
||||||
ApplicationEntity = function() {
|
ApplicationEntity = function() {
|
||||||
ValueRepresentation.call(this, 'AE');
|
ValueRepresentation.call(this, "AE");
|
||||||
this.maxLength = 16;
|
this.maxLength = 16;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(ApplicationEntity, ValueRepresentation);
|
util.inherits(ApplicationEntity, ValueRepresentation);
|
||||||
|
|
||||||
ApplicationEntity.prototype.readBytes = function(stream, length) {
|
ApplicationEntity.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_ASCII, length).trim();
|
return stream.read(C.TYPE_ASCII, length).trim();
|
||||||
};
|
}
|
||||||
|
|
||||||
ApplicationEntity.prototype.getFields = function(value) {
|
ApplicationEntity.prototype.getFields = function(value) {
|
||||||
return ApplicationEntity.super_.prototype.getFields.call(this, [new FilledField(value, 16)]);
|
return ApplicationEntity.super_.prototype.getFields.call(this, [new FilledField(value, 16)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
CodeString = function() {
|
CodeString = function() {
|
||||||
ValueRepresentation.call(this, 'CS');
|
ValueRepresentation.call(this, "CS");
|
||||||
this.maxLength = 16;
|
this.maxLength = 16;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CodeString, ValueRepresentation);
|
util.inherits(CodeString, ValueRepresentation);
|
||||||
|
|
||||||
CodeString.prototype.readBytes = function(stream, length) {
|
CodeString.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return str.trim();
|
return str.trim();
|
||||||
};
|
}
|
||||||
|
|
||||||
CodeString.prototype.getFields = function(value) {
|
CodeString.prototype.getFields = function(value) {
|
||||||
return CodeString.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return CodeString.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
AgeString = function() {
|
AgeString = function() {
|
||||||
ValueRepresentation.call(this, 'AS');
|
ValueRepresentation.call(this, "AS");
|
||||||
this.maxLength = 4;
|
this.maxLength = 4;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = '';
|
this.defaultValue = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(AgeString, ValueRepresentation);
|
util.inherits(AgeString, ValueRepresentation);
|
||||||
|
|
||||||
AgeString.prototype.getFields = function(value) {
|
AgeString.prototype.getFields = function(value) {
|
||||||
var str = '';
|
var str = "";
|
||||||
if (value) {
|
if (value) {
|
||||||
if (value.days) {
|
if (value.days) {
|
||||||
str = paddingLeft('000' + value.days) + 'D';
|
str = paddingLeft("000" + value.days) + "D";
|
||||||
} else if (value.weeks) {
|
} else if (value.weeks) {
|
||||||
str = paddingLeft('000' + value.weeks) + 'W';
|
str = paddingLeft("000" + value.weeks) + "W";
|
||||||
} else if (value.months) {
|
} else if (value.months) {
|
||||||
str = paddingLeft('000' + value.months) + 'M';
|
str = paddingLeft("000" + value.months) + "M";
|
||||||
} else if (value.years) {
|
} else if (value.years) {
|
||||||
str = paddingLeft('000' + value.years) + 'Y';
|
str = paddingLeft("000" + value.years) + "Y";
|
||||||
} else {
|
} else {
|
||||||
throw 'Invalid age string';
|
throw "Invalid age string";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return AgeString.super_.prototype.getFields.call(this, [new StringField(str)]);
|
return AgeString.super_.prototype.getFields.call(this, [new StringField(str)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
AttributeTag = function() {
|
AttributeTag = function() {
|
||||||
ValueRepresentation.call(this, 'AT');
|
ValueRepresentation.call(this, "AT");
|
||||||
this.maxLength = 4;
|
this.maxLength = 4;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(AttributeTag, ValueRepresentation);
|
util.inherits(AttributeTag, ValueRepresentation);
|
||||||
|
|
||||||
AttributeTag.prototype.readBytes = function(stream, length) {
|
AttributeTag.prototype.readBytes = function(stream, length) {
|
||||||
var group = stream.read(C.TYPE_UINT16), element = stream.read(C.TYPE_UINT16);
|
var group = stream.read(C.TYPE_UINT16), element = stream.read(C.TYPE_UINT16);
|
||||||
return tagFromNumbers(group, element);
|
return tagFromNumbers(group, element);
|
||||||
};
|
}
|
||||||
|
|
||||||
AttributeTag.prototype.getFields = function(value) {
|
AttributeTag.prototype.getFields = function(value) {
|
||||||
return AttributeTag.super_.prototype.getFields.call(this, [new UInt16Field(value.group()), new UInt16Field(value.element())]);
|
return AttributeTag.super_.prototype.getFields.call(this, [new UInt16Field(value.group()), new UInt16Field(value.element())]);
|
||||||
};
|
}
|
||||||
|
|
||||||
DateValue = function() {
|
DateValue = function() {
|
||||||
ValueRepresentation.call(this, 'DA');
|
ValueRepresentation.call(this, "DA");
|
||||||
this.maxLength = 8;
|
this.maxLength = 8;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = '';
|
this.defaultValue = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(DateValue, ValueRepresentation);
|
util.inherits(DateValue, ValueRepresentation);
|
||||||
|
|
||||||
DateValue.prototype.readBytes = function(stream, length) {
|
DateValue.prototype.readBytes = function(stream, length) {
|
||||||
@ -227,152 +218,144 @@ DateValue.prototype.readBytes = function(stream, length) {
|
|||||||
month = parseInt(datestr.substring(4,6)),
|
month = parseInt(datestr.substring(4,6)),
|
||||||
day = parseInt(datestr.substring(6,8));
|
day = parseInt(datestr.substring(6,8));
|
||||||
return datestr;//new Date(year, month, day);
|
return datestr;//new Date(year, month, day);
|
||||||
};
|
}
|
||||||
|
|
||||||
DateValue.prototype.getFields = function(date) {
|
DateValue.prototype.getFields = function(date) {
|
||||||
var str = null;
|
var str = null;
|
||||||
if (typeof date == 'object') {
|
if (typeof date == 'object') {
|
||||||
var year = date.getFullYear(), month = paddingLeft('00', date.getMonth()), day = paddingLeft('00', date.getDate());
|
var year = date.getFullYear(), month = paddingLeft("00", date.getMonth()), day = paddingLeft("00", date.getDate());
|
||||||
str = year + month + day;
|
str = year + month + day;
|
||||||
} else if (date && date.length > 0) {
|
} else if (date && date.length > 0) {
|
||||||
this.maxLength = 18;
|
this.maxLength = 18;
|
||||||
this.fixed = false;
|
this.fixed = false;
|
||||||
str = date;
|
str = date;
|
||||||
} else {
|
} else {
|
||||||
str = '';
|
str = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return DateValue.super_.prototype.getFields.call(this, [new StringField(str)]);
|
return DateValue.super_.prototype.getFields.call(this, [new StringField(str)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
DecimalString = function() {
|
DecimalString = function() {
|
||||||
ValueRepresentation.call(this, 'DS');
|
ValueRepresentation.call(this, "DS");
|
||||||
this.maxLength = 16;
|
this.maxLength = 16;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(DecimalString, ValueRepresentation);
|
util.inherits(DecimalString, ValueRepresentation);
|
||||||
|
|
||||||
DecimalString.prototype.readBytes = function(stream, length) {
|
DecimalString.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return str.trim();
|
return str.trim();
|
||||||
};
|
}
|
||||||
|
|
||||||
DecimalString.prototype.getFields = function(value) {
|
DecimalString.prototype.getFields = function(value) {
|
||||||
var f = parseFloat(value);
|
var f = parseFloat(value);
|
||||||
return DecimalString.super_.prototype.getFields.call(this, [new StringField(isNaN(f) ? '' : f.toExponential())]);
|
return DecimalString.super_.prototype.getFields.call(this, [new StringField(isNaN(f) ? '' : f.toExponential())]);
|
||||||
};
|
}
|
||||||
|
|
||||||
DateTime = function() {
|
DateTime = function() {
|
||||||
ValueRepresentation.call(this, 'DT');
|
ValueRepresentation.call(this, "DT");
|
||||||
this.maxLength = 26;
|
this.maxLength = 26;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(DateTime, ValueRepresentation);
|
util.inherits(DateTime, ValueRepresentation);
|
||||||
|
|
||||||
DateTime.prototype.getFields = function(value) {
|
DateTime.prototype.getFields = function(value) {
|
||||||
var year = date.getUTCFullYear(), month = paddingLeft('00', date.getUTCMonth()),
|
var year = date.getUTCFullYear(), month = paddingLeft("00", date.getUTCMonth()),
|
||||||
day = paddingLeft('00', date.getUTCDate()), hour = paddingLeft('00', date.getUTCHours()),
|
day = paddingLeft("00", date.getUTCDate()), hour = paddingLeft("00", date.getUTCHours()),
|
||||||
minute = paddingLeft('00', date.getUTCMinutes()), second = paddingLeft('00', date.getUTCSeconds()),
|
minute = paddingLeft("00", date.getUTCMinutes()), second = paddingLeft("00", date.getUTCSeconds()),
|
||||||
millisecond = paddingLeft('000', date.getUTCMilliseconds());
|
millisecond = paddingLeft("000", date.getUTCMilliseconds());
|
||||||
|
|
||||||
return DateTime.super_.prototype.getFields.call(this, [ new StringField(year + month + day + hour + minute + second + '.' + millisecond + '+0000') ]);
|
return DateTime.super_.prototype.getFields.call(this, [new StringField(year + month + day + hour + minute + second + "." + millisecond + "+0000")]);
|
||||||
};
|
}
|
||||||
|
|
||||||
FloatingPointSingle = function() {
|
FloatingPointSingle = function() {
|
||||||
ValueRepresentation.call(this, 'FL');
|
ValueRepresentation.call(this, "FL");
|
||||||
this.maxLength = 4;
|
this.maxLength = 4;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = 0.0;
|
this.defaultValue = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(FloatingPointSingle, ValueRepresentation);
|
util.inherits(FloatingPointSingle, ValueRepresentation);
|
||||||
|
|
||||||
FloatingPointSingle.prototype.readBytes = function(stream, length) {
|
FloatingPointSingle.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_FLOAT);
|
return stream.read(C.TYPE_FLOAT);
|
||||||
};
|
}
|
||||||
|
|
||||||
FloatingPointSingle.prototype.getFields = function(value) {
|
FloatingPointSingle.prototype.getFields = function(value) {
|
||||||
return FloatingPointSingle.super_.prototype.getFields.call(this, [new FloatField(value)]);
|
return FloatingPointSingle.super_.prototype.getFields.call(this, [new FloatField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
FloatingPointDouble = function() {
|
FloatingPointDouble = function() {
|
||||||
ValueRepresentation.call(this, 'FD');
|
ValueRepresentation.call(this, "FD");
|
||||||
this.maxLength = 8;
|
this.maxLength = 8;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = 0.0;
|
this.defaultValue = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(FloatingPointDouble, ValueRepresentation);
|
util.inherits(FloatingPointDouble, ValueRepresentation);
|
||||||
|
|
||||||
FloatingPointDouble.prototype.readBytes = function(stream, length) {
|
FloatingPointDouble.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_DOUBLE);
|
return stream.read(C.TYPE_DOUBLE);
|
||||||
};
|
}
|
||||||
|
|
||||||
FloatingPointDouble.prototype.getFields = function(value) {
|
FloatingPointDouble.prototype.getFields = function(value) {
|
||||||
return FloatingPointDouble.super_.prototype.getFields.call(this, [new DoubleField(value)]);
|
return FloatingPointDouble.super_.prototype.getFields.call(this, [new DoubleField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
IntegerString = function() {
|
IntegerString = function() {
|
||||||
ValueRepresentation.call(this, 'IS');
|
ValueRepresentation.call(this, "IS");
|
||||||
this.maxLength = 12;
|
this.maxLength = 12;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(IntegerString, ValueRepresentation);
|
util.inherits(IntegerString, ValueRepresentation);
|
||||||
|
|
||||||
IntegerString.prototype.readBytes = function(stream, length) {
|
IntegerString.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return str.trim();
|
return str.trim();
|
||||||
};
|
}
|
||||||
|
|
||||||
IntegerString.prototype.getFields = function(value) {
|
IntegerString.prototype.getFields = function(value) {
|
||||||
return IntegerString.super_.prototype.getFields.call(this, [new StringField(value.toString())]);
|
return IntegerString.super_.prototype.getFields.call(this, [new StringField(value.toString())]);
|
||||||
};
|
}
|
||||||
|
|
||||||
LongString = function() {
|
LongString = function() {
|
||||||
ValueRepresentation.call(this, 'LO');
|
ValueRepresentation.call(this, "LO");
|
||||||
this.maxCharLength = 64;
|
this.maxCharLength = 64;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(LongString, ValueRepresentation);
|
util.inherits(LongString, ValueRepresentation);
|
||||||
|
|
||||||
LongString.prototype.readBytes = function(stream, length) {
|
LongString.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return str.trim();
|
return str.trim();
|
||||||
};
|
}
|
||||||
|
|
||||||
LongString.prototype.getFields = function(value) {
|
LongString.prototype.getFields = function(value) {
|
||||||
return LongString.super_.prototype.getFields.call(this, [ new StringField(value ? value : '') ]);
|
return LongString.super_.prototype.getFields.call(this, [new StringField(value ? value : "")]);
|
||||||
};
|
}
|
||||||
|
|
||||||
LongText = function() {
|
LongText = function() {
|
||||||
ValueRepresentation.call(this, 'LT');
|
ValueRepresentation.call(this, "LT");
|
||||||
this.maxCharLength = 10240;
|
this.maxCharLength = 10240;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(LongText, ValueRepresentation);
|
util.inherits(LongText, ValueRepresentation);
|
||||||
|
|
||||||
LongText.prototype.readBytes = function(stream, length) {
|
LongText.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return rtrim(str);
|
return rtrim(str);
|
||||||
};
|
}
|
||||||
|
|
||||||
LongText.prototype.getFields = function(value) {
|
LongText.prototype.getFields = function(value) {
|
||||||
return LongText.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return LongText.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
PersonName = function() {
|
PersonName = function() {
|
||||||
ValueRepresentation.call(this, 'PN');
|
ValueRepresentation.call(this, "PN");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(PersonName, ValueRepresentation);
|
util.inherits(PersonName, ValueRepresentation);
|
||||||
|
|
||||||
PersonName.prototype.checkLength = function(field) {
|
PersonName.prototype.checkLength = function(field) {
|
||||||
@ -381,70 +364,66 @@ PersonName.prototype.checkLength = function(field) {
|
|||||||
var cmp = cmps[i];
|
var cmp = cmps[i];
|
||||||
if (cmp.length > 64) return false;
|
if (cmp.length > 64) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
PersonName.prototype.readBytes = function(stream, length) {
|
PersonName.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return rtrim(str);
|
return rtrim(str);
|
||||||
};
|
}
|
||||||
|
|
||||||
PersonName.prototype.getFields = function(value) {
|
PersonName.prototype.getFields = function(value) {
|
||||||
var str = null;
|
var str = null;
|
||||||
if (typeof value == 'string') {
|
if (typeof value == 'string') {
|
||||||
str = value;
|
str = value;
|
||||||
} else if (value) {
|
} else if (value) {
|
||||||
var fName = value.family || '', gName = value.given || '',
|
var fName = value.family || "", gName = value.given || "",
|
||||||
middle = value.middle || '', prefix = value.prefix || '', suffix = value.suffix || '';
|
middle = value.middle || "", prefix = value.prefix || "", suffix = value.suffix || "";
|
||||||
|
|
||||||
str = [ fName, gName, middle, prefix, suffix ].join('^');
|
str = [fName, gName, middle, prefix, suffix].join("^");
|
||||||
} else str = '';
|
} else str = '';
|
||||||
|
|
||||||
return PersonName.super_.prototype.getFields.call(this, [new StringField(str)]);
|
return PersonName.super_.prototype.getFields.call(this, [new StringField(str)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
ShortString = function() {
|
ShortString = function() {
|
||||||
ValueRepresentation.call(this, 'SH');
|
ValueRepresentation.call(this, "SH");
|
||||||
this.maxCharLength = 16;
|
this.maxCharLength = 16;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(ShortString, ValueRepresentation);
|
util.inherits(ShortString, ValueRepresentation);
|
||||||
|
|
||||||
ShortString.prototype.readBytes = function(stream, length) {
|
ShortString.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return str.trim();
|
return str.trim();
|
||||||
};
|
}
|
||||||
|
|
||||||
ShortString.prototype.getFields = function(value) {
|
ShortString.prototype.getFields = function(value) {
|
||||||
return ShortString.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return ShortString.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
SignedLong = function() {
|
SignedLong = function() {
|
||||||
ValueRepresentation.call(this, 'SL');
|
ValueRepresentation.call(this, "SL");
|
||||||
this.maxLength = 4;
|
this.maxLength = 4;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = 0;
|
this.defaultValue = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(SignedLong, ValueRepresentation);
|
util.inherits(SignedLong, ValueRepresentation);
|
||||||
|
|
||||||
SignedLong.prototype.readBytes = function(stream, length) {
|
SignedLong.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_INT32);
|
return stream.read(C.TYPE_INT32);
|
||||||
};
|
}
|
||||||
|
|
||||||
SignedLong.prototype.getFields = function(value) {
|
SignedLong.prototype.getFields = function(value) {
|
||||||
return SignedLong.super_.prototype.getFields.call(this, [new Int32Field(value)]);
|
return SignedLong.super_.prototype.getFields.call(this, [new Int32Field(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
SequenceOfItems = function() {
|
SequenceOfItems = function() {
|
||||||
ValueRepresentation.call(this, 'SQ');
|
ValueRepresentation.call(this, "SQ");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(SequenceOfItems, ValueRepresentation);
|
util.inherits(SequenceOfItems, ValueRepresentation);
|
||||||
|
|
||||||
SequenceOfItems.prototype.readBytes = function(stream, sqlength, syntax) {
|
SequenceOfItems.prototype.readBytes = function(stream, sqlength, syntax) {
|
||||||
@ -458,7 +437,7 @@ SequenceOfItems.prototype.readBytes = function(stream, sqlength, syntax) {
|
|||||||
read += 4;
|
read += 4;
|
||||||
|
|
||||||
if (tag.is(0xfffee0dd)) {
|
if (tag.is(0xfffee0dd)) {
|
||||||
stream.read(C.TYPE_UINT32);
|
stream.read(C.TYPE_UINT32)
|
||||||
break;
|
break;
|
||||||
} else if (!undefLength && (read == sqlength)) {
|
} else if (!undefLength && (read == sqlength)) {
|
||||||
break;
|
break;
|
||||||
@ -506,16 +485,14 @@ SequenceOfItems.prototype.readBytes = function(stream, sqlength, syntax) {
|
|||||||
|
|
||||||
elements.push(parseElements(itemStream, syntax));
|
elements.push(parseElements(itemStream, syntax));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!undefLength && (read == sqlength)) {
|
if (!undefLength && (read == sqlength)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
SequenceOfItems.prototype.getFields = function(value, syntax) {
|
SequenceOfItems.prototype.getFields = function(value, syntax) {
|
||||||
var fields = [];
|
var fields = [];
|
||||||
@ -541,199 +518,189 @@ SequenceOfItems.prototype.getFields = function(value, syntax) {
|
|||||||
fields.push(new UInt32Field(0x00000000));
|
fields.push(new UInt32Field(0x00000000));
|
||||||
|
|
||||||
return SequenceOfItems.super_.prototype.getFields.call(this, fields);
|
return SequenceOfItems.super_.prototype.getFields.call(this, fields);
|
||||||
};
|
}
|
||||||
|
|
||||||
SignedShort = function() {
|
SignedShort = function() {
|
||||||
ValueRepresentation.call(this, 'SS');
|
ValueRepresentation.call(this, "SS");
|
||||||
this.maxLength = 2;
|
this.maxLength = 2;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = 0;
|
this.defaultValue = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(SignedShort, ValueRepresentation);
|
util.inherits(SignedShort, ValueRepresentation);
|
||||||
|
|
||||||
SignedShort.prototype.readBytes = function(stream, length) {
|
SignedShort.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_INT16);
|
return stream.read(C.TYPE_INT16);
|
||||||
};
|
}
|
||||||
|
|
||||||
SignedShort.prototype.getFields = function(value) {
|
SignedShort.prototype.getFields = function(value) {
|
||||||
return SignedShort.super_.prototype.getFields.call(this, [new Int16Field(value)]);
|
return SignedShort.super_.prototype.getFields.call(this, [new Int16Field(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
ShortText = function() {
|
ShortText = function() {
|
||||||
ValueRepresentation.call(this, 'ST');
|
ValueRepresentation.call(this, "ST");
|
||||||
this.maxCharLength = 1024;
|
this.maxCharLength = 1024;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(ShortText, ValueRepresentation);
|
util.inherits(ShortText, ValueRepresentation);
|
||||||
|
|
||||||
ShortText.prototype.readBytes = function(stream, length) {
|
ShortText.prototype.readBytes = function(stream, length) {
|
||||||
var str = this.readNullPaddedString(stream, length);
|
var str = this.readNullPaddedString(stream, length);
|
||||||
return rtrim(str);
|
return rtrim(str);
|
||||||
};
|
}
|
||||||
|
|
||||||
ShortText.prototype.getFields = function(value) {
|
ShortText.prototype.getFields = function(value) {
|
||||||
return ShortText.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return ShortText.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
TimeValue = function() {
|
TimeValue = function() {
|
||||||
ValueRepresentation.call(this, 'TM');
|
ValueRepresentation.call(this, "TM");
|
||||||
this.maxLength = 14;
|
this.maxLength = 14;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(TimeValue, ValueRepresentation);
|
util.inherits(TimeValue, ValueRepresentation);
|
||||||
|
|
||||||
TimeValue.prototype.readBytes = function(stream, length) {
|
TimeValue.prototype.readBytes = function(stream, length) {
|
||||||
return rtrim(stream.read(C.TYPE_ASCII, length));
|
return rtrim(stream.read(C.TYPE_ASCII, length));
|
||||||
};
|
}
|
||||||
|
|
||||||
TimeValue.prototype.getFields = function(date) {
|
TimeValue.prototype.getFields = function(date) {
|
||||||
var dateStr = '';
|
var dateStr = '';
|
||||||
if (date) {
|
if (date) {
|
||||||
var hour = paddingLeft('00', date.getHours()),
|
var hour = paddingLeft("00", date.getHours()),
|
||||||
minute = paddingLeft('00', date.getMinutes()), second = paddingLeft('00', date.getSeconds()),
|
minute = paddingLeft("00", date.getMinutes()), second = paddingLeft("00", date.getSeconds()),
|
||||||
millisecond = paddingLeft('000', date.getMilliseconds());
|
millisecond = paddingLeft("000", date.getMilliseconds());
|
||||||
dateStr = hour + minute + second + '.' + millisecond;
|
dateStr = hour + minute + second + "." + millisecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TimeValue.super_.prototype.getFields.call(this, [new StringField(dateStr)]);
|
return TimeValue.super_.prototype.getFields.call(this, [new StringField(dateStr)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnlimitedCharacters = function() {
|
UnlimitedCharacters = function() {
|
||||||
ValueRepresentation.call(this, 'UC');
|
ValueRepresentation.call(this, "UC");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.multi = true;
|
this.multi = true;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UnlimitedCharacters, ValueRepresentation);
|
util.inherits(UnlimitedCharacters, ValueRepresentation);
|
||||||
|
|
||||||
UnlimitedCharacters.prototype.readBytes = function(stream, length) {
|
UnlimitedCharacters.prototype.readBytes = function(stream, length) {
|
||||||
return rtrim(stream.read(C.TYPE_ASCII, length));
|
return rtrim(stream.read(C.TYPE_ASCII, length));
|
||||||
};
|
}
|
||||||
|
|
||||||
UnlimitedCharacters.prototype.getFields = function(value) {
|
UnlimitedCharacters.prototype.getFields = function(value) {
|
||||||
return UnlimitedCharacters.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return UnlimitedCharacters.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnlimitedText = function() {
|
UnlimitedText = function() {
|
||||||
ValueRepresentation.call(this, 'UT');
|
ValueRepresentation.call(this, "UT");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UnlimitedText, ValueRepresentation);
|
util.inherits(UnlimitedText, ValueRepresentation);
|
||||||
|
|
||||||
UnlimitedText.prototype.readBytes = function(stream, length) {
|
UnlimitedText.prototype.readBytes = function(stream, length) {
|
||||||
return this.readNullPaddedString(stream, length);
|
return this.readNullPaddedString(stream, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnlimitedText.prototype.getFields = function(value) {
|
UnlimitedText.prototype.getFields = function(value) {
|
||||||
return UnlimitedText.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return UnlimitedText.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnsignedShort = function() {
|
UnsignedShort = function() {
|
||||||
ValueRepresentation.call(this, 'US');
|
ValueRepresentation.call(this, "US");
|
||||||
this.maxLength = 2;
|
this.maxLength = 2;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = 0;
|
this.defaultValue = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UnsignedShort, ValueRepresentation);
|
util.inherits(UnsignedShort, ValueRepresentation);
|
||||||
|
|
||||||
UnsignedShort.prototype.readBytes = function(stream, length) {
|
UnsignedShort.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_UINT16);
|
return stream.read(C.TYPE_UINT16);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnsignedShort.prototype.getFields = function(value) {
|
UnsignedShort.prototype.getFields = function(value) {
|
||||||
return UnsignedShort.super_.prototype.getFields.call(this, [new UInt16Field(value)]);
|
return UnsignedShort.super_.prototype.getFields.call(this, [new UInt16Field(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnsignedLong = function() {
|
UnsignedLong = function() {
|
||||||
ValueRepresentation.call(this, 'UL');
|
ValueRepresentation.call(this, "UL");
|
||||||
this.maxLength = 4;
|
this.maxLength = 4;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.defaultValue = 0;
|
this.defaultValue = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UnsignedLong, ValueRepresentation);
|
util.inherits(UnsignedLong, ValueRepresentation);
|
||||||
|
|
||||||
UnsignedLong.prototype.readBytes = function(stream, length) {
|
UnsignedLong.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_UINT32);
|
return stream.read(C.TYPE_UINT32);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnsignedLong.prototype.getFields = function(value) {
|
UnsignedLong.prototype.getFields = function(value) {
|
||||||
return UnsignedLong.super_.prototype.getFields.call(this, [new UInt32Field(value)]);
|
return UnsignedLong.super_.prototype.getFields.call(this, [new UInt32Field(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UniqueIdentifier = function() {
|
UniqueIdentifier = function() {
|
||||||
ValueRepresentation.call(this, 'UI');
|
ValueRepresentation.call(this, "UI");
|
||||||
this.maxLength = 64;
|
this.maxLength = 64;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UniqueIdentifier, ValueRepresentation);
|
util.inherits(UniqueIdentifier, ValueRepresentation);
|
||||||
|
|
||||||
UniqueIdentifier.prototype.readBytes = function(stream, length) {
|
UniqueIdentifier.prototype.readBytes = function(stream, length) {
|
||||||
return this.readNullPaddedString(stream, length);
|
return this.readNullPaddedString(stream, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
UniqueIdentifier.prototype.getFields = function(value) {
|
UniqueIdentifier.prototype.getFields = function(value) {
|
||||||
return UniqueIdentifier.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return UniqueIdentifier.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UniversalResource = function() {
|
UniversalResource = function() {
|
||||||
ValueRepresentation.call(this, 'UR');
|
ValueRepresentation.call(this, "UR");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.padByte = '20';
|
this.padByte = "20";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UniversalResource, ValueRepresentation);
|
util.inherits(UniversalResource, ValueRepresentation);
|
||||||
|
|
||||||
UniversalResource.prototype.readBytes = function(stream, length) {
|
UniversalResource.prototype.readBytes = function(stream, length) {
|
||||||
return rtrim(stream.read(C.TYPE_ASCII, length));
|
return rtrim(stream.read(C.TYPE_ASCII, length));
|
||||||
};
|
}
|
||||||
|
|
||||||
UniversalResource.prototype.getFields = function(value) {
|
UniversalResource.prototype.getFields = function(value) {
|
||||||
return UniversalResource.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return UniversalResource.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnknownValue = function() {
|
UnknownValue = function() {
|
||||||
ValueRepresentation.call(this, 'UN');
|
ValueRepresentation.call(this, "UN");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UnknownValue, ValueRepresentation);
|
util.inherits(UnknownValue, ValueRepresentation);
|
||||||
|
|
||||||
UnknownValue.prototype.readBytes = function(stream, length) {
|
UnknownValue.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_ASCII, length);
|
return stream.read(C.TYPE_ASCII, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
UnknownValue.prototype.getFields = function(value) {
|
UnknownValue.prototype.getFields = function(value) {
|
||||||
return UnknownValue.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return UnknownValue.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
OtherWordString = function() {
|
OtherWordString = function() {
|
||||||
ValueRepresentation.call(this, 'OW');
|
ValueRepresentation.call(this, "OW");
|
||||||
this.maxLength = null;
|
this.maxLength = null;
|
||||||
this.padByte = '00';
|
this.padByte = "00";
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(OtherWordString, ValueRepresentation);
|
util.inherits(OtherWordString, ValueRepresentation);
|
||||||
|
|
||||||
OtherWordString.prototype.readBytes = function(stream, length) {
|
OtherWordString.prototype.readBytes = function(stream, length) {
|
||||||
return stream.read(C.TYPE_ASCII, length);
|
return stream.read(C.TYPE_ASCII, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
OtherWordString.prototype.getFields = function(value) {
|
OtherWordString.prototype.getFields = function(value) {
|
||||||
return OtherWordString.super_.prototype.getFields.call(this, [new StringField(value)]);
|
return OtherWordString.super_.prototype.getFields.call(this, [new StringField(value)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
elementByType = function(type, value, syntax) {
|
elementByType = function(type, value, syntax) {
|
||||||
var elem = null, nk = DicomElements.dicomNDict[type];
|
var elem = null, nk = DicomElements.dicomNDict[type];
|
||||||
@ -746,7 +713,6 @@ elementByType = function(type, value, syntax) {
|
|||||||
for (var tag in el) {
|
for (var tag in el) {
|
||||||
values.push(elementByType(tag, el[tag], syntax));
|
values.push(elementByType(tag, el[tag], syntax));
|
||||||
}
|
}
|
||||||
|
|
||||||
sq.push(values);
|
sq.push(values);
|
||||||
});
|
});
|
||||||
elem = new DataElement(type, nk.vr, nk.vm, sq, false, syntax);
|
elem = new DataElement(type, nk.vr, nk.vm, sq, false, syntax);
|
||||||
@ -754,62 +720,60 @@ elementByType = function(type, value, syntax) {
|
|||||||
elem = new DataElement(type, nk.vr, nk.vm, value, false, syntax);
|
elem = new DataElement(type, nk.vr, nk.vm, value, false, syntax);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw 'Unrecognized element type';
|
throw "Unrecognized element type";
|
||||||
}
|
}
|
||||||
|
|
||||||
return elem;
|
return elem;
|
||||||
};
|
}
|
||||||
|
|
||||||
elementDataByTag = function(tag) {
|
elementDataByTag = function(tag) {
|
||||||
var nk = DicomElements.dicomNDict[tag];
|
var nk = DicomElements.dicomNDict[tag];
|
||||||
if (nk) {
|
if (nk) {
|
||||||
return nk;
|
return nk;
|
||||||
}
|
}
|
||||||
|
throw ("Unrecognized tag " + (tag >>> 0).toString(16));
|
||||||
throw ('Unrecognized tag ' + (tag >>> 0).toString(16));
|
}
|
||||||
};
|
|
||||||
|
|
||||||
elementKeywordByTag = function(tag) {
|
elementKeywordByTag = function(tag) {
|
||||||
var nk = elementDataByTag(tag);
|
var nk = elementDataByTag(tag);
|
||||||
return nk.keyword;
|
return nk.keyword;
|
||||||
};
|
}
|
||||||
|
|
||||||
vrByType = function(type) {
|
vrByType = function(type) {
|
||||||
var vr = null;
|
var vr = null;
|
||||||
if (type == 'AE') vr = new ApplicationEntity();
|
if (type == "AE") vr = new ApplicationEntity();
|
||||||
else if (type == 'AS') vr = new AgeString();
|
else if (type == "AS") vr = new AgeString();
|
||||||
else if (type == 'AT') vr = new AttributeTag();
|
else if (type == "AT") vr = new AttributeTag();
|
||||||
else if (type == 'CS') vr = new CodeString();
|
else if (type == "CS") vr = new CodeString();
|
||||||
else if (type == 'DA') vr = new DateValue();
|
else if (type == "DA") vr = new DateValue();
|
||||||
else if (type == 'DS') vr = new DecimalString();
|
else if (type == "DS") vr = new DecimalString();
|
||||||
else if (type == 'DT') vr = new DateTime();
|
else if (type == "DT") vr = new DateTime();
|
||||||
else if (type == 'FL') vr = new FloatingPointSingle();
|
else if (type == "FL") vr = new FloatingPointSingle();
|
||||||
else if (type == 'FD') vr = new FloatingPointDouble();
|
else if (type == "FD") vr = new FloatingPointDouble();
|
||||||
else if (type == 'IS') vr = new IntegerString();
|
else if (type == "IS") vr = new IntegerString();
|
||||||
else if (type == 'LO') vr = new LongString();
|
else if (type == "LO") vr = new LongString();
|
||||||
else if (type == 'LT') vr = new LongText();
|
else if (type == "LT") vr = new LongText();
|
||||||
else if (type == 'OB') vr = new OtherByteString();
|
else if (type == "OB") vr = new OtherByteString();
|
||||||
else if (type == 'OD') vr = new OtherDoubleString();
|
else if (type == "OD") vr = new OtherDoubleString();
|
||||||
else if (type == 'OF') vr = new OtherFloatString();
|
else if (type == "OF") vr = new OtherFloatString();
|
||||||
else if (type == 'OW') vr = new OtherWordString();
|
else if (type == "OW") vr = new OtherWordString();
|
||||||
else if (type == 'PN') vr = new PersonName();
|
else if (type == "PN") vr = new PersonName();
|
||||||
else if (type == 'SH') vr = new ShortString();
|
else if (type == "SH") vr = new ShortString();
|
||||||
else if (type == 'SL') vr = new SignedLong();
|
else if (type == "SL") vr = new SignedLong();
|
||||||
else if (type == 'SQ') vr = new SequenceOfItems();
|
else if (type == "SQ") vr = new SequenceOfItems();
|
||||||
else if (type == 'SS') vr = new SignedShort();
|
else if (type == "SS") vr = new SignedShort();
|
||||||
else if (type == 'ST') vr = new ShortText();
|
else if (type == "ST") vr = new ShortText();
|
||||||
else if (type == 'TM') vr = new TimeValue();
|
else if (type == "TM") vr = new TimeValue();
|
||||||
else if (type == 'UC') vr = new UnlimitedCharacters();
|
else if (type == "UC") vr = new UnlimitedCharacters();
|
||||||
else if (type == 'UI') vr = new UniqueIdentifier();
|
else if (type == "UI") vr = new UniqueIdentifier();
|
||||||
else if (type == 'UL') vr = new UnsignedLong();
|
else if (type == "UL") vr = new UnsignedLong();
|
||||||
else if (type == 'UN') vr = new UnknownValue();
|
else if (type == "UN") vr = new UnknownValue();
|
||||||
else if (type == 'UR') vr = new UniversalResource();
|
else if (type == "UR") vr = new UniversalResource();
|
||||||
else if (type == 'US') vr = new UnsignedShort();
|
else if (type == "US") vr = new UnsignedShort();
|
||||||
else if (type == 'UT') vr = new UnlimitedText();
|
else if (type == "UT") vr = new UnlimitedText();
|
||||||
else throw 'Invalid vr type ' + type;
|
else throw "Invalid vr type " + type;
|
||||||
|
|
||||||
return vr;
|
return vr;
|
||||||
};
|
}
|
||||||
|
|
||||||
readElements = function(stream, syntax) {
|
readElements = function(stream, syntax) {
|
||||||
if (stream.end()) return false;
|
if (stream.end()) return false;
|
||||||
@ -823,10 +787,10 @@ readElements = function(stream, syntax) {
|
|||||||
length = stream.read(C.TYPE_UINT32);
|
length = stream.read(C.TYPE_UINT32);
|
||||||
|
|
||||||
stream.setEndian(oldEndian);
|
stream.setEndian(oldEndian);
|
||||||
};
|
}
|
||||||
|
|
||||||
var explicitVRList = [ 'OB', 'OW', 'OF', 'SQ', 'UC', 'UR', 'UT', 'UN' ],
|
var explicitVRList = ["OB", "OW", "OF", "SQ", "UC", "UR", "UT", "UN"],
|
||||||
binaryVRs = [ 'FL', 'FD', 'SL', 'SS', 'UL', 'US' ];
|
binaryVRs = ["FL", "FD", "SL", "SS", "UL", "US"];
|
||||||
|
|
||||||
DataElement = function(tag, vr, vm, value, vvr, syntax, options) {
|
DataElement = function(tag, vr, vm, value, vvr, syntax, options) {
|
||||||
this.vr = vr ? vrByType(vr) : null;
|
this.vr = vr ? vrByType(vr) : null;
|
||||||
@ -839,16 +803,14 @@ DataElement = function(tag, vr, vm, value, vvr, syntax, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DataElement.prototype.setOptions = function(options) {
|
DataElement.prototype.setOptions = function(options) {
|
||||||
this.options = Object.assign({
|
this.options = Object.assign({split : true}, options);
|
||||||
split: true
|
}
|
||||||
}, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
DataElement.prototype.setSyntax = function(syn) {
|
DataElement.prototype.setSyntax = function(syn) {
|
||||||
this.syntax = syn;
|
this.syntax = syn;
|
||||||
this.implicit = this.syntax == C.IMPLICIT_LITTLE_ENDIAN ? true : false;
|
this.implicit = this.syntax == C.IMPLICIT_LITTLE_ENDIAN ? true : false;
|
||||||
this.endian = (this.syntax == C.IMPLICIT_LITTLE_ENDIAN || this.syntax == C.EXPLICIT_LITTLE_ENDIAN) ? C.LITTLE_ENDIAN : C.BIG_ENDIAN;
|
this.endian = (this.syntax == C.IMPLICIT_LITTLE_ENDIAN || this.syntax == C.EXPLICIT_LITTLE_ENDIAN) ? C.LITTLE_ENDIAN : C.BIG_ENDIAN;
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.getValue = function() {
|
DataElement.prototype.getValue = function() {
|
||||||
if (!this.singleValue() && !this.isBinaryNumber()) {
|
if (!this.singleValue() && !this.isBinaryNumber()) {
|
||||||
@ -856,11 +818,11 @@ DataElement.prototype.getValue = function() {
|
|||||||
} else {
|
} else {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.singleValue = function() {
|
DataElement.prototype.singleValue = function() {
|
||||||
return this.vm == C.VM_SINGLE ? true : false;
|
return this.vm == C.VM_SINGLE ? true : false;
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.getVMNum = function() {
|
DataElement.prototype.getVMNum = function() {
|
||||||
var num = 1;
|
var num = 1;
|
||||||
@ -873,16 +835,16 @@ DataElement.prototype.getVMNum = function() {
|
|||||||
default : break;
|
default : break;
|
||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.isBinaryNumber = function() {
|
DataElement.prototype.isBinaryNumber = function() {
|
||||||
return binaryVRs.indexOf(this.vr.type) != -1;
|
return binaryVRs.indexOf(this.vr.type) != -1;
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.length = function(fields) {
|
DataElement.prototype.length = function(fields) {
|
||||||
//let fields = this.vr.getFields(this.value);
|
//let fields = this.vr.getFields(this.value);
|
||||||
return fieldsLength(fields);
|
return fieldsLength(fields);
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.readBytes = function(stream) {
|
DataElement.prototype.readBytes = function(stream) {
|
||||||
var oldEndian = stream.endian;
|
var oldEndian = stream.endian;
|
||||||
@ -926,7 +888,7 @@ DataElement.prototype.readBytes = function(stream) {
|
|||||||
//} catch (e) { console.log('error', vr, length); }
|
//} catch (e) { console.log('error', vr, length); }
|
||||||
|
|
||||||
stream.setEndian(oldEndian);
|
stream.setEndian(oldEndian);
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.write = function(stream) {
|
DataElement.prototype.write = function(stream) {
|
||||||
var oldEndian = stream.endian;
|
var oldEndian = stream.endian;
|
||||||
@ -938,13 +900,13 @@ DataElement.prototype.write = function(stream) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
stream.setEndian(oldEndian);
|
stream.setEndian(oldEndian);
|
||||||
};
|
}
|
||||||
|
|
||||||
DataElement.prototype.getFields = function() {
|
DataElement.prototype.getFields = function() {
|
||||||
var fields = [new UInt16Field(this.tag.group()), new UInt16Field(this.tag.element())],
|
var fields = [new UInt16Field(this.tag.group()), new UInt16Field(this.tag.element())],
|
||||||
valueFields = this.vr.getFields(this.value, this.syntax), valueLength = fieldsLength(valueFields), vrType = this.vr.type;
|
valueFields = this.vr.getFields(this.value, this.syntax), valueLength = fieldsLength(valueFields), vrType = this.vr.type;
|
||||||
|
|
||||||
if (vrType == 'SQ') {
|
if (vrType == "SQ") {
|
||||||
valueLength = 0xffffffff;
|
valueLength = 0xffffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -960,5 +922,6 @@ DataElement.prototype.getFields = function() {
|
|||||||
|
|
||||||
fields = fields.concat(valueFields);
|
fields = fields.concat(valueFields);
|
||||||
return fields;
|
return fields;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,32 +5,30 @@ Field = function(type, value) {
|
|||||||
|
|
||||||
Field.prototype.length = function() {
|
Field.prototype.length = function() {
|
||||||
return calcLength(this.type, this.value);
|
return calcLength(this.type, this.value);
|
||||||
};
|
}
|
||||||
|
|
||||||
Field.prototype.write = function(stream) {
|
Field.prototype.write = function(stream) {
|
||||||
stream.write(this.type, this.value);
|
stream.write(this.type, this.value);
|
||||||
};
|
}
|
||||||
|
|
||||||
Field.prototype.isNumeric = function() {
|
Field.prototype.isNumeric = function() {
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
StringField = function(str) {
|
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);
|
util.inherits(StringField, Field);
|
||||||
|
|
||||||
FilledField = function(value, length) {
|
FilledField = function(value, length) {
|
||||||
Field.call(this, C.TYPE_COMPOSITE, value);
|
Field.call(this, C.TYPE_COMPOSITE, value);
|
||||||
this.fillLength = length;
|
this.fillLength = length;
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(FilledField, Field);
|
util.inherits(FilledField, Field);
|
||||||
|
|
||||||
FilledField.prototype.length = function() {
|
FilledField.prototype.length = function() {
|
||||||
return this.fillLength;
|
return this.fillLength;
|
||||||
};
|
}
|
||||||
|
|
||||||
FilledField.prototype.write = function(stream) {
|
FilledField.prototype.write = function(stream) {
|
||||||
var len = this.value.length;
|
var len = this.value.length;
|
||||||
@ -38,104 +36,93 @@ FilledField.prototype.write = function(stream) {
|
|||||||
if (len > 0)
|
if (len > 0)
|
||||||
stream.write(C.TYPE_ASCII, this.value);
|
stream.write(C.TYPE_ASCII, this.value);
|
||||||
var zeroLength = this.fillLength - len;
|
var zeroLength = this.fillLength - len;
|
||||||
stream.write(C.TYPE_HEX, '20'.repeat(zeroLength));
|
stream.write(C.TYPE_HEX, "20".repeat(zeroLength));
|
||||||
} else if (len == this.fillLength) {
|
} else if (len == this.fillLength) {
|
||||||
stream.write(C.TYPE_ASCII, this.value);
|
stream.write(C.TYPE_ASCII, this.value);
|
||||||
} else {
|
} else {
|
||||||
throw 'Length mismatch';
|
throw "Length mismatch";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
HexField = function(hex) {
|
HexField = function(hex) {
|
||||||
Field.call(this, C.TYPE_HEX, hex);
|
Field.call(this, C.TYPE_HEX, hex);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(HexField, Field);
|
util.inherits(HexField, Field);
|
||||||
|
|
||||||
ReservedField = function(length) {
|
ReservedField = function(length) {
|
||||||
length = length || 1;
|
length = length || 1;
|
||||||
Field.call(this, C.TYPE_HEX, '00'.repeat(length));
|
Field.call(this, C.TYPE_HEX, "00".repeat(length));
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(ReservedField, Field);
|
util.inherits(ReservedField, Field);
|
||||||
|
|
||||||
UInt8Field = function(value) {
|
UInt8Field = function(value) {
|
||||||
Field.call(this, C.TYPE_UINT8, value);
|
Field.call(this, C.TYPE_UINT8, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(UInt8Field, Field);
|
util.inherits(UInt8Field, Field);
|
||||||
|
|
||||||
UInt8Field.prototype.isNumeric = function() {
|
UInt8Field.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
UInt16Field = function(value) {
|
UInt16Field = function(value) {
|
||||||
Field.call(this, C.TYPE_UINT16, value);
|
Field.call(this, C.TYPE_UINT16, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(UInt16Field, Field);
|
util.inherits(UInt16Field, Field);
|
||||||
|
|
||||||
UInt16Field.prototype.isNumeric = function() {
|
UInt16Field.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
UInt32Field = function(value) {
|
UInt32Field = function(value) {
|
||||||
Field.call(this, C.TYPE_UINT32, value);
|
Field.call(this, C.TYPE_UINT32, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(UInt32Field, Field);
|
util.inherits(UInt32Field, Field);
|
||||||
|
|
||||||
UInt32Field.prototype.isNumeric = function() {
|
UInt32Field.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
Int8Field = function(value) {
|
Int8Field = function(value) {
|
||||||
Field.call(this, C.TYPE_INT8, value);
|
Field.call(this, C.TYPE_INT8, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(Int8Field, Field);
|
util.inherits(Int8Field, Field);
|
||||||
|
|
||||||
Int8Field.prototype.isNumeric = function() {
|
Int8Field.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
Int16Field = function(value) {
|
Int16Field = function(value) {
|
||||||
Field.call(this, C.TYPE_INT16, value);
|
Field.call(this, C.TYPE_INT16, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(Int16Field, Field);
|
util.inherits(Int16Field, Field);
|
||||||
|
|
||||||
Int16Field.prototype.isNumeric = function() {
|
Int16Field.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
Int32Field = function(value) {
|
Int32Field = function(value) {
|
||||||
Field.call(this, C.TYPE_INT32, value);
|
Field.call(this, C.TYPE_INT32, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(Int32Field, Field);
|
util.inherits(Int32Field, Field);
|
||||||
|
|
||||||
Int32Field.prototype.isNumeric = function() {
|
Int32Field.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
FloatField = function(value) {
|
FloatField = function(value) {
|
||||||
Field.call(this, C.TYPE_FLOAT, value);
|
Field.call(this, C.TYPE_FLOAT, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(FloatField, Field);
|
util.inherits(FloatField, Field);
|
||||||
|
|
||||||
FloatField.prototype.isNumeric = function() {
|
FloatField.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
DoubleField = function(value) {
|
DoubleField = function(value) {
|
||||||
Field.call(this, C.TYPE_DOUBLE, value);
|
Field.call(this, C.TYPE_DOUBLE, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(DoubleField, Field);
|
util.inherits(DoubleField, Field);
|
||||||
|
|
||||||
DoubleField.prototype.isNumeric = function() {
|
DoubleField.prototype.isNumeric = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ DicomMessage = function(syntax) {
|
|||||||
|
|
||||||
DicomMessage.prototype.isCommand = function() {
|
DicomMessage.prototype.isCommand = function() {
|
||||||
return this.type == C.DATA_TYPE_COMMAND;
|
return this.type == C.DATA_TYPE_COMMAND;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setSyntax = function(syntax) {
|
DicomMessage.prototype.setSyntax = function(syntax) {
|
||||||
this.syntax = syntax;
|
this.syntax = syntax;
|
||||||
@ -15,15 +15,15 @@ DicomMessage.prototype.setSyntax = function(syntax) {
|
|||||||
for (var tag in this.elementPairs) {
|
for (var tag in this.elementPairs) {
|
||||||
this.elementPairs[tag].setSyntax(this.syntax);
|
this.elementPairs[tag].setSyntax(this.syntax);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setMessageId = function(id) {
|
DicomMessage.prototype.setMessageId = function(id) {
|
||||||
this.messageId = id;
|
this.messageId = id;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setReplyMessageId = function(id) {
|
DicomMessage.prototype.setReplyMessageId = function(id) {
|
||||||
this.replyMessageId = id;
|
this.replyMessageId = id;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.command = function(cmds) {
|
DicomMessage.prototype.command = function(cmds) {
|
||||||
cmds.unshift(this.newElement(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
cmds.unshift(this.newElement(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
||||||
@ -39,12 +39,13 @@ DicomMessage.prototype.command = function(cmds) {
|
|||||||
|
|
||||||
cmds.unshift(this.newElement(0x00000000, length));
|
cmds.unshift(this.newElement(0x00000000, length));
|
||||||
return cmds;
|
return cmds;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.response = function(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(0x00000800, this.dataSetPresent ? C.DATA_SET_PRESENT : C.DATE_SET_ABSENCE));
|
||||||
cmds.unshift(this.newElement(0x00000120, this.replyMessageId));
|
cmds.unshift(this.newElement(0x00000120, this.replyMessageId));
|
||||||
cmds.unshift(this.newElement(0x00000100, this.commandType));
|
cmds.unshift(this.newElement(0x00000100, this.commandType));
|
||||||
|
if (this.contextUID)
|
||||||
cmds.unshift(this.newElement(0x00000002, this.contextUID));
|
cmds.unshift(this.newElement(0x00000002, this.contextUID));
|
||||||
|
|
||||||
var length = 0;
|
var length = 0;
|
||||||
@ -54,77 +55,75 @@ DicomMessage.prototype.response = function(cmds) {
|
|||||||
|
|
||||||
cmds.unshift(this.newElement(0x00000000, length));
|
cmds.unshift(this.newElement(0x00000000, length));
|
||||||
return cmds;
|
return cmds;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setElements = function(pairs) {
|
DicomMessage.prototype.setElements = function(pairs) {
|
||||||
var p = {};
|
var p = {};
|
||||||
for (var tag in pairs) {
|
for (var tag in pairs) {
|
||||||
p[tag] = this.newElement(tag, pairs[tag]);
|
p[tag] = this.newElement(tag, pairs[tag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.elementPairs = p;
|
this.elementPairs = p;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.newElement = function(tag, value) {
|
DicomMessage.prototype.newElement = function(tag, value) {
|
||||||
return elementByType(tag, value, this.syntax);
|
return elementByType(tag, value, this.syntax);
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setElement = function(key, value) {
|
DicomMessage.prototype.setElement = function(key, value) {
|
||||||
this.elementPairs[key] = elementByType(key, value);
|
this.elementPairs[key] = elementByType(key, value);
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setElementPairs = function(pairs) {
|
DicomMessage.prototype.setElementPairs = function(pairs) {
|
||||||
this.elementPairs = pairs;
|
this.elementPairs = pairs;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setContextId = function(context) {
|
DicomMessage.prototype.setContextId = function(context) {
|
||||||
this.contextUID = context;
|
this.contextUID = context;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setPriority = function(pri) {
|
DicomMessage.prototype.setPriority = function(pri) {
|
||||||
this.priority = pri;
|
this.priority = pri;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setType = function(type) {
|
DicomMessage.prototype.setType = function(type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.setDataSetPresent = function(present) {
|
DicomMessage.prototype.setDataSetPresent = function(present) {
|
||||||
this.dataSetPresent = present == 0x0101 ? false : true;
|
this.dataSetPresent = present == 0x0101 ? false : true;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.haveData = function() {
|
DicomMessage.prototype.haveData = function() {
|
||||||
return this.dataSetPresent;
|
return this.dataSetPresent;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.tags = function() {
|
DicomMessage.prototype.tags = function() {
|
||||||
return Object.keys(this.elementPairs);
|
return Object.keys(this.elementPairs);
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.key = function(tag) {
|
DicomMessage.prototype.key = function(tag) {
|
||||||
return elementKeywordByTag(tag);
|
return elementKeywordByTag(tag);
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.getValue = function(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() {
|
DicomMessage.prototype.affectedSOPClassUID = function() {
|
||||||
return this.getValue(0x00000002);
|
return this.getValue(0x00000002);
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.getMessageId = function() {
|
DicomMessage.prototype.getMessageId = function() {
|
||||||
return this.getValue(0x00000110);
|
return this.getValue(0x00000110);
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.getFields = function() {
|
DicomMessage.prototype.getFields = function() {
|
||||||
var eles = [];
|
var eles = [];
|
||||||
for (var tag in this.elementPairs) {
|
for (var tag in this.elementPairs) {
|
||||||
eles.push(this.elementPairs[tag]);
|
eles.push(this.elementPairs[tag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return eles;
|
return eles;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.length = function(elems) {
|
DicomMessage.prototype.length = function(elems) {
|
||||||
var len = 0;
|
var len = 0;
|
||||||
@ -132,15 +131,15 @@ DicomMessage.prototype.length = function(elems) {
|
|||||||
len += elem.length(elem.getFields());
|
len += elem.length(elem.getFields());
|
||||||
});
|
});
|
||||||
return len;
|
return len;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.isResponse = function() {
|
DicomMessage.prototype.isResponse = function() {
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.is = function(type) {
|
DicomMessage.prototype.is = function(type) {
|
||||||
return this.commandType == type;
|
return this.commandType == type;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.write = function(stream) {
|
DicomMessage.prototype.write = function(stream) {
|
||||||
var fields = this.getFields(), o = this;
|
var fields = this.getFields(), o = this;
|
||||||
@ -148,55 +147,53 @@ DicomMessage.prototype.write = function(stream) {
|
|||||||
field.setSyntax(o.syntax);
|
field.setSyntax(o.syntax);
|
||||||
field.write(stream);
|
field.write(stream);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.printElements = function(pairs, indent) {
|
DicomMessage.prototype.printElements = function(pairs, indent) {
|
||||||
var typeName = '';
|
var typeName = "";
|
||||||
for (var tag in pairs) {
|
for (var tag in pairs) {
|
||||||
var value = pairs[tag].getValue();
|
var value = pairs[tag].getValue();
|
||||||
typeName += (' '.repeat(indent)) + this.key(tag) + ' : ';
|
typeName += (" ".repeat(indent)) + this.key(tag) + " : ";
|
||||||
if (value instanceof Array) {
|
if (value instanceof Array) {
|
||||||
var o = this;
|
var o = this;
|
||||||
value.forEach(function(p) {
|
value.forEach(function(p) {
|
||||||
if (typeof p == 'object') {
|
if (typeof p == "object") {
|
||||||
typeName += '[\n' + o.printElements(p, indent + 2) + (' '.repeat(indent)) + ']';
|
typeName += "[\n" + o.printElements(p, indent + 2) + (" ".repeat(indent)) + "]";
|
||||||
} else {
|
} else {
|
||||||
typeName += '[' + p + ']';
|
typeName += "[" + p + "]";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (typeName[typeName.length - 1] != '\n') {
|
if (typeName[typeName.length-1] != "\n") {
|
||||||
typeName += '\n';
|
typeName += "\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
typeName += value + '\n';
|
typeName += value + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeName;
|
return typeName;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.toString = function() {
|
DicomMessage.prototype.toString = function() {
|
||||||
var typeName = '';
|
var typeName = "";
|
||||||
if (!this.isCommand()) {
|
if (!this.isCommand()) {
|
||||||
typeName = 'DateSet Message';
|
typeName = "DateSet Message";
|
||||||
} else {
|
} else {
|
||||||
switch (this.commandType) {
|
switch (this.commandType) {
|
||||||
case C.COMMAND_C_GET_RSP : typeName = 'C-GET-RSP'; break;
|
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_MOVE_RSP : typeName = "C-MOVE-RSP"; break;
|
||||||
case C.COMMAND_C_GET_RQ : typeName = 'C-GET-RQ'; 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_STORE_RQ : typeName = "C-STORE-RQ"; break;
|
||||||
case C.COMMAND_C_FIND_RSP : typeName = 'C-FIND-RSP'; 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_MOVE_RQ : typeName = "C-MOVE-RQ"; break;
|
||||||
case C.COMMAND_C_FIND_RQ : typeName = 'C-FIND-RQ'; break;
|
case C.COMMAND_C_FIND_RQ : typeName = "C-FIND-RQ"; break;
|
||||||
case C.COMMAND_C_STORE_RSP : typeName = 'C-STORE-RSP'; break;
|
case C.COMMAND_C_STORE_RSP : typeName = "C-STORE-RSP"; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
typeName += " [\n";
|
||||||
typeName += ' [\n';
|
|
||||||
typeName += this.printElements(this.elementPairs, 0);
|
typeName += this.printElements(this.elementPairs, 0);
|
||||||
typeName += ']';
|
typeName += "]";
|
||||||
return typeName;
|
return typeName;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.walkObject = function(pairs) {
|
DicomMessage.prototype.walkObject = function(pairs) {
|
||||||
var obj = {}, o = this;
|
var obj = {}, o = this;
|
||||||
@ -210,18 +207,17 @@ DicomMessage.prototype.walkObject = function(pairs) {
|
|||||||
} else u.push(a);
|
} else u.push(a);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
obj[tag] = u;
|
obj[tag] = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
}
|
||||||
|
|
||||||
DicomMessage.prototype.toObject = function() {
|
DicomMessage.prototype.toObject = function() {
|
||||||
return this.walkObject(this.elementPairs);
|
return this.walkObject(this.elementPairs);
|
||||||
};
|
}
|
||||||
|
|
||||||
readMessage = function(stream, type, syntax, options) {
|
DicomMessage.read = function(stream, type, syntax, options) {
|
||||||
var elements = [], pairs = {}, useSyntax = type == C.DATA_TYPE_COMMAND ? C.IMPLICIT_LITTLE_ENDIAN : syntax;
|
var elements = [], pairs = {}, useSyntax = type == C.DATA_TYPE_COMMAND ? C.IMPLICIT_LITTLE_ENDIAN : syntax;
|
||||||
stream.reset();
|
stream.reset();
|
||||||
while (!stream.end()) {
|
while (!stream.end()) {
|
||||||
@ -229,7 +225,6 @@ readMessage = function(stream, type, syntax, options) {
|
|||||||
if (options) {
|
if (options) {
|
||||||
elem.setOptions(options);
|
elem.setOptions(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.setSyntax(useSyntax);
|
elem.setSyntax(useSyntax);
|
||||||
elem.readBytes(stream);//return;
|
elem.readBytes(stream);//return;
|
||||||
pairs[elem.tag.value] = elem;
|
pairs[elem.tag.value] = elem;
|
||||||
@ -245,7 +240,7 @@ readMessage = function(stream, type, syntax, options) {
|
|||||||
case 0x8010 : message = new CGetRSP(useSyntax); break;
|
case 0x8010 : message = new CGetRSP(useSyntax); break;
|
||||||
case 0x0001 : message = new CStoreRQ(useSyntax); break;
|
case 0x0001 : message = new CStoreRQ(useSyntax); break;
|
||||||
case 0x0020 : message = new CFindRQ(useSyntax); break;
|
case 0x0020 : message = new CFindRQ(useSyntax); break;
|
||||||
default : throw 'Unrecognized command type ' + cmdType.toString(16); break;
|
default : throw "Unrecognized command type " + cmdType.toString(16); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.setElementPairs(pairs);
|
message.setElementPairs(pairs);
|
||||||
@ -260,128 +255,121 @@ readMessage = function(stream, type, syntax, options) {
|
|||||||
message = new DataSetMessage(useSyntax);
|
message = new DataSetMessage(useSyntax);
|
||||||
message.setElementPairs(pairs);
|
message.setElementPairs(pairs);
|
||||||
} else {
|
} else {
|
||||||
throw 'Unrecognized message type';
|
throw "Unrecognized message type";
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
};
|
}
|
||||||
|
|
||||||
DataSetMessage = function(syntax){
|
DataSetMessage = function(syntax){
|
||||||
DicomMessage.call(this, syntax);
|
DicomMessage.call(this, syntax);
|
||||||
this.type = C.DATA_TYPE_DATA;
|
this.type = C.DATA_TYPE_DATA;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(DataSetMessage, DicomMessage);
|
util.inherits(DataSetMessage, DicomMessage);
|
||||||
|
|
||||||
DataSetMessage.prototype.is = function(type) {
|
DataSetMessage.prototype.is = function(type) {
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandMessage = function(syntax) {
|
CommandMessage = function(syntax) {
|
||||||
DicomMessage.call(this, syntax);
|
DicomMessage.call(this, syntax);
|
||||||
this.type = C.DATA_TYPE_COMMAND;
|
this.type = C.DATA_TYPE_COMMAND;
|
||||||
this.priority = C.PRIORITY_MEDIUM;
|
this.priority = C.PRIORITY_MEDIUM;
|
||||||
this.dataSetPresent = true;
|
this.dataSetPresent = true;
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(CommandMessage, DicomMessage);
|
util.inherits(CommandMessage, DicomMessage);
|
||||||
|
|
||||||
CommandMessage.prototype.getFields = function() {
|
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) {
|
CommandResponse = function(syntax) {
|
||||||
DicomMessage.call(this, syntax);
|
DicomMessage.call(this, syntax);
|
||||||
this.type = C.DATA_TYPE_COMMAND;
|
this.type = C.DATA_TYPE_COMMAND;
|
||||||
this.dataSetPresent = true;
|
this.dataSetPresent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CommandResponse, DicomMessage);
|
util.inherits(CommandResponse, DicomMessage);
|
||||||
|
|
||||||
CommandResponse.prototype.isResponse = function() {
|
CommandResponse.prototype.isResponse = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.respondedTo = function() {
|
CommandResponse.prototype.respondedTo = function() {
|
||||||
return this.getValue(0x00000120);
|
return this.getValue(0x00000120);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.isFinal = function() {
|
CommandResponse.prototype.isFinal = function() {
|
||||||
return this.success() || this.failure() || this.cancel();
|
return this.success() || this.failure() || this.cancel();
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.warning = function() {
|
CommandResponse.prototype.warning = function() {
|
||||||
var status = this.getStatus();
|
var status = this.getStatus();
|
||||||
return (status == 0x0001) || (status >> 12 == 0xb);
|
return (status == 0x0001) || (status >> 12 == 0xb);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.success = function() {
|
CommandResponse.prototype.success = function() {
|
||||||
return this.getStatus() == 0x0000;
|
return this.getStatus() == 0x0000;
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.failure = function() {
|
CommandResponse.prototype.failure = function() {
|
||||||
var status = this.getStatus();
|
var status = this.getStatus();
|
||||||
return (status >> 12 == 0xa) || (status >> 12 == 0xc) || (status >> 8 == 0x1);
|
return (status >> 12 == 0xa) || (status >> 12 == 0xc) || (status >> 8 == 0x1)
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.cancel = function() {
|
CommandResponse.prototype.cancel = function() {
|
||||||
return this.getStatus() == C.STATUS_CANCEL;
|
return this.getStatus() == C.STATUS_CANCEL;
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.pending = function() {
|
CommandResponse.prototype.pending = function() {
|
||||||
var status = this.getStatus();
|
var status = this.getStatus();
|
||||||
return (status == 0xff00) || (status == 0xff01);
|
return (status == 0xff00) || (status == 0xff01);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.getStatus = function() {
|
CommandResponse.prototype.getStatus = function() {
|
||||||
return this.getValue(0x00000900);
|
return this.getValue(0x00000900);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.setStatus = function(status) {
|
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
|
// following four methods only available to C-GET-RSP and C-MOVE-RSP
|
||||||
CommandResponse.prototype.getNumOfRemainingSubOperations = function() {
|
CommandResponse.prototype.getNumOfRemainingSubOperations = function() {
|
||||||
return this.getValue(0x00001020);
|
return this.getValue(0x00001020);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.getNumOfCompletedSubOperations = function() {
|
CommandResponse.prototype.getNumOfCompletedSubOperations = function() {
|
||||||
return this.getValue(0x00001021);
|
return this.getValue(0x00001021);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.getNumOfFailedSubOperations = function() {
|
CommandResponse.prototype.getNumOfFailedSubOperations = function() {
|
||||||
return this.getValue(0x00001022);
|
return this.getValue(0x00001022);
|
||||||
};
|
}
|
||||||
|
|
||||||
CommandResponse.prototype.getNumOfWarningSubOperations = function() {
|
CommandResponse.prototype.getNumOfWarningSubOperations = function() {
|
||||||
return this.getValue(0x00001023);
|
return this.getValue(0x00001023);
|
||||||
};
|
}
|
||||||
//end
|
//end
|
||||||
|
|
||||||
CommandResponse.prototype.getFields = function() {
|
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) {
|
CFindRSP = function(syntax) {
|
||||||
CommandResponse.call(this, syntax);
|
CommandResponse.call(this, syntax);
|
||||||
this.commandType = 0x8020;
|
this.commandType = 0x8020;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CFindRSP, CommandResponse);
|
util.inherits(CFindRSP, CommandResponse);
|
||||||
|
|
||||||
CGetRSP = function(syntax) {
|
CGetRSP = function(syntax) {
|
||||||
CommandResponse.call(this, syntax);
|
CommandResponse.call(this, syntax);
|
||||||
this.commandType = 0x8010;
|
this.commandType = 0x8010;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CGetRSP, CommandResponse);
|
util.inherits(CGetRSP, CommandResponse);
|
||||||
|
|
||||||
CMoveRSP = function(syntax) {
|
CMoveRSP = function(syntax) {
|
||||||
CommandResponse.call(this, syntax);
|
CommandResponse.call(this, syntax);
|
||||||
this.commandType = 0x8021;
|
this.commandType = 0x8021;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CMoveRSP, CommandResponse);
|
util.inherits(CMoveRSP, CommandResponse);
|
||||||
|
|
||||||
CFindRQ = function(syntax) {
|
CFindRQ = function(syntax) {
|
||||||
@ -389,27 +377,39 @@ CFindRQ = function(syntax) {
|
|||||||
this.commandType = 0x20;
|
this.commandType = 0x20;
|
||||||
this.contextUID = C.SOP_STUDY_ROOT_FIND;
|
this.contextUID = C.SOP_STUDY_ROOT_FIND;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CFindRQ, CommandMessage);
|
util.inherits(CFindRQ, CommandMessage);
|
||||||
|
|
||||||
|
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) {
|
CMoveRQ = function(syntax, destination) {
|
||||||
CommandMessage.call(this, syntax);
|
CommandMessage.call(this, syntax);
|
||||||
this.commandType = 0x21;
|
this.commandType = 0x21;
|
||||||
this.contextUID = C.SOP_STUDY_ROOT_MOVE;
|
this.contextUID = C.SOP_STUDY_ROOT_MOVE;
|
||||||
this.setDestination(destination || '');
|
this.setDestination(destination || "");
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CMoveRQ, CommandMessage);
|
util.inherits(CMoveRQ, CommandMessage);
|
||||||
|
|
||||||
CMoveRQ.prototype.setStore = function(cstr) {
|
CMoveRQ.prototype.setStore = function(cstr) {
|
||||||
this.store = cstr;
|
this.store = cstr;
|
||||||
};
|
}
|
||||||
|
|
||||||
CMoveRQ.prototype.setDestination = function(dest) {
|
CMoveRQ.prototype.setDestination = function(dest) {
|
||||||
this.setElements({
|
this.setElement(0x00000600, dest);
|
||||||
0x00000600: dest
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
CGetRQ = function(syntax) {
|
CGetRQ = function(syntax) {
|
||||||
CommandMessage.call(this, syntax);
|
CommandMessage.call(this, syntax);
|
||||||
@ -417,32 +417,30 @@ CGetRQ = function(syntax) {
|
|||||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||||
this.store = null;
|
this.store = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CGetRQ, CommandMessage);
|
util.inherits(CGetRQ, CommandMessage);
|
||||||
|
|
||||||
CGetRQ.prototype.setStore = function(cstr) {
|
CGetRQ.prototype.setStore = function(cstr) {
|
||||||
this.store = cstr;
|
this.store = cstr;
|
||||||
};
|
}
|
||||||
|
|
||||||
CStoreRQ = function(syntax) {
|
CStoreRQ = function(syntax) {
|
||||||
CommandMessage.call(this, syntax);
|
CommandMessage.call(this, syntax);
|
||||||
this.commandType = 0x01;
|
this.commandType = 0x01;
|
||||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CStoreRQ, CommandMessage);
|
util.inherits(CStoreRQ, CommandMessage);
|
||||||
|
|
||||||
CStoreRQ.prototype.getOriginAETitle = function() {
|
CStoreRQ.prototype.getOriginAETitle = function() {
|
||||||
return this.getValue(0x00001030);
|
return this.getValue(0x00001030);
|
||||||
};
|
}
|
||||||
|
|
||||||
CStoreRQ.prototype.getMoveMessageId = function() {
|
CStoreRQ.prototype.getMoveMessageId = function() {
|
||||||
return this.getValue(0x00001031);
|
return this.getValue(0x00001031);
|
||||||
};
|
}
|
||||||
|
|
||||||
CStoreRQ.prototype.getSOPInstanceUID = function() {
|
CStoreRQ.prototype.getSOPInstanceUID = function() {
|
||||||
return this.getValue(0x00001000);
|
return this.getValue(0x00001000);
|
||||||
};
|
}
|
||||||
|
|
||||||
CStoreRSP = function(syntax) {
|
CStoreRSP = function(syntax) {
|
||||||
CommandResponse.call(this, syntax);
|
CommandResponse.call(this, syntax);
|
||||||
@ -450,14 +448,12 @@ CStoreRSP = function(syntax) {
|
|||||||
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
this.contextUID = C.SOP_STUDY_ROOT_GET;
|
||||||
this.dataSetPresent = false;
|
this.dataSetPresent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(CStoreRSP, CommandResponse);
|
util.inherits(CStoreRSP, CommandResponse);
|
||||||
|
|
||||||
CStoreRSP.prototype.setAffectedSOPInstanceUID = function(uid) {
|
CStoreRSP.prototype.setAffectedSOPInstanceUID = function(uid) {
|
||||||
this.setElement(0x00001000, uid);
|
this.setElement(0x00001000, uid);
|
||||||
};
|
}
|
||||||
|
|
||||||
CStoreRSP.prototype.getAffectedSOPInstanceUID = function(uid) {
|
CStoreRSP.prototype.getAffectedSOPInstanceUID = function(uid) {
|
||||||
return this.getValue(0x00001000);
|
return this.getValue(0x00001000);
|
||||||
};
|
}
|
||||||
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
PDU = function() {
|
PDU = function() {
|
||||||
this.fields = [];
|
this.fields = [];
|
||||||
this.lengthBytes = 4;
|
this.lengthBytes = 4;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.length = function(fields) {
|
PDU.prototype.length = function(fields) {
|
||||||
var len = 0;
|
var len = 0;
|
||||||
@ -9,11 +9,11 @@ PDU.prototype.length = function(fields) {
|
|||||||
len += !f.getFields ? f.length() : f.length(f.getFields());
|
len += !f.getFields ? f.length() : f.length(f.getFields());
|
||||||
});
|
});
|
||||||
return len;
|
return len;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.is = function(type) {
|
PDU.prototype.is = function(type) {
|
||||||
return this.type == type;
|
return this.type == type;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.getFields = function(fields) {
|
PDU.prototype.getFields = function(fields) {
|
||||||
var len = this.lengthField(fields);
|
var len = this.lengthField(fields);
|
||||||
@ -24,7 +24,7 @@ PDU.prototype.getFields = function(fields) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.lengthField = function(fields) {
|
PDU.prototype.lengthField = function(fields) {
|
||||||
if (this.lengthBytes == 4) {
|
if (this.lengthBytes == 4) {
|
||||||
@ -32,19 +32,19 @@ PDU.prototype.lengthField = function(fields) {
|
|||||||
} else if (this.lengthBytes == 2) {
|
} else if (this.lengthBytes == 2) {
|
||||||
return new UInt16Field(this.length(fields));
|
return new UInt16Field(this.length(fields));
|
||||||
} else {
|
} else {
|
||||||
throw 'Invalid length bytes';
|
throw "Invalid length bytes";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
PDU.prototype.read = function(stream) {
|
PDU.prototype.read = function(stream) {
|
||||||
stream.read(C.TYPE_HEX, 1);
|
stream.read(C.TYPE_HEX, 1);
|
||||||
var length = stream.read(C.TYPE_UINT32);
|
var length = stream.read(C.TYPE_UINT32);
|
||||||
this.readBytes(stream, length);
|
this.readBytes(stream, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.load = function(stream) {
|
PDU.prototype.load = function(stream) {
|
||||||
return pduByStream(stream);
|
return PDU.createByStream(stream);
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.loadPDV = function(stream, length) {
|
PDU.prototype.loadPDV = function(stream, length) {
|
||||||
if (stream.end()) return false;
|
if (stream.end()) return false;
|
||||||
@ -59,12 +59,12 @@ PDU.prototype.loadPDV = function(stream, length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return pdvs;
|
return pdvs;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.loadDicomMessage = function(stream, isCommand, isLast) {
|
PDU.prototype.loadDicomMessage = function(stream, isCommand, isLast) {
|
||||||
var message = readMessage(stream, isCommand, isLast);
|
var message = DicomMessage.read(stream, isCommand, isLast);
|
||||||
return message;
|
return message;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.stream = function() {
|
PDU.prototype.stream = function() {
|
||||||
var stream = new WriteStream(),
|
var stream = new WriteStream(),
|
||||||
@ -76,15 +76,15 @@ PDU.prototype.stream = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
};
|
}
|
||||||
|
|
||||||
PDU.prototype.buffer = function() {
|
PDU.prototype.buffer = function() {
|
||||||
return this.stream().buffer();
|
return this.stream().buffer();
|
||||||
};
|
}
|
||||||
|
|
||||||
var interpretCommand = function(stream, isLast) {
|
var interpretCommand = function(stream, isLast) {
|
||||||
parseDicomMessage(stream);
|
parseDicomMessage(stream);
|
||||||
};
|
}
|
||||||
|
|
||||||
mergePDVs = function(pdvs) {
|
mergePDVs = function(pdvs) {
|
||||||
var merges = [], count = pdvs.length, i = 0;
|
var merges = [], count = pdvs.length, i = 0;
|
||||||
@ -94,18 +94,40 @@ mergePDVs = function(pdvs) {
|
|||||||
while (!pdvs[j++].isLast && j < count) {
|
while (!pdvs[j++].isLast && j < count) {
|
||||||
pdvs[i].messageStream.concat(pdvs[j].messageStream);
|
pdvs[i].messageStream.concat(pdvs[j].messageStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
merges.push(pdvs[i]);
|
merges.push(pdvs[i]);
|
||||||
i = j;
|
i = j;
|
||||||
} else {
|
} else {
|
||||||
merges.push(pdvs[i++]);
|
merges.push(pdvs[i++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return merges;
|
return merges;
|
||||||
};
|
}
|
||||||
|
|
||||||
pduByStream = function(stream) {
|
PDU.typeToString = function(type) {
|
||||||
|
var pdu = null, typeNum = parseInt(type, 16);
|
||||||
|
//console.log("RECEIVED PDU-TYPE ", typeNum);
|
||||||
|
switch (typeNum) {
|
||||||
|
case 0x01 : pdu = 'ASSOCIATE-RQ'; break;
|
||||||
|
case 0x02 : pdu = 'ASSOCIATE-AC'; break;
|
||||||
|
case 0x04 : pdu = 'P-DATA-TF'; break;
|
||||||
|
case 0x06 : pdu = 'RELEASE-RP'; break;
|
||||||
|
case 0x07 : pdu = 'ASSOCIATE-ABORT'; break;
|
||||||
|
case 0x10 : pdu = 'APPLICATION-CONTEXT-ITEM'; break;
|
||||||
|
case 0x20 : pdu = 'PRESENTATION-CONTEXT-ITEM'; break;
|
||||||
|
case 0x21 : pdu = 'PRESENTATION-CONTEXT-ITEM-AC'; break;
|
||||||
|
case 0x30 : pdu = 'ABSTRACT-SYNTAX-ITEM'; break;
|
||||||
|
case 0x40 : pdu = 'TRANSFER-SYNTAX-ITEM'; break;
|
||||||
|
case 0x50 : pdu = 'USER-INFORMATION-ITEM'; break;
|
||||||
|
case 0x51 : pdu = 'MAXIMUM-LENGTH-ITEM'; break;
|
||||||
|
case 0x52 : pdu = 'IMPLEMENTATION-CLASS-UID-ITEM'; break;
|
||||||
|
case 0x55 : pdu = 'IMPLEMENTATION-VERSION-NAME-ITEM'; break;
|
||||||
|
default : break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pdu;
|
||||||
|
}
|
||||||
|
|
||||||
|
PDU.createByStream = function(stream) {
|
||||||
if (stream.end()) return null;
|
if (stream.end()) return null;
|
||||||
|
|
||||||
var pduType = stream.read(C.TYPE_HEX, 1), typeNum = parseInt(pduType, 16), pdu = null;
|
var pduType = stream.read(C.TYPE_HEX, 1), typeNum = parseInt(pduType, 16), pdu = null;
|
||||||
@ -125,13 +147,13 @@ pduByStream = function(stream) {
|
|||||||
case 0x51 : pdu = new MaximumLengthItem(); break;
|
case 0x51 : pdu = new MaximumLengthItem(); break;
|
||||||
case 0x52 : pdu = new ImplementationClassUIDItem(); break;
|
case 0x52 : pdu = new ImplementationClassUIDItem(); break;
|
||||||
case 0x55 : pdu = new ImplementationVersionNameItem(); break;
|
case 0x55 : pdu = new ImplementationVersionNameItem(); break;
|
||||||
default : throw 'Unrecoginized pdu type ' + pduType; break;
|
default : throw "Unrecoginized pdu type " + pduType; break;
|
||||||
}
|
}
|
||||||
if (pdu)
|
if (pdu)
|
||||||
pdu.read(stream);
|
pdu.read(stream);
|
||||||
|
|
||||||
return pdu;
|
return pdu;
|
||||||
};
|
}
|
||||||
|
|
||||||
var nextItemIs = function(stream, pduType) {
|
var nextItemIs = function(stream, pduType) {
|
||||||
if (stream.end()) return false;
|
if (stream.end()) return false;
|
||||||
@ -139,48 +161,47 @@ var nextItemIs = function(stream, pduType) {
|
|||||||
var nextType = stream.read(C.TYPE_HEX, 1);
|
var nextType = stream.read(C.TYPE_HEX, 1);
|
||||||
stream.increment(-1);
|
stream.increment(-1);
|
||||||
return pduType == nextType;
|
return pduType == nextType;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ = function() {
|
AssociateRQ = function() {
|
||||||
PDU.call(this);
|
PDU.call(this);
|
||||||
this.type = C.ITEM_TYPE_PDU_ASSOCIATE_RQ;
|
this.type = C.ITEM_TYPE_PDU_ASSOCIATE_RQ;
|
||||||
this.protocolVersion = 1;
|
this.protocolVersion = 1;
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(AssociateRQ, PDU);
|
util.inherits(AssociateRQ, PDU);
|
||||||
|
|
||||||
AssociateRQ.prototype.setProtocolVersion = function(version) {
|
AssociateRQ.prototype.setProtocolVersion = function(version) {
|
||||||
this.protocolVersion = version;
|
this.protocolVersion = version;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.setCalledAETitle = function(title) {
|
AssociateRQ.prototype.setCalledAETitle = function(title) {
|
||||||
this.calledAETitle = title;
|
this.calledAETitle = title;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.setCallingAETitle = function(title) {
|
AssociateRQ.prototype.setCallingAETitle = function(title) {
|
||||||
this.callingAETitle = title;
|
this.callingAETitle = title;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.setApplicationContextItem = function(item) {
|
AssociateRQ.prototype.setApplicationContextItem = function(item) {
|
||||||
this.applicationContextItem = item;
|
this.applicationContextItem = item;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.setPresentationContextItems = function(items) {
|
AssociateRQ.prototype.setPresentationContextItems = function(items) {
|
||||||
this.presentationContextItems = items;
|
this.presentationContextItems = items;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.setUserInformationItem = function(item) {
|
AssociateRQ.prototype.setUserInformationItem = function(item) {
|
||||||
this.userInformationItem = item;
|
this.userInformationItem = item;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.allAccepted = function() {
|
AssociateRQ.prototype.allAccepted = function() {
|
||||||
for (var i in this.presentationContextItems) {
|
for (var i in this.presentationContextItems) {
|
||||||
var item = this.presentationContextItems[i];
|
var item = this.presentationContextItems[i];
|
||||||
if (!item.accepted()) return false;
|
if (!item.accepted()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.getFields = function() {
|
AssociateRQ.prototype.getFields = function() {
|
||||||
var f = [
|
var f = [
|
||||||
@ -193,7 +214,7 @@ AssociateRQ.prototype.getFields = function() {
|
|||||||
});
|
});
|
||||||
f.push(this.userInformationItem);
|
f.push(this.userInformationItem);
|
||||||
return AssociateRQ.super_.prototype.getFields.call(this, f);
|
return AssociateRQ.super_.prototype.getFields.call(this, f);
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.readBytes = function(stream, length) {
|
AssociateRQ.prototype.readBytes = function(stream, length) {
|
||||||
this.type = C.ITEM_TYPE_PDU_ASSOCIATE_RQ;
|
this.type = C.ITEM_TYPE_PDU_ASSOCIATE_RQ;
|
||||||
@ -212,16 +233,16 @@ AssociateRQ.prototype.readBytes = function(stream, length) {
|
|||||||
var presContexts = [];
|
var presContexts = [];
|
||||||
do {
|
do {
|
||||||
presContexts.push(this.load(stream));
|
presContexts.push(this.load(stream));
|
||||||
} while (nextItemIs(stream, C.ITEM_TYPE_PRESENTATION_CONTEXT_AC));
|
} while (nextItemIs(stream, C.ITEM_TYPE_PRESENTATION_CONTEXT));
|
||||||
this.setPresentationContextItems(presContexts);
|
this.setPresentationContextItems(presContexts);
|
||||||
|
|
||||||
var userItem = this.load(stream);
|
var userItem = this.load(stream);
|
||||||
this.setUserInformationItem(userItem);
|
this.setUserInformationItem(userItem);
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateRQ.prototype.buffer = function() {
|
AssociateRQ.prototype.buffer = function() {
|
||||||
return AssociateRQ.super_.prototype.buffer.call(this);
|
return AssociateRQ.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateAC = function() {
|
AssociateAC = function() {
|
||||||
AssociateRQ.call(this);
|
AssociateRQ.call(this);
|
||||||
@ -246,24 +267,24 @@ AssociateAC.prototype.readBytes = function(stream, length) {
|
|||||||
|
|
||||||
var userItem = this.load(stream);
|
var userItem = this.load(stream);
|
||||||
this.setUserInformationItem(userItem);
|
this.setUserInformationItem(userItem);
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateAbort = function() {
|
AssociateAbort = function() {
|
||||||
this.type = C.ITEM_TYPE_PDU_AABORT;
|
this.type = C.ITEM_TYPE_PDU_AABORT;
|
||||||
this.source = 1;
|
this.source = 1;
|
||||||
this.reason = 0;
|
this.reason = 0;
|
||||||
PDU.call(this);
|
PDU.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(AssociateAbort, PDU);
|
util.inherits(AssociateAbort, PDU);
|
||||||
|
|
||||||
AssociateAbort.prototype.setSource = function(src) {
|
AssociateAbort.prototype.setSource = function(src) {
|
||||||
this.source = src;
|
this.source = src;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateAbort.prototype.setReason = function(reason) {
|
AssociateAbort.prototype.setReason = function(reason) {
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateAbort.prototype.readBytes = function(stream, length) {
|
AssociateAbort.prototype.readBytes = function(stream, length) {
|
||||||
stream.increment(2);
|
stream.increment(2);
|
||||||
@ -273,14 +294,14 @@ AssociateAbort.prototype.readBytes = function(stream, length) {
|
|||||||
|
|
||||||
var reason = stream.read(C.TYPE_UINT8);
|
var reason = stream.read(C.TYPE_UINT8);
|
||||||
this.setReason(reason);
|
this.setReason(reason);
|
||||||
};
|
}
|
||||||
|
|
||||||
AssociateAbort.prototype.getFields = function() {
|
AssociateAbort.prototype.getFields = function() {
|
||||||
return AssociateAbort.super_.prototype.getFields.call(this, [
|
return AssociateAbort.super_.prototype.getFields.call(this, [
|
||||||
new ReservedField(), new ReservedField(),
|
new ReservedField(), new ReservedField(),
|
||||||
new UInt8Field(this.source), new UInt8Field(this.reason)
|
new UInt8Field(this.source), new UInt8Field(this.reason)
|
||||||
]);
|
]);
|
||||||
};
|
}
|
||||||
|
|
||||||
ReleaseRQ = function() {
|
ReleaseRQ = function() {
|
||||||
this.type = C.ITEM_TYPE_PDU_RELEASE_RQ;
|
this.type = C.ITEM_TYPE_PDU_RELEASE_RQ;
|
||||||
@ -296,7 +317,7 @@ ReleaseRQ.prototype.getFields = function() {
|
|||||||
ReleaseRP = function() {
|
ReleaseRP = function() {
|
||||||
this.type = C.ITEM_TYPE_PDU_RELEASE_RP;
|
this.type = C.ITEM_TYPE_PDU_RELEASE_RP;
|
||||||
PDU.call(this);
|
PDU.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(ReleaseRP, PDU);
|
util.inherits(ReleaseRP, PDU);
|
||||||
|
|
||||||
@ -306,53 +327,51 @@ ReleaseRP.prototype.readBytes = function(stream, length) {
|
|||||||
|
|
||||||
ReleaseRP.prototype.getFields = function() {
|
ReleaseRP.prototype.getFields = function() {
|
||||||
return ReleaseRP.super_.prototype.getFields.call(this, [new ReservedField(4)]);
|
return ReleaseRP.super_.prototype.getFields.call(this, [new ReservedField(4)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
PDataTF = function() {
|
PDataTF = function() {
|
||||||
this.type = C.ITEM_TYPE_PDU_PDATA;
|
this.type = C.ITEM_TYPE_PDU_PDATA;
|
||||||
this.presentationDataValueItems = [];
|
this.presentationDataValueItems = [];
|
||||||
PDU.call(this);
|
PDU.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(PDataTF, PDU);
|
util.inherits(PDataTF, PDU);
|
||||||
|
|
||||||
PDataTF.prototype.setPresentationDataValueItems = function(items) {
|
PDataTF.prototype.setPresentationDataValueItems = function(items) {
|
||||||
this.presentationDataValueItems = items ? items : [];
|
this.presentationDataValueItems = items ? items : [];
|
||||||
};
|
}
|
||||||
|
|
||||||
PDataTF.prototype.getFields = function() {
|
PDataTF.prototype.getFields = function() {
|
||||||
var fields = this.presentationDataValueItems;
|
var fields = this.presentationDataValueItems;
|
||||||
|
|
||||||
return PDataTF.super_.prototype.getFields.call(this, fields);
|
return PDataTF.super_.prototype.getFields.call(this, fields);
|
||||||
};
|
}
|
||||||
|
|
||||||
PDataTF.prototype.readBytes = function(stream, length) {
|
PDataTF.prototype.readBytes = function(stream, length) {
|
||||||
var pdvs = this.loadPDV(stream, length);
|
var pdvs = this.loadPDV(stream, length);
|
||||||
//let merges = mergePDVs(pdvs);
|
//let merges = mergePDVs(pdvs);
|
||||||
|
|
||||||
this.setPresentationDataValueItems(pdvs);
|
this.setPresentationDataValueItems(pdvs);
|
||||||
};
|
}
|
||||||
|
|
||||||
Item = function() {
|
Item = function() {
|
||||||
PDU.call(this);
|
PDU.call(this);
|
||||||
this.lengthBytes = 2;
|
this.lengthBytes = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(Item, PDU);
|
util.inherits(Item, PDU);
|
||||||
|
|
||||||
Item.prototype.read = function(stream) {
|
Item.prototype.read = function(stream) {
|
||||||
stream.read(C.TYPE_HEX, 1);
|
stream.read(C.TYPE_HEX, 1);
|
||||||
var length = stream.read(C.TYPE_UINT16);
|
var length = stream.read(C.TYPE_UINT16);
|
||||||
this.readBytes(stream, length);
|
this.readBytes(stream, length);
|
||||||
};
|
}
|
||||||
|
|
||||||
Item.prototype.write = function(stream) {
|
Item.prototype.write = function(stream) {
|
||||||
stream.concat(this.stream());
|
stream.concat(this.stream());
|
||||||
};
|
}
|
||||||
|
|
||||||
Item.prototype.getFields = function(fields) {
|
Item.prototype.getFields = function(fields) {
|
||||||
return Item.super_.prototype.getFields.call(this, fields);
|
return Item.super_.prototype.getFields.call(this, fields);
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem = function(context) {
|
PresentationDataValueItem = function(context) {
|
||||||
this.type = null;
|
this.type = null;
|
||||||
@ -364,28 +383,27 @@ PresentationDataValueItem = function(context) {
|
|||||||
|
|
||||||
this.lengthBytes = 4;
|
this.lengthBytes = 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(PresentationDataValueItem, Item);
|
util.inherits(PresentationDataValueItem, Item);
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.setContextId = function(id) {
|
PresentationDataValueItem.prototype.setContextId = function(id) {
|
||||||
this.contextId = id;
|
this.contextId = id;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.setFlag = function(flag) {
|
PresentationDataValueItem.prototype.setFlag = function(flag) {
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.setPresentationDataValue = function(pdv) {
|
PresentationDataValueItem.prototype.setPresentationDataValue = function(pdv) {
|
||||||
this.pdv = pdv;
|
this.pdv = pdv;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.setMessage = function(msg) {
|
PresentationDataValueItem.prototype.setMessage = function(msg) {
|
||||||
this.dataFragment = msg;
|
this.dataFragment = msg;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.getMessage = function() {
|
PresentationDataValueItem.prototype.getMessage = function() {
|
||||||
return this.dataFragment;
|
return this.dataFragment;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.readBytes = function(stream, length) {
|
PresentationDataValueItem.prototype.readBytes = function(stream, length) {
|
||||||
this.contextId = stream.read(C.TYPE_UINT8);
|
this.contextId = stream.read(C.TYPE_UINT8);
|
||||||
@ -395,7 +413,7 @@ PresentationDataValueItem.prototype.readBytes = function(stream, length) {
|
|||||||
|
|
||||||
//load dicom messages
|
//load dicom messages
|
||||||
this.messageStream = stream.more(length - 2);
|
this.messageStream = stream.more(length - 2);
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationDataValueItem.prototype.getFields = function() {
|
PresentationDataValueItem.prototype.getFields = function() {
|
||||||
var fields = [new UInt8Field(this.contextId)];
|
var fields = [new UInt8Field(this.contextId)];
|
||||||
@ -415,59 +433,57 @@ PresentationDataValueItem.prototype.getFields = function() {
|
|||||||
|
|
||||||
console.log(tag.toString(), rst.read(C.TYPE_UINT32));*/
|
console.log(tag.toString(), rst.read(C.TYPE_UINT32));*/
|
||||||
return PresentationDataValueItem.super_.prototype.getFields.call(this, fields);
|
return PresentationDataValueItem.super_.prototype.getFields.call(this, fields);
|
||||||
};
|
}
|
||||||
|
|
||||||
ApplicationContextItem = function() {
|
ApplicationContextItem = function() {
|
||||||
this.type = C.ITEM_TYPE_APPLICATION_CONTEXT;
|
this.type = C.ITEM_TYPE_APPLICATION_CONTEXT;
|
||||||
this.applicationContextName = C.APPLICATION_CONTEXT_NAME;
|
this.applicationContextName = C.APPLICATION_CONTEXT_NAME;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(ApplicationContextItem, Item);
|
util.inherits(ApplicationContextItem, Item);
|
||||||
|
|
||||||
ApplicationContextItem.prototype.setApplicationContextName = function(name) {
|
ApplicationContextItem.prototype.setApplicationContextName = function(name) {
|
||||||
this.applicationContextName = name;
|
this.applicationContextName = name;
|
||||||
};
|
}
|
||||||
|
|
||||||
ApplicationContextItem.prototype.getFields = function() {
|
ApplicationContextItem.prototype.getFields = function() {
|
||||||
return ApplicationContextItem.super_.prototype.getFields.call(this, [new StringField(this.applicationContextName)]);
|
return ApplicationContextItem.super_.prototype.getFields.call(this, [new StringField(this.applicationContextName)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
ApplicationContextItem.prototype.readBytes = function(stream, length) {
|
ApplicationContextItem.prototype.readBytes = function(stream, length) {
|
||||||
var appContext = stream.read(C.TYPE_ASCII, length);
|
var appContext = stream.read(C.TYPE_ASCII, length);
|
||||||
this.setApplicationContextName(appContext);
|
this.setApplicationContextName(appContext);
|
||||||
};
|
}
|
||||||
|
|
||||||
ApplicationContextItem.prototype.buffer = function() {
|
ApplicationContextItem.prototype.buffer = function() {
|
||||||
return ApplicationContextItem.super_.prototype.buffer.call(this);
|
return ApplicationContextItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem = function() {
|
PresentationContextItem = function() {
|
||||||
this.type = C.ITEM_TYPE_PRESENTATION_CONTEXT;
|
this.type = C.ITEM_TYPE_PRESENTATION_CONTEXT;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(PresentationContextItem, Item);
|
util.inherits(PresentationContextItem, Item);
|
||||||
|
|
||||||
PresentationContextItem.prototype.setPresentationContextID = function(id) {
|
PresentationContextItem.prototype.setPresentationContextID = function(id) {
|
||||||
this.presentationContextID = id;
|
this.presentationContextID = id;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.setAbstractSyntaxItem = function(item) {
|
PresentationContextItem.prototype.setAbstractSyntaxItem = function(item) {
|
||||||
this.abstractSyntaxItem = item;
|
this.abstractSyntaxItem = item;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.setTransferSyntaxesItems = function(items) {
|
PresentationContextItem.prototype.setTransferSyntaxesItems = function(items) {
|
||||||
this.transferSyntaxesItems = items;
|
this.transferSyntaxesItems = items;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.setResultReason = function(reason) {
|
PresentationContextItem.prototype.setResultReason = function(reason) {
|
||||||
this.resultReason = reason;
|
this.resultReason = reason;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.accepted = function() {
|
PresentationContextItem.prototype.accepted = function() {
|
||||||
return this.resultReason == 0;
|
return this.resultReason == 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.readBytes = function(stream, length) {
|
PresentationContextItem.prototype.readBytes = function(stream, length) {
|
||||||
var contextId = stream.read(C.TYPE_UINT8);
|
var contextId = stream.read(C.TYPE_UINT8);
|
||||||
@ -484,7 +500,7 @@ PresentationContextItem.prototype.readBytes = function(stream, length) {
|
|||||||
transContexts.push(this.load(stream));
|
transContexts.push(this.load(stream));
|
||||||
} while (nextItemIs(stream, C.ITEM_TYPE_TRANSFER_CONTEXT));
|
} while (nextItemIs(stream, C.ITEM_TYPE_TRANSFER_CONTEXT));
|
||||||
this.setTransferSyntaxesItems(transContexts);
|
this.setTransferSyntaxesItems(transContexts);
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.getFields = function() {
|
PresentationContextItem.prototype.getFields = function() {
|
||||||
var f = [
|
var f = [
|
||||||
@ -495,17 +511,16 @@ PresentationContextItem.prototype.getFields = function() {
|
|||||||
f.push(syntaxItem);
|
f.push(syntaxItem);
|
||||||
});
|
});
|
||||||
return PresentationContextItem.super_.prototype.getFields.call(this, f);
|
return PresentationContextItem.super_.prototype.getFields.call(this, f);
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItem.prototype.buffer = function() {
|
PresentationContextItem.prototype.buffer = function() {
|
||||||
return PresentationContextItem.super_.prototype.buffer.call(this);
|
return PresentationContextItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
PresentationContextItemAC = function() {
|
PresentationContextItemAC = function() {
|
||||||
this.type = C.ITEM_TYPE_PRESENTATION_CONTEXT_AC;
|
this.type = C.ITEM_TYPE_PRESENTATION_CONTEXT_AC;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(PresentationContextItemAC, PresentationContextItem);
|
util.inherits(PresentationContextItemAC, PresentationContextItem);
|
||||||
|
|
||||||
PresentationContextItemAC.prototype.readBytes = function(stream, length) {
|
PresentationContextItemAC.prototype.readBytes = function(stream, length) {
|
||||||
@ -518,66 +533,63 @@ PresentationContextItemAC.prototype.readBytes = function(stream, length) {
|
|||||||
|
|
||||||
var transItem = this.load(stream);
|
var transItem = this.load(stream);
|
||||||
this.setTransferSyntaxesItems([transItem]);
|
this.setTransferSyntaxesItems([transItem]);
|
||||||
};
|
}
|
||||||
|
|
||||||
AbstractSyntaxItem = function() {
|
AbstractSyntaxItem = function() {
|
||||||
this.type = C.ITEM_TYPE_ABSTRACT_CONTEXT;
|
this.type = C.ITEM_TYPE_ABSTRACT_CONTEXT;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(AbstractSyntaxItem, Item);
|
util.inherits(AbstractSyntaxItem, Item);
|
||||||
|
|
||||||
AbstractSyntaxItem.prototype.setAbstractSyntaxName = function(name) {
|
AbstractSyntaxItem.prototype.setAbstractSyntaxName = function(name) {
|
||||||
this.abstractSyntaxName = name;
|
this.abstractSyntaxName = name;
|
||||||
};
|
}
|
||||||
|
|
||||||
AbstractSyntaxItem.prototype.getFields = function() {
|
AbstractSyntaxItem.prototype.getFields = function() {
|
||||||
return AbstractSyntaxItem.super_.prototype.getFields.call(this, [new StringField(this.abstractSyntaxName)]);
|
return AbstractSyntaxItem.super_.prototype.getFields.call(this, [new StringField(this.abstractSyntaxName)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
AbstractSyntaxItem.prototype.buffer = function() {
|
AbstractSyntaxItem.prototype.buffer = function() {
|
||||||
return AbstractSyntaxItem.super_.prototype.buffer.call(this);
|
return AbstractSyntaxItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
AbstractSyntaxItem.prototype.readBytes = function(stream, length) {
|
AbstractSyntaxItem.prototype.readBytes = function(stream, length) {
|
||||||
var name = stream.read(C.TYPE_ASCII, length);
|
var name = stream.read(C.TYPE_ASCII, length);
|
||||||
this.setAbstractSyntaxName(name);
|
this.setAbstractSyntaxName(name);
|
||||||
};
|
}
|
||||||
|
|
||||||
TransferSyntaxItem = function() {
|
TransferSyntaxItem = function() {
|
||||||
this.type = C.ITEM_TYPE_TRANSFER_CONTEXT;
|
this.type = C.ITEM_TYPE_TRANSFER_CONTEXT;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(TransferSyntaxItem, Item);
|
util.inherits(TransferSyntaxItem, Item);
|
||||||
|
|
||||||
TransferSyntaxItem.prototype.setTransferSyntaxName = function(name) {
|
TransferSyntaxItem.prototype.setTransferSyntaxName = function(name) {
|
||||||
this.transferSyntaxName = name;
|
this.transferSyntaxName = name;
|
||||||
};
|
}
|
||||||
|
|
||||||
TransferSyntaxItem.prototype.readBytes = function(stream, length) {
|
TransferSyntaxItem.prototype.readBytes = function(stream, length) {
|
||||||
var transfer = stream.read(C.TYPE_ASCII, length);
|
var transfer = stream.read(C.TYPE_ASCII, length);
|
||||||
this.setTransferSyntaxName(transfer);
|
this.setTransferSyntaxName(transfer);
|
||||||
};
|
}
|
||||||
|
|
||||||
TransferSyntaxItem.prototype.getFields = function() {
|
TransferSyntaxItem.prototype.getFields = function() {
|
||||||
return TransferSyntaxItem.super_.prototype.getFields.call(this, [new StringField(this.transferSyntaxName)]);
|
return TransferSyntaxItem.super_.prototype.getFields.call(this, [new StringField(this.transferSyntaxName)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
TransferSyntaxItem.prototype.buffer = function() {
|
TransferSyntaxItem.prototype.buffer = function() {
|
||||||
return TransferSyntaxItem.super_.prototype.buffer.call(this);
|
return TransferSyntaxItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
UserInformationItem = function() {
|
UserInformationItem = function() {
|
||||||
this.type = C.ITEM_TYPE_USER_INFORMATION;
|
this.type = C.ITEM_TYPE_USER_INFORMATION;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
util.inherits(UserInformationItem, Item);
|
util.inherits(UserInformationItem, Item);
|
||||||
|
|
||||||
UserInformationItem.prototype.setUserDataItems = function(items) {
|
UserInformationItem.prototype.setUserDataItems = function(items) {
|
||||||
this.userDataItems = items;
|
this.userDataItems = items;
|
||||||
};
|
}
|
||||||
|
|
||||||
UserInformationItem.prototype.readBytes = function(stream, length) {
|
UserInformationItem.prototype.readBytes = function(stream, length) {
|
||||||
var items = [], pdu = this.load(stream);
|
var items = [], pdu = this.load(stream);
|
||||||
@ -586,7 +598,7 @@ UserInformationItem.prototype.readBytes = function(stream, length) {
|
|||||||
items.push(pdu);
|
items.push(pdu);
|
||||||
} while (pdu = this.load(stream));
|
} while (pdu = this.load(stream));
|
||||||
this.setUserDataItems(items);
|
this.setUserDataItems(items);
|
||||||
};
|
}
|
||||||
|
|
||||||
UserInformationItem.prototype.getFields = function() {
|
UserInformationItem.prototype.getFields = function() {
|
||||||
var f = [];
|
var f = [];
|
||||||
@ -594,82 +606,79 @@ UserInformationItem.prototype.getFields = function() {
|
|||||||
f.push(userData);
|
f.push(userData);
|
||||||
});
|
});
|
||||||
return UserInformationItem.super_.prototype.getFields.call(this, f);
|
return UserInformationItem.super_.prototype.getFields.call(this, f);
|
||||||
};
|
}
|
||||||
|
|
||||||
UserInformationItem.prototype.buffer = function() {
|
UserInformationItem.prototype.buffer = function() {
|
||||||
return UserInformationItem.super_.prototype.buffer.call(this);
|
return UserInformationItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationClassUIDItem = function() {
|
ImplementationClassUIDItem = function() {
|
||||||
this.type = C.ITEM_TYPE_IMPLEMENTATION_UID;
|
this.type = C.ITEM_TYPE_IMPLEMENTATION_UID;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(ImplementationClassUIDItem, Item);
|
util.inherits(ImplementationClassUIDItem, Item);
|
||||||
|
|
||||||
ImplementationClassUIDItem.prototype.setImplementationClassUID = function(id) {
|
ImplementationClassUIDItem.prototype.setImplementationClassUID = function(id) {
|
||||||
this.implementationClassUID = id;
|
this.implementationClassUID = id;
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationClassUIDItem.prototype.readBytes = function(stream, length) {
|
ImplementationClassUIDItem.prototype.readBytes = function(stream, length) {
|
||||||
var uid = stream.read(C.TYPE_ASCII, length);
|
var uid = stream.read(C.TYPE_ASCII, length);
|
||||||
this.setImplementationClassUID(uid);
|
this.setImplementationClassUID(uid);
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationClassUIDItem.prototype.getFields = function() {
|
ImplementationClassUIDItem.prototype.getFields = function() {
|
||||||
return ImplementationClassUIDItem.super_.prototype.getFields.call(this, [new StringField(this.implementationClassUID)]);
|
return ImplementationClassUIDItem.super_.prototype.getFields.call(this, [new StringField(this.implementationClassUID)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationClassUIDItem.prototype.buffer = function() {
|
ImplementationClassUIDItem.prototype.buffer = function() {
|
||||||
return ImplementationClassUIDItem.super_.prototype.buffer.call(this);
|
return ImplementationClassUIDItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationVersionNameItem = function() {
|
ImplementationVersionNameItem = function() {
|
||||||
this.type = C.ITEM_TYPE_IMPLEMENTATION_VERSION;
|
this.type = C.ITEM_TYPE_IMPLEMENTATION_VERSION;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(ImplementationVersionNameItem, Item);
|
util.inherits(ImplementationVersionNameItem, Item);
|
||||||
|
|
||||||
ImplementationVersionNameItem.prototype.setImplementationVersionName = function(name) {
|
ImplementationVersionNameItem.prototype.setImplementationVersionName = function(name) {
|
||||||
this.implementationVersionName = name;
|
this.implementationVersionName = name;
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationVersionNameItem.prototype.readBytes = function(stream, length) {
|
ImplementationVersionNameItem.prototype.readBytes = function(stream, length) {
|
||||||
var name = stream.read(C.TYPE_ASCII, length);
|
var name = stream.read(C.TYPE_ASCII, length);
|
||||||
this.setImplementationVersionName(name);
|
this.setImplementationVersionName(name);
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationVersionNameItem.prototype.getFields = function() {
|
ImplementationVersionNameItem.prototype.getFields = function() {
|
||||||
return ImplementationVersionNameItem.super_.prototype.getFields.call(this, [new StringField(this.implementationVersionName)]);
|
return ImplementationVersionNameItem.super_.prototype.getFields.call(this, [new StringField(this.implementationVersionName)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
ImplementationVersionNameItem.prototype.buffer = function() {
|
ImplementationVersionNameItem.prototype.buffer = function() {
|
||||||
return ImplementationVersionNameItem.super_.prototype.buffer.call(this);
|
return ImplementationVersionNameItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
MaximumLengthItem = function() {
|
MaximumLengthItem = function() {
|
||||||
this.type = C.ITEM_TYPE_MAXIMUM_LENGTH;
|
this.type = C.ITEM_TYPE_MAXIMUM_LENGTH;
|
||||||
this.maximumLengthReceived = 32768;
|
this.maximumLengthReceived = 32768;
|
||||||
Item.call(this);
|
Item.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(MaximumLengthItem, Item);
|
util.inherits(MaximumLengthItem, Item);
|
||||||
|
|
||||||
MaximumLengthItem.prototype.setMaximumLengthReceived = function(length) {
|
MaximumLengthItem.prototype.setMaximumLengthReceived = function(length) {
|
||||||
this.maximumLengthReceived = length;
|
this.maximumLengthReceived = length;
|
||||||
};
|
}
|
||||||
|
|
||||||
MaximumLengthItem.prototype.readBytes = function(stream, length) {
|
MaximumLengthItem.prototype.readBytes = function(stream, length) {
|
||||||
var l = stream.read(C.TYPE_UINT32);
|
var l = stream.read(C.TYPE_UINT32);
|
||||||
this.setMaximumLengthReceived(l);
|
this.setMaximumLengthReceived(l);
|
||||||
};
|
}
|
||||||
|
|
||||||
MaximumLengthItem.prototype.getFields = function() {
|
MaximumLengthItem.prototype.getFields = function() {
|
||||||
return MaximumLengthItem.super_.prototype.getFields.call(this, [new UInt32Field(this.maximumLengthReceived)]);
|
return MaximumLengthItem.super_.prototype.getFields.call(this, [new UInt32Field(this.maximumLengthReceived)]);
|
||||||
};
|
}
|
||||||
|
|
||||||
MaximumLengthItem.prototype.buffer = function() {
|
MaximumLengthItem.prototype.buffer = function() {
|
||||||
return MaximumLengthItem.super_.prototype.buffer.call(this);
|
return MaximumLengthItem.super_.prototype.buffer.call(this);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ calcLength = function(type, value) {
|
|||||||
default :break;
|
default :break;
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
};
|
}
|
||||||
|
|
||||||
var RWStream = function() {
|
var RWStream = function() {
|
||||||
this.endian = C.BIG_ENDIAN;
|
this.endian = C.BIG_ENDIAN;
|
||||||
@ -28,19 +28,19 @@ var RWStream = function() {
|
|||||||
|
|
||||||
RWStream.prototype.setEndian = function(endian) {
|
RWStream.prototype.setEndian = function(endian) {
|
||||||
this.endian = endian;
|
this.endian = endian;
|
||||||
};
|
}
|
||||||
|
|
||||||
RWStream.prototype.getEncoding = function(type) {
|
RWStream.prototype.getEncoding = function(type) {
|
||||||
return RWStream.encodings[type];
|
return RWStream.encodings[type];
|
||||||
};
|
}
|
||||||
|
|
||||||
RWStream.prototype.getWriteType = function(type) {
|
RWStream.prototype.getWriteType = function(type) {
|
||||||
return RWStream.writes[this.endian][type];
|
return RWStream.writes[this.endian][type];
|
||||||
};
|
}
|
||||||
|
|
||||||
RWStream.prototype.getReadType = function(type) {
|
RWStream.prototype.getReadType = function(type) {
|
||||||
return RWStream.reads[this.endian][type];
|
return RWStream.reads[this.endian][type];
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream = function() {
|
WriteStream = function() {
|
||||||
RWStream.call(this);
|
RWStream.call(this);
|
||||||
@ -48,7 +48,7 @@ WriteStream = function() {
|
|||||||
this.rawBuffer = new Buffer(this.defaultBufferSize);
|
this.rawBuffer = new Buffer(this.defaultBufferSize);
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
this.contentSize = 0;
|
this.contentSize = 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
util.inherits(WriteStream, RWStream);
|
util.inherits(WriteStream, RWStream);
|
||||||
|
|
||||||
@ -57,15 +57,15 @@ WriteStream.prototype.increment = function(add) {
|
|||||||
if (this.offset > this.contentSize) {
|
if (this.offset > this.contentSize) {
|
||||||
this.contentSize = this.offset;
|
this.contentSize = this.offset;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.size = function() {
|
WriteStream.prototype.size = function() {
|
||||||
return this.contentSize;
|
return this.contentSize;
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.skip = function(amount) {
|
WriteStream.prototype.skip = function(amount) {
|
||||||
this.increment(amount);
|
this.increment(amount);
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.checkSize = function(length) {
|
WriteStream.prototype.checkSize = function(length) {
|
||||||
if (this.offset + length > this.rawBuffer.length) {
|
if (this.offset + length > this.rawBuffer.length) {
|
||||||
@ -75,15 +75,15 @@ WriteStream.prototype.checkSize = function(length) {
|
|||||||
this.rawBuffer.copy(newBuffer, 0, 0, this.contentSize);
|
this.rawBuffer.copy(newBuffer, 0, 0, this.contentSize);
|
||||||
this.rawBuffer = newBuffer;
|
this.rawBuffer = newBuffer;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.writeToBuffer = function(type, value, length) {
|
WriteStream.prototype.writeToBuffer = function(type, value, length) {
|
||||||
if (value === '' || value === null) return;
|
if (value === "" || value === null) return;
|
||||||
|
|
||||||
this.checkSize(length);
|
this.checkSize(length);
|
||||||
this.rawBuffer[this.getWriteType(type)](value, this.offset);
|
this.rawBuffer[this.getWriteType(type)](value, this.offset);
|
||||||
this.increment(length);
|
this.increment(length);
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.write = function(type, value) {
|
WriteStream.prototype.write = function(type, value) {
|
||||||
if (isString(type)) {
|
if (isString(type)) {
|
||||||
@ -91,28 +91,28 @@ WriteStream.prototype.write = function(type, value) {
|
|||||||
} else {
|
} else {
|
||||||
this.writeToBuffer(type, value, calcLength(type));
|
this.writeToBuffer(type, value, calcLength(type));
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.writeString = function(string, type) {
|
WriteStream.prototype.writeString = function(string, type) {
|
||||||
var encoding = this.getEncoding(type), length = Buffer.byteLength(string, encoding);
|
var encoding = this.getEncoding(type), length = Buffer.byteLength(string, encoding);
|
||||||
this.rawBuffer.write(string, this.offset, length, encoding);
|
this.rawBuffer.write(string, this.offset, length, encoding);
|
||||||
this.increment(length);
|
this.increment(length);
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.buffer = function() {
|
WriteStream.prototype.buffer = function() {
|
||||||
return this.rawBuffer.slice(0, this.contentSize);
|
return this.rawBuffer.slice(0, this.contentSize);
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.toReadBuffer = function() {
|
WriteStream.prototype.toReadBuffer = function() {
|
||||||
return new ReadStream(this.buffer());
|
return new ReadStream(this.buffer());
|
||||||
};
|
}
|
||||||
|
|
||||||
WriteStream.prototype.concat = function(newStream) {
|
WriteStream.prototype.concat = function(newStream) {
|
||||||
var newSize = this.size() + newStream.size();
|
var newSize = this.size() + newStream.size();
|
||||||
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
||||||
this.contentSize = newSize;
|
this.contentSize = newSize;
|
||||||
this.offset = newSize;
|
this.offset = newSize;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream = function(buffer) {
|
ReadStream = function(buffer) {
|
||||||
RWStream.call(this);
|
RWStream.call(this);
|
||||||
@ -124,26 +124,26 @@ util.inherits(ReadStream, RWStream);
|
|||||||
|
|
||||||
ReadStream.prototype.size = function() {
|
ReadStream.prototype.size = function() {
|
||||||
return this.rawBuffer.length;
|
return this.rawBuffer.length;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.increment = function(add) {
|
ReadStream.prototype.increment = function(add) {
|
||||||
this.offset += add;
|
this.offset += add;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.more = function(length) {
|
ReadStream.prototype.more = function(length) {
|
||||||
var newBuf = this.rawBuffer.slice(this.offset, this.offset + length);
|
var newBuf = this.rawBuffer.slice(this.offset, this.offset + length);
|
||||||
this.increment(length);
|
this.increment(length);
|
||||||
return new ReadStream(newBuf);
|
return new ReadStream(newBuf);
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.reset = function() {
|
ReadStream.prototype.reset = function() {
|
||||||
this.offset = 0;
|
this.offset = 0;
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.end = function() {
|
ReadStream.prototype.end = function() {
|
||||||
return this.offset >= this.size();
|
return this.offset >= this.size();
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.readFromBuffer = function(type, length) {
|
ReadStream.prototype.readFromBuffer = function(type, length) {
|
||||||
//this.checkSize(length);
|
//this.checkSize(length);
|
||||||
@ -151,7 +151,7 @@ ReadStream.prototype.readFromBuffer = function(type, length) {
|
|||||||
var value = this.rawBuffer[this.getReadType(type)](this.offset);
|
var value = this.rawBuffer[this.getReadType(type)](this.offset);
|
||||||
this.increment(length);
|
this.increment(length);
|
||||||
return value;
|
return value;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.read = function(type, length) {
|
ReadStream.prototype.read = function(type, length) {
|
||||||
var value = null;
|
var value = null;
|
||||||
@ -162,68 +162,68 @@ ReadStream.prototype.read = function(type, length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.readString = function(length, type) {
|
ReadStream.prototype.readString = function(length, type) {
|
||||||
var encoding = this.getEncoding(type),
|
var encoding = this.getEncoding(type),
|
||||||
str = this.rawBuffer.toString(encoding, this.offset, this.offset + length);
|
str = this.rawBuffer.toString(encoding, this.offset, this.offset + length);
|
||||||
this.increment(length);
|
this.increment(length);
|
||||||
return str;
|
return str;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.buffer = function() {
|
ReadStream.prototype.buffer = function() {
|
||||||
return this.rawBuffer;
|
return this.rawBuffer;
|
||||||
};
|
}
|
||||||
|
|
||||||
ReadStream.prototype.concat = function(newStream) {
|
ReadStream.prototype.concat = function(newStream) {
|
||||||
var newSize = this.size() + newStream.size();
|
var newSize = this.size() + newStream.size();
|
||||||
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
this.rawBuffer = Buffer.concat([this.buffer(), newStream.buffer()], newSize);
|
||||||
this.contentSize = newSize;
|
this.contentSize = newSize;
|
||||||
this.offset = newSize;
|
this.offset = newSize;
|
||||||
};
|
}
|
||||||
|
|
||||||
RWStream.writes = {};
|
RWStream.writes = {};
|
||||||
RWStream.writes[C.BIG_ENDIAN] = {};
|
RWStream.writes[C.BIG_ENDIAN] = {};
|
||||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT8] = 'writeUInt8';
|
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_UINT16] = "writeUInt16BE";
|
||||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_UINT32] = 'writeUInt32BE';
|
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_INT8] = "writeInt8";
|
||||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_INT16] = 'writeInt16BE';
|
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_INT32] = "writeInt32BE";
|
||||||
RWStream.writes[C.BIG_ENDIAN][C.TYPE_FLOAT] = 'writeFloatBE';
|
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_DOUBLE] = "writeDoubleBE";
|
||||||
|
|
||||||
RWStream.writes[C.LITTLE_ENDIAN] = {};
|
RWStream.writes[C.LITTLE_ENDIAN] = {};
|
||||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT8] = 'writeUInt8';
|
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_UINT16] = "writeUInt16LE";
|
||||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_UINT32] = 'writeUInt32LE';
|
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_INT8] = "writeInt8";
|
||||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_INT16] = 'writeInt16LE';
|
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_INT32] = "writeInt32LE";
|
||||||
RWStream.writes[C.LITTLE_ENDIAN][C.TYPE_FLOAT] = 'writeFloatLE';
|
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_DOUBLE] = "writeDoubleLE";
|
||||||
|
|
||||||
RWStream.reads = {};
|
RWStream.reads = {};
|
||||||
RWStream.reads[C.BIG_ENDIAN] = {};
|
RWStream.reads[C.BIG_ENDIAN] = {};
|
||||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT8] = 'readUInt8';
|
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_UINT16] = "readUInt16BE";
|
||||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_UINT32] = 'readUInt32BE';
|
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_INT8] = "readInt8";
|
||||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_INT16] = 'readInt16BE';
|
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_INT32] = "readInt32BE";
|
||||||
RWStream.reads[C.BIG_ENDIAN][C.TYPE_FLOAT] = 'readFloatBE';
|
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_DOUBLE] = "readDoubleBE";
|
||||||
|
|
||||||
RWStream.reads[C.LITTLE_ENDIAN] = {};
|
RWStream.reads[C.LITTLE_ENDIAN] = {};
|
||||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT8] = 'readUInt8';
|
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_UINT16] = "readUInt16LE";
|
||||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_UINT32] = 'readUInt32LE';
|
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_INT8] = "readInt8";
|
||||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_INT16] = 'readInt16LE';
|
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_INT32] = "readInt32LE";
|
||||||
RWStream.reads[C.LITTLE_ENDIAN][C.TYPE_FLOAT] = 'readFloatLE';
|
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_DOUBLE] = "readDoubleLE";
|
||||||
|
|
||||||
RWStream.encodings = {};
|
RWStream.encodings = {};
|
||||||
RWStream.encodings[C.TYPE_HEX] = 'hex';
|
RWStream.encodings[C.TYPE_HEX] = "hex";
|
||||||
RWStream.encodings[C.TYPE_ASCII] = 'ascii';
|
RWStream.encodings[C.TYPE_ASCII] = "ascii";
|
||||||
@ -1,36 +1,37 @@
|
|||||||
C = {
|
C = {
|
||||||
IMPLEM_UID: '1.2.840.0.1.3680045.8.641',
|
IMPLEM_UID : "1.2.840.0.1.3680045.8.641",
|
||||||
IMPLEM_VERSION: 'OHIF-DCM-0.1',
|
IMPLEM_VERSION : "OHIF-DCM-0.1",
|
||||||
APPLICATION_CONTEXT_NAME: '1.2.840.10008.3.1.1.1',
|
DEFAULT_MAX_PACKAGE_SIZE : 32768,
|
||||||
PROTOCOL_VERSION: '0001',
|
APPLICATION_CONTEXT_NAME : "1.2.840.10008.3.1.1.1",
|
||||||
ITEM_TYPE_RESERVED: '00',
|
PROTOCOL_VERSION : "0001",
|
||||||
ITEM_TYPE_APPLICATION_CONTEXT: '10',
|
ITEM_TYPE_RESERVED : "00",
|
||||||
ITEM_TYPE_PDU_ASSOCIATE_RQ: '01',
|
ITEM_TYPE_APPLICATION_CONTEXT : "10",
|
||||||
ITEM_TYPE_PDU_ASSOCIATE_AC: '02',
|
ITEM_TYPE_PDU_ASSOCIATE_RQ : "01",
|
||||||
ITEM_TYPE_PDU_PDATA: '04',
|
ITEM_TYPE_PDU_ASSOCIATE_AC : "02",
|
||||||
ITEM_TYPE_PDU_RELEASE_RQ: '05',
|
ITEM_TYPE_PDU_PDATA : "04",
|
||||||
ITEM_TYPE_PDU_RELEASE_RP: '06',
|
ITEM_TYPE_PDU_RELEASE_RQ : "05",
|
||||||
ITEM_TYPE_PDU_AABORT: '07',
|
ITEM_TYPE_PDU_RELEASE_RP : "06",
|
||||||
ITEM_TYPE_PRESENTATION_CONTEXT: '20',
|
ITEM_TYPE_PDU_AABORT : "07",
|
||||||
ITEM_TYPE_PRESENTATION_CONTEXT_AC: '21',
|
ITEM_TYPE_PRESENTATION_CONTEXT : "20",
|
||||||
ITEM_TYPE_ABSTRACT_CONTEXT: '30',
|
ITEM_TYPE_PRESENTATION_CONTEXT_AC : "21",
|
||||||
ITEM_TYPE_TRANSFER_CONTEXT: '40',
|
ITEM_TYPE_ABSTRACT_CONTEXT : "30",
|
||||||
ITEM_TYPE_USER_INFORMATION: '50',
|
ITEM_TYPE_TRANSFER_CONTEXT : "40",
|
||||||
ITEM_TYPE_MAXIMUM_LENGTH: '51',
|
ITEM_TYPE_USER_INFORMATION : "50",
|
||||||
ITEM_TYPE_IMPLEMENTATION_UID: '52',
|
ITEM_TYPE_MAXIMUM_LENGTH : "51",
|
||||||
ITEM_TYPE_IMPLEMENTATION_VERSION: '55',
|
ITEM_TYPE_IMPLEMENTATION_UID : "52",
|
||||||
IMPLICIT_LITTLE_ENDIAN: '1.2.840.10008.1.2',
|
ITEM_TYPE_IMPLEMENTATION_VERSION : "55",
|
||||||
EXPLICIT_LITTLE_ENDIAN: '1.2.840.10008.1.2.1',
|
IMPLICIT_LITTLE_ENDIAN : "1.2.840.10008.1.2",
|
||||||
EXPLICIT_BIG_ENDIAN: '1.2.840.10008.1.2.2',
|
EXPLICIT_LITTLE_ENDIAN : "1.2.840.10008.1.2.1",
|
||||||
SOP_PATIENT_ROOT_FIND: '1.2.840.10008.5.1.4.1.2.1.1',
|
EXPLICIT_BIG_ENDIAN : "1.2.840.10008.1.2.2",
|
||||||
SOP_PATIENT_ROOT_MOVE: '1.2.840.10008.5.1.4.1.2.1.2',
|
SOP_PATIENT_ROOT_FIND : "1.2.840.10008.5.1.4.1.2.1.1",
|
||||||
SOP_PATIENT_ROOT_GET: '1.2.840.10008.5.1.4.1.2.1.3',
|
SOP_PATIENT_ROOT_MOVE : "1.2.840.10008.5.1.4.1.2.1.2",
|
||||||
SOP_STUDY_ROOT_FIND: '1.2.840.10008.5.1.4.1.2.2.1',
|
SOP_PATIENT_ROOT_GET : "1.2.840.10008.5.1.4.1.2.1.3",
|
||||||
SOP_STUDY_ROOT_MOVE: '1.2.840.10008.5.1.4.1.2.2.2',
|
SOP_STUDY_ROOT_FIND : "1.2.840.10008.5.1.4.1.2.2.1",
|
||||||
SOP_STUDY_ROOT_GET: '1.2.840.10008.5.1.4.1.2.2.3',
|
SOP_STUDY_ROOT_MOVE : "1.2.840.10008.5.1.4.1.2.2.2",
|
||||||
SOP_VERIFICATION: '1.2.840.10008.1.1',
|
SOP_STUDY_ROOT_GET : "1.2.840.10008.5.1.4.1.2.2.3",
|
||||||
SOP_HANGING_PROTOCOL_FIND: '1.2.840.10008.5.1.4.38.2',
|
SOP_VERIFICATION : "1.2.840.10008.1.1",
|
||||||
SOP_MR_IMAGE_STORAGE: '1.2.840.10008.5.1.4.1.1.4',
|
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_ASCII : 1,
|
||||||
TYPE_HEX : 2,
|
TYPE_HEX : 2,
|
||||||
TYPE_UINT8 : 3,
|
TYPE_UINT8 : 3,
|
||||||
@ -78,10 +79,10 @@ C = {
|
|||||||
DATA_NOT_LAST : 0,
|
DATA_NOT_LAST : 0,
|
||||||
SOURCE_SERVICE_USER : 0,
|
SOURCE_SERVICE_USER : 0,
|
||||||
SOURCE_SERVICE_PROVIDER : 2,
|
SOURCE_SERVICE_PROVIDER : 2,
|
||||||
QUERY_RETRIEVE_LEVEL_PATIENT: 'PATIENT',
|
QUERY_RETRIEVE_LEVEL_PATIENT : "PATIENT",
|
||||||
QUERY_RETRIEVE_LEVEL_STUDY: 'STUDY',
|
QUERY_RETRIEVE_LEVEL_STUDY : "STUDY",
|
||||||
QUERY_RETRIEVE_LEVEL_SERIES: 'SERIES',
|
QUERY_RETRIEVE_LEVEL_SERIES : "SERIES",
|
||||||
QUERY_RETRIEVE_LEVEL_IMAGE: 'IMAGE',
|
QUERY_RETRIEVE_LEVEL_IMAGE : "IMAGE",
|
||||||
VALUE_LENGTH_UNDEFINED : 0xffffffff,
|
VALUE_LENGTH_UNDEFINED : 0xffffffff,
|
||||||
STATUS_SUCCESS : 0x0000,
|
STATUS_SUCCESS : 0x0000,
|
||||||
STATUS_CANCEL : 0xfe00,
|
STATUS_CANCEL : 0xfe00,
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
util = Npm.require('util');
|
util = Npm.require("util");
|
||||||
@ -18,10 +18,10 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dimse" : {
|
"dimse" : [{
|
||||||
"host" : "localhost",
|
"host" : "localhost",
|
||||||
"port" : 4242,
|
"port" : 4242,
|
||||||
"hostAE" : "ORTHANC"
|
"aeTitle" : "ORTHANCLOCAL"
|
||||||
},
|
}],
|
||||||
"defaultServiceType": "dimse"
|
"defaultServiceType": "dimse"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user