fw4spl
SInitNewSeries.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/action/SInitNewSeries.hpp"
8 
9 #include "uiMedDataQt/constants.hpp"
10 #include "uiMedDataQt/InsertSeries.hpp"
11 
12 #include <fwCore/base.hpp>
13 
14 #include <fwData/String.hpp>
15 
16 #include <fwMedData/Equipment.hpp>
17 #include <fwMedData/Patient.hpp>
18 #include <fwMedData/Series.hpp>
19 #include <fwMedData/SeriesDB.hpp>
20 #include <fwMedData/Study.hpp>
21 
22 #include <fwMedDataTools/helper/SeriesDB.hpp>
23 
24 #include <fwServices/macros.hpp>
25 
26 #include <fwTools/dateAndTime.hpp>
27 
28 #include <boost/algorithm/string/classification.hpp>
29 #include <boost/algorithm/string/split.hpp>
30 #include <boost/date_time/posix_time/posix_time.hpp>
31 
32 #include <utility>
33 #include <vector>
34 
35 namespace uiMedDataQt
36 {
37 
38 namespace action
39 {
40 
41 //------------------------------------------------------------------------------
42 
44 
45 //------------------------------------------------------------------------------
46 
48  m_defaultInstitution("")
49 {
50 }
51 
52 //------------------------------------------------------------------------------
53 
54 SInitNewSeries::~SInitNewSeries() noexcept
55 {
56 }
57 
58 //------------------------------------------------------------------------------
59 
60 void SInitNewSeries::info(std::ostream& _sstream )
61 {
62  // Update message
63  _sstream << std::string("SInitNewSeries");
64 }
65 
66 //------------------------------------------------------------------------------
67 
68 void SInitNewSeries::starting()
69 {
70  FW_DEPRECATED_MSG("This service is no longer supported.", "18.0");
71  this->actionServiceStarting();
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 void SInitNewSeries::stopping()
77 {
78  this->actionServiceStopping();
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 void SInitNewSeries::updating()
84 {
85  using namespace ::boost::posix_time;
86 
87  ::fwMedData::SeriesDB::sptr seriesDB = this->getObject< ::fwMedData::SeriesDB >();
88  seriesDB->getContainer().clear();
89 
90  ::fwTools::Object::sptr obj = ::fwTools::fwID::getObject(m_seriesDBId);
91  SLM_ASSERT("Didn't find object with UID '" + m_seriesDBId + "'", obj);
92  ::fwMedData::SeriesDB::sptr srcSeriesDB = ::fwMedData::SeriesDB::dynamicCast(obj);
93 
94  ::fwMedDataTools::helper::SeriesDB helper(seriesDB);
95 
96  for(const ::fwMedData::Series::sptr& series : srcSeriesDB->getContainer())
97  {
98  helper.add(series);
99  }
100 
101  typedef std::map< std::string, ::fwMedData::Patient::sptr> StudyToPatientType;
102  typedef std::map< std::string, ::fwMedData::Study::sptr> StudyMapType;
103 
104  StudyToPatientType studyToPatient;
105  StudyMapType studies;
106 
107  for(const ::fwMedData::Series::sptr& series : seriesDB->getContainer())
108  {
109  const std::string& studyUID = series->getStudy()->getInstanceUID();
110 
111  studies[studyUID] = series->getStudy();
112  studyToPatient[studyUID] = series->getPatient();
113  }
114 
115  ptime now = second_clock::local_time();
116 
117  const std::string date = ::fwTools::getDate(now);
118  const std::string time = ::fwTools::getTime(now);
119 
120  for(const StudyMapType::value_type& study : studies)
121  {
122  ::fwMedData::Series::sptr newSeries = ::uiMedDataQt::InsertSeries::New();
123  newSeries->setDescription(s_INSERT_NEW_SERIES_TEXT);
124  newSeries->setDate(date);
125  newSeries->setTime(time);
126  newSeries->setStudy(study.second);
127  newSeries->setPatient(studyToPatient[study.first]);
128 
129  helper.add(newSeries);
130  }
131 
132  ::fwMedData::Study::sptr newStudy = ::fwMedData::Study::New();
133  newStudy->setField(s_NEW_STUDY_FIELD_NAME, ::fwData::String::New("NEW_STUDY"));
134  newStudy->setDate(date);
135  newStudy->setTime(time);
136  newStudy->setDescription(s_NEW_STUDY_TEXT);
137 
138  ::fwMedData::Patient::sptr newPatient = ::fwMedData::Patient::New();
139  newPatient->setField(s_NEW_PATIENT_FIELD_NAME, ::fwData::String::New("NEW_PATIENT"));
140  newPatient->setName(s_NEW_PATIENT_TEXT);
141  newPatient->setBirthdate(date + " " + time);
142 
143  ::fwMedData::Equipment::sptr newEquipment = ::fwMedData::Equipment::New();
144  newEquipment->setInstitutionName(m_defaultInstitution);
145 
146  ::fwMedData::Series::sptr newSeries = ::uiMedDataQt::InsertSeries::New();
147  newSeries->setDescription(s_INSERT_NEW_SERIES_TEXT);
148  newSeries->setStudy(newStudy);
149  newSeries->setPatient(newPatient);
150  newSeries->setEquipment(newEquipment);
151  newSeries->setDate(date);
152  newSeries->setTime(time);
153 
154  helper.add(newSeries);
155  helper.notify();
156 }
157 
158 //------------------------------------------------------------------------------
159 
160 void SInitNewSeries::configuring()
161 {
163 
164  std::vector < ::fwRuntime::ConfigurationElement::sptr > seriesCfg = m_configuration->find("seriesDB");
165  SLM_ASSERT("Missing tag 'seriesDB'", !seriesCfg.empty());
166 
167  m_seriesDBId = seriesCfg.front()->getValue();
168  SLM_ASSERT("seriesDB must not be empty", !m_seriesDBId.empty());
169 
170  std::vector < ::fwRuntime::ConfigurationElement::sptr > institutionCfg = m_configuration->find("institution");
171  if(!institutionCfg.empty())
172  {
173  m_defaultInstitution = institutionCfg.front()->getValue();
174  }
175 }
176 
177 //------------------------------------------------------------------------------
178 
179 } // namespace action
180 }
The namespace uiMedDataQt contains editors for medical data.
FWMEDDATATOOLS_API void add(::fwMedData::Series::sptr newSeries)
Add a Series in the SeriesDB.
This action allows to update uiMedDataQt::editor::SSelector UI in order to add new series...
#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...
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
#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
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
UIMEDDATAQT_API SInitNewSeries()
Constructor.
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
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