# HG changeset patch # User Sebastien Jodogne # Date 1359383804 -3600 # Node ID 8031f9cfe7fe702e92b364da3eeaf7ea3a571f97 # Parent c5edf0cc6e9538969d48bd4ce02c248e44e6e7de removal of old code diff -r c5edf0cc6e95 -r 8031f9cfe7fe OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Mon Jan 28 15:33:44 2013 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Mon Jan 28 15:36:44 2013 +0100 @@ -869,6 +869,7 @@ { typedef std::set Removals; typedef std::map Replacements; + typedef std::map< std::pair, std::string> UidMap; } static void ReplaceInstanceInternal(ParsedDicomFile& toModify, @@ -1159,193 +1160,6 @@ } - static void AnonymizeOrModifySeries(Removals& removals, - Replacements& replacements, - bool removePrivateTags, - MetadataType metadataType, - ChangeType changeType, - RestApi::PostCall& call) - { - Json::Value result = Json::objectValue; - - { - boost::mutex::scoped_lock lock(cacheMutex_); - RETRIEVE_CONTEXT(call); - - typedef std::list Instances; - Instances instances; - std::string id = call.GetUriComponent("id", ""); - context.GetIndex().GetChildInstances(instances, id); - - if (instances.size() == 0) - { - return; - } - - replacements[DICOM_TAG_SERIES_INSTANCE_UID] = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series); - - std::string newSeriesId, newPatientId; - for (Instances::const_iterator it = instances.begin(); - it != instances.end(); it++) - { - LOG(INFO) << "Modifying instance " << *it; - ParsedDicomFile& original = context.GetDicomFile(*it); - std::auto_ptr modified(original.Clone()); - ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); - - std::string modifiedInstance; - if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) - { - LOG(ERROR) << "Error while storing a modified instance " << *it; - return; - } - - DicomInstanceHasher modifiedHasher = modified->GetHasher(); - DicomInstanceHasher originalHasher = original.GetHasher(); - - if (newSeriesId.size() == 0) - { - assert(id == originalHasher.HashSeries()); - newSeriesId = modifiedHasher.HashSeries(); - context.GetIndex().SetMetadata(newSeriesId, metadataType, id); - } - - if (newPatientId.size() == 0) - { - newPatientId = modifiedHasher.HashPatient(); - } - - assert(*it == originalHasher.HashInstance()); - assert(modifiedInstance == modifiedHasher.HashInstance()); - context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it); - } - - context.GetIndex().LogChange(changeType, newSeriesId); - - assert(newSeriesId.size() != 0); - result["Type"] = ToString(ResourceType_Series); - result["ID"] = newSeriesId; - result["Path"] = GetBasePath(ResourceType_Series, newSeriesId); - result["PatientID"] = newPatientId; - } - - // Do not answer before the lock has been released - call.GetOutput().AnswerJson(result); - } - - - static void AnonymizeOrModifyStudy(Removals& removals, - Replacements& replacements, - bool removePrivateTags, - MetadataType metadataType, - ChangeType changeType, - RestApi::PostCall& call) - { - Json::Value result = Json::objectValue; - - { - boost::mutex::scoped_lock lock(cacheMutex_); - RETRIEVE_CONTEXT(call); - - typedef std::list Instances; - typedef std::map SeriesUidMap; - - Instances instances; - std::string id = call.GetUriComponent("id", ""); - context.GetIndex().GetChildInstances(instances, id); - - if (instances.size() == 0) - { - return; - } - - std::string newPatientId; - std::string newStudyId; - replacements[DICOM_TAG_STUDY_INSTANCE_UID] = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Study); - - SeriesUidMap seriesUidMap; - for (Instances::const_iterator it = instances.begin(); - it != instances.end(); it++) - { - LOG(INFO) << "Modifying instance " << *it; - ParsedDicomFile& original = context.GetDicomFile(*it); - - std::string seriesUid; - if (!original.GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID)) - { - throw OrthancException(ErrorCode_InternalError); - } - - bool isNewSeries; - SeriesUidMap::const_iterator it2 = seriesUidMap.find(seriesUid); - if (it2 == seriesUidMap.end()) - { - std::string newSeriesUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Series); - seriesUidMap[seriesUid] = newSeriesUid; - replacements[DICOM_TAG_SERIES_INSTANCE_UID] = newSeriesUid; - isNewSeries = true; - } - else - { - replacements[DICOM_TAG_SERIES_INSTANCE_UID] = it2->second; - isNewSeries = false; - } - - std::auto_ptr modified(original.Clone()); - ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); - - std::string modifiedInstance; - if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) - { - LOG(ERROR) << "Error while storing a modified instance " << *it; - return; - } - - DicomInstanceHasher modifiedHasher = modified->GetHasher(); - DicomInstanceHasher originalHasher = original.GetHasher(); - - if (isNewSeries) - { - context.GetIndex().SetMetadata - (modifiedHasher.HashSeries(), metadataType, originalHasher.HashSeries()); - } - - if (newStudyId.size() == 0) - { - newStudyId = modifiedHasher.HashStudy(); - context.GetIndex().SetMetadata(newStudyId, metadataType, originalHasher.HashStudy()); - } - - if (newPatientId.size() == 0) - { - newPatientId = modifiedHasher.HashPatient(); - } - - assert(*it == originalHasher.HashInstance()); - assert(modifiedInstance == modifiedHasher.HashInstance()); - context.GetIndex().SetMetadata(modifiedInstance, metadataType, *it); - } - - context.GetIndex().LogChange(changeType, newStudyId); - - assert(newStudyId.size() != 0); - result["Type"] = ToString(ResourceType_Study); - result["ID"] = newStudyId; - result["Path"] = GetBasePath(ResourceType_Study, newStudyId); - result["PatientID"] = newPatientId; - } - - // Do not answer before the lock has been released - call.GetOutput().AnswerJson(result); - } - - - - namespace - { - typedef std::map< std::pair, std::string> UidMap; - } - static bool RetrieveMappedUid(ParsedDicomFile& dicom, DicomRootLevel level, Replacements& replacements,