Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 1572:904096e7367e
More information about the origin request in OnStoredInstance() callbacks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 Aug 2015 12:10:12 +0200 |
parents | 2bd2c280f9b5 |
children | bd1889029cbb |
comparison
equal
deleted
inserted
replaced
1571:3232f1c995a5 | 1572:904096e7367e |
---|---|
276 | 276 |
277 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); | 277 std::auto_ptr<ParsedDicomFile> modified(original.Clone()); |
278 modification.Apply(*modified); | 278 modification.Apply(*modified); |
279 | 279 |
280 DicomInstanceToStore toStore; | 280 DicomInstanceToStore toStore; |
281 toStore.SetRestOrigin(call); | |
281 toStore.SetParsedDicomFile(*modified); | 282 toStore.SetParsedDicomFile(*modified); |
282 | 283 |
283 | 284 |
284 /** | 285 /** |
285 * Prepare the metadata information to associate with the | 286 * Prepare the metadata information to associate with the |
429 } | 430 } |
430 } | 431 } |
431 | 432 |
432 | 433 |
433 static void StoreCreatedInstance(std::string& id /* out */, | 434 static void StoreCreatedInstance(std::string& id /* out */, |
434 ServerContext& context, | 435 RestApiPostCall& call, |
435 ParsedDicomFile& dicom) | 436 ParsedDicomFile& dicom) |
436 { | 437 { |
437 DicomInstanceToStore toStore; | 438 DicomInstanceToStore toStore; |
439 toStore.SetRestOrigin(call); | |
438 toStore.SetParsedDicomFile(dicom); | 440 toStore.SetParsedDicomFile(dicom); |
439 | 441 |
442 ServerContext& context = OrthancRestApi::GetContext(call); | |
440 StoreStatus status = context.Store(id, toStore); | 443 StoreStatus status = context.Store(id, toStore); |
441 | 444 |
442 if (status == StoreStatus_Failure) | 445 if (status == StoreStatus_Failure) |
443 { | 446 { |
444 throw OrthancException("Error while storing a manually-created instance"); | 447 throw OrthancException("Error while storing a manually-created instance"); |
445 } | 448 } |
446 } | 449 } |
447 | 450 |
448 | 451 |
449 static void CreateDicomV1(ParsedDicomFile& dicom, | 452 static void CreateDicomV1(ParsedDicomFile& dicom, |
453 RestApiPostCall& call, | |
450 const Json::Value& request) | 454 const Json::Value& request) |
451 { | 455 { |
452 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World"}' | 456 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World"}' |
453 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World","PixelData":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="}' | 457 // curl http://localhost:8042/tools/create-dicom -X POST -d '{"PatientName":"Hello^World","PixelData":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="}' |
454 | 458 |
568 | 572 |
569 dicom->EmbedContent(payload->asString()); | 573 dicom->EmbedContent(payload->asString()); |
570 dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); | 574 dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast<std::string>(i + 1)); |
571 dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); | 575 dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast<std::string>(i + 1)); |
572 | 576 |
573 StoreCreatedInstance(someInstance, context, *dicom); | 577 StoreCreatedInstance(someInstance, call, *dicom); |
574 } | 578 } |
575 } | 579 } |
576 catch (OrthancException& e) | 580 catch (OrthancException& e) |
577 { | 581 { |
578 // Error: Remove the newly-created series | 582 // Error: Remove the newly-created series |
783 return; | 787 return; |
784 } | 788 } |
785 } | 789 } |
786 | 790 |
787 std::string id; | 791 std::string id; |
788 StoreCreatedInstance(id, context, dicom); | 792 StoreCreatedInstance(id, call, dicom); |
789 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success); | 793 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success); |
790 | 794 |
791 return; | 795 return; |
792 } | 796 } |
793 | 797 |
806 CreateDicomV2(call, request); | 810 CreateDicomV2(call, request); |
807 } | 811 } |
808 else | 812 else |
809 { | 813 { |
810 // Compatibility with Orthanc <= 0.9.3 | 814 // Compatibility with Orthanc <= 0.9.3 |
811 ServerContext& context = OrthancRestApi::GetContext(call); | |
812 ParsedDicomFile dicom; | 815 ParsedDicomFile dicom; |
813 CreateDicomV1(dicom, request); | 816 CreateDicomV1(dicom, call, request); |
814 | 817 |
815 std::string id; | 818 std::string id; |
816 StoreCreatedInstance(id, context, dicom); | 819 StoreCreatedInstance(id, call, dicom); |
817 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success); | 820 OrthancRestApi::GetApi(call).AnswerStoredResource(call, id, ResourceType_Instance, StoreStatus_Success); |
818 } | 821 } |
819 } | 822 } |
820 | 823 |
821 | 824 |