comparison UnitTestsSources/FromDcmtkTests.cpp @ 1307:f796207e3df1

Fix replacement and insertion of private DICOM tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Feb 2015 10:26:17 +0100
parents 6e7e5ed91c2d
children 7f0aa3c0f659
comparison
equal deleted inserted replaced
1306:8cd5784a6d80 1307:f796207e3df1
87 } 87 }
88 88
89 89
90 TEST(DicomModification, Anonymization) 90 TEST(DicomModification, Anonymization)
91 { 91 {
92 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, FromDcmtkBridge::ParseTag("PatientName"));
93
92 const DicomTag privateTag(0x0045, 0x0010); 94 const DicomTag privateTag(0x0045, 0x0010);
95 const DicomTag privateTag2(FromDcmtkBridge::ParseTag("0031-1020"));
93 ASSERT_TRUE(FromDcmtkBridge::IsPrivateTag(privateTag)); 96 ASSERT_TRUE(FromDcmtkBridge::IsPrivateTag(privateTag));
94 97 ASSERT_TRUE(FromDcmtkBridge::IsPrivateTag(privateTag2));
98 ASSERT_EQ(0x0031, privateTag2.GetGroup());
99 ASSERT_EQ(0x1020, privateTag2.GetElement());
100
101 std::string s;
95 ParsedDicomFile o; 102 ParsedDicomFile o;
96 o.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); 103 o.Replace(DICOM_TAG_PATIENT_NAME, "coucou");
97 o.Replace(privateTag, "private tag"); 104 ASSERT_FALSE(o.GetTagValue(s, privateTag));
98 105 o.Insert(privateTag, "private tag");
99 std::string s; 106 ASSERT_TRUE(o.GetTagValue(s, privateTag));
107 ASSERT_STREQ("private tag", s.c_str());
108
109 ASSERT_FALSE(o.GetTagValue(s, privateTag2));
110 ASSERT_THROW(o.Replace(privateTag2, "hello", DicomReplaceMode_ThrowIfAbsent), OrthancException);
111 ASSERT_FALSE(o.GetTagValue(s, privateTag2));
112 o.Replace(privateTag2, "hello", DicomReplaceMode_IgnoreIfAbsent);
113 ASSERT_FALSE(o.GetTagValue(s, privateTag2));
114 o.Replace(privateTag2, "hello", DicomReplaceMode_InsertIfAbsent);
115 ASSERT_TRUE(o.GetTagValue(s, privateTag2));
116 ASSERT_STREQ("hello", s.c_str());
117 o.Replace(privateTag2, "hello world");
118 ASSERT_TRUE(o.GetTagValue(s, privateTag2));
119 ASSERT_STREQ("hello world", s.c_str());
120
100 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); 121 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME));
101 ASSERT_FALSE(Toolbox::IsUuid(s)); 122 ASSERT_FALSE(Toolbox::IsUuid(s));
102 123
103 DicomModification m; 124 DicomModification m;
104 m.SetupAnonymization(); 125 m.SetupAnonymization();
107 m.Apply(o); 128 m.Apply(o);
108 129
109 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME)); 130 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME));
110 ASSERT_TRUE(Toolbox::IsUuid(s)); 131 ASSERT_TRUE(Toolbox::IsUuid(s));
111 ASSERT_TRUE(o.GetTagValue(s, privateTag)); 132 ASSERT_TRUE(o.GetTagValue(s, privateTag));
112 ASSERT_EQ("private tag", s); 133 ASSERT_STREQ("private tag", s.c_str());
113 134
114 m.SetupAnonymization(); 135 m.SetupAnonymization();
115 m.Apply(o); 136 m.Apply(o);
116 ASSERT_FALSE(o.GetTagValue(s, privateTag)); 137 ASSERT_FALSE(o.GetTagValue(s, privateTag));
117 } 138 }