Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/DicomMapTests.cpp @ 4932:b7ce2bb6b881 more-tags
refactored the list of MainDicomTags to be able to change it dynamicaly. Unit tests and Integration tests ok
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 09 Mar 2022 11:17:08 +0100 |
parents | 43e613a7756b |
children | 312c6f4da888 |
comparison
equal
deleted
inserted
replaced
4930:1ce32c1ec4cf | 4932:b7ce2bb6b881 |
---|---|
43 | 43 |
44 #include <boost/lexical_cast.hpp> | 44 #include <boost/lexical_cast.hpp> |
45 | 45 |
46 using namespace Orthanc; | 46 using namespace Orthanc; |
47 | 47 |
48 TEST(DicomMap, MainTags) | 48 |
49 { | 49 namespace Orthanc |
50 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID)); | 50 { |
51 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient)); | 51 // The namespace is necessary because of FRIEND_TEST |
52 ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study)); | 52 // http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members |
53 | 53 |
54 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); | 54 class DicomMapMainTagsTests : public ::testing::Test |
55 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_ACCESSION_NUMBER)); | 55 { |
56 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); | 56 public: |
57 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SOP_INSTANCE_UID)); | 57 DicomMapMainTagsTests() |
58 | 58 { |
59 std::set<DicomTag> s; | 59 } |
60 DicomMap::GetMainDicomTags(s); | 60 |
61 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | 61 virtual void SetUp() ORTHANC_OVERRIDE |
62 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | 62 { |
63 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | 63 DicomMap::ResetDefaultMainDicomTags(); |
64 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | 64 } |
65 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | 65 |
66 | 66 virtual void TearDown() ORTHANC_OVERRIDE |
67 DicomMap::GetMainDicomTags(s, ResourceType_Patient); | 67 { |
68 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | 68 DicomMap::ResetDefaultMainDicomTags(); |
69 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | 69 } |
70 | 70 }; |
71 DicomMap::GetMainDicomTags(s, ResourceType_Study); | 71 |
72 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | 72 TEST_F(DicomMapMainTagsTests, MainTags) |
73 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | 73 { |
74 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | 74 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID)); |
75 | 75 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Patient)); |
76 DicomMap::GetMainDicomTags(s, ResourceType_Series); | 76 ASSERT_FALSE(DicomMap::IsMainDicomTag(DICOM_TAG_PATIENT_ID, ResourceType_Study)); |
77 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | 77 |
78 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | 78 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_STUDY_INSTANCE_UID)); |
79 | 79 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_ACCESSION_NUMBER)); |
80 DicomMap::GetMainDicomTags(s, ResourceType_Instance); | 80 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SERIES_INSTANCE_UID)); |
81 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | 81 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_SOP_INSTANCE_UID)); |
82 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | 82 |
83 } | 83 { |
84 | 84 const std::set<DicomTag>& s = DicomMap::GetAllMainDicomTags(); |
85 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | |
86 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
87 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | |
88 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | |
89 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
90 } | |
91 | |
92 { | |
93 const std::set<DicomTag>& s = DicomMap::GetMainDicomTags(ResourceType_Patient); | |
94 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_PATIENT_ID)); | |
95 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
96 } | |
97 | |
98 { | |
99 const std::set<DicomTag>& s = DicomMap::GetMainDicomTags(ResourceType_Study); | |
100 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_STUDY_INSTANCE_UID)); | |
101 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_ACCESSION_NUMBER)); | |
102 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
103 } | |
104 | |
105 { | |
106 const std::set<DicomTag>& s = DicomMap::GetMainDicomTags(ResourceType_Series); | |
107 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SERIES_INSTANCE_UID)); | |
108 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
109 } | |
110 | |
111 { | |
112 const std::set<DicomTag>& s = DicomMap::GetMainDicomTags(ResourceType_Instance); | |
113 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
114 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_PATIENT_ID)); | |
115 } | |
116 } | |
117 | |
118 TEST_F(DicomMapMainTagsTests, AddMainTags) | |
119 { | |
120 DicomMap::AddMainDicomTag(DICOM_TAG_BITS_ALLOCATED, "BitsAllocated", ResourceType_Instance); | |
121 | |
122 { | |
123 const std::set<DicomTag>& s = DicomMap::GetMainDicomTags(ResourceType_Instance); | |
124 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_BITS_ALLOCATED)); | |
125 ASSERT_TRUE(s.end() != s.find(DICOM_TAG_SOP_INSTANCE_UID)); | |
126 } | |
127 { | |
128 const std::set<DicomTag>& s = DicomMap::GetMainDicomTags(ResourceType_Series); | |
129 ASSERT_TRUE(s.end() == s.find(DICOM_TAG_BITS_ALLOCATED)); | |
130 } | |
131 | |
132 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_BITS_ALLOCATED)); | |
133 ASSERT_TRUE(DicomMap::IsMainDicomTag(DICOM_TAG_BITS_ALLOCATED, ResourceType_Instance)); | |
134 | |
135 // adding the same tag should throw | |
136 ASSERT_THROW(DicomMap::AddMainDicomTag(DICOM_TAG_BITS_ALLOCATED, "BitsAllocated", ResourceType_Instance), OrthancException); | |
137 | |
138 // adding another tag with same name should throw | |
139 ASSERT_THROW(DicomMap::AddMainDicomTag(DICOM_TAG_BITS_STORED, "BitsAllocated", ResourceType_Instance), OrthancException); | |
140 } | |
141 } | |
85 | 142 |
86 TEST(DicomMap, Tags) | 143 TEST(DicomMap, Tags) |
87 { | 144 { |
88 std::set<DicomTag> s; | 145 std::set<DicomTag> s; |
89 | 146 |
155 DicomModule module) | 212 DicomModule module) |
156 { | 213 { |
157 // REFERENCE: DICOM PS3.3 2015c - Information Object Definitions | 214 // REFERENCE: DICOM PS3.3 2015c - Information Object Definitions |
158 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html | 215 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html |
159 | 216 |
160 std::set<DicomTag> moduleTags, main; | 217 std::set<DicomTag> moduleTags; |
218 const std::set<DicomTag>& main = DicomMap::GetMainDicomTags(level); | |
161 DicomTag::AddTagsForModule(moduleTags, module); | 219 DicomTag::AddTagsForModule(moduleTags, module); |
162 DicomMap::GetMainDicomTags(main, level); | |
163 | 220 |
164 // The main dicom tags are a subset of the module | 221 // The main dicom tags are a subset of the module |
165 for (std::set<DicomTag>::const_iterator it = main.begin(); it != main.end(); ++it) | 222 for (std::set<DicomTag>::const_iterator it = main.begin(); it != main.end(); ++it) |
166 { | 223 { |
167 bool ok = moduleTags.find(*it) != moduleTags.end(); | 224 bool ok = moduleTags.find(*it) != moduleTags.end(); |
620 | 677 |
621 for (int i = ResourceType_Patient; i <= ResourceType_Instance; i++) | 678 for (int i = ResourceType_Patient; i <= ResourceType_Instance; i++) |
622 { | 679 { |
623 ResourceType level = static_cast<ResourceType>(i); | 680 ResourceType level = static_cast<ResourceType>(i); |
624 | 681 |
625 std::set<DicomTag> tags; | 682 const std::set<DicomTag>& tags = DicomMap::GetMainDicomTags(level); |
626 DicomMap::GetMainDicomTags(tags, level); | |
627 | 683 |
628 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it) | 684 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it) |
629 { | 685 { |
630 DicomMap a; | 686 DicomMap a; |
631 a.SetValue(*it, "TEST", false); | 687 a.SetValue(*it, "TEST", false); |