Mercurial > hg > orthanc
comparison UnitTestsSources/DicomMapTests.cpp @ 3198:7724ed267b5c
unit testing dicomweb conversion
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Feb 2019 07:28:58 +0100 |
parents | 24a76ed0d8a3 |
children | 9316f341e40f |
comparison
equal
deleted
inserted
replaced
3197:24a76ed0d8a3 | 3198:7724ed267b5c |
---|---|
719 const DicomTag& tag, | 719 const DicomTag& tag, |
720 ValueRepresentation vr, | 720 ValueRepresentation vr, |
721 const void* data, | 721 const void* data, |
722 size_t size) ORTHANC_OVERRIDE | 722 size_t size) ORTHANC_OVERRIDE |
723 { | 723 { |
724 if (tag.GetElement() != 0x0000 && | 724 assert(vr == ValueRepresentation_OtherByte || |
725 vr != ValueRepresentation_NotSupported /*&& | 725 vr == ValueRepresentation_OtherDouble || |
726 !bulkUriRoot_.empty()*/) | 726 vr == ValueRepresentation_OtherFloat || |
727 vr == ValueRepresentation_OtherLong || | |
728 vr == ValueRepresentation_OtherWord || | |
729 vr == ValueRepresentation_Unknown); | |
730 | |
731 if (tag.GetElement() != 0x0000 /*&& | |
732 !bulkUriRoot_.empty()*/) | |
727 { | 733 { |
728 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | 734 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); |
729 node[KEY_VR] = EnumerationToString(vr); | 735 node[KEY_VR] = EnumerationToString(vr); |
730 | 736 |
731 std::string tmp(static_cast<const char*>(data), size); | 737 std::string tmp(static_cast<const char*>(data), size); |
815 const std::vector<size_t>& parentIndexes, | 821 const std::vector<size_t>& parentIndexes, |
816 const DicomTag& tag, | 822 const DicomTag& tag, |
817 ValueRepresentation vr, | 823 ValueRepresentation vr, |
818 const std::string& tutu) ORTHANC_OVERRIDE | 824 const std::string& tutu) ORTHANC_OVERRIDE |
819 { | 825 { |
820 if (vr == ValueRepresentation_OtherByte || | 826 if (tag.GetElement() == 0x0000 || |
821 vr == ValueRepresentation_OtherDouble || | 827 vr == ValueRepresentation_NotSupported) |
822 vr == ValueRepresentation_OtherFloat || | |
823 vr == ValueRepresentation_OtherLong || | |
824 vr == ValueRepresentation_OtherWord || | |
825 vr == ValueRepresentation_Unknown) | |
826 { | |
827 VisitBinary(parentTags, parentIndexes, tag, vr, tutu.c_str(), tutu.size()); | |
828 return Action_None; | |
829 } | |
830 else if (tag.GetElement() == 0x0000 || | |
831 vr == ValueRepresentation_NotSupported) | |
832 { | 828 { |
833 return Action_None; | 829 return Action_None; |
834 } | 830 } |
835 else | 831 else |
836 { | 832 { |
871 node[KEY_VALUE].append(value); | 867 node[KEY_VALUE].append(value); |
872 break; | 868 break; |
873 } | 869 } |
874 | 870 |
875 case ValueRepresentation_IntegerString: | 871 case ValueRepresentation_IntegerString: |
876 { | 872 if (tokens[i].empty()) |
877 int64_t value = boost::lexical_cast<int64_t>(tokens[i]); | 873 { |
878 node[KEY_VALUE].append(FormatInteger(value)); | 874 node[KEY_VALUE].append(Json::nullValue); |
875 } | |
876 else | |
877 { | |
878 int64_t value = boost::lexical_cast<int64_t>(tokens[i]); | |
879 node[KEY_VALUE].append(FormatInteger(value)); | |
880 } | |
881 | |
879 break; | 882 break; |
880 } | |
881 | 883 |
882 case ValueRepresentation_DecimalString: | 884 case ValueRepresentation_DecimalString: |
883 { | 885 if (tokens[i].empty()) |
884 double value = boost::lexical_cast<double>(tokens[i]); | 886 { |
885 node[KEY_VALUE].append(FormatDouble(value)); | 887 node[KEY_VALUE].append(Json::nullValue); |
888 } | |
889 else | |
890 { | |
891 double value = boost::lexical_cast<double>(tokens[i]); | |
892 node[KEY_VALUE].append(FormatDouble(value)); | |
893 } | |
886 break; | 894 break; |
887 } | |
888 | 895 |
889 default: | 896 default: |
890 if (tokens[i].empty()) | 897 if (tokens[i].empty()) |
891 { | 898 { |
892 node[KEY_VALUE].append(Json::nullValue); | 899 node[KEY_VALUE].append(Json::nullValue); |
929 import sys | 936 import sys |
930 j = json.loads(sys.stdin.read().decode("utf-8-sig")) | 937 j = json.loads(sys.stdin.read().decode("utf-8-sig")) |
931 print(json.dumps(j, indent=4, sort_keys=True, ensure_ascii=False).encode('utf-8')) | 938 print(json.dumps(j, indent=4, sort_keys=True, ensure_ascii=False).encode('utf-8')) |
932 EOF | 939 EOF |
933 | 940 |
934 DCMDICTPATH=/home/jodogne/Downloads/dcmtk-3.6.4/dcmdata/data/dicom.dic /home/jodogne/Downloads/dcmtk-3.6.4/i/bin/dcm2json ~/Subversion/orthanc-tests/Database/Brainix/Epi/IM-0001-0018.dcm | tr -d '\0' | sed 's/\\u0000//g' | sed 's/\.0$//' | python /tmp/tutu.py > /tmp/a.json | 941 DCMDICTPATH=/home/jodogne/Downloads/dcmtk-3.6.4/dcmdata/data/dicom.dic /home/jodogne/Downloads/dcmtk-3.6.4/i/bin/dcm2json ~/Subversion/orthanc-tests/Database/DummyCT.dcm | tr -d '\0' | sed 's/\\u0000//g' | sed 's/\.0$//' | python /tmp/tutu.py > /tmp/a.json |
935 | 942 |
936 make -j4 && ./UnitTests --gtest_filter=DicomWeb* && python /tmp/tutu.py < /tmp/tutu.json > /tmp/b.json && diff -i /tmp/a.json /tmp/b.json | 943 make -j4 && ./UnitTests --gtest_filter=DicomWeb* && python /tmp/tutu.py < tutu.json > /tmp/b.json && diff -i /tmp/a.json /tmp/b.json |
937 | 944 |
938 */ | 945 */ |
939 | 946 |
940 TEST(DicomWebJson, Basic) | 947 TEST(DicomWebJson, Basic) |
941 { | 948 { |
942 std::string content; | 949 std::string content; |
943 Orthanc::SystemToolbox::ReadFile(content, "/home/jodogne/Subversion/orthanc-tests/Database/Brainix/Epi/IM-0001-0018.dcm"); | 950 Orthanc::SystemToolbox::ReadFile(content, "/home/jodogne/Subversion/orthanc-tests/Database/DummyCT.dcm"); |
944 | 951 |
945 Orthanc::ParsedDicomFile dicom(content); | 952 Orthanc::ParsedDicomFile dicom(content); |
946 | 953 |
947 Orthanc::DicomJsonVisitor visitor; | 954 Orthanc::DicomJsonVisitor visitor; |
948 dicom.Apply(visitor); | 955 dicom.Apply(visitor); |
949 | 956 |
950 Orthanc::SystemToolbox::WriteFile(visitor.GetResult().toStyledString(), "/tmp/tutu.json"); | 957 Orthanc::SystemToolbox::WriteFile(visitor.GetResult().toStyledString(), "tutu.json"); |
951 } | 958 } |
959 | |
960 | |
961 TEST(DicomWebJson, Multiplicity) | |
962 { | |
963 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.4.html | |
964 | |
965 ParsedDicomFile dicom(false); | |
966 dicom.ReplacePlainString(DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "1\\2.3\\4"); | |
967 dicom.ReplacePlainString(DICOM_TAG_IMAGE_POSITION_PATIENT, ""); | |
968 | |
969 Orthanc::DicomJsonVisitor visitor; | |
970 dicom.Apply(visitor); | |
971 | |
972 { | |
973 const Json::Value& tag = visitor.GetResult() ["00200037"]; | |
974 const Json::Value& value = tag["Value"]; | |
975 | |
976 ASSERT_EQ(EnumerationToString(ValueRepresentation_DecimalString), tag["vr"].asString()); | |
977 ASSERT_EQ(2u, tag.getMemberNames().size()); | |
978 ASSERT_EQ(3u, value.size()); | |
979 ASSERT_EQ(Json::realValue, value[1].type()); | |
980 ASSERT_FLOAT_EQ(1.0f, value[0].asFloat()); | |
981 ASSERT_FLOAT_EQ(2.3f, value[1].asFloat()); | |
982 ASSERT_FLOAT_EQ(4.0f, value[2].asFloat()); | |
983 } | |
984 | |
985 { | |
986 const Json::Value& tag = visitor.GetResult() ["00200032"]; | |
987 ASSERT_EQ(EnumerationToString(ValueRepresentation_DecimalString), tag["vr"].asString()); | |
988 ASSERT_EQ(1u, tag.getMemberNames().size()); | |
989 } | |
990 } | |
991 | |
992 | |
993 TEST(DicomWebJson, NullValue) | |
994 { | |
995 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.5.html | |
996 | |
997 ParsedDicomFile dicom(false); | |
998 dicom.ReplacePlainString(DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "1.5\\\\\\2.5"); | |
999 | |
1000 Orthanc::DicomJsonVisitor visitor; | |
1001 dicom.Apply(visitor); | |
1002 | |
1003 { | |
1004 const Json::Value& tag = visitor.GetResult() ["00200037"]; | |
1005 const Json::Value& value = tag["Value"]; | |
1006 | |
1007 ASSERT_EQ(EnumerationToString(ValueRepresentation_DecimalString), tag["vr"].asString()); | |
1008 ASSERT_EQ(2u, tag.getMemberNames().size()); | |
1009 ASSERT_EQ(4u, value.size()); | |
1010 ASSERT_EQ(Json::realValue, value[0].type()); | |
1011 ASSERT_EQ(Json::nullValue, value[1].type()); | |
1012 ASSERT_EQ(Json::nullValue, value[2].type()); | |
1013 ASSERT_EQ(Json::realValue, value[3].type()); | |
1014 ASSERT_FLOAT_EQ(1.5f, value[0].asFloat()); | |
1015 ASSERT_FLOAT_EQ(2.5f, value[3].asFloat()); | |
1016 } | |
1017 } | |
1018 | |
1019 | |
1020 TEST(DicomWebJson, ValueRepresentation) | |
1021 { | |
1022 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.3.html | |
1023 | |
1024 ParsedDicomFile dicom(false); | |
1025 dicom.ReplacePlainString(DicomTag(0x0040, 0x0241), "AE"); | |
1026 dicom.ReplacePlainString(DicomTag(0x0010, 0x1010), "AS"); | |
1027 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()-> | |
1028 putAndInsertTagKey(DcmTag(0x0020, 0x9165), | |
1029 DcmTagKey(0x0010, 0x0020)).good()); | |
1030 dicom.ReplacePlainString(DicomTag(0x0008, 0x0052), "CS"); | |
1031 dicom.ReplacePlainString(DicomTag(0x0008, 0x0012), "DA"); | |
1032 dicom.ReplacePlainString(DicomTag(0x0010, 0x1020), "42"); // DS | |
1033 dicom.ReplacePlainString(DicomTag(0x0008, 0x002a), "DT"); | |
1034 dicom.ReplacePlainString(DicomTag(0x0010, 0x9431), "43"); // FL | |
1035 dicom.ReplacePlainString(DicomTag(0x0008, 0x1163), "44"); // FD | |
1036 dicom.ReplacePlainString(DicomTag(0x0008, 0x1160), "45"); // IS | |
1037 dicom.ReplacePlainString(DicomTag(0x0008, 0x0070), "LO"); | |
1038 dicom.ReplacePlainString(DicomTag(0x0008, 0x0108), "LT"); | |
1039 | |
1040 Orthanc::DicomJsonVisitor visitor; | |
1041 dicom.Apply(visitor); | |
1042 | |
1043 std::cout << visitor.GetResult(); | |
1044 ASSERT_EQ("AE", visitor.GetResult() ["00400241"]["vr"].asString()); | |
1045 ASSERT_EQ("AE", visitor.GetResult() ["00400241"]["Value"][0].asString()); | |
1046 ASSERT_EQ("AS", visitor.GetResult() ["00101010"]["vr"].asString()); | |
1047 ASSERT_EQ("AS", visitor.GetResult() ["00101010"]["Value"][0].asString()); | |
1048 ASSERT_EQ("AT", visitor.GetResult() ["00209165"]["vr"].asString()); | |
1049 ASSERT_EQ("00100020", visitor.GetResult() ["00209165"]["Value"][0].asString()); | |
1050 ASSERT_EQ("CS", visitor.GetResult() ["00080052"]["vr"].asString()); | |
1051 ASSERT_EQ("CS", visitor.GetResult() ["00080052"]["Value"][0].asString()); | |
1052 ASSERT_EQ("DA", visitor.GetResult() ["00080012"]["vr"].asString()); | |
1053 ASSERT_EQ("DA", visitor.GetResult() ["00080012"]["Value"][0].asString()); | |
1054 ASSERT_EQ("DS", visitor.GetResult() ["00101020"]["vr"].asString()); | |
1055 ASSERT_FLOAT_EQ(42.0f, visitor.GetResult() ["00101020"]["Value"][0].asFloat()); | |
1056 ASSERT_EQ("DT", visitor.GetResult() ["0008002A"]["vr"].asString()); | |
1057 ASSERT_EQ("DT", visitor.GetResult() ["0008002A"]["Value"][0].asString()); | |
1058 ASSERT_EQ("FL", visitor.GetResult() ["00109431"]["vr"].asString()); | |
1059 ASSERT_FLOAT_EQ(43.0f, visitor.GetResult() ["00109431"]["Value"][0].asFloat()); | |
1060 ASSERT_EQ("FD", visitor.GetResult() ["00081163"]["vr"].asString()); | |
1061 ASSERT_FLOAT_EQ(44.0f, visitor.GetResult() ["00081163"]["Value"][0].asFloat()); | |
1062 ASSERT_EQ("IS", visitor.GetResult() ["00081160"]["vr"].asString()); | |
1063 ASSERT_FLOAT_EQ(45.0f, visitor.GetResult() ["00081160"]["Value"][0].asFloat()); | |
1064 ASSERT_EQ("LO", visitor.GetResult() ["00080070"]["vr"].asString()); | |
1065 ASSERT_EQ("LO", visitor.GetResult() ["00080070"]["Value"][0].asString()); | |
1066 ASSERT_EQ("LT", visitor.GetResult() ["00080108"]["vr"].asString()); | |
1067 ASSERT_EQ("LT", visitor.GetResult() ["00080108"]["Value"][0].asString()); | |
1068 } | |
1069 | |
952 | 1070 |
953 #endif | 1071 #endif |