fw4spl
StudyEditor.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/widget/StudyEditor.hpp"
8 
9 #include "uiMedDataQt/constants.hpp"
10 #include "uiMedDataQt/InsertSeries.hpp"
11 
12 #include <fwData/String.hpp>
13 
14 #include <fwMedData/Series.hpp>
15 #include <fwMedData/Study.hpp>
16 
17 #include <fwMedDataTools/functions.hpp>
18 
19 #include <boost/algorithm/string.hpp>
20 
21 #include <QFormLayout>
22 #include <QGroupBox>
23 #include <QLineEdit>
24 
25 namespace uiMedDataQt
26 {
27 namespace widget
28 {
29 
30 //-----------------------------------------------------------------------------
31 
32 StudyEditor::StudyEditor(QWidget* parent) :
33  QWidget(parent)
34 {
35  m_date = new QLineEdit();
36  m_time = new QLineEdit();
37  m_referringPhysicianName = new QLineEdit();
38  m_description = new QLineEdit();
39  m_patientAge = new QLineEdit();
40 
41  QFormLayout* layout = new QFormLayout();
42 
43  layout->addRow(tr("Date"), m_date);
44  layout->addRow(tr("Time"), m_time);
45  layout->addRow(tr("Referring physician name"), m_referringPhysicianName);
46  layout->addRow(tr("Description"), m_description);
47  layout->addRow(tr("Patient age"), m_patientAge);
48 
49  QObject::connect(m_date, SIGNAL(textChanged(const QString&)), this, SLOT(onDateChanged(const QString&)));
50  QObject::connect(m_time, SIGNAL(textChanged(const QString&)), this, SLOT(onTimeChanged(const QString&)));
51  QObject::connect(m_description, SIGNAL(textChanged(const QString&)), this, SLOT(onDescChanged(const QString&)));
52 
53  QGroupBox* group = new QGroupBox(tr("Study"));
54  group->setLayout(layout);
55  QVBoxLayout* topLayout = new QVBoxLayout();
56  topLayout->addWidget(group);
57  this->setLayout(topLayout);
58 }
59 
60 //-----------------------------------------------------------------------------
61 
63 {
64  QObject::disconnect(m_date, SIGNAL(textChanged(const QString&)), this, SLOT(onDateChanged(const QString&)));
65  QObject::disconnect(m_time, SIGNAL(textChanged(const QString&)), this, SLOT(onTimeChanged(const QString&)));
66  QObject::disconnect(m_description, SIGNAL(textChanged(const QString&)), this,
67  SLOT(onDescChanged(const QString&)));
68 }
69 
70 //-----------------------------------------------------------------------------
71 
73 {
74  return !m_date->text().trimmed().isEmpty()
75  && m_description->text().trimmed().toStdString() != s_NEW_STUDY_TEXT
76  && !m_time->text().trimmed().isEmpty();
77 }
78 
79 //-----------------------------------------------------------------------------
80 
82 {
83  ::fwMedData::Study::sptr srcStudy = m_series->getStudy();
84  ::fwMedData::Study::sptr study = ::fwMedData::Study::New();
85  study->setDescription(m_description->text().trimmed().toStdString());
86  study->setDate(m_date->text().trimmed().toStdString());
87  study->setTime(m_time->text().trimmed().toStdString());
88  study->setReferringPhysicianName(m_referringPhysicianName->text().trimmed().toStdString());
89  study->setInstanceUID(srcStudy->getInstanceUID());
90  study->setPatientAge(srcStudy->getPatientAge());
91 
92  std::string date = srcStudy->getDate();
93  ::boost::algorithm::trim(date);
94  std::string time = srcStudy->getTime();
95  ::boost::algorithm::trim(time);
96  std::string refP = srcStudy->getReferringPhysicianName();
97  ::boost::algorithm::trim(refP);
98  std::string age = srcStudy->getPatientAge();
99  ::boost::algorithm::trim(age);
100 
101  // Study description comparison ommitted here
102  const bool same = study->getDate() == date
103  && study->getTime() == time
104  && study->getReferringPhysicianName() == refP
105  && study->getInstanceUID() == srcStudy->getInstanceUID()
106  && study->getPatientAge() == age;
107 
108  ::fwData::String::sptr fieldNewStudy = srcStudy->getField< ::fwData::String>(s_NEW_STUDY_FIELD_NAME);
109  if(fieldNewStudy || !same)
110  {
111  study->setInstanceUID(::fwMedDataTools::generateStudyInstanceUid());
112  }
113 
114  return study;
115 }
116 
117 //-----------------------------------------------------------------------------
118 
119 void StudyEditor::onDateChanged(const QString& text)
120 {
121  if(m_date->text().trimmed().isEmpty())
122  {
123  m_paletteDate.setColor(QPalette::Base, QColor(Qt::red));
124  }
125  else
126  {
127  m_paletteDate.setColor(QPalette::Base, QColor(Qt::white));
128  }
129 
130  m_date->setPalette(m_paletteDate);
131 }
132 
133 //-----------------------------------------------------------------------------
134 
135 void StudyEditor::onTimeChanged(const QString& text)
136 {
137  if(m_time->text().trimmed().isEmpty())
138  {
139  m_paletteTime.setColor(QPalette::Base, QColor(Qt::red));
140  }
141  else
142  {
143  m_paletteTime.setColor(QPalette::Base, QColor(Qt::white));
144  }
145 
146  m_time->setPalette(m_paletteTime);
147 }
148 
149 //-----------------------------------------------------------------------------
150 
151 void StudyEditor::onDescChanged(const QString& text)
152 {
153  if(m_description->text().trimmed().toStdString() == s_NEW_STUDY_TEXT)
154  {
155  m_paletteTime.setColor(QPalette::Base, QColor(Qt::red));
156  }
157  else
158  {
159  m_paletteTime.setColor(QPalette::Base, QColor(Qt::white));
160  }
161 
162  m_description->setPalette(m_paletteTime);
163 }
164 
165 //-----------------------------------------------------------------------------
166 
168 {
169  SLM_ASSERT("Given series is null", series);
170  m_series = series;
171 
172  ::fwMedData::Study::sptr study = m_series->getStudy();
173  SLM_ASSERT("Given series study is null", study);
174 
175  m_date->setText(QString::fromStdString(study->getDate()).trimmed());
176  m_time->setText(QString::fromStdString(study->getTime()).trimmed());
177  m_referringPhysicianName->setText(QString::fromStdString(study->getReferringPhysicianName()).trimmed());
178  m_description->setText(QString::fromStdString(study->getDescription()).trimmed());
179  m_patientAge->setText(QString::fromStdString(study->getPatientAge()).trimmed());
180 
181  // force signal (manage empty text case)
182  this->onTimeChanged(m_time->text());
183  this->onDateChanged(m_date->text());
184 
185 }
186 
187 //-----------------------------------------------------------------------------
188 
189 } // namespace widget
190 } // namespace uiMedDataQt
The namespace uiMedDataQt contains editors for medical data.
#define SPTR(_cls_)
UIMEDDATAQT_API StudyEditor(QWidget *parent=0)
Constructor.
Definition: StudyEditor.cpp:32
void onDateChanged(const QString &)
Triggered when study date text changes.
void onTimeChanged(const QString &)
Triggered when study time text changes.
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...
UIMEDDATAQT_API bool isValid() const
Returns true if the study information given through the editor is valid.
Definition: StudyEditor.cpp:72
UIMEDDATAQT_API void setSeries(std::shared_ptr< ::fwMedData::Series > series)
Set referring series.
Widget to edit fwMedData::Study information.
Definition: StudyEditor.hpp:34
UIMEDDATAQT_API ~StudyEditor()
Destructor.
Definition: StudyEditor.cpp:62
UIMEDDATAQT_API std::shared_ptr< ::fwMedData::Study > getStudy()
Returns the study object created by this editor.
Definition: StudyEditor.cpp:81
#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
void onDescChanged(const QString &)
Triggered when study description text changes.
This class contains an std::string value.