comparison OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5593:862b54b4cfe2 find-refactoring

implemented the default multi-stage find/expand
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 04 May 2024 11:35:34 +0200
parents 1e2631b8b9af
children a906dc19264c
comparison
equal deleted inserted replaced
5592:1e2631b8b9af 5593:862b54b4cfe2
28 28
29 namespace Orthanc 29 namespace Orthanc
30 { 30 {
31 namespace Compatibility 31 namespace Compatibility
32 { 32 {
33 void GenericFind::Execute(FindResponse& response, 33 void GenericFind::ExecuteFind(std::list<std::string>& identifiers,
34 const FindRequest& request) 34 const FindRequest& request,
35 const std::vector<DatabaseConstraint>& normalized)
35 { 36 {
36 if (!request.GetOrthancIdentifiers().HasPatientId() && 37 if (!request.GetOrthancIdentifiers().HasPatientId() &&
37 !request.GetOrthancIdentifiers().HasStudyId() && 38 !request.GetOrthancIdentifiers().HasStudyId() &&
38 !request.GetOrthancIdentifiers().HasSeriesId() && 39 !request.GetOrthancIdentifiers().HasSeriesId() &&
39 !request.GetOrthancIdentifiers().HasInstanceId() && 40 !request.GetOrthancIdentifiers().HasInstanceId() &&
40 request.GetDicomTagConstraintsCount() == 0 && 41 request.GetDicomTagConstraintsCount() == 0 &&
41 request.GetMetadataConstraintsCount() == 0 && 42 request.GetMetadataConstraintsCount() == 0 &&
42 request.GetOrdering().empty() && 43 request.GetOrdering().empty() &&
43 request.GetLabels().empty()) 44 request.GetLabels().empty())
44 { 45 {
45 std::list<std::string> ids;
46
47 if (request.HasLimits()) 46 if (request.HasLimits())
48 { 47 {
49 transaction_.GetAllPublicIds(ids, request.GetLevel(), request.GetLimitsSince(), request.GetLimitsCount()); 48 transaction_.GetAllPublicIds(identifiers, request.GetLevel(), request.GetLimitsSince(), request.GetLimitsCount());
50 } 49 }
51 else 50 else
52 { 51 {
53 transaction_.GetAllPublicIds(ids, request.GetLevel()); 52 transaction_.GetAllPublicIds(identifiers, request.GetLevel());
54 }
55
56 for (std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
57 {
58 int64_t internalId;
59 ResourceType t;
60 if (!transaction_.LookupResource(internalId, t, *it) ||
61 t != request.GetLevel())
62 {
63 throw OrthancException(ErrorCode_InternalError);
64 }
65
66 std::unique_ptr<FindResponse::Resource> resource(new FindResponse::Resource(request.GetLevel(), *it));
67
68 if (request.IsRetrieveMainDicomTags())
69 {
70 DicomMap m;
71 transaction_.GetMainDicomTags(m, internalId);
72
73 DicomArray a(m);
74 for (size_t i = 0; i < a.GetSize(); i++)
75 {
76 const DicomElement& element = a.GetElement(i);
77 if (element.GetValue().IsString())
78 {
79 resource->AddStringDicomTag(element.GetTag().GetGroup(), element.GetTag().GetElement(),
80 element.GetValue().GetContent());
81 }
82 else
83 {
84 throw OrthancException(ErrorCode_BadParameterType);
85 }
86 }
87 }
88
89 if (request.IsRetrieveParentIdentifier())
90 {
91 int64_t parentId;
92 if (transaction_.LookupParent(parentId, internalId))
93 {
94 resource->SetParentIdentifier(transaction_.GetPublicId(parentId));
95 }
96 else
97 {
98 throw OrthancException(ErrorCode_InternalError);
99 }
100 }
101
102 // TODO-FIND: Continue
103
104 response.Add(resource.release());
105 } 53 }
106 } 54 }
107 else 55 else
108 { 56 {
109 throw OrthancException(ErrorCode_NotImplemented); 57 throw OrthancException(ErrorCode_NotImplemented); // Not supported
110 } 58 }
59 }
60
61
62 void GenericFind::ExecuteExpand(FindResponse& response,
63 const FindRequest& request,
64 const std::string& identifier)
65 {
66 int64_t internalId;
67 ResourceType t;
68 if (!transaction_.LookupResource(internalId, t, identifier) ||
69 t != request.GetLevel())
70 {
71 throw OrthancException(ErrorCode_InternalError);
72 }
73
74 std::unique_ptr<FindResponse::Resource> resource(new FindResponse::Resource(request.GetLevel(), identifier));
75
76 if (request.IsRetrieveMainDicomTags())
77 {
78 DicomMap m;
79 transaction_.GetMainDicomTags(m, internalId);
80
81 DicomArray a(m);
82 for (size_t i = 0; i < a.GetSize(); i++)
83 {
84 const DicomElement& element = a.GetElement(i);
85 if (element.GetValue().IsString())
86 {
87 resource->AddStringDicomTag(element.GetTag().GetGroup(), element.GetTag().GetElement(),
88 element.GetValue().GetContent());
89 }
90 else
91 {
92 throw OrthancException(ErrorCode_BadParameterType);
93 }
94 }
95 }
96
97 if (request.IsRetrieveParentIdentifier())
98 {
99 int64_t parentId;
100 if (transaction_.LookupParent(parentId, internalId))
101 {
102 resource->SetParentIdentifier(transaction_.GetPublicId(parentId));
103 }
104 else
105 {
106 throw OrthancException(ErrorCode_InternalError);
107 }
108 }
109
110 // TODO-FIND: Continue
111 111
112 112
113 /** 113 /**
114 * Sanity checks 114 * Sanity checks
115 **/ 115 **/
116 116
117 for (size_t i = 0; i < response.GetSize(); i++) 117 if (request.IsRetrieveMainDicomTags())
118 { 118 {
119 const FindResponse::Resource& resource = response.GetResource(i); 119 DicomMap tmp;
120 resource->GetMainDicomTags(tmp);
121 if (tmp.GetSize() == 0)
122 {
123 throw OrthancException(ErrorCode_InternalError);
124 }
125 }
120 126
121 if (request.IsRetrieveMainDicomTags())
122 {
123 DicomMap tmp;
124 resource.GetMainDicomTags(tmp);
125 if (tmp.GetSize() == 0)
126 {
127 throw OrthancException(ErrorCode_InternalError);
128 }
129 }
130 127
131 // TODO: other sanity checks 128 response.Add(resource.release());
132 }
133 } 129 }
134 } 130 }
135 } 131 }