comparison OrthancServer/ServerIndex.cpp @ 198:663cc6c46d0a

before refactoring of ServerIndex::GetXXX
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Nov 2012 15:49:42 +0100
parents 530a25320461
children dfa2899d9960
comparison
equal deleted inserted replaced
197:530a25320461 198:663cc6c46d0a
785 785
786 return SeriesStatus_Complete; 786 return SeriesStatus_Complete;
787 } 787 }
788 788
789 789
790 void ServerIndex::MainDicomTagsToJson2(Json::Value& target,
791 int64_t resourceId)
792 {
793 DicomMap tags;
794 db2_->GetMainDicomTags(tags, resourceId);
795 target["MainDicomTags"] = Json::objectValue;
796 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags);
797 }
798
799 bool ServerIndex::LookupResource(Json::Value& result,
800 const std::string& publicId)
801 {
802 result = Json::objectValue;
803
804 // Lookup for the requested resource
805 int64_t id;
806 ResourceType type;
807 if (!db2_->LookupResource(publicId, id, type))
808 {
809 return false;
810 }
811
812 // Find the parent resource (if it exists)
813 if (type != ResourceType_Patient)
814 {
815 int64_t parentId;
816 if (!db2_->LookupParent(parentId, id))
817 {
818 throw OrthancException(ErrorCode_InternalError);
819 }
820
821 std::string parent = db2_->GetPublicId(parentId);
822
823 switch (type)
824 {
825 case ResourceType_Study:
826 result["ParentPatient"] = parent;
827 break;
828
829 case ResourceType_Series:
830 result["ParentStudy"] = parent;
831 break;
832
833 case ResourceType_Instance:
834 result["ParentSeries"] = parent;
835 break;
836
837 default:
838 throw OrthancException(ErrorCode_InternalError);
839 }
840 }
841
842 // List the children resources
843 std::list<std::string> children;
844 db2_->GetChildrenPublicId(children, id);
845
846 if (type != ResourceType_Instance)
847 {
848 Json::Value c = Json::arrayValue;
849
850 for (std::list<std::string>::const_iterator
851 it = children.begin(); it != children.end(); it++)
852 {
853 c.append(*it);
854 }
855
856 switch (type)
857 {
858 case ResourceType_Patient:
859 result["Studies"] = c;
860 break;
861
862 case ResourceType_Study:
863 result["Series"] = c;
864 break;
865
866 case ResourceType_Series:
867 result["Instances"] = c;
868 break;
869
870 default:
871 throw OrthancException(ErrorCode_InternalError);
872 }
873 }
874
875 // Set the resource type
876 switch (type)
877 {
878 case ResourceType_Patient:
879 result["Type"] = "Patient";
880 break;
881
882 case ResourceType_Study:
883 result["Type"] = "Study";
884 break;
885
886 case ResourceType_Series:
887 result["Type"] = "Series";
888 break;
889
890 case ResourceType_Instance:
891 result["Type"] = "Instance";
892 break;
893
894 default:
895 throw OrthancException(ErrorCode_InternalError);
896 }
897
898 // Record the remaining information
899 result["ID"] = publicId;
900 MainDicomTagsToJson2(result, id);
901
902 return true;
903 }
904
790 905
791 bool ServerIndex::GetInstance(Json::Value& result, 906 bool ServerIndex::GetInstance(Json::Value& result,
792 const std::string& instanceUuid) 907 const std::string& instanceUuid)
793 { 908 {
794 assert(result.type() == Json::objectValue); 909 assert(result.type() == Json::objectValue);
815 else 930 else
816 { 931 {
817 result["IndexInSeries"] = s.ColumnInt(4); 932 result["IndexInSeries"] = s.ColumnInt(4);
818 } 933 }
819 934
935 result["Type"] = "Instance";
936
820 return true; 937 return true;
821 } 938 }
822 } 939 }
823 940
824 941
878 case SeriesStatus_Unknown: 995 case SeriesStatus_Unknown:
879 result["Status"] = "Unknown"; 996 result["Status"] = "Unknown";
880 break; 997 break;
881 } 998 }
882 999
1000 result["Type"] = "Series";
1001
883 return true; 1002 return true;
884 } 1003 }
885 1004
886 1005
887 bool ServerIndex::GetStudy(Json::Value& result, 1006 bool ServerIndex::GetStudy(Json::Value& result,
908 { 1027 {
909 series.append(s2.ColumnString(0)); 1028 series.append(s2.ColumnString(0));
910 } 1029 }
911 1030
912 result["Series"] = series; 1031 result["Series"] = series;
1032 result["Type"] = "Study";
913 return true; 1033 return true;
914 } 1034 }
915 1035
916 1036
917 bool ServerIndex::GetPatient(Json::Value& result, 1037 bool ServerIndex::GetPatient(Json::Value& result,
937 { 1057 {
938 studies.append(s2.ColumnString(0)); 1058 studies.append(s2.ColumnString(0));
939 } 1059 }
940 1060
941 result["Studies"] = studies; 1061 result["Studies"] = studies;
1062 result["Type"] = "Patient";
942 return true; 1063 return true;
1064
1065 //return LookupResource(result, patientUuid);
943 } 1066 }
944 1067
945 1068
946 bool ServerIndex::GetFile(std::string& fileUuid, 1069 bool ServerIndex::GetFile(std::string& fileUuid,
947 CompressionType& compressionType, 1070 CompressionType& compressionType,