comparison OrthancServer/ServerIndex.cpp @ 1238:6c07108ff1e2

cleaning
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Dec 2014 16:14:57 +0100
parents 0f3716b88af7
children 92c6b3b57699
comparison
equal deleted inserted replaced
1237:0f3716b88af7 1238:6c07108ff1e2
418 } 418 }
419 419
420 420
421 421
422 422
423 bool ServerIndex::GetMetadataAsInteger(int& result, 423 bool ServerIndex::GetMetadataAsInteger(int64_t& result,
424 int64_t id, 424 int64_t id,
425 MetadataType type) 425 MetadataType type)
426 { 426 {
427 std::string s = db_->GetMetadata(id, type, ""); 427 std::string s;
428 if (s.size() == 0) 428 if (!db_->LookupMetadata(s, id, type))
429 { 429 {
430 return false; 430 return false;
431 } 431 }
432 432
433 try 433 try
434 { 434 {
435 result = boost::lexical_cast<int>(s); 435 result = boost::lexical_cast<int64_t>(s);
436 return true; 436 return true;
437 } 437 }
438 catch (boost::bad_lexical_cast&) 438 catch (boost::bad_lexical_cast&)
439 { 439 {
440 return false; 440 return false;
770 770
771 771
772 SeriesStatus ServerIndex::GetSeriesStatus(int64_t id) 772 SeriesStatus ServerIndex::GetSeriesStatus(int64_t id)
773 { 773 {
774 // Get the expected number of instances in this series (from the metadata) 774 // Get the expected number of instances in this series (from the metadata)
775 std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances, ""); 775 int64_t expected;
776 776 if (!GetMetadataAsInteger(expected, id, MetadataType_Series_ExpectedNumberOfInstances))
777 size_t expected;
778 try
779 {
780 expected = boost::lexical_cast<size_t>(s);
781 }
782 catch (boost::bad_lexical_cast&)
783 { 777 {
784 return SeriesStatus_Unknown; 778 return SeriesStatus_Unknown;
785 } 779 }
786 780
787 // Loop over the instances of this series 781 // Loop over the instances of this series
788 std::list<int64_t> children; 782 std::list<int64_t> children;
789 db_->GetChildrenInternalId(children, id); 783 db_->GetChildrenInternalId(children, id);
790 784
791 std::set<size_t> instances; 785 std::set<int64_t> instances;
792 for (std::list<int64_t>::const_iterator 786 for (std::list<int64_t>::const_iterator
793 it = children.begin(); it != children.end(); ++it) 787 it = children.begin(); it != children.end(); ++it)
794 { 788 {
795 // Get the index of this instance in the series 789 // Get the index of this instance in the series
796 s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries, ""); 790 int64_t index;
797 size_t index; 791 if (!GetMetadataAsInteger(index, *it, MetadataType_Instance_IndexInSeries))
798 try
799 {
800 index = boost::lexical_cast<size_t>(s);
801 }
802 catch (boost::bad_lexical_cast&)
803 { 792 {
804 return SeriesStatus_Unknown; 793 return SeriesStatus_Unknown;
805 } 794 }
806 795
807 if (!(index > 0 && index <= expected)) 796 if (!(index > 0 && index <= expected))
817 } 806 }
818 807
819 instances.insert(index); 808 instances.insert(index);
820 } 809 }
821 810
822 if (instances.size() == expected) 811 if (static_cast<int64_t>(instances.size()) == expected)
823 { 812 {
824 return SeriesStatus_Complete; 813 return SeriesStatus_Complete;
825 } 814 }
826 else 815 else
827 { 816 {
934 case ResourceType_Series: 923 case ResourceType_Series:
935 { 924 {
936 result["Type"] = "Series"; 925 result["Type"] = "Series";
937 result["Status"] = EnumerationToString(GetSeriesStatus(id)); 926 result["Status"] = EnumerationToString(GetSeriesStatus(id));
938 927
939 int i; 928 int64_t i;
940 if (GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances)) 929 if (GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances))
941 result["ExpectedNumberOfInstances"] = i; 930 result["ExpectedNumberOfInstances"] = static_cast<int>(i);
942 else 931 else
943 result["ExpectedNumberOfInstances"] = Json::nullValue; 932 result["ExpectedNumberOfInstances"] = Json::nullValue;
944 933
945 break; 934 break;
946 } 935 }
956 } 945 }
957 946
958 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize()); 947 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize());
959 result["FileUuid"] = attachment.GetUuid(); 948 result["FileUuid"] = attachment.GetUuid();
960 949
961 int i; 950 int64_t i;
962 if (GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) 951 if (GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries))
963 result["IndexInSeries"] = i; 952 result["IndexInSeries"] = static_cast<int>(i);
964 else 953 else
965 result["IndexInSeries"] = Json::nullValue; 954 result["IndexInSeries"] = Json::nullValue;
966 955
967 break; 956 break;
968 } 957 }
975 result["ID"] = publicId; 964 result["ID"] = publicId;
976 MainDicomTagsToJson(result, id); 965 MainDicomTagsToJson(result, id);
977 966
978 std::string tmp; 967 std::string tmp;
979 968
980 tmp = db_->GetMetadata(id, MetadataType_AnonymizedFrom, ""); 969 if (db_->LookupMetadata(tmp, id, MetadataType_AnonymizedFrom))
981 if (tmp.size() != 0)
982 { 970 {
983 result["AnonymizedFrom"] = tmp; 971 result["AnonymizedFrom"] = tmp;
984 } 972 }
985 973
986 tmp = db_->GetMetadata(id, MetadataType_ModifiedFrom, ""); 974 if (db_->LookupMetadata(tmp, id, MetadataType_ModifiedFrom))
987 if (tmp.size() != 0)
988 { 975 {
989 result["ModifiedFrom"] = tmp; 976 result["ModifiedFrom"] = tmp;
990 } 977 }
991 978
992 if (type == ResourceType_Patient || 979 if (type == ResourceType_Patient ||
993 type == ResourceType_Study || 980 type == ResourceType_Study ||
994 type == ResourceType_Series) 981 type == ResourceType_Series)
995 { 982 {
996 result["IsStable"] = !unstableResources_.Contains(id); 983 result["IsStable"] = !unstableResources_.Contains(id);
997 984
998 tmp = db_->GetMetadata(id, MetadataType_LastUpdate, ""); 985 if (db_->LookupMetadata(tmp, id, MetadataType_LastUpdate))
999 if (tmp.size() != 0)
1000 { 986 {
1001 result["LastUpdate"] = tmp; 987 result["LastUpdate"] = tmp;
1002 } 988 }
1003 } 989 }
1004 990
1911 1897
1912 for (std::list<MetadataType>::const_iterator 1898 for (std::list<MetadataType>::const_iterator
1913 it = metadata.begin(); it != metadata.end(); it++) 1899 it = metadata.begin(); it != metadata.end(); it++)
1914 { 1900 {
1915 std::string key = EnumerationToString(*it); 1901 std::string key = EnumerationToString(*it);
1916 std::string value = db_->GetMetadata(id, *it, ""); 1902
1903 std::string value;
1904 if (!db_->LookupMetadata(value, id, *it))
1905 {
1906 value.clear();
1907 }
1908
1917 target[key] = value; 1909 target[key] = value;
1918 } 1910 }
1919 1911
1920 return true; 1912 return true;
1921 } 1913 }