comparison OrthancServer/DicomModification.cpp @ 2310:b7fba68747f6 issue-46-anonymization

DicomModification::Clear()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2017 14:00:00 +0200
parents 4dc313b9a20a
children 78dcb3ddea9f
comparison
equal deleted inserted replaced
2309:4dc313b9a20a 2310:b7fba68747f6
169 } 169 }
170 170
171 void DicomModification::Keep(const DicomTag& tag) 171 void DicomModification::Keep(const DicomTag& tag)
172 { 172 {
173 removals_.erase(tag); 173 removals_.erase(tag);
174 clearings_.erase(tag);
174 RemoveInternal(tag); 175 RemoveInternal(tag);
175 176
176 if (tag.IsPrivate()) 177 if (tag.IsPrivate())
177 { 178 {
178 privateTagsToKeep_.insert(tag); 179 privateTagsToKeep_.insert(tag);
192 } 193 }
193 194
194 void DicomModification::Remove(const DicomTag& tag) 195 void DicomModification::Remove(const DicomTag& tag)
195 { 196 {
196 removals_.insert(tag); 197 removals_.insert(tag);
198 clearings_.erase(tag);
197 RemoveInternal(tag); 199 RemoveInternal(tag);
198 privateTagsToKeep_.erase(tag); 200 privateTagsToKeep_.erase(tag);
199 201
200 MarkNotOrthancAnonymization(); 202 MarkNotOrthancAnonymization();
201 } 203 }
202 204
205 void DicomModification::Clear(const DicomTag& tag)
206 {
207 removals_.erase(tag);
208 clearings_.insert(tag);
209 RemoveInternal(tag);
210 privateTagsToKeep_.erase(tag);
211
212 MarkNotOrthancAnonymization();
213 }
214
203 bool DicomModification::IsRemoved(const DicomTag& tag) const 215 bool DicomModification::IsRemoved(const DicomTag& tag) const
204 { 216 {
205 return removals_.find(tag) != removals_.end(); 217 return removals_.find(tag) != removals_.end();
218 }
219
220 bool DicomModification::IsCleared(const DicomTag& tag) const
221 {
222 return clearings_.find(tag) != clearings_.end();
206 } 223 }
207 224
208 void DicomModification::Replace(const DicomTag& tag, 225 void DicomModification::Replace(const DicomTag& tag,
209 const Json::Value& value, 226 const Json::Value& value,
210 bool safeForAnonymization) 227 bool safeForAnonymization)
211 { 228 {
229 clearings_.erase(tag);
212 removals_.erase(tag); 230 removals_.erase(tag);
213 privateTagsToKeep_.erase(tag); 231 privateTagsToKeep_.erase(tag);
214 ReplaceInternal(tag, value); 232 ReplaceInternal(tag, value);
215 233
216 if (!safeForAnonymization) 234 if (!safeForAnonymization)
604 622
605 623
606 void DicomModification::SetupAnonymization(DicomVersion version) 624 void DicomModification::SetupAnonymization(DicomVersion version)
607 { 625 {
608 removals_.clear(); 626 removals_.clear();
627 clearings_.clear();
609 ClearReplacements(); 628 ClearReplacements();
610 removePrivateTags_ = true; 629 removePrivateTags_ = true;
611 level_ = ResourceType_Patient; 630 level_ = ResourceType_Patient;
612 uidMap_.clear(); 631 uidMap_.clear();
613 privateTagsToKeep_.clear(); 632 privateTagsToKeep_.clear();
754 if (removePrivateTags_) 773 if (removePrivateTags_)
755 { 774 {
756 toModify.RemovePrivateTags(privateTagsToKeep_); 775 toModify.RemovePrivateTags(privateTagsToKeep_);
757 } 776 }
758 777
759 // (2) Remove the tags specified by the user 778 // (2) Clear the tags specified by the user
779 for (SetOfTags::const_iterator it = clearings_.begin();
780 it != clearings_.end(); ++it)
781 {
782 toModify.Clear(*it, true /* only clear if the tag exists in the original file */);
783 }
784
785 // (3) Remove the tags specified by the user
760 for (SetOfTags::const_iterator it = removals_.begin(); 786 for (SetOfTags::const_iterator it = removals_.begin();
761 it != removals_.end(); ++it) 787 it != removals_.end(); ++it)
762 { 788 {
763 toModify.Remove(*it); 789 toModify.Remove(*it);
764 } 790 }
765 791
766 // (3) Replace the tags 792 // (4) Replace the tags
767 for (Replacements::const_iterator it = replacements_.begin(); 793 for (Replacements::const_iterator it = replacements_.begin();
768 it != replacements_.end(); ++it) 794 it != replacements_.end(); ++it)
769 { 795 {
770 toModify.Replace(it->first, *it->second, true /* decode data URI scheme */, DicomReplaceMode_InsertIfAbsent); 796 toModify.Replace(it->first, *it->second, true /* decode data URI scheme */, DicomReplaceMode_InsertIfAbsent);
771 } 797 }
772 798
773 // (4) Update the DICOM identifiers 799 // (5) Update the DICOM identifiers
774 if (level_ <= ResourceType_Study && 800 if (level_ <= ResourceType_Study &&
775 !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID)) 801 !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
776 { 802 {
777 if (keepStudyInstanceUid_) 803 if (keepStudyInstanceUid_)
778 { 804 {