Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 1641:4e56b5a206b7
Support of binary tags encoded using data URI scheme
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Sep 2015 12:43:05 +0200 |
parents | 48224db51ee7 |
children | 1558b3226b18 |
comparison
equal
deleted
inserted
replaced
1640:48224db51ee7 | 1641:4e56b5a206b7 |
---|---|
38 #include "../FromDcmtkBridge.h" | 38 #include "../FromDcmtkBridge.h" |
39 #include "../ServerContext.h" | 39 #include "../ServerContext.h" |
40 #include "../OrthancInitialization.h" | 40 #include "../OrthancInitialization.h" |
41 | 41 |
42 #include <boost/lexical_cast.hpp> | 42 #include <boost/lexical_cast.hpp> |
43 #include <boost/algorithm/string/predicate.hpp> | |
43 | 44 |
44 namespace Orthanc | 45 namespace Orthanc |
45 { | 46 { |
46 // Modification of DICOM instances ------------------------------------------ | 47 // Modification of DICOM instances ------------------------------------------ |
47 | 48 |
483 } | 484 } |
484 } | 485 } |
485 | 486 |
486 | 487 |
487 static void InjectTags(ParsedDicomFile& dicom, | 488 static void InjectTags(ParsedDicomFile& dicom, |
488 const Json::Value& tags) | 489 const Json::Value& tags, |
490 bool interpretBinaryTags) | |
489 { | 491 { |
490 if (tags.type() != Json::objectValue) | 492 if (tags.type() != Json::objectValue) |
491 { | 493 { |
492 throw OrthancException(ErrorCode_BadRequest); | 494 throw OrthancException(ErrorCode_BadRequest); |
493 } | 495 } |
501 { | 503 { |
502 throw OrthancException(ErrorCode_CreateDicomNotString); | 504 throw OrthancException(ErrorCode_CreateDicomNotString); |
503 } | 505 } |
504 | 506 |
505 std::string value = tags[name].asString(); | 507 std::string value = tags[name].asString(); |
506 | |
507 DicomTag tag = FromDcmtkBridge::ParseTag(name); | 508 DicomTag tag = FromDcmtkBridge::ParseTag(name); |
509 | |
508 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) | 510 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) |
509 { | 511 { |
510 if (tag != DICOM_TAG_PATIENT_ID && | 512 if (tag != DICOM_TAG_PATIENT_ID && |
511 tag != DICOM_TAG_ACQUISITION_DATE && | 513 tag != DICOM_TAG_ACQUISITION_DATE && |
512 tag != DICOM_TAG_ACQUISITION_TIME && | 514 tag != DICOM_TAG_ACQUISITION_TIME && |
525 | 527 |
526 if (tag == DICOM_TAG_PIXEL_DATA) | 528 if (tag == DICOM_TAG_PIXEL_DATA) |
527 { | 529 { |
528 throw OrthancException(ErrorCode_CreateDicomUseContent); | 530 throw OrthancException(ErrorCode_CreateDicomUseContent); |
529 } | 531 } |
532 else if (interpretBinaryTags && | |
533 boost::starts_with(value, "data:application/octet-stream;base64,")) | |
534 { | |
535 std::string mime, binary; | |
536 Toolbox::DecodeDataUriScheme(mime, binary, value); | |
537 dicom.Replace(tag, binary); | |
538 } | |
530 else | 539 else |
531 { | 540 { |
532 dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, dicom.GetEncoding())); | 541 dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, dicom.GetEncoding())); |
533 } | 542 } |
534 } | 543 } |
536 } | 545 } |
537 | 546 |
538 | 547 |
539 static void CreateSeries(RestApiPostCall& call, | 548 static void CreateSeries(RestApiPostCall& call, |
540 ParsedDicomFile& base /* in */, | 549 ParsedDicomFile& base /* in */, |
541 const Json::Value& content) | 550 const Json::Value& content, |
551 bool interpretBinaryTags) | |
542 { | 552 { |
543 assert(content.isArray()); | 553 assert(content.isArray()); |
544 assert(content.size() > 0); | 554 assert(content.size() > 0); |
545 ServerContext& context = OrthancRestApi::GetContext(call); | 555 ServerContext& context = OrthancRestApi::GetContext(call); |
546 | 556 |
569 | 579 |
570 payload = &content[i]["Content"]; | 580 payload = &content[i]["Content"]; |
571 | 581 |
572 if (content[i].isMember("Tags")) | 582 if (content[i].isMember("Tags")) |
573 { | 583 { |
574 InjectTags(*dicom, content[i]["Tags"]); | 584 InjectTags(*dicom, content[i]["Tags"], interpretBinaryTags); |
575 } | 585 } |
576 } | 586 } |
577 | 587 |
578 if (payload == NULL || | 588 if (payload == NULL || |
579 payload->type() != Json::stringValue) | 589 payload->type() != Json::stringValue) |
742 } | 752 } |
743 } | 753 } |
744 } | 754 } |
745 } | 755 } |
746 | 756 |
757 | |
758 bool interpretBinaryTags = true; | |
759 if (request.isMember("InterpretBinaryTags")) | |
760 { | |
761 const Json::Value& v = request["InterpretBinaryTags"]; | |
762 if (v.type() != Json::booleanValue) | |
763 { | |
764 throw OrthancException(ErrorCode_BadRequest); | |
765 } | |
766 | |
767 interpretBinaryTags = v.asBool(); | |
768 } | |
769 | |
747 | 770 |
748 // Inject time-related information | 771 // Inject time-related information |
749 std::string date, time; | 772 std::string date, time; |
750 Toolbox::GetNowDicom(date, time); | 773 Toolbox::GetNowDicom(date, time); |
751 dicom.Replace(DICOM_TAG_ACQUISITION_DATE, date); | 774 dicom.Replace(DICOM_TAG_ACQUISITION_DATE, date); |
769 dicom.Replace(DICOM_TAG_STUDY_DATE, date); | 792 dicom.Replace(DICOM_TAG_STUDY_DATE, date); |
770 dicom.Replace(DICOM_TAG_STUDY_TIME, time); | 793 dicom.Replace(DICOM_TAG_STUDY_TIME, time); |
771 } | 794 } |
772 | 795 |
773 | 796 |
774 InjectTags(dicom, request["Tags"]); | 797 InjectTags(dicom, request["Tags"], interpretBinaryTags); |
775 | 798 |
776 | 799 |
777 // Inject the content (either an image, or a PDF file) | 800 // Inject the content (either an image, or a PDF file) |
778 if (request.isMember("Content")) | 801 if (request.isMember("Content")) |
779 { | 802 { |
787 else if (content.type() == Json::arrayValue) | 810 else if (content.type() == Json::arrayValue) |
788 { | 811 { |
789 if (content.size() > 0) | 812 if (content.size() > 0) |
790 { | 813 { |
791 // Let's create a series instead of a single instance | 814 // Let's create a series instead of a single instance |
792 CreateSeries(call, dicom, content); | 815 CreateSeries(call, dicom, content, interpretBinaryTags); |
793 return; | 816 return; |
794 } | 817 } |
795 } | 818 } |
796 else | 819 else |
797 { | 820 { |