7 #include "uiMedDataQt/widget/PatientEditor.hpp" 9 #include "uiMedDataQt/constants.hpp" 11 #include <fwData/String.hpp> 13 #include <fwMedData/Patient.hpp> 14 #include <fwMedData/Series.hpp> 16 #include <fwMedDataTools/functions.hpp> 18 #include <boost/algorithm/string.hpp> 21 #include <QFormLayout> 36 m_txtName =
new QLineEdit();
38 m_txtBirthdate =
new QLineEdit();
40 m_cbSex =
new QComboBox();
41 m_cbSex->addItem(QString::fromStdString(
"Male"));
42 m_cbSex->addItem(QString::fromStdString(
"Female"));
43 m_cbSex->addItem(QString::fromStdString(
"Unknown"));
45 QFormLayout* layout =
new QFormLayout();
46 layout->addRow(tr(
"&Name"), m_txtName);
47 layout->addRow(tr(
"&Birthdate"), m_txtBirthdate);
48 layout->addRow(tr(
"&Sex"), m_cbSex);
50 QObject::connect(m_txtName, SIGNAL(textChanged(
const QString &)),
this, SLOT(onNameChanged(
const QString &)));
51 QObject::connect(m_txtBirthdate, SIGNAL(textChanged(
const QString &)),
this, SLOT(onBirthChanged(
const QString &)));
53 QGroupBox* group =
new QGroupBox(tr(
"Patient"));
54 group->setLayout(layout);
55 QVBoxLayout* topLayout =
new QVBoxLayout();
56 topLayout->addWidget(group);
57 this->setLayout(topLayout);
64 QObject::disconnect(m_txtName, SIGNAL(textChanged(QString)),
this, SLOT(onNameChanged));
65 QObject::disconnect(m_txtBirthdate, SIGNAL(textChanged(QString)),
this, SLOT(onBirthdateChanged));
72 return !m_txtName->text().trimmed().isEmpty()
73 && m_txtName->text().trimmed().toStdString() != s_NEW_PATIENT_TEXT
74 && !m_txtBirthdate->text().trimmed().isEmpty();
79 void PatientEditor::onNameChanged(
const QString& text)
81 if(m_txtName->text().trimmed().isEmpty() || m_txtName->text().trimmed().toStdString() == s_NEW_PATIENT_TEXT)
83 m_paletteName.setColor(QPalette::Base, QColor(Qt::red));
87 m_paletteName.setColor(QPalette::Base, QColor(Qt::white));
90 m_txtName->setPalette(m_paletteName);
95 void PatientEditor::onBirthChanged(
const QString& text)
97 if(m_txtBirthdate->text().trimmed().isEmpty())
99 m_paletteBirthdate.setColor(QPalette::Base, QColor(Qt::red));
103 m_paletteBirthdate.setColor(QPalette::Base, QColor(Qt::white));
106 m_txtBirthdate->setPalette(m_paletteBirthdate);
113 ::fwMedData::Patient::sptr srcPatient = m_series->getPatient();
114 ::fwMedData::Patient::sptr patient = ::fwMedData::Patient::New();
115 patient->setName(m_txtName->text().trimmed().toStdString());
116 patient->setBirthdate(m_txtBirthdate->text().trimmed().toStdString());
117 patient->setPatientId(srcPatient->getPatientId());
119 const std::string sex = m_cbSex->currentText().toStdString();
122 patient->setSex(
"M");
124 else if(sex ==
"Female")
126 patient->setSex(
"F");
130 patient->setSex(
"O");
134 std::string srcPatientSex = srcPatient->getSex();
135 ::boost::algorithm::trim(srcPatientSex);
136 const bool compareSex = (srcPatientSex ==
"M" || srcPatientSex ==
"F" || srcPatientSex ==
"O");
138 std::string name = patient->getName();
139 ::boost::algorithm::trim(name);
140 std::string birth = patient->getBirthdate();
141 ::boost::algorithm::trim(birth);
142 std::string sexStr = patient->getSex();
143 ::boost::algorithm::trim(sexStr);
145 const bool same = srcPatient->getName() == name
146 && srcPatient->getBirthdate() == birth
147 && (compareSex ? (srcPatientSex == sexStr) :
true)
148 && srcPatient->getPatientId() == patient->getPatientId();
150 ::fwData::String::sptr fieldPatient = srcPatient->getField<
::fwData::String >(s_NEW_PATIENT_FIELD_NAME);
151 if(fieldPatient || !same)
166 ::fwMedData::Patient::sptr patient = m_series->getPatient();
167 SLM_ASSERT(
"Given series patient is null", patient);
169 m_txtName->setText(QString::fromStdString(patient->getName()).trimmed());
170 m_txtBirthdate->setText(QString::fromStdString(patient->getBirthdate()).trimmed());
173 this->onNameChanged(m_txtName->text());
174 this->onBirthChanged(m_txtBirthdate->text());
176 std::string sex = patient->getSex();
177 ::boost::algorithm::trim(sex);
181 m_cbSex->setCurrentIndex(0);
185 m_cbSex->setCurrentIndex(1);
189 m_cbSex->setCurrentIndex(2);
190 SLM_WARN_IF(
"Unknown patient sex for value '" + patient->getSex() +
"'", patient->getSex() !=
"O");
The namespace uiMedDataQt contains editors for medical data.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Holds patient information.
Holds series information.
This class contains an std::string value.
#define SLM_WARN_IF(message, cond)