comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 782:a60040857ce6

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 May 2014 12:59:05 +0200
parents aebf0071020e
children ac18946afa74
comparison
equal deleted inserted replaced
780:e7eb70772fbe 782:a60040857ce6
34 34
35 #include <glog/logging.h> 35 #include <glog/logging.h>
36 36
37 namespace Orthanc 37 namespace Orthanc
38 { 38 {
39 // Raw access to the DICOM tags of an instance ------------------------------
40
41 static void GetRawContent(RestApi::GetCall& call)
42 {
43 std::string id = call.GetUriComponent("id", "");
44
45 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
46
47 locker.GetDicom().SendPathValue(call.GetOutput(), call.GetTrailingUri());
48 }
49
50
51
52 // Modification of DICOM instances ------------------------------------------ 39 // Modification of DICOM instances ------------------------------------------
53 40
54 namespace 41 namespace
55 { 42 {
56 typedef std::set<DicomTag> Removals; 43 typedef std::set<DicomTag> Removals;
59 } 46 }
60 47
61 static void ReplaceInstanceInternal(ParsedDicomFile& toModify, 48 static void ReplaceInstanceInternal(ParsedDicomFile& toModify,
62 const Removals& removals, 49 const Removals& removals,
63 const Replacements& replacements, 50 const Replacements& replacements,
64 DicomReplaceMode mode,
65 bool removePrivateTags) 51 bool removePrivateTags)
66 { 52 {
67 if (removePrivateTags) 53 if (removePrivateTags)
68 { 54 {
69 toModify.RemovePrivateTags(); 55 toModify.RemovePrivateTags();
76 } 62 }
77 63
78 for (Replacements::const_iterator it = replacements.begin(); 64 for (Replacements::const_iterator it = replacements.begin();
79 it != replacements.end(); ++it) 65 it != replacements.end(); ++it)
80 { 66 {
81 toModify.Replace(it->first, it->second, mode); 67 toModify.Replace(it->first, it->second, DicomReplaceMode_InsertIfAbsent);
82 } 68 }
83 69
84 // A new SOP instance UID is automatically generated 70 // A new SOP instance UID is automatically generated
85 std::string instanceUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance); 71 std::string instanceUid = FromDcmtkBridge::GenerateUniqueIdentifier(DicomRootLevel_Instance);
86 toModify.Replace(DICOM_TAG_SOP_INSTANCE_UID, instanceUid, DicomReplaceMode_InsertIfAbsent); 72 toModify.Replace(DICOM_TAG_SOP_INSTANCE_UID, instanceUid, DicomReplaceMode_InsertIfAbsent);
334 std::string id = call.GetUriComponent("id", ""); 320 std::string id = call.GetUriComponent("id", "");
335 321
336 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); 322 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id);
337 323
338 std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone()); 324 std::auto_ptr<ParsedDicomFile> modified(locker.GetDicom().Clone());
339 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); 325 ReplaceInstanceInternal(*modified, removals, replacements, removePrivateTags);
340 modified->Answer(call.GetOutput()); 326 modified->Answer(call.GetOutput());
341 } 327 }
342 328
343 329
344 static bool RetrieveMappedUid(ParsedDicomFile& dicom, 330 static bool RetrieveMappedUid(ParsedDicomFile& dicom,
458 /** 444 /**
459 * Compute the resulting DICOM instance and store it into the Orthanc store. 445 * Compute the resulting DICOM instance and store it into the Orthanc store.
460 **/ 446 **/
461 447
462 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); 448 std::auto_ptr<ParsedDicomFile> modified(original.Clone());
463 ReplaceInstanceInternal(*modified, removals, replacements, DicomReplaceMode_InsertIfAbsent, removePrivateTags); 449 ReplaceInstanceInternal(*modified, removals, replacements, removePrivateTags);
464 450
465 std::string modifiedInstance; 451 std::string modifiedInstance;
466 if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success) 452 if (context.Store(modifiedInstance, modified->GetDicom()) != StoreStatus_Success)
467 { 453 {
468 LOG(ERROR) << "Error while storing a modified instance " << *it; 454 LOG(ERROR) << "Error while storing a modified instance " << *it;
678 664
679 665
680 666
681 void OrthancRestApi::RegisterAnonymizeModify() 667 void OrthancRestApi::RegisterAnonymizeModify()
682 { 668 {
683 Register("/instances/{id}/content/*", GetRawContent);
684
685 Register("/instances/{id}/modify", ModifyInstance); 669 Register("/instances/{id}/modify", ModifyInstance);
686 Register("/series/{id}/modify", ModifySeriesInplace); 670 Register("/series/{id}/modify", ModifySeriesInplace);
687 Register("/studies/{id}/modify", ModifyStudyInplace); 671 Register("/studies/{id}/modify", ModifyStudyInplace);
688 //Register("/patients/{id}/modify", ModifyPatientInplace); 672 //Register("/patients/{id}/modify", ModifyPatientInplace);
689 673