fw4spl
SExportSeries.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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/action/SExportSeries.hpp"
8 
9 #include <fwActivities/registry/Activities.hpp>
10 
11 #include <fwCom/Slot.hpp>
12 #include <fwCom/Slot.hxx>
13 #include <fwCom/Slots.hpp>
14 #include <fwCom/Slots.hxx>
15 
16 #include <fwCore/base.hpp>
17 
18 #include <fwGui/dialog/InputDialog.hpp>
19 
20 #include <fwMedData/ActivitySeries.hpp>
21 #include <fwMedData/SeriesDB.hpp>
22 
23 #include <fwMedDataTools/helper/SeriesDB.hpp>
24 
25 #include <fwServices/macros.hpp>
26 
27 #include <fwTools/Os.hpp>
28 
29 namespace uiMedDataQt
30 {
31 
32 namespace action
33 {
34 //------------------------------------------------------------------------------
35 
37 
38 const ::fwCom::Slots::SlotKeyType SExportSeries::s_CHECK_ADDED_SERIES_SLOT = "checkAddedSeries";
39 const ::fwCom::Slots::SlotKeyType SExportSeries::s_CHECK_REMOVED_SERIES_SLOT = "CheckRemovesSeries";
40 
41 const static std::string s_SERIESDB_INOUT = "seriesDB";
42 
43 //------------------------------------------------------------------------------
44 
46 {
47  newSlot(s_CHECK_ADDED_SERIES_SLOT, &SExportSeries::checkAddedSeries, this);
48  newSlot(s_CHECK_REMOVED_SERIES_SLOT, &SExportSeries::checkRemovedSeries, this);
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61  KeyConnectionsMap connections;
62  connections.push( s_SERIESDB_INOUT, ::fwMedData::SeriesDB::s_ADDED_SERIES_SIG, s_CHECK_ADDED_SERIES_SLOT );
63  connections.push( s_SERIESDB_INOUT, ::fwMedData::SeriesDB::s_REMOVED_SERIES_SIG, s_CHECK_REMOVED_SERIES_SLOT );
64 
65  return connections;
66 }
67 
68 //------------------------------------------------------------------------------
69 
71 {
73 }
74 
75 //------------------------------------------------------------------------------
76 
78 {
79  this->actionServiceStarting();
80  ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB>(s_SERIESDB_INOUT);
81 
82  for( ::fwMedData::Series::sptr series : seriesDB->getContainer() )
83  {
84  if(series == this->getSeries())
85  {
86  this->setIsExecutable(false);
87  }
88  }
89 }
90 
91 //------------------------------------------------------------------------------
92 
94 {
95  this->actionServiceStopping();
96 }
97 
98 //------------------------------------------------------------------------------
99 
101 {
102  ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB>(s_SERIESDB_INOUT);
103  ::fwMedData::Series::sptr series = this->getSeries();
104 
105  std::string description = series->getDescription();
106 
107  ::fwMedData::ActivitySeries::sptr activitySeries = ::fwMedData::ActivitySeries::dynamicCast(series);
108  if (activitySeries)
109  {
110  ::fwActivities::registry::Activities::sptr registry = ::fwActivities::registry::Activities::getDefault();
111  std::string id = activitySeries->getActivityConfigId();
112  OSLM_ASSERT("Activity information not found for" << id, registry->hasInfo(id));
113 
115  activityInfo = registry->getInfo(id);
116 
117  description = activitySeries->getDescription();
118  if(description.empty())
119  {
120  description = activityInfo.description;
121  }
122  }
123 
125  "Export activity", "Enter the series description", description);
126 
127  if(!description.empty())
128  {
129  ::fwMedData::DicomValuesType physicians = series->getPerformingPhysiciansName();
130  if(physicians.empty())
131  {
132  std::string username = ::fwTools::os::getEnv("USERNAME", fwTools::os::getEnv("LOGNAME", "Unknown"));
133  physicians.push_back(username);
134  }
135 
136  series->setPerformingPhysiciansName(physicians);
137  series->setDescription(description);
138 
139  ::fwMedDataTools::helper::SeriesDB seriesDBHelper(seriesDB);
140  seriesDBHelper.add(series);
141  seriesDBHelper.notify();
142  this->setIsExecutable(false);
143  }
144 }
145 
146 //------------------------------------------------------------------------------
147 
148 void SExportSeries::info(std::ostream& _sstream )
149 {
150  // Update message
151  _sstream << std::string("SExportSeries");
152 }
153 
154 //------------------------------------------------------------------------------
155 
156 ::fwMedData::Series::sptr SExportSeries::getSeries()
157 {
158  ::fwMedData::Series::sptr series = this->getInOut< ::fwMedData::Series>("series");
159  return series;
160 }
161 
162 //------------------------------------------------------------------------------
163 
164 void SExportSeries::checkAddedSeries(::fwMedData::SeriesDB::ContainerType addedSeries)
165 {
166  for( ::fwMedData::Series::sptr series : addedSeries )
167  {
168  if(series == this->getSeries())
169  {
170  this->setIsExecutable(false);
171  }
172  }
173 }
174 
175 //------------------------------------------------------------------------------
176 
177 void SExportSeries::checkRemovedSeries(::fwMedData::SeriesDB::ContainerType removedSeries)
178 {
179  for( ::fwMedData::Series::sptr series : removedSeries )
180  {
181  if(series == this->getSeries())
182  {
183  this->setIsExecutable(true);
184  }
185  }
186 }
187 
188 //------------------------------------------------------------------------------
189 
190 } // namespace action
191 } // namespace uiMedDataQt
The namespace uiMedDataQt contains editors for medical data.
Contains fwAtomsFilter::registry details.
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
virtual FWGUI_API void setIsExecutable(bool isExecutable)
Set the action service executable or not.
Definition: IActionSrv.cpp:205
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
Holds Activities configuration.
Definition: Activities.hpp:175
#define OSLM_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:310
static FWACTIVITIES_API Activities::sptr getDefault()
Return the default global instance of Activities.
Definition: Activities.cpp:226
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
This action allows to export the series specified in config to the SeriesDB. The export is performed ...
FWMEDDATATOOLS_API void add(::fwMedData::Series::sptr newSeries)
Add a Series in the SeriesDB.
Defines an helper to modify an fwMedData::SeriesDB and create in parallel the message to announce thi...
virtual UIMEDDATAQT_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_SERIES_SIG
Type of signal when series are added.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_SERIES_SIG
Type of signal when series are added.
virtual UIMEDDATAQT_API ~SExportSeries() noexcept
Destructor.
virtual void updating() override
Adds the series specified by m_seriesId in the SeriesDB.
FWTOOLS_API std::string getEnv(const std::string &name, bool *ok=NULL)
Returns a environment variable value.
Definition: Os.cpp:20
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
static FWGUI_API std::string showInputDialog(const std::string &title, const std::string &message, const std::string &text="")
virtual void stopping() override
Stops service. Does nothing.
virtual void starting() override
Starts service. If series associated with m_seriesId exists in SeriesDB, this action is not executabl...
virtual void info(std::ostream &_sstream) override
Write information in a stream.
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
virtual void configuring() override
This method is used to configure the service parameters.
UIMEDDATAQT_API SExportSeries()
Constructor.