ctkDICOMPersonName.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. // Qt include
  16. #include <QSharedData>
  17. // CTK DICOM Core
  18. #include "ctkDICOMPersonName.h"
  19. //------------------------------------------------------------------------------
  20. class ctkDICOMPersonNameData : public QSharedData
  21. {
  22. public:
  23. QString m_LastName;
  24. QString m_FirstName;
  25. QString m_MiddleName;
  26. QString m_NamePrefix;
  27. QString m_NameSuffix;
  28. };
  29. //------------------------------------------------------------------------------
  30. ctkDICOMPersonName::ctkDICOMPersonName(const QString& lastName,
  31. const QString& firstName,
  32. const QString& middleName,
  33. const QString& namePrefix,
  34. const QString& nameSuffix)
  35. : d(new ctkDICOMPersonNameData)
  36. {
  37. d->m_LastName = lastName;
  38. d->m_FirstName = firstName;
  39. d->m_MiddleName = middleName;
  40. d->m_NamePrefix = namePrefix;
  41. d->m_NameSuffix = nameSuffix;
  42. }
  43. //------------------------------------------------------------------------------
  44. ctkDICOMPersonName::ctkDICOMPersonName(const ctkDICOMPersonName& other)
  45. : d(other.d)
  46. {
  47. }
  48. //------------------------------------------------------------------------------
  49. ctkDICOMPersonName& ctkDICOMPersonName::operator=(const ctkDICOMPersonName& other)
  50. {
  51. d = other.d;
  52. return *this;
  53. }
  54. //------------------------------------------------------------------------------
  55. ctkDICOMPersonName::~ctkDICOMPersonName()
  56. {
  57. }
  58. //------------------------------------------------------------------------------
  59. QString ctkDICOMPersonName::formattedName() const
  60. {
  61. QString result("");
  62. /* not sortable
  63. if (!m_NamePrefix.isEmpty()) result += QString("%1 ").arg(m_NamePrefix);
  64. if (!m_FirstName.isEmpty()) result += QString("%1 " ).arg(m_FirstName);
  65. if (!m_MiddleName.isEmpty()) result += QString("%1 ").arg(m_MiddleName);
  66. if (!m_LastName.isEmpty()) result += QString("%1").arg(m_LastName);
  67. if (!m_NameSuffix.isEmpty()) result += QString(", %1").arg(m_NameSuffix); // this might be unclean if last name is empty
  68. */
  69. if (!d->m_LastName.isEmpty()) result += QString("%1").arg(d->m_LastName);
  70. if (!d->m_FirstName.isEmpty()) result += QString(", %1" ).arg(d->m_FirstName);
  71. if (!d->m_MiddleName.isEmpty()) result += QString(" %1").arg(d->m_MiddleName);
  72. if (!d->m_NameSuffix.isEmpty()) result += QString(", %1").arg(d->m_NameSuffix); // this might be unclean if last name is empty
  73. return result;
  74. }
  75. //------------------------------------------------------------------------------
  76. QString ctkDICOMPersonName::lastName() const
  77. {
  78. return d->m_LastName;
  79. }
  80. //------------------------------------------------------------------------------
  81. QString ctkDICOMPersonName::firstName() const
  82. {
  83. return d->m_FirstName;
  84. }
  85. //------------------------------------------------------------------------------
  86. QString ctkDICOMPersonName::middleName() const
  87. {
  88. return d->m_MiddleName;
  89. }
  90. //------------------------------------------------------------------------------
  91. QString ctkDICOMPersonName::namePrefix() const
  92. {
  93. return d->m_NamePrefix;
  94. }
  95. //------------------------------------------------------------------------------
  96. QString ctkDICOMPersonName::nameSuffix() const
  97. {
  98. return d->m_NameSuffix;
  99. }
  100. //------------------------------------------------------------------------------
  101. ctkDICOMPersonName::operator QString() const
  102. {
  103. return this->formattedName();
  104. }
  105. //------------------------------------------------------------------------------
  106. std::string ctkDICOMPersonName::toStdString() const
  107. {
  108. // the complicated looking .toLocal8Bit().constData() is on purpose.
  109. // if we'd use .toStdString(), the string would be converted to ASCII
  110. // instead of the local 8bit character encoding.
  111. // changes for correctly looking output of the strings are higher with .toLocal8Bit()
  112. return this->formattedName().toLocal8Bit().constData();
  113. }