Mercurial > hg > orthanc
comparison UnitTestsSources/DicomMapTests.cpp @ 3193:c6cfd502bf79
dicomweb
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 05 Feb 2019 17:00:45 +0100 |
parents | 4bbadcd03966 |
children | 47ef29168698 |
comparison
equal
deleted
inserted
replaced
3192:595bfee4391a | 3193:c6cfd502bf79 |
---|---|
578 { | 578 { |
579 assert(parentTags.size() == parentIndexes.size()); | 579 assert(parentTags.size() == parentIndexes.size()); |
580 | 580 |
581 Json::Value* node = &result_; | 581 Json::Value* node = &result_; |
582 | 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++) | 583 for (size_t i = 0; i < parentTags.size(); i++) |
589 { | 584 { |
590 std::string t = FormatTag(parentTags[i]); | 585 std::string t = FormatTag(parentTags[i]); |
591 | 586 |
592 if (!node->isMember(t)) | 587 if (!node->isMember(t)) |
596 item["Value"] = Json::arrayValue; | 591 item["Value"] = Json::arrayValue; |
597 item["Value"].append(Json::objectValue); | 592 item["Value"].append(Json::objectValue); |
598 (*node) [t] = item; | 593 (*node) [t] = item; |
599 | 594 |
600 node = &(*node)[t]["Value"][0]; | 595 node = &(*node)[t]["Value"][0]; |
601 std::cout << result_.toStyledString(); | |
602 } | 596 } |
603 else if ((*node) [t].type() != Json::objectValue || | 597 else if ((*node) [t].type() != Json::objectValue || |
604 !(*node) [t].isMember("vr") || | 598 !(*node) [t].isMember("vr") || |
605 (*node) [t]["vr"].type() != Json::stringValue || | 599 (*node) [t]["vr"].type() != Json::stringValue || |
606 (*node) [t]["vr"].asString() != "SQ" || | 600 (*node) [t]["vr"].asString() != "SQ" || |
607 !(*node) [t].isMember("Value") || | 601 !(*node) [t].isMember("Value") || |
608 (*node) [t]["Value"].type() != Json::arrayValue) | 602 (*node) [t]["Value"].type() != Json::arrayValue) |
609 { | 603 { |
610 throw OrthancException(ErrorCode_InternalError); | 604 throw OrthancException(ErrorCode_InternalError); |
611 } | 605 } |
612 else | 606 else |
613 { | 607 { |
614 std::cout << result_.toStyledString(); | 608 size_t currentSize = (*node) [t]["Value"].size(); |
615 printf("%d %d\n", (*node) [t]["Value"].size(), parentIndexes[i]); | 609 |
616 | 610 if (parentIndexes[i] < currentSize) |
617 if ((*node) [t]["Value"].size() >= parentIndexes[i]) | 611 { |
612 // The node already exists | |
613 } | |
614 else if (parentIndexes[i] == currentSize) | |
615 { | |
616 (*node) [t]["Value"].append(Json::objectValue); | |
617 } | |
618 else | |
618 { | 619 { |
619 throw OrthancException(ErrorCode_InternalError); | 620 throw OrthancException(ErrorCode_InternalError); |
620 } | 621 } |
621 else | 622 |
622 { | 623 node = &(*node) [t]["Value"][Json::ArrayIndex(parentIndexes[i])]; |
623 (*node) [t]["Value"].append(Json::objectValue); | |
624 node = &(*node) [t]["Value"][Json::ArrayIndex(parentIndexes[i])]; | |
625 } | |
626 } | 624 } |
627 } | 625 } |
628 | 626 |
629 assert(node->type() == Json::objectValue); | 627 assert(node->type() == Json::objectValue); |
630 | 628 |
673 const DicomTag& tag, | 671 const DicomTag& tag, |
674 ValueRepresentation vr, | 672 ValueRepresentation vr, |
675 const void* data, | 673 const void* data, |
676 size_t size) ORTHANC_OVERRIDE | 674 size_t size) ORTHANC_OVERRIDE |
677 { | 675 { |
678 if (!bulkUriRoot_.empty()) | 676 if (vr != ValueRepresentation_NotSupported && |
677 !bulkUriRoot_.empty()) | |
679 { | 678 { |
680 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | 679 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); |
680 node["vr"] = EnumerationToString(vr); | |
681 } | 681 } |
682 } | 682 } |
683 | 683 |
684 virtual void VisitInteger(const std::vector<DicomTag>& parentTags, | 684 virtual void VisitInteger(const std::vector<DicomTag>& parentTags, |
685 const std::vector<size_t>& parentIndexes, | 685 const std::vector<size_t>& parentIndexes, |
686 const DicomTag& tag, | 686 const DicomTag& tag, |
687 ValueRepresentation vr, | 687 ValueRepresentation vr, |
688 int64_t value) ORTHANC_OVERRIDE | 688 int64_t value) ORTHANC_OVERRIDE |
689 { | 689 { |
690 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | 690 if (vr != ValueRepresentation_NotSupported) |
691 | 691 { |
692 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
693 node["vr"] = EnumerationToString(vr); | |
694 | |
695 Json::Value content = Json::arrayValue; | |
696 if (value < 0) | |
697 { | |
698 content.append(static_cast<int32_t>(value)); | |
699 } | |
700 else | |
701 { | |
702 content.append(static_cast<uint32_t>(value)); | |
703 } | |
704 node["Value"] = content; | |
705 } | |
692 } | 706 } |
693 | 707 |
694 virtual void VisitDouble(const std::vector<DicomTag>& parentTags, | 708 virtual void VisitDouble(const std::vector<DicomTag>& parentTags, |
695 const std::vector<size_t>& parentIndexes, | 709 const std::vector<size_t>& parentIndexes, |
696 const DicomTag& tag, | 710 const DicomTag& tag, |
697 ValueRepresentation vr, | 711 ValueRepresentation vr, |
698 double value) ORTHANC_OVERRIDE | 712 double value) ORTHANC_OVERRIDE |
699 { | 713 { |
700 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | 714 if (vr != ValueRepresentation_NotSupported) |
701 | 715 { |
716 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
717 node["vr"] = EnumerationToString(vr); | |
718 | |
719 Json::Value content = Json::arrayValue; | |
720 content.append(value); | |
721 node["Value"] = content; | |
722 } | |
702 } | 723 } |
703 | 724 |
704 virtual void VisitAttribute(const std::vector<DicomTag>& parentTags, | 725 virtual void VisitAttribute(const std::vector<DicomTag>& parentTags, |
705 const std::vector<size_t>& parentIndexes, | 726 const std::vector<size_t>& parentIndexes, |
706 const DicomTag& tag, | 727 const DicomTag& tag, |
707 ValueRepresentation vr, | 728 ValueRepresentation vr, |
708 const DicomTag& value) ORTHANC_OVERRIDE | 729 const DicomTag& value) ORTHANC_OVERRIDE |
709 { | 730 { |
710 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | 731 if (vr != ValueRepresentation_NotSupported) |
711 | 732 { |
733 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
734 node["vr"] = EnumerationToString(vr); | |
735 } | |
712 } | 736 } |
713 | 737 |
714 virtual Action VisitString(std::string& newValue, | 738 virtual Action VisitString(std::string& newValue, |
715 const std::vector<DicomTag>& parentTags, | 739 const std::vector<DicomTag>& parentTags, |
716 const std::vector<size_t>& parentIndexes, | 740 const std::vector<size_t>& parentIndexes, |
717 const DicomTag& tag, | 741 const DicomTag& tag, |
718 ValueRepresentation vr, | 742 ValueRepresentation vr, |
719 const std::string& value) ORTHANC_OVERRIDE | 743 const std::string& value) ORTHANC_OVERRIDE |
720 { | 744 { |
721 printf("[%s] [%s]\n", FormatTag(tag).c_str(), value.c_str()); | 745 if (vr != ValueRepresentation_NotSupported) |
722 | 746 { |
723 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | 747 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); |
748 node["vr"] = EnumerationToString(vr); | |
749 | |
750 std::vector<std::string> tokens; | |
751 Toolbox::TokenizeString(tokens, value, '\\'); | |
752 | |
753 node["Value"] = Json::arrayValue; | |
754 for (size_t i = 0; i < tokens.size(); i++) | |
755 { | |
756 try | |
757 { | |
758 switch (vr) | |
759 { | |
760 case ValueRepresentation_PersonName: | |
761 { | |
762 Json::Value value = Json::objectValue; | |
763 value["Alphabetic"] = tokens[i]; | |
764 node["Value"].append(value); | |
765 break; | |
766 } | |
767 | |
768 case ValueRepresentation_IntegerString: | |
769 { | |
770 int64_t value = boost::lexical_cast<int64_t>(tokens[i]); | |
771 if (value < 0) | |
772 { | |
773 node["Value"].append(static_cast<int32_t>(value)); | |
774 } | |
775 else | |
776 { | |
777 node["Value"].append(static_cast<uint32_t>(value)); | |
778 } | |
779 break; | |
780 } | |
781 | |
782 case ValueRepresentation_DecimalString: | |
783 { | |
784 double value = boost::lexical_cast<double>(tokens[i]); | |
785 node["Value"].append(value); | |
786 break; | |
787 } | |
788 | |
789 default: | |
790 node["Value"].append(tokens[i]); | |
791 break; | |
792 } | |
793 } | |
794 catch (boost::bad_lexical_cast&) | |
795 { | |
796 throw OrthancException(ErrorCode_BadFileFormat); | |
797 } | |
798 } | |
799 } | |
724 | 800 |
725 return Action_None; | 801 return Action_None; |
726 } | 802 } |
727 }; | 803 }; |
728 } | 804 } |
729 | 805 |
730 #include "../Core/SystemToolbox.h" | 806 #include "../Core/SystemToolbox.h" |
731 | 807 |
732 | 808 |
809 /* | |
810 | |
811 cd /home/jodogne/Subversion/orthanc/s/dcmtk-3.6.2/i/bin | |
812 DCMDICTPATH=/home/jodogne/Downloads/dcmtk-3.6.2/dcmdata/data/dicom.dic ./dcm2json ~/Subversion/orthanc-tests/Database/DummyCT.dcm | python -mjson.tool > /tmp/a.json | |
813 | |
814 make -j4 && ./UnitTests --gtest_filter=DicomWeb* && python -mjson.tool /tmp/tutu.json > /tmp/b.json | |
815 diff /tmp/a.json /tmp/b.json | |
816 | |
817 */ | |
818 | |
733 TEST(DicomWebJson, Basic) | 819 TEST(DicomWebJson, Basic) |
734 { | 820 { |
735 std::string content; | 821 std::string content; |
736 Orthanc::SystemToolbox::ReadFile(content, "/home/jodogne/Subversion/orthanc-tests/Database/DummyCT.dcm"); | 822 Orthanc::SystemToolbox::ReadFile(content, "/home/jodogne/Subversion/orthanc-tests/Database/DummyCT.dcm"); |
737 | 823 |
738 Orthanc::ParsedDicomFile dicom(content); | 824 Orthanc::ParsedDicomFile dicom(content); |
739 | 825 |
740 Orthanc::DicomJsonVisitor visitor; | 826 Orthanc::DicomJsonVisitor visitor; |
741 dicom.Apply(visitor); | 827 dicom.Apply(visitor); |
742 | 828 |
743 std::cout << visitor.GetResult().toStyledString() << std::endl; | 829 Orthanc::SystemToolbox::WriteFile(visitor.GetResult().toStyledString(), "/tmp/tutu.json"); |
744 } | 830 } |
745 | 831 |
746 #endif | 832 #endif |