Mercurial > hg > orthanc
changeset 312:1642a354fec8
flexible
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2012 13:36:50 +0100 |
parents | 26efccdff583 |
children | 60429bb2551e |
files | OrthancServer/OrthancRestApi.cpp |
diffstat | 1 files changed, 54 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi.cpp Fri Dec 21 12:44:32 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Fri Dec 21 13:36:50 2012 +0100 @@ -850,8 +850,14 @@ static void ReplaceInstanceInternal(ParsedDicomFile& toModify, const Removals& removals, const Replacements& replacements, - DicomReplaceMode mode) + DicomReplaceMode mode, + bool removePrivateTags) { + if (removePrivateTags) + { + toModify.RemovePrivateTags(); + } + for (Removals::const_iterator it = removals.begin(); it != removals.end(); it++) { @@ -920,9 +926,6 @@ static void SetupAnonymization(Removals& removals, Replacements& replacements) { - removals.clear(); - replacements.clear(); - // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles removals.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID //removals.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set by ReplaceInstanceInternal() @@ -992,8 +995,10 @@ static bool ParseModifyRequest(Removals& removals, Replacements& replacements, + bool& removePrivateTags, const RestApi::PostCall& call) { + removePrivateTags = false; Json::Value request; if (call.ParseJsonRequest(request) && request.isObject()) @@ -1011,6 +1016,11 @@ replacementsPart = request["Replace"]; } + if (request.isMember("RemovePrivateTags")) + { + removePrivateTags = true; + } + ParseRemovals(removals, removalsPart); ParseReplacements(replacements, replacementsPart); @@ -1035,6 +1045,9 @@ request.isObject()) { Json::Value keepPart = Json::arrayValue; + Json::Value removalsPart = Json::arrayValue; + Json::Value replacementsPart = Json::objectValue; + if (request.isMember("Keep")) { keepPart = request["Keep"]; @@ -1045,6 +1058,11 @@ removePrivateTags = false; } + if (request.isMember("Replace")) + { + replacementsPart = request["Replace"]; + } + Removals toKeep; ParseRemovals(toKeep, keepPart); @@ -1055,6 +1073,17 @@ removals.erase(*it); } + Removals additionalRemovals; + ParseRemovals(additionalRemovals, removalsPart); + + for (Removals::iterator it = additionalRemovals.begin(); + it != additionalRemovals.end(); it++) + { + removals.erase(*it); + } + + ParseReplacements(replacements, replacementsPart); + return true; } else @@ -1073,11 +1102,12 @@ Removals removals; Replacements replacements; + bool removePrivateTags; - if (ParseModifyRequest(removals, replacements, call)) + if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) { std::auto_ptr<ParsedDicomFile> modified(dicom.Clone()); - ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent); + ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); context.GetIndex().SetMetadata(id, MetadataType_ModifiedFrom, id); modified->Answer(call.GetOutput()); } @@ -1097,23 +1127,21 @@ if (ParseAnonymizationRequest(removals, replacements, removePrivateTags, call)) { - // Generate random Patient's name - removals.erase(DicomTag(0x0010, 0x0010)); - replacements.insert(std::make_pair(DicomTag(0x0010, 0x0010), GeneratePatientName(context))); + // Generate random Patient's Name if none is specified + if (replacements.find(DicomTag(0x0010, 0x0010)) == replacements.end()) + { + replacements.insert(std::make_pair(DicomTag(0x0010, 0x0010), GeneratePatientName(context))); + } - // Generate random Patient ID - removals.erase(DICOM_TAG_PATIENT_ID); - replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID, - FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient))); + // Generate random Patient's ID if none is specified + if (replacements.find(DICOM_TAG_PATIENT_ID) == replacements.end()) + { + replacements.insert(std::make_pair(DICOM_TAG_PATIENT_ID, + FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Patient))); + } std::auto_ptr<ParsedDicomFile> anonymized(dicom.Clone()); - - if (removePrivateTags) - { - anonymized->RemovePrivateTags(); - } - - ReplaceInstanceInternal(*anonymized, removals, replacements, DicomReplaceMode_InsertIfAbsent); + ReplaceInstanceInternal(*anonymized, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); context.GetIndex().SetMetadata(id, MetadataType_AnonymizedFrom, id); anonymized->Answer(call.GetOutput()); @@ -1137,8 +1165,9 @@ Removals removals; Replacements replacements; + bool removePrivateTags; - if (ParseModifyRequest(removals, replacements, call)) + if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) { std::string newSeriesId; replacements[DICOM_TAG_SERIES_INSTANCE_UID] = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series); @@ -1149,7 +1178,7 @@ LOG(INFO) << "Modifying instance " << *it; ParsedDicomFile& dicom = context.GetDicomFile(*it); std::auto_ptr<ParsedDicomFile> modified(dicom.Clone()); - ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent); + ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); std::string modifiedInstance; if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) @@ -1193,8 +1222,9 @@ SeriesUidMap seriesUidMap; Removals removals; Replacements replacements; + bool removePrivateTags; - if (ParseModifyRequest(removals, replacements, call)) + if (ParseModifyRequest(removals, replacements, removePrivateTags, call)) { std::string newStudyId; replacements[DICOM_TAG_STUDY_INSTANCE_UID] = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study); @@ -1224,7 +1254,7 @@ } std::auto_ptr<ParsedDicomFile> modified(dicom.Clone()); - ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent); + ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); std::string modifiedInstance; if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success)