7 #include "ioDicomWeb/SSeriesPusher.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwData/Vector.hpp> 16 #include <fwGui/dialog/MessageDialog.hpp> 18 #include <fwMedData/DicomSeries.hpp> 19 #include <fwMedData/Series.hpp> 21 #include <fwNetworkIO/exceptions/Base.hpp> 22 #include <fwNetworkIO/helper/Series.hpp> 23 #include <fwNetworkIO/http/Request.hpp> 25 #include <fwPreferences/helper.hpp> 27 #include <fwServices/macros.hpp> 34 static const ::fwServices::IService::KeyType s_SERIES_IN =
"selectedSeries";
52 ::fwServices::IService::ConfigType configuration = this->
getConfigTree();
54 if(configuration.count(
"server"))
56 const std::string serverInfo = configuration.get(
"server",
"");
57 const std::string::size_type splitPosition = serverInfo.find(
':');
58 SLM_ASSERT(
"Server info not formatted correctly", splitPosition != std::string::npos);
60 const std::string hostnameStr = serverInfo.substr(0, splitPosition);
61 const std::string portStr = serverInfo.substr(splitPosition + 1, serverInfo.size());
63 m_serverHostnameKey = this->getPreferenceKey(hostnameStr);
64 m_serverPortKey = this->getPreferenceKey(portStr);
66 if(m_serverHostnameKey.empty())
68 m_serverHostname = hostnameStr;
70 if(m_serverPortKey.empty())
72 m_serverPort = std::stoi(portStr);
77 throw ::fwTools::Failed(
"'server' element not found");
83 std::string SSeriesPusher::getPreferenceKey(
const std::string& key)
const 85 std::string keyResult;
86 const size_t first = key.find(
'%');
87 const size_t last = key.rfind(
'%');
88 if (first == 0 && last == key.size() - 1)
90 keyResult = key.substr(1, key.size() - 2);
111 if(!m_serverHostnameKey.empty())
113 const std::string hostname = ::fwPreferences::getPreference(m_serverHostnameKey);
114 if(!hostname.empty())
116 m_serverHostname = hostname;
119 if(!m_serverPortKey.empty())
121 const std::string port = ::fwPreferences::getPreference(m_serverPortKey);
124 m_serverPort = std::stoi(port);
128 ::fwData::Vector::csptr selectedSeries = this->getInput< ::fwData::Vector >(s_SERIES_IN);
134 messageBox.
setTitle(
"Pushing Series");
135 messageBox.
setMessage(
"The service is already pushing data. Please wait until the pushing is done " 136 "before sending a new push request." );
137 messageBox.
setIcon(::fwGui::dialog::IMessageDialog::INFO);
138 messageBox.
addButton(::fwGui::dialog::IMessageDialog::OK);
141 else if(selectedSeries->empty())
145 messageBox.
setTitle(
"Pushing Series");
146 messageBox.
setMessage(
"Unable to push series, there is no series selected." );
147 messageBox.
setIcon(::fwGui::dialog::IMessageDialog::INFO);
148 messageBox.
addButton(::fwGui::dialog::IMessageDialog::OK);
160 void SSeriesPusher::pushSeries()
164 ::fwData::Vector::csptr seriesVector = this->getInput< ::fwData::Vector >(s_SERIES_IN);
166 const std::vector< ::fwMedData::DicomSeries::sptr > dataVector =
169 const size_t seriesVectorSize = seriesVector->size();
170 size_t nbSeriesSuccess = 0;
171 for(
const auto& dicomSeries : dataVector)
175 ::fwMedData::DicomSeries::DicomContainerType dicomContainer = dicomSeries->
getDicomContainer();
176 const size_t dicomContainerSize = dicomContainer.size();
178 size_t nbInstanceSuccess = 0;
181 for(
const auto& item : dicomContainer)
183 const ::fwMemory::BufferObject::sptr bufferObj = item.second;
184 const ::fwMemory::BufferObject::Lock lockerDest(bufferObj);
185 const char* buffer =
static_cast<char*
>(lockerDest.getBuffer());
186 const size_t size = bufferObj->getSize();
188 const QByteArray fileBuffer = QByteArray::fromRawData(buffer, size);
191 const std::string pacsServer(
"http://" + m_serverHostname +
":" + std::to_string(m_serverPort));
192 ::fwNetworkIO::http::Request::sptr request =
194 QByteArray seriesAnswer;
195 if (fileBuffer.size() != 0)
197 seriesAnswer = m_clientQt.
post(request, fileBuffer);
198 if (!seriesAnswer.isEmpty())
203 if (dicomContainerSize == nbInstanceSuccess)
205 this->displayMessage(
"Upload successful: " + std::to_string(nbSeriesSuccess) +
"/" +
206 std::to_string(seriesVectorSize),
false);
212 std::stringstream ss;
213 ss <<
"Host not found.\n" 214 <<
"Please check your configuration: \n" 215 <<
"Pacs host name: " << m_serverHostname <<
"\n" 216 <<
"Pacs port: " << m_serverPort <<
"\n";
217 this->displayMessage(ss.str(),
true);
228 void SSeriesPusher::displayMessage(
const std::string& message,
bool error)
const 232 messageBox.
setTitle((error ?
"Error" :
"Information"));
234 messageBox.
setIcon(error ? (::fwGui::dialog::IMessageDialog::CRITICAL): (::fwGui::dialog::IMessageDialog::INFO));
235 messageBox.
addButton(::fwGui::dialog::IMessageDialog::OK);
FWNETWORKIO_API QByteArray post(Request::sptr request, const QByteArray &body)
Performs POST request.
static FWNETWORKIO_API Request::sptr New(const std::string &url)
Creates a new Request with given url.
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Defines the generic message box for IHM. Use the Delegate design pattern.
virtual IODICOMWEB_API void starting() override
Does nothing.
#define SLM_WARN(message)
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
IODICOMWEB_API void updating() override
Checks the configuration and push the series.
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
IODICOMWEB_API SSeriesPusher() noexcept
Constructor.
virtual IODICOMWEB_API ~SSeriesPusher() noexcept
Destructor.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
virtual IODICOMWEB_API void stopping() override
Does nothing.
Implements exception for an HTTP host not found errors.
ioDicomWeb contains services use to deal with PACS through HTTP.
virtual IODICOMWEB_API void configuring() override
Gets the configuration.
const DicomContainerType & getDicomContainer() const
Dicom container.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
#define SLM_WARN_IF(message, cond)
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.