comparison UnitTestsSources/DicomMapTests.cpp @ 3187:4bbadcd03966

refactoring retrieval of metadata from database
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Feb 2019 12:06:19 +0100
parents 4e43e67f8ecf
children c6cfd502bf79
comparison
equal deleted inserted replaced
3184:5d1f5984dc41 3187:4bbadcd03966
549 ASSERT_EQ("C", b.GetValue(DICOM_TAG_SERIES_DESCRIPTION).GetContent()); 549 ASSERT_EQ("C", b.GetValue(DICOM_TAG_SERIES_DESCRIPTION).GetContent());
550 ASSERT_EQ("D", b.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).GetContent()); 550 ASSERT_EQ("D", b.GetValue(DICOM_TAG_NUMBER_OF_FRAMES).GetContent());
551 ASSERT_EQ("F", b.GetValue(DICOM_TAG_SLICE_THICKNESS).GetContent()); 551 ASSERT_EQ("F", b.GetValue(DICOM_TAG_SLICE_THICKNESS).GetContent());
552 ASSERT_FALSE(b.HasOnlyMainDicomTags()); 552 ASSERT_FALSE(b.HasOnlyMainDicomTags());
553 } 553 }
554
555
556
557
558 #if 0
559
560 namespace Orthanc
561 {
562 class DicomJsonVisitor : public ITagVisitor
563 {
564 private:
565 Json::Value result_;
566 std::string bulkUriRoot_;
567
568 static std::string FormatTag(const DicomTag& tag)
569 {
570 char buf[16];
571 sprintf(buf, "%04X%04X", tag.GetGroup(), tag.GetElement());
572 return std::string(buf);
573 }
574
575 Json::Value& CreateNode(const std::vector<DicomTag>& parentTags,
576 const std::vector<size_t>& parentIndexes,
577 const DicomTag& tag)
578 {
579 assert(parentTags.size() == parentIndexes.size());
580
581 Json::Value* node = &result_;
582
583 if (parentTags.size() != 0)
584 {
585 printf("ICI %s\n", FormatTag(parentTags[0]).c_str());
586 }
587
588 for (size_t i = 0; i < parentTags.size(); i++)
589 {
590 std::string t = FormatTag(parentTags[i]);
591
592 if (!node->isMember(t))
593 {
594 Json::Value item = Json::objectValue;
595 item["vr"] = "SQ";
596 item["Value"] = Json::arrayValue;
597 item["Value"].append(Json::objectValue);
598 (*node) [t] = item;
599
600 node = &(*node)[t]["Value"][0];
601 std::cout << result_.toStyledString();
602 }
603 else if ((*node) [t].type() != Json::objectValue ||
604 !(*node) [t].isMember("vr") ||
605 (*node) [t]["vr"].type() != Json::stringValue ||
606 (*node) [t]["vr"].asString() != "SQ" ||
607 !(*node) [t].isMember("Value") ||
608 (*node) [t]["Value"].type() != Json::arrayValue)
609 {
610 throw OrthancException(ErrorCode_InternalError);
611 }
612 else
613 {
614 std::cout << result_.toStyledString();
615 printf("%d %d\n", (*node) [t]["Value"].size(), parentIndexes[i]);
616
617 if ((*node) [t]["Value"].size() >= parentIndexes[i])
618 {
619 throw OrthancException(ErrorCode_InternalError);
620 }
621 else
622 {
623 (*node) [t]["Value"].append(Json::objectValue);
624 node = &(*node) [t]["Value"][Json::ArrayIndex(parentIndexes[i])];
625 }
626 }
627 }
628
629 assert(node->type() == Json::objectValue);
630
631 std::string t = FormatTag(tag);
632 if (node->isMember(t))
633 {
634 throw OrthancException(ErrorCode_InternalError);
635 }
636 else
637 {
638 (*node) [t] = Json::objectValue;
639 return (*node) [t];
640 }
641 }
642
643 public:
644 DicomJsonVisitor()
645 {
646 Clear();
647 }
648
649 void SetBulkUriRoot(const std::string& root)
650 {
651 bulkUriRoot_ = root;
652 }
653
654 void Clear()
655 {
656 result_ = Json::objectValue;
657 }
658
659 const Json::Value& GetResult() const
660 {
661 return result_;
662 }
663
664 virtual void VisitUnknown(const std::vector<DicomTag>& parentTags,
665 const std::vector<size_t>& parentIndexes,
666 const DicomTag& tag,
667 ValueRepresentation vr) ORTHANC_OVERRIDE
668 {
669 }
670
671 virtual void VisitBinary(const std::vector<DicomTag>& parentTags,
672 const std::vector<size_t>& parentIndexes,
673 const DicomTag& tag,
674 ValueRepresentation vr,
675 const void* data,
676 size_t size) ORTHANC_OVERRIDE
677 {
678 if (!bulkUriRoot_.empty())
679 {
680 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
681 }
682 }
683
684 virtual void VisitInteger(const std::vector<DicomTag>& parentTags,
685 const std::vector<size_t>& parentIndexes,
686 const DicomTag& tag,
687 ValueRepresentation vr,
688 int64_t value) ORTHANC_OVERRIDE
689 {
690 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
691
692 }
693
694 virtual void VisitDouble(const std::vector<DicomTag>& parentTags,
695 const std::vector<size_t>& parentIndexes,
696 const DicomTag& tag,
697 ValueRepresentation vr,
698 double value) ORTHANC_OVERRIDE
699 {
700 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
701
702 }
703
704 virtual void VisitAttribute(const std::vector<DicomTag>& parentTags,
705 const std::vector<size_t>& parentIndexes,
706 const DicomTag& tag,
707 ValueRepresentation vr,
708 const DicomTag& value) ORTHANC_OVERRIDE
709 {
710 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
711
712 }
713
714 virtual Action VisitString(std::string& newValue,
715 const std::vector<DicomTag>& parentTags,
716 const std::vector<size_t>& parentIndexes,
717 const DicomTag& tag,
718 ValueRepresentation vr,
719 const std::string& value) ORTHANC_OVERRIDE
720 {
721 printf("[%s] [%s]\n", FormatTag(tag).c_str(), value.c_str());
722
723 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
724
725 return Action_None;
726 }
727 };
728 }
729
730 #include "../Core/SystemToolbox.h"
731
732
733 TEST(DicomWebJson, Basic)
734 {
735 std::string content;
736 Orthanc::SystemToolbox::ReadFile(content, "/home/jodogne/Subversion/orthanc-tests/Database/DummyCT.dcm");
737
738 Orthanc::ParsedDicomFile dicom(content);
739
740 Orthanc::DicomJsonVisitor visitor;
741 dicom.Apply(visitor);
742
743 std::cout << visitor.GetResult().toStyledString() << std::endl;
744 }
745
746 #endif