194 lines
6.9 KiB
C++
194 lines
6.9 KiB
C++
#include "WorklistTableModel.h"
|
|
|
|
#include "event/EventCenter.h"
|
|
|
|
WorklistTableModel::WorklistTableModel(QObject* aParent)
|
|
: QAbstractItemModel(aParent)
|
|
, mPatientList()
|
|
, mHeader(QStringList()<< tr("ID") << tr("Name") << tr("Birth Date") << tr("Gender") << tr("Add Date"))
|
|
{
|
|
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, this, &WorklistTableModel::reloadLanguage);
|
|
}
|
|
|
|
WorklistTableModel::~WorklistTableModel()
|
|
{
|
|
qDeleteAll(mPatientList);
|
|
}
|
|
|
|
QVariant WorklistTableModel::headerData(int aSection, Qt::Orientation aOrientation, int aRole) const
|
|
{
|
|
if(aOrientation == Qt::Horizontal && aRole == Qt::DisplayRole)
|
|
{
|
|
if(aSection < mHeader.size())
|
|
{
|
|
return mHeader[aSection];
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
int WorklistTableModel::rowCount(const QModelIndex &aParent) const
|
|
{
|
|
if (!aParent.isValid())
|
|
{
|
|
return mPatientList.count();
|
|
}
|
|
|
|
AbstractPatientInfomation* item = static_cast<AbstractPatientInfomation*>(aParent.internalPointer());
|
|
if(item->getType() != AbstractPatientInfomation::PatientType)
|
|
{
|
|
return 0;
|
|
}
|
|
PatientInformation* patientItem = static_cast<PatientInformation*>(item);
|
|
return patientItem->mAccessionList.count();
|
|
}
|
|
|
|
int WorklistTableModel::columnCount(const QModelIndex &aParent) const
|
|
{
|
|
return mHeader.size();
|
|
}
|
|
|
|
QModelIndex WorklistTableModel::index(int aRow, int aColumn, const QModelIndex &aParent) const
|
|
{
|
|
if (!hasIndex(aRow, aColumn, aParent))
|
|
{
|
|
return QModelIndex();
|
|
}
|
|
if (!aParent.isValid())
|
|
{
|
|
return createIndex(aRow, aColumn, mPatientList[aRow]);
|
|
}
|
|
AbstractPatientInfomation* item = static_cast<AbstractPatientInfomation*>(aParent.internalPointer());
|
|
|
|
if(item->getType() == AbstractPatientInfomation::PatientType)
|
|
{
|
|
PatientInformation* patientItem = static_cast<PatientInformation*>(item);
|
|
return createIndex(aRow, aColumn, patientItem->mAccessionList[aRow]);
|
|
}
|
|
return QModelIndex();
|
|
}
|
|
|
|
QVariant WorklistTableModel::data(const QModelIndex &aIndex, int aRole) const
|
|
{
|
|
if (aRole != Qt::DisplayRole)
|
|
{
|
|
return QVariant();
|
|
}
|
|
if (!aIndex.isValid())
|
|
{
|
|
return QVariant();
|
|
}
|
|
|
|
AbstractPatientInfomation* item = static_cast<AbstractPatientInfomation*>(aIndex.internalPointer());
|
|
if(item->getType() == AbstractPatientInfomation::PatientType)
|
|
{
|
|
PatientInformation* patientItem = dynamic_cast<PatientInformation*>(item);
|
|
switch (aIndex.column())
|
|
{
|
|
case 0:return patientItem->ID;
|
|
case 1:return patientItem->Name;
|
|
case 2:return patientItem->BirthDate;
|
|
case 3:return patientItem->Sex == "F" ? tr("Female") : (patientItem->Sex == "M" ? tr("Male") : tr("Other"));
|
|
case 4:return patientItem->AddDate;
|
|
default:return QVariant();
|
|
}
|
|
}
|
|
|
|
if(item->getType() == AbstractPatientInfomation::AccessionType)
|
|
{
|
|
AccessionInformation* accessionItem = static_cast<AccessionInformation*>(item);
|
|
switch (aIndex.column())
|
|
{
|
|
case 1:return accessionItem->mAccessionNumber;
|
|
case 2:return accessionItem->getProtocolText();
|
|
case 3:return accessionItem->mScheduledStartDate;
|
|
default:return QVariant();
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
QModelIndex WorklistTableModel::parent(const QModelIndex &aChild) const
|
|
{
|
|
if (!aChild.isValid())
|
|
{
|
|
return QModelIndex();
|
|
}
|
|
AbstractPatientInfomation *item = static_cast<AbstractPatientInfomation*>(aChild.internalPointer());
|
|
if(item->getType() != AbstractPatientInfomation::AccessionType)
|
|
{
|
|
return QModelIndex();
|
|
}
|
|
AccessionInformation* accessionItem = static_cast<AccessionInformation*>(item);
|
|
int row = mPatientList.indexOf(accessionItem->mPatient);
|
|
//parent column must be 0
|
|
return createIndex(row, 0, accessionItem->mPatient);
|
|
}
|
|
|
|
void WorklistTableModel::reloadLanguage()
|
|
{
|
|
beginResetModel();
|
|
mHeader = QStringList()<< tr("ID") << tr("Name") << tr("Birth Date") << tr("Gender") << tr("Add Date");
|
|
emit headerDataChanged(Qt::Horizontal, 0, mHeader.count() - 1);
|
|
for(int i=0; i<mPatientList.size(); ++i)
|
|
{
|
|
mPatientList[i]->reloadHeaderLanguage();
|
|
}
|
|
endResetModel();
|
|
}
|
|
|
|
void WorklistTableModel::instertPatients(const QList<PatientInformation*>& aPatientList)
|
|
{
|
|
beginResetModel();
|
|
qDeleteAll(mPatientList);
|
|
mPatientList.clear();
|
|
mPatientList = aPatientList;
|
|
endResetModel();
|
|
// PatientInformation* p1 = new PatientInformation("PAT001","Sun","F","1998-08-21","2022-03-03 19:25:23");
|
|
// AccessionInformation* a = new AccessionInformation("a1",ScanLeft,"a3", p1, p1);
|
|
// AccessionInformation* b = new AccessionInformation("b1",ScanLeft,"b3", p1, p1);
|
|
// p1->setAccessionList(QList<AccessionInformation*>()<<a<<b);
|
|
// mPatientList << p1;
|
|
|
|
// PatientInformation* p2 = new PatientInformation("PAT002","wang","F","1998-08-21","2022-03-03 19:25:23");
|
|
// AccessionInformation* c = new AccessionInformation("c1",ScanNone,"c3", p2, p2);
|
|
// AccessionInformation* d = new AccessionInformation("c1",ScanLeft,"c3", p2, p2);
|
|
// p2->setAccessionList(QList<AccessionInformation*>()<<c<<d);
|
|
// mPatientList << p2 ;
|
|
|
|
// PatientInformation* p;
|
|
// AccessionInformation* ac;
|
|
// p = new PatientInformation("PAT003","jed","F","1998-08-21","2022-03-03 19:25:23");
|
|
// ac = new AccessionInformation("left",ScanLeft,"1998-08-21", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("right",ScanRight,"1998-08-21", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// mPatientList << p;
|
|
|
|
// for(int i=0; i<20; ++i)
|
|
// {
|
|
// p = new PatientInformation("PAT005","abc","F","1998-08-21","2022-03-03 19:25:23");
|
|
// ac = new AccessionInformation("a1",ScanNone,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanLeft,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanRight,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanRight,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanNone,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanNone,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanLeftRight,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanLeftRight,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// ac = new AccessionInformation("a1",ScanNone,"a3", p, p);
|
|
// p->setAccessionList(QList<AccessionInformation*>()<<ac);
|
|
// mPatientList << p;
|
|
// }
|
|
|
|
|
|
}
|