Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 1689:26083d84d237
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 Oct 2015 16:54:05 +0200 |
parents | 69f7822ee254 |
children | 18c02c6987d5 |
comparison
equal
deleted
inserted
replaced
1688:27d70e9ee2e4 | 1689:26083d84d237 |
---|---|
485 } | 485 } |
486 | 486 |
487 | 487 |
488 static void InjectTags(ParsedDicomFile& dicom, | 488 static void InjectTags(ParsedDicomFile& dicom, |
489 const Json::Value& tags, | 489 const Json::Value& tags, |
490 bool interpretBinaryTags) | 490 bool decodeBinaryTags) |
491 { | 491 { |
492 if (tags.type() != Json::objectValue) | 492 if (tags.type() != Json::objectValue) |
493 { | 493 { |
494 throw OrthancException(ErrorCode_BadRequest); | 494 throw OrthancException(ErrorCode_BadRequest); |
495 } | 495 } |
527 | 527 |
528 if (tag == DICOM_TAG_PIXEL_DATA) | 528 if (tag == DICOM_TAG_PIXEL_DATA) |
529 { | 529 { |
530 throw OrthancException(ErrorCode_CreateDicomUseContent); | 530 throw OrthancException(ErrorCode_CreateDicomUseContent); |
531 } | 531 } |
532 else if (interpretBinaryTags && | 532 else if (decodeBinaryTags && |
533 boost::starts_with(value, "data:application/octet-stream;base64,")) | 533 boost::starts_with(value, "data:application/octet-stream;base64,")) |
534 { | 534 { |
535 std::string mime, binary; | 535 std::string mime, binary; |
536 Toolbox::DecodeDataUriScheme(mime, binary, value); | 536 Toolbox::DecodeDataUriScheme(mime, binary, value); |
537 dicom.Replace(tag, binary); | 537 dicom.Replace(tag, binary); |
546 | 546 |
547 | 547 |
548 static void CreateSeries(RestApiPostCall& call, | 548 static void CreateSeries(RestApiPostCall& call, |
549 ParsedDicomFile& base /* in */, | 549 ParsedDicomFile& base /* in */, |
550 const Json::Value& content, | 550 const Json::Value& content, |
551 bool interpretBinaryTags) | 551 bool decodeBinaryTags) |
552 { | 552 { |
553 assert(content.isArray()); | 553 assert(content.isArray()); |
554 assert(content.size() > 0); | 554 assert(content.size() > 0); |
555 ServerContext& context = OrthancRestApi::GetContext(call); | 555 ServerContext& context = OrthancRestApi::GetContext(call); |
556 | 556 |
579 | 579 |
580 payload = &content[i]["Content"]; | 580 payload = &content[i]["Content"]; |
581 | 581 |
582 if (content[i].isMember("Tags")) | 582 if (content[i].isMember("Tags")) |
583 { | 583 { |
584 InjectTags(*dicom, content[i]["Tags"], interpretBinaryTags); | 584 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags); |
585 } | 585 } |
586 } | 586 } |
587 | 587 |
588 if (payload == NULL || | 588 if (payload == NULL || |
589 payload->type() != Json::stringValue) | 589 payload->type() != Json::stringValue) |
753 } | 753 } |
754 } | 754 } |
755 } | 755 } |
756 | 756 |
757 | 757 |
758 bool interpretBinaryTags = true; | 758 bool decodeBinaryTags = true; |
759 if (request.isMember("InterpretBinaryTags")) | 759 if (request.isMember("InterpretBinaryTags")) |
760 { | 760 { |
761 const Json::Value& v = request["InterpretBinaryTags"]; | 761 const Json::Value& v = request["InterpretBinaryTags"]; |
762 if (v.type() != Json::booleanValue) | 762 if (v.type() != Json::booleanValue) |
763 { | 763 { |
764 throw OrthancException(ErrorCode_BadRequest); | 764 throw OrthancException(ErrorCode_BadRequest); |
765 } | 765 } |
766 | 766 |
767 interpretBinaryTags = v.asBool(); | 767 decodeBinaryTags = v.asBool(); |
768 } | 768 } |
769 | 769 |
770 | 770 |
771 // Inject time-related information | 771 // Inject time-related information |
772 std::string date, time; | 772 std::string date, time; |
792 dicom.Replace(DICOM_TAG_STUDY_DATE, date); | 792 dicom.Replace(DICOM_TAG_STUDY_DATE, date); |
793 dicom.Replace(DICOM_TAG_STUDY_TIME, time); | 793 dicom.Replace(DICOM_TAG_STUDY_TIME, time); |
794 } | 794 } |
795 | 795 |
796 | 796 |
797 InjectTags(dicom, request["Tags"], interpretBinaryTags); | 797 InjectTags(dicom, request["Tags"], decodeBinaryTags); |
798 | 798 |
799 | 799 |
800 // Inject the content (either an image, or a PDF file) | 800 // Inject the content (either an image, or a PDF file) |
801 if (request.isMember("Content")) | 801 if (request.isMember("Content")) |
802 { | 802 { |
810 else if (content.type() == Json::arrayValue) | 810 else if (content.type() == Json::arrayValue) |
811 { | 811 { |
812 if (content.size() > 0) | 812 if (content.size() > 0) |
813 { | 813 { |
814 // Let's create a series instead of a single instance | 814 // Let's create a series instead of a single instance |
815 CreateSeries(call, dicom, content, interpretBinaryTags); | 815 CreateSeries(call, dicom, content, decodeBinaryTags); |
816 return; | 816 return; |
817 } | 817 } |
818 } | 818 } |
819 else | 819 else |
820 { | 820 { |