comparison OrthancServer/FromDcmtkBridge.cpp @ 1738:15a788a63846

DicomToJsonFlags_IncludeBinary
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 22 Oct 2015 09:28:08 +0200
parents ec66a16aa398
children df331354cea2
comparison
equal deleted inserted replaced
1737:ec66a16aa398 1738:15a788a63846
398 // http://support.dcmtk.org/docs/dcvr_8h-source.html 398 // http://support.dcmtk.org/docs/dcvr_8h-source.html
399 switch (element.getVR()) 399 switch (element.getVR())
400 { 400 {
401 401
402 /** 402 /**
403 * TODO. 403 * Deal with binary data (including PixelData).
404 **/ 404 **/
405 405
406 case EVR_OB: // other byte 406 case EVR_OB: // other byte
407 case EVR_OF: // other float 407 case EVR_OF: // other float
408 case EVR_OW: // other word 408 case EVR_OW: // other word
409 case EVR_UN: // unknown value representation 409 case EVR_UN: // unknown value representation
410 {
411 DicomTag tag(Convert(element.getTag()));
412
413 if ((tag == DICOM_TAG_PIXEL_DATA && flags & DicomToJsonFlags_IncludePixelData) ||
414 (tag != DICOM_TAG_PIXEL_DATA && flags & DicomToJsonFlags_IncludeBinary))
415 {
416 Uint8* data = NULL;
417 if (element.getUint8Array(data) == EC_Normal)
418 {
419 return new DicomValue(reinterpret_cast<const char*>(data), element.getLength(), true);
420 }
421 }
422
410 return new DicomValue; 423 return new DicomValue;
424 }
411 425
412 /** 426 /**
413 * String types, should never happen at this point because of 427 * String types, should never happen at this point because of
414 * "element.isaString()". 428 * "element.isaString()".
415 **/ 429 **/
619 633
620 634
621 static void LeafValueToJson(Json::Value& target, 635 static void LeafValueToJson(Json::Value& target,
622 const DicomValue& value, 636 const DicomValue& value,
623 DicomToJsonFormat format, 637 DicomToJsonFormat format,
638 DicomToJsonFlags flags,
624 unsigned int maxStringLength) 639 unsigned int maxStringLength)
625 { 640 {
641 Json::Value* targetValue = NULL;
642 Json::Value* targetType = NULL;
643
626 switch (format) 644 switch (format)
627 { 645 {
628 case DicomToJsonFormat_Short: 646 case DicomToJsonFormat_Short:
629 case DicomToJsonFormat_Simple: 647 case DicomToJsonFormat_Simple:
630 { 648 {
631 assert(target.type() == Json::nullValue); 649 assert(target.type() == Json::nullValue);
632 650 targetValue = &target;
633 if (!value.IsNull() &&
634 (maxStringLength == 0 ||
635 value.GetContent().size() <= maxStringLength))
636 {
637 target = value.GetContent();
638 }
639
640 break; 651 break;
641 } 652 }
642 653
643 case DicomToJsonFormat_Full: 654 case DicomToJsonFormat_Full:
644 { 655 {
645 assert(target.type() == Json::objectValue); 656 assert(target.type() == Json::objectValue);
646 657 target["Value"] = Json::nullValue;
647 if (value.IsNull()) 658 target["Type"] = Json::nullValue;
648 { 659 targetType = &target["Type"];
649 target["Type"] = "Null"; 660 targetValue = &target["Value"];
650 target["Value"] = Json::nullValue;
651 }
652 else
653 {
654 if (maxStringLength == 0 ||
655 value.GetContent().size() <= maxStringLength)
656 {
657 target["Type"] = "String";
658 target["Value"] = value.GetContent();
659 }
660 else
661 {
662 target["Type"] = "TooLong";
663 target["Value"] = Json::nullValue;
664 }
665 }
666 break; 661 break;
667 } 662 }
668 663
669 default: 664 default:
670 throw OrthancException(ErrorCode_ParameterOutOfRange); 665 throw OrthancException(ErrorCode_ParameterOutOfRange);
666 }
667
668 assert(targetValue != NULL);
669 assert(targetValue->type() == Json::nullValue);
670 assert(targetType == NULL || targetType->type() == Json::nullValue);
671
672 if (value.IsNull())
673 {
674 if (targetType != NULL)
675 {
676 *targetType = "Null";
677 }
678 }
679 else if (value.IsBinary())
680 {
681 if (flags & DicomToJsonFlags_ConvertBinaryToAscii)
682 {
683 *targetValue = Toolbox::ConvertToAscii(value.GetContent());
684 }
685 else
686 {
687 std::string s;
688 value.FormatDataUriScheme(s);
689 *targetValue = s;
690 }
691
692 if (targetType != NULL)
693 {
694 *targetType = "Binary";
695 }
696 }
697 else if (maxStringLength == 0 ||
698 value.GetContent().size() <= maxStringLength)
699 {
700 *targetValue = value.GetContent();
701
702 if (targetType != NULL)
703 {
704 *targetType = "String";
705 }
706 }
707 else
708 {
709 if (targetType != NULL)
710 {
711 *targetType = "TooLong";
712 }
671 } 713 }
672 } 714 }
673 715
674 716
675 static void DatasetToJson(Json::Value& parent, 717 static void DatasetToJson(Json::Value& parent,
696 Json::Value& target = PrepareNode(parent, element, format); 738 Json::Value& target = PrepareNode(parent, element, format);
697 739
698 if (element.isLeaf()) 740 if (element.isLeaf())
699 { 741 {
700 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, flags, encoding)); 742 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, flags, encoding));
701 LeafValueToJson(target, *v, format, maxStringLength); 743 LeafValueToJson(target, *v, format, flags, maxStringLength);
702 } 744 }
703 else 745 else
704 { 746 {
705 assert(target.type() == Json::nullValue); 747 assert(target.type() == Json::nullValue);
706 target = Json::arrayValue; 748 target = Json::arrayValue;