Parcourir la source

Merge remote-tracking branch 'pieper/slicerrt-25-dicom-personname-display'

* pieper/slicerrt-25-dicom-personname-display:
  Improve name formatting to Last, First Middle, Suffix (Prefix)
  Fix namespace-related compile error in hosting types
  Display formatted person name, to remove internal delimeters

Closes #274 and SlicerRT issue 25.
Steve Pieper il y a 12 ans
Parent
commit
c4b8a51347
1 fichiers modifiés avec 72 ajouts et 22 suppressions
  1. 72 22
      Libs/DICOM/Core/ctkDICOMModel.cpp

+ 72 - 22
Libs/DICOM/Core/ctkDICOMModel.cpp

@@ -29,6 +29,9 @@
 #include <QTime>
 #include <QDebug>
 
+// dcmtk includes
+#include "dcvrpn.h"
+
 // ctkDICOMCore includes
 #include "ctkDICOMModel.h"
 #include "ctkLogger.h"
@@ -45,7 +48,7 @@ class ctkDICOMModelPrivate
   Q_DECLARE_PUBLIC(ctkDICOMModel);
 protected:
   ctkDICOMModel* const q_ptr;
-  
+
 public:
   ctkDICOMModelPrivate(ctkDICOMModel&);
   virtual ~ctkDICOMModelPrivate();
@@ -150,7 +153,7 @@ QModelIndexList ctkDICOMModelPrivate::indexListFromNode(const Node* node)const
   Q_Q(const ctkDICOMModel);
   Q_ASSERT(node);
   QModelIndexList indexList;
-  
+
   Node* parentNode = node->Parent;
   if (parentNode == 0)
     {
@@ -230,7 +233,7 @@ Node* ctkDICOMModelPrivate::createNode(int row, const QModelIndex& parentValue)c
     }
   else
     {
-    nodeParent = this->nodeFromIndex(parentValue); 
+    nodeParent = this->nodeFromIndex(parentValue);
     nodeParent->Children.push_back(node);
     node->Parent = nodeParent;
     node->Type = ctkDICOMModel::IndexType(nodeParent->Type + 1);
@@ -244,13 +247,13 @@ Node* ctkDICOMModelPrivate::createNode(int row, const QModelIndex& parentValue)c
     node->Data[Qt::CheckStateRole] = node->Parent->Data[Qt::CheckStateRole];
 #endif
     }
-  
+
   node->RowCount = 0;
   node->AtEnd = false;
   node->Fetching = false;
 
   this->updateQueries(node);
-  
+
   return node;
 }
 
@@ -259,7 +262,7 @@ QVariant ctkDICOMModelPrivate::value(const QModelIndex& parentValue, int row, in
 {
   Node* node = this->nodeFromIndex(parentValue);
   if (row >= node->RowCount)
-    {      
+    {
     const_cast<ctkDICOMModelPrivate *>(this)->fetch(parentValue, row + 256);
     }
   return this->value(node, row, column);
@@ -272,7 +275,7 @@ QVariant ctkDICOMModelPrivate::value(Node* parentNode, int row, int column) cons
     {
     return QVariant();
     }
-  
+
   if (!parentNode->Query.seek(row))
     {
     qDebug() << parentNode->Query.lastError();
@@ -381,35 +384,35 @@ void ctkDICOMModelPrivate::fetch(const QModelIndex& indexValue, int limit)
   const int oldRowCount = node->RowCount;
 
   // try to seek directly
-  if (node->Query.seek(limit - 1)) 
+  if (node->Query.seek(limit - 1))
     {
     newRowCount = limit;
-    } 
-  else 
+    }
+  else
     {
     newRowCount = qMax(oldRowCount, 1);
-    if (node->Query.seek(newRowCount - 1)) 
+    if (node->Query.seek(newRowCount - 1))
       {
       while (node->Query.next())
         {
         ++newRowCount;
         }
-      } 
-    else 
+      }
+    else
       {
       // empty or invalid query
       newRowCount = 0;
       }
     node->AtEnd = true; // this is the end.
     }
-  if (newRowCount > 0 && newRowCount > node->RowCount) 
+  if (newRowCount > 0 && newRowCount > node->RowCount)
     {
     q->beginInsertRows(indexValue, node->RowCount, newRowCount - 1);
     node->RowCount = newRowCount;
     node->Fetching = false;
     q->endInsertRows();
-    } 
-  else 
+    }
+  else
     {
     node->RowCount = newRowCount;
     node->Fetching = false;
@@ -485,7 +488,7 @@ QVariant ctkDICOMModel::data ( const QModelIndex & dataIndex, int role ) const
   QModelIndex parentIndex = this->parent(dataIndex);
   Node* parentNode = d->nodeFromIndex(parentIndex);
   if (dataIndex.row() >= parentNode->RowCount)
-    {      
+    {
     const_cast<ctkDICOMModelPrivate *>(d)->fetch(dataIndex, dataIndex.row());
     }
   QString columnName = d->Headers[dataIndex.column()][Qt::DisplayRole].toString();
@@ -506,6 +509,53 @@ QVariant ctkDICOMModel::data ( const QModelIndex & dataIndex, int role ) const
       return QString("No description");
     }
   }
+
+  if (columnName.compare("Name")==0)
+    {
+    OFString dicomName = dataValue.toString().toStdString().c_str();
+    OFString formattedName;
+    OFString lastName, firstName, middleName, namePrefix, nameSuffix;
+    OFCondition l_error = DcmPersonName::getNameComponentsFromString(dicomName,
+                                          lastName, firstName, middleName, namePrefix, nameSuffix);
+    if (l_error.good())
+      {
+      formattedName.clear();
+      /* concatenate name components per this convention
+       * Last, First Middle, Suffix (Prefix)
+       * */
+      if (!lastName.empty())
+        {
+        formattedName += lastName;
+        if ( !(firstName.empty() && middleName.empty()) )
+          {
+          formattedName += ",";
+          }
+        }
+      if (!firstName.empty())
+        {
+        formattedName += " ";
+        formattedName += firstName;
+        }
+      if (!middleName.empty())
+        {
+        formattedName += " ";
+        formattedName += middleName;
+        }
+      if (!nameSuffix.empty())
+        {
+        formattedName += ", ";
+        formattedName += nameSuffix;
+        }
+      if (!namePrefix.empty())
+        {
+        formattedName += " (";
+        formattedName += namePrefix;
+        formattedName += ")";
+        }
+      }
+      return QString(formattedName.c_str());
+    }
+
   return dataValue;
 }
 
@@ -796,7 +846,7 @@ void ctkDICOMModel::setDatabase(const QSqlDatabase &db)
 
   this->beginResetModel();
   d->DataBase = db;
-  
+
   delete d->RootNode;
   d->RootNode = 0;
 
@@ -806,14 +856,14 @@ void ctkDICOMModel::setDatabase(const QSqlDatabase &db)
     this->endResetModel();
     return;
     }
-    
+
   d->RootNode = d->createNode(-1, QModelIndex());
-  
+
   this->endResetModel();
 
   // TODO, use hasQuerySize everywhere, not only in setDataBase()
   bool hasQuerySize = d->RootNode->Query.driver()->hasFeature(QSqlDriver::QuerySize);
-  if (hasQuerySize && d->RootNode->Query.size() > 0) 
+  if (hasQuerySize && d->RootNode->Query.size() > 0)
     {
     int newRowCount= d->RootNode->Query.size();
     beginInsertRows(QModelIndex(), 0, qMax(0, newRowCount - 1));
@@ -908,7 +958,7 @@ void ctkDICOMModel::sort(int column, Qt::SortOrder order)
     .arg(d->Headers[column][Qt::DisplayRole].toString())
     .arg(order == Qt::AscendingOrder ? "ASC" : "DESC");
   d->RootNode = d->createNode(-1, QModelIndex());
-  
+
   this->endResetModel();
 }