Closed liaohongxing closed 8 months ago
Hello @liaohongxing! Thank you for your question!
Here's a snippet (actually it is a cut-down version of the SCP example) that can store a Dataset
received through C-STORE SCP to disk, as a DICOM part10 file.
const dcmjsDimse = require('dcmjs-dimse');
const { Server, Scp } = dcmjsDimse;
const { CStoreResponse } = dcmjsDimse.responses;
const {
Status,
PresentationContextResult,
TransferSyntax,
} = dcmjsDimse.constants;
class DcmjsDimseScp extends Scp {
constructor(socket, opts) {
super(socket, opts);
this.association = undefined;
}
// Handle incoming association requests
associationRequested(association) {
this.association = association;
const contexts = association.getPresentationContexts();
// TODO: Here you can filter only the image storage classes
// for which you are only interested
contexts.forEach((c) => {
const context = association.getPresentationContext(c.id);
context.setResult(
PresentationContextResult.Accept,
TransferSyntax.ExplicitVRLittleEndian);
});
this.sendAssociationAccept();
}
// Handle incoming C-STORE requests
cStoreRequest(request, callback) {
// Get received dataset
const dataset = request.getDataset();
// Generate a random filename based on time
const randomFileName = new Date().getTime().toString();
// Save the received dataset to disk, as a DICOM part10 file
dataset.toFile(`${randomFileName}.DCM`);
// Create a positive response
const response = CStoreResponse.fromRequest(request);
response.setStatus(Status.Success);
// Send back the response
callback(response);
}
// Handle incoming association release requests
associationReleaseRequested() {
this.sendAssociationReleaseResponse();
}
}
const server = new Server(DcmjsDimseScp);
server.on('networkError', (e) => {
console.log('Network error: ', e);
});
server.listen(2104);
Let me know if that works for you.
Thanks for your example, it seems that dcm elements data is stored in this example, I wonder if pixel data also exists in this dcm file
Yes, this example saves all received elements, including the pixel data.
Thank you for your patient answer, I will continue to try this library, this library is amazing
Thank you Sir!
An example of SCP-Cstore stored as a dcm file , Can you give me some guidance or an example