comparison OrthancServer/FromDcmtkBridge.cpp @ 1686:14a32b2fa63e

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 Oct 2015 13:57:26 +0200
parents 5360cdba70d8
children 4d80fc990dae
comparison
equal deleted inserted replaced
1685:22e7e2ba99db 1686:14a32b2fa63e
573 return new DicomNullValue; 573 return new DicomNullValue;
574 } 574 }
575 } 575 }
576 576
577 577
578 static void StoreElement(Json::Value& target, 578 static void DatasetToJson(Json::Value& target,
579 DcmElement& element, 579 DcmItem& item,
580 unsigned int maxStringLength, 580 DicomToJsonFormat format,
581 Encoding encoding); 581 unsigned int maxStringLength,
582 582 Encoding encoding);
583 static void StoreItem(Json::Value& target, 583
584 DcmItem& item, 584 static void ElementToJson(Json::Value& target,
585 unsigned int maxStringLength, 585 DcmElement& element,
586 Encoding encoding) 586 DicomToJsonFormat format,
587 { 587 unsigned int maxStringLength,
588 target = Json::Value(Json::objectValue); 588 Encoding encoding)
589
590 for (unsigned long i = 0; i < item.card(); i++)
591 {
592 DcmElement* element = item.getElement(i);
593 StoreElement(target, *element, maxStringLength, encoding);
594 }
595 }
596
597
598 static void StoreElement(Json::Value& target,
599 DcmElement& element,
600 unsigned int maxStringLength,
601 Encoding encoding)
602 { 589 {
603 assert(target.type() == Json::objectValue); 590 assert(target.type() == Json::objectValue);
604 591
605 DicomTag tag(FromDcmtkBridge::GetTag(element)); 592 DicomTag tag(FromDcmtkBridge::GetTag(element));
606 const std::string formattedTag = tag.Format(); 593 const std::string formattedTag = tag.Format();
607 594
608 #if 0
609 const std::string tagName = FromDcmtkBridge::GetName(tag);
610 #else
611 // This version of the code gives access to the name of the private tags 595 // This version of the code gives access to the name of the private tags
612 DcmTag tagbis(element.getTag()); 596 DcmTag tagbis(element.getTag());
613 const std::string tagName(tagbis.getTagName()); 597 const std::string tagName(tagbis.getTagName());
614 #endif
615 598
616 if (element.isLeaf()) 599 if (element.isLeaf())
617 { 600 {
618 Json::Value value(Json::objectValue); 601 Json::Value value(Json::objectValue);
619 value["Name"] = tagName; 602 value["Name"] = tagName;
658 641
659 for (unsigned long i = 0; i < sequence.card(); i++) 642 for (unsigned long i = 0; i < sequence.card(); i++)
660 { 643 {
661 DcmItem* child = sequence.getItem(i); 644 DcmItem* child = sequence.getItem(i);
662 Json::Value& v = children.append(Json::objectValue); 645 Json::Value& v = children.append(Json::objectValue);
663 StoreItem(v, *child, maxStringLength, encoding); 646 DatasetToJson(v, *child, format, maxStringLength, encoding);
664 } 647 }
665 648
666 target[formattedTag]["Name"] = tagName; 649 target[formattedTag]["Name"] = tagName;
667 target[formattedTag]["Type"] = "Sequence"; 650 target[formattedTag]["Type"] = "Sequence";
668 target[formattedTag]["Value"] = children; 651 target[formattedTag]["Value"] = children;
669 } 652 }
670 } 653 }
671 654
672 655
656 static void DatasetToJson(Json::Value& target,
657 DcmItem& item,
658 DicomToJsonFormat format,
659 unsigned int maxStringLength,
660 Encoding encoding)
661 {
662 target = Json::objectValue;
663
664 for (unsigned long i = 0; i < item.card(); i++)
665 {
666 DcmElement* element = item.getElement(i);
667 ElementToJson(target, *element, format, maxStringLength, encoding);
668 }
669 }
670
671
673 void FromDcmtkBridge::ToJson(Json::Value& root, 672 void FromDcmtkBridge::ToJson(Json::Value& root,
674 DcmDataset& dataset, 673 DcmDataset& dataset,
674 DicomToJsonFormat format,
675 unsigned int maxStringLength) 675 unsigned int maxStringLength)
676 { 676 {
677 StoreItem(root, dataset, maxStringLength, DetectEncoding(dataset)); 677 DatasetToJson(root, dataset, format, maxStringLength, DetectEncoding(dataset));
678 } 678 }
679 679
680 680
681 681
682 void FromDcmtkBridge::ToJson(Json::Value& target, 682 void FromDcmtkBridge::ToJson(Json::Value& target,
683 const std::string& path, 683 const std::string& path,
684 DicomToJsonFormat format,
684 unsigned int maxStringLength) 685 unsigned int maxStringLength)
685 { 686 {
686 DcmFileFormat dicom; 687 DcmFileFormat dicom;
687 if (!dicom.loadFile(path.c_str()).good()) 688 if (!dicom.loadFile(path.c_str()).good())
688 { 689 {
689 throw OrthancException(ErrorCode_BadFileFormat); 690 throw OrthancException(ErrorCode_BadFileFormat);
690 } 691 }
691 else 692 else
692 { 693 {
693 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); 694 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), format, maxStringLength);
694 } 695 }
695 } 696 }
696 697
697 698
698 699