fw4spl
SSeries.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "uiMedDataQt/editor/SSeries.hpp"
8 
9 #include "uiMedDataQt/widget/EquipmentEditor.hpp"
10 #include "uiMedDataQt/widget/PatientEditor.hpp"
11 #include "uiMedDataQt/widget/SeriesEditor.hpp"
12 #include "uiMedDataQt/widget/StudyEditor.hpp"
13 
14 #include <fwCom/Signal.hxx>
15 #include <fwCom/Slots.hxx>
16 
17 #include <fwData/Vector.hpp>
18 
19 #include <fwGui/dialog/MessageDialog.hpp>
20 
21 #include <fwGuiQt/container/QtContainer.hpp>
22 
23 #include <fwMedData/Patient.hpp>
24 #include <fwMedData/Study.hpp>
25 
26 #include <fwMedDataTools/functions.hpp>
27 #include <fwMedDataTools/helper/SeriesDB.hpp>
28 
29 #include <fwServices/macros.hpp>
30 
31 #include <fwTools/Object.hpp>
32 
33 #include <QHBoxLayout>
34 #include <QLabel>
35 #include <QLineEdit>
36 #include <QPushButton>
37 #include <QVBoxLayout>
38 #include <QWidget>
39 
40 namespace uiMedDataQt
41 {
42 namespace editor
43 {
44 
45 fwServicesRegisterMacro( ::fwGui::editor::IEditor, ::uiMedDataQt::editor::SSeries, ::fwData::Vector );
46 
47 const ::fwCom::Signals::SignalKeyType SSeries::s_EXPORT_SLOT = "export";
48 const ::fwCom::Signals::SignalKeyType SSeries::s_SERIES_EXPORTED_SIG = "seriesExported";
49 const ::fwCom::Signals::SignalKeyType SSeries::s_CAN_EXPORT_SIG = "canExport";
50 
51 //------------------------------------------------------------------------------
52 
54 {
55  m_slotExport = ::fwCom::newSlot( &SSeries::onExportClicked, this );
56  ::fwCom::HasSlots::m_slots( s_EXPORT_SLOT, m_slotExport );
57 
58  m_sigCanExport = CanExportSignalType::New();
59  m_sigSeriesExported = SeriesExportedSignalType::New();
60 
61  ::fwCom::HasSignals::m_signals
62  (s_CAN_EXPORT_SIG, m_sigCanExport)
63  (s_SERIES_EXPORTED_SIG, m_sigSeriesExported)
64  ;
65 
66  // worker was set by IService
67  ::fwCom::HasSlots::m_slots.setWorker( m_associatedWorker );
68 }
69 
70 //------------------------------------------------------------------------------
71 
73 {
74 }
75 
76 //------------------------------------------------------------------------------
77 
79 {
80  FW_DEPRECATED_MSG("This service is no longer supported.", "18.0");
81 
83 
84  ::fwGuiQt::container::QtContainer::sptr qtContainer
85  = ::fwGuiQt::container::QtContainer::dynamicCast(this->getContainer());
86 
87  QWidget* const container = qtContainer->getQtContainer();
88  SLM_ASSERT("container not instanced", container);
89 
90  m_patientEditor = new ::uiMedDataQt::widget::PatientEditor();
91  m_studyEditor = new ::uiMedDataQt::widget::StudyEditor();
92  m_equipmentEditor = new ::uiMedDataQt::widget::EquipmentEditor();
93  m_seriesEditor = new ::uiMedDataQt::widget::SeriesEditor();
94 
95  QVBoxLayout* studyEquipmentLayout = new QVBoxLayout();
96  studyEquipmentLayout->addWidget(m_studyEditor);
97  studyEquipmentLayout->addWidget(m_equipmentEditor);
98 
99  QHBoxLayout* editorLayout = new QHBoxLayout();
100  editorLayout->addWidget(m_patientEditor);
101  editorLayout->addLayout(studyEquipmentLayout);
102  editorLayout->addWidget(m_seriesEditor);
103 
104  QVBoxLayout* layout = new QVBoxLayout(container);
105  layout->addLayout(editorLayout);
106 
107  m_btnExport = new QPushButton(tr("Export series"));
108  m_btnExport->setEnabled(false);
109  m_btnExport->setVisible(m_sigCanExport->getNumberOfConnections() == 0);
110  m_sigCanExport->asyncEmit(false);
111  QHBoxLayout* btnLayout = new QHBoxLayout();
112  btnLayout->setAlignment(Qt::AlignRight);
113  btnLayout->setSizeConstraint(QLayout::SetFixedSize);
114  btnLayout->addWidget(m_btnExport);
115  layout->addLayout(btnLayout);
116  QObject::connect(m_btnExport, SIGNAL(clicked()), this, SLOT(onExportClicked()));
117 }
118 
119 //------------------------------------------------------------------------------
120 
122 {
123  this->destroy();
124 }
125 
126 //------------------------------------------------------------------------------
127 
129 {
130  ::fwData::Vector::sptr vector = this->getObject< ::fwData::Vector >();
131  SLM_ASSERT("Failed to retrieve vector", vector);
132 
133  m_btnExport->setVisible(m_sigCanExport->getNumberOfConnections() == 0);
134 
135  if(!vector->empty())
136  {
137 
138  ::fwTools::Object::sptr obj = ::fwTools::fwID::getObject(m_seriesId);
139  SLM_ASSERT("Failed to retrieve object with UID '" + m_seriesId + "'", obj);
140  ::fwMedData::Series::sptr seriesSrc = ::fwMedData::Series::dynamicCast(obj);
141  SLM_ASSERT("Failed to retrieve a ::fwMedData::Series from object '" << m_seriesId << "'", seriesSrc);
142 
143  ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast((*vector)[0]);
144  SLM_ASSERT("Failed to retrieve ::fwMedData::Series from vector", series);
145  series->setDescription(seriesSrc->getDescription());
146  series->setPerformingPhysiciansName(seriesSrc->getPerformingPhysiciansName());
147 
148  m_patientEditor->setSeries(series);
149  m_studyEditor->setSeries(series);
150  m_equipmentEditor->setSeries(series);
151  m_seriesEditor->setSeries(series);
152  m_btnExport->setEnabled(true);
153  m_sigCanExport->asyncEmit(true);
154  }
155  else
156  {
157  m_btnExport->setEnabled(false);
158  m_sigCanExport->asyncEmit(false);
159  }
160 }
161 
162 //------------------------------------------------------------------------------
163 
165 {
166  SLM_TRACE_FUNC();
167 
168  ::fwTools::Object::sptr obj = ::fwTools::fwID::getObject(m_seriesId);
169  SLM_ASSERT("Failed to retrieve object with UID '" + m_seriesId + "'", obj);
170  ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
171  SLM_ASSERT("Failed to retrieve a ::fwMedData::Series from object '" << m_seriesId << "'", series);
172 
173  ::fwTools::Object::sptr objDB = ::fwTools::fwID::getObject(m_seriesDBId);
174  SLM_ASSERT("Failed to retrieve object with UID '" + m_seriesDBId + "'", objDB);
175  ::fwMedData::SeriesDB::sptr seriesDB = ::fwMedData::SeriesDB::dynamicCast(objDB);
176  SLM_ASSERT("Failed to retrieve a ::fwMedData::SeriesDB from object '" << m_seriesDBId << "'", seriesDB);
177 
178  if(m_patientEditor->isValid() && m_studyEditor->isValid()
179  && m_equipmentEditor->isValid() && m_seriesEditor->isValid())
180  {
181 
182  ::fwData::Vector::sptr vector = this->getObject< ::fwData::Vector >();
183  SLM_ASSERT("Failed to retrieve vector", vector);
184  ::fwMedData::Series::sptr seriesVec = ::fwMedData::Series::dynamicCast((*vector)[0]);
185  SLM_ASSERT("Failed to retrieve ::fwMedData::Series from vector", seriesVec);
186 
187  ::fwMedData::Patient::sptr patient = m_patientEditor->getPatient();
188  ::fwMedData::Study::sptr study = m_studyEditor->getStudy();
189 
190  // If a new patient is being created but the study edition didn't change a new study instance UID must be set
191  if(patient->getPatientId() != seriesVec->getPatient()->getPatientId())
192  {
193  study->setInstanceUID(::fwMedDataTools::generateStudyInstanceUid());
194  }
195 
196  series->setPatient(patient);
197  series->setStudy(study);
198  series->setEquipment(m_equipmentEditor->getEquipment());
199 
200  ::fwMedData::Series::sptr seriesInfo = m_seriesEditor->getSeries();
201  series->setModality(seriesInfo->getModality());
202  series->setDate(seriesInfo->getDate());
203  series->setTime(seriesInfo->getTime());
204  series->setDescription(seriesInfo->getDescription());
205  series->setPerformingPhysiciansName(seriesInfo->getPerformingPhysiciansName());
206 
207  ::fwMedDataTools::helper::SeriesDB helper(seriesDB);
208  ::fwMedData::SeriesDB::iterator it = std::find(seriesDB->begin(), seriesDB->end(), series);
209  if(it != seriesDB->end())
210  {
212  dlg.setTitle("The series already exists");
213  dlg.setMessage("This series has already been exported in series selector");
214  dlg.setIcon(::fwGui::dialog::IMessageDialog::INFO);
215 
216  dlg.show();
217  }
218  else
219  {
220  helper.add(series);
221  helper.notify();
222  }
223  m_sigSeriesExported->asyncEmit();
224  }
225  else
226  {
228  dlg.setTitle("Error : information validation failed");
229  dlg.setMessage("Given information are not valid : please fix incorrect values before exporting");
230  dlg.setIcon(::fwGui::dialog::IMessageDialog::CRITICAL);
231 
232  dlg.show();
233  }
234 }
235 
236 //------------------------------------------------------------------------------
237 
239 {
241 
242  std::vector< ::fwRuntime::ConfigurationElement::sptr > seriesCfg = m_configuration->find("seriesId");
243  SLM_ASSERT("Missing tag 'seriesId'", !seriesCfg.empty());
244 
245  m_seriesId = seriesCfg.front()->getValue();
246  SLM_ASSERT("seriesId must not be empty", !m_seriesId.empty());
247 
248  std::vector< ::fwRuntime::ConfigurationElement::sptr > seriesDBCfg = m_configuration->find("seriesDBId");
249  SLM_ASSERT("Missing tag 'seriesDBId'", !seriesDBCfg.empty());
250 
251  m_seriesDBId = seriesDBCfg.front()->getValue();
252  SLM_ASSERT("seriesDBId must not be empty", !m_seriesDBId.empty());
253 }
254 
255 //------------------------------------------------------------------------------
256 
258 {
259  KeyConnectionsType connections;
260 
261  connections.push_back( std::make_pair( ::fwData::Vector::s_ADDED_OBJECTS_SIG, s_UPDATE_SLOT ) );
262  connections.push_back( std::make_pair( ::fwData::Vector::s_REMOVED_OBJECTS_SIG, s_UPDATE_SLOT ) );
263 
264  return connections;
265 }
266 
267 //------------------------------------------------------------------------------
268 
269 } // namespace editor
270 } // namespace uiMedDataQt
virtual UIMEDDATAQT_API KeyConnectionsType getObjSrvConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: SSeries.cpp:257
The namespace uiMedDataQt contains editors for medical data.
FWMEDDATATOOLS_API std::string generateStudyInstanceUid()
Generates a random Dicom Study Instance UID using current time. It must be 16 char long and may be nu...
static UIMEDDATAQT_APIconst::fwCom::Slots::SlotKeyType s_EXPORT_SLOT
Slot triggering export.
Definition: SSeries.hpp:69
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Defines the service interface managing the editor service for object.
Definition: IEditor.hpp:25
Defines the generic message box for IHM. Use the Delegate design pattern.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
virtual UIMEDDATAQT_API ~SSeries() noexcept
Destructor.
Definition: SSeries.cpp:72
virtual void starting() override
Installs GUI : create container and add selector.
Definition: SSeries.cpp:78
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_OBJECTS_SIG
Type of signal when objects are added.
FWMEDDATATOOLS_API void add(::fwMedData::Series::sptr newSeries)
Add a Series in the SeriesDB.
UIMEDDATAQT_API SSeries()
Constructor.
Definition: SSeries.cpp:53
#define FW_DEPRECATED_MSG(message, version)
Use this macro when deprecating a function to warn the developer.
Definition: spyLog.hpp:360
Defines an helper to modify an fwMedData::SeriesDB and create in parallel the message to announce thi...
static UIMEDDATAQT_APIconst::fwCom::Signals::SignalKeyType s_SERIES_EXPORTED_SIG
Signal type and key triggered when the series has been exported to related series DB...
Definition: SSeries.hpp:55
This class defines a vector of objects.
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
virtual void updating() override
Fill selector with the series contained in SeriesDB.
Definition: SSeries.cpp:128
virtual void stopping() override
Destroys GUI.
Definition: SSeries.cpp:121
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: IService.hpp:449
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
void onExportClicked()
Triggered when export button is clicked.
Definition: SSeries.cpp:164
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
static UIMEDDATAQT_APIconst::fwCom::Signals::SignalKeyType s_CAN_EXPORT_SIG
Signal type and key triggered when the service export ability changes.
Definition: SSeries.hpp:62
std::shared_ptr< ::fwThread::Worker > m_associatedWorker
Associated worker.
Definition: IService.hpp:699
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_OBJECTS_SIG
Type of signal when objects are added.
Shows and edit fwMedData::Series information.
Definition: SSeries.hpp:37
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
FWGUI_API void initialize()
Initialize managers.
virtual void configuring() override
Definition: SSeries.cpp:238
static FWTOOLS_API std::shared_ptr< ::fwTools::Object > getObject(IDType requestID)
Retrieve the object attached to the given id. Return a null sptr if no correspondence exist...
Definition: fwID.cpp:117