7 #include "fwPacsIO/SeriesRetriever.hpp" 9 #include "fwPacsIO/exceptions/RequestFailure.hpp" 11 #include <fwDcmtkTools/Dictionary.hpp> 13 #include <fwRuntime/operations.hpp> 15 #include <fwThread/Worker.hpp> 17 #include <fwTools/System.hpp> 19 #include <boost/filesystem/operations.hpp> 21 #include <dcmtk/config/osconfig.h> 22 #include <dcmtk/dcmnet/diutil.h> 27 const ::fwCom::Slots::SlotKeyType SeriesRetriever::s_PROGRESS_CALLBACK_SLOT =
"CMoveProgressCallback";
46 unsigned short applicationport,
int timeout,
47 ProgressCallbackSlotType::sptr progressCallback)
54 if (!::boost::filesystem::exists(
m_path))
56 ::boost::filesystem::create_directories(
m_path);
63 this->setAETitle(applicationTitle.c_str());
64 this->setPort(applicationport);
67 ::boost::filesystem::path cfgPath =
68 ::fwRuntime::getLibraryResourceFilePath(
"fwPacsIO-" FWPACSIO_VER
"/storescp.cfg");
69 SLM_ASSERT(
"storescp.cfg not found !", ::boost::filesystem::exists(cfgPath));
70 this->loadAssociationCfgFile(cfgPath.string().c_str());
71 this->setAndCheckAssociationProfile(
"Default");
74 this->setConnectionTimeout(timeout);
75 this->setConnectionBlockingMode(DUL_NOBLOCK);
86 return this->listen().good();
92 const DcmPresentationContextInfo& presContextInfo)
97 if( incomingMsg->CommandField == DIMSE_C_STORE_RQ )
104 cond = DcmSCP::handleIncomingCommand(incomingMsg, presContextInfo);
113 T_ASC_PresentationContextID presID)
120 OSLM_TRACE(DIMSE_dumpMessage(tempStr, incomingMsg->msg.CStoreRQ, DIMSE_INCOMING, NULL, presID));
123 DcmDataset* dataset =
new DcmDataset();
124 if (this->receiveDIMSEDataset(&presID, &dataset).good())
131 if(dataset->findAndGetOFStringArray(DCM_SeriesInstanceUID, seriesID).good())
133 SLM_TRACE(
"Series Instance UID: " + std::string(seriesID.c_str()));
138 if (dataset->findAndGetOFStringArray(DCM_SOPInstanceUID, iname).good())
140 SLM_TRACE(
"SOP Instance UID: " + std::string(iname.c_str()));
144 ::boost::filesystem::path seriesPath = ::boost::filesystem::path(
m_path.string() + seriesID.c_str() +
"/");
145 if (!::boost::filesystem::exists(seriesPath))
147 ::boost::filesystem::create_directories(seriesPath);
151 std::string filePath = seriesPath.string() + iname.c_str();
152 dataset->saveFile(filePath.c_str());
155 T_DIMSE_C_StoreRSP rsp;
156 rsp.DimseStatus = STATUS_Success;
157 cond = this->sendSTOREResponse(presID, incomingMsg->msg.CStoreRQ, rsp.DimseStatus);
161 OSLM_TRACE(DIMSE_dumpMessage(tempStr, rsp, DIMSE_OUTGOING, NULL, presID));
165 const std::string msg =
"Cannot send C-STORE Response to the server.";
166 throw ::fwPacsIO::exceptions::RequestFailure(msg);
170 SLM_TRACE(
"C-STORE Response successfully sent.");
virtual OFCondition handleSTORERequest(T_DIMSE_Message *incomingMsg, T_ASC_PresentationContextID presID)
Handle C-STORE Request.
FWPACSIO_API void initialize(const std::string &applicationTitle, unsigned short applicationport, int timeout=3, ProgressCallbackSlotType::sptr progressCallback=ProgressCallbackSlotType::sptr())
Initialize the connection.
FWPACSIO_API ~SeriesRetriever()
Destructor.
fwPacsIO contains classes used to communicate with a PACS.
#define OSLM_TRACE(message)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual OFCondition handleIncomingCommand(T_DIMSE_Message *incomingMsg, const DcmPresentationContextInfo &presContextInfo) override
Handle Incoming Command (Override)
FWPACSIO_API bool start()
Start the server.
FWPACSIO_API SeriesRetriever()
Constructor.
#define SLM_TRACE(message)
ProgressCallbackSlotType::sptr m_progressCallback
Progress callback slot.
unsigned int m_instanceIndex
Dowloaded instance index.
::boost::filesystem::path m_path
Path where the files must be saved.