movescu operation save images at specified directory

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
focus
Posts: 77
Joined: Wed, 2005-03-16, 20:29
Location: Catalonia

movescu operation save images at specified directory

#1 Post by focus »

Hello! I'm developing a movescu program, I have been succesful in retrieve a study with all its images to my computer. But the problem is that I want to save the images in a specified directory like ./StudyUID/SeriesUID, like do efilm

Is there any way to get the StudyUID and SeriesUID during the retrive operation before starts to store images? I know that they can be get in the StoreScpCallback operation, but I would wish to get them before this operation, without using findscu.

Or the only way is using findscu before starts my movescu program? thanks for your help

Thomas Wilkens
DCMTK Developer
Posts: 117
Joined: Tue, 2004-11-02, 17:21
Location: Oldenburg, Germany
Contact:

#2 Post by Thomas Wilkens »

Unfortunately, the StudyInstanceUID and the SeriesInstanceUID are not known before the execution of the application enters the StoreScpCallback function.

However, I would like to point you to our command line application "storescp" which already has an option "--sort-conc-studies" through which it is possible to "sort concerning studies into subdirectories that start with prefix p" (from storescp.man). With regard to this option there are two possibilities for you:

a) You could integrate this "--sort-conc-studies" option into the storescp part of movescu; moreover, adding functionality to be able to sort the serieses into corresponding subdirectories should also not be that complicated.

b) You could configure movescu to send images not to itself but to a locally running storescp application which has option "--sort-conc-studies" turned on; as for your "sort serieses into subdirectories" requirement, you could modify the storescp application. (And if you did that, we would definitely be interested in the corresponding code. ;-))

If you ask me for my opinion, I think the latter alternative is the better one.

tjbrosnan
Posts: 2
Joined: Thu, 2006-01-12, 19:34

#3 Post by tjbrosnan »

Why not just modify storeSCPCallback() in movescu.cc?
Something like this seems to work:

Code: Select all

      if ((imageDataSet)&&(*imageDataSet)&&(!opt_bitPreserving)&&(!opt_ignore))
       {
         StoreCallbackData *cbdata = (StoreCallbackData*) callbackData;
         //const char* fileName = cbdata->imageFileName;

          OFString value;
          DcmTagKey key(0x0020, 0x000d);  // StudyInstanceUID
          OFCondition cond = (*imageDataSet)->findAndGetOFString(key, value);
          char StudyUID[64];
          sscanf(value.data(), "%s", StudyUID);

          key.set(0x0020, 0x000e);  // SeriesInstanceUID
          cond = (*imageDataSet)->findAndGetOFString(key, value);
          char SeriesUID[64];
          sscanf(value.data(), "%s", SeriesUID);

          key.set(0x0020, 0x0013);  // Instance Number (image number)
          cond = (*imageDataSet)->findAndGetOFString(key, value);
          unsigned int Image_number = 0;
          sscanf(value.data(), "%d", &Image_number);
          char command[1024];
          char output[1024];
          char newFileName[1024];
          sprintf(newFileName,"%s/%s/I%04d.dcm", StudyUID, SeriesUID,Image_number);
          sprintf(output,"I%04d.dcm", Image_number);

          if (opt_verbose) {
            cout << command << endl;
          }
         sprintf(command,"mkdir -p %s/%s", StudyUID, SeriesUID);
         system(command);
         const char* fileName = newFileName;
         cout << output << endl;

         E_TransferSyntax xfer = opt_writeTransferSyntax;
         if (xfer == EXS_Unknown) xfer = (*imageDataSet)->getOriginalXfer();

         cond = cbdata->dcmff->saveFile(fileName, xfer, opt_sequenceType, opt_groupLength,
           opt_paddingType, (Uint32)opt_filepad, (Uint32)opt_itempad, !opt_useMetaheader);
         if (cond.bad())
         {
           fprintf(stderr, "storescp: Cannot write image file: %s\n", fileName);
           rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources;
         }
         else {
            filesTransferred++;
         }

I defined filesTransferred at the top somewhere:

Code: Select all

int filesTransferred = 0;
This works for me.

Tom

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest