comparison OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5592:1e2631b8b9af find-refactoring

GenericFind::Execute() is working for a basic request
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 03 May 2024 21:26:06 +0200
parents 8b32213af23e
children 862b54b4cfe2
comparison
equal deleted inserted replaced
5591:043c8016ed6a 5592:1e2631b8b9af
20 **/ 20 **/
21 21
22 22
23 #include "GenericFind.h" 23 #include "GenericFind.h"
24 24
25 #include "../../../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
25 #include "../../../../OrthancFramework/Sources/OrthancException.h" 26 #include "../../../../OrthancFramework/Sources/OrthancException.h"
26 27
27 28
28 namespace Orthanc 29 namespace Orthanc
29 { 30 {
36 !request.GetOrthancIdentifiers().HasStudyId() && 37 !request.GetOrthancIdentifiers().HasStudyId() &&
37 !request.GetOrthancIdentifiers().HasSeriesId() && 38 !request.GetOrthancIdentifiers().HasSeriesId() &&
38 !request.GetOrthancIdentifiers().HasInstanceId() && 39 !request.GetOrthancIdentifiers().HasInstanceId() &&
39 request.GetDicomTagConstraintsCount() == 0 && 40 request.GetDicomTagConstraintsCount() == 0 &&
40 request.GetMetadataConstraintsCount() == 0 && 41 request.GetMetadataConstraintsCount() == 0 &&
41 !request.IsRetrieveTagsAtLevel(ResourceType_Patient) &&
42 !request.IsRetrieveTagsAtLevel(ResourceType_Study) &&
43 !request.IsRetrieveTagsAtLevel(ResourceType_Series) &&
44 !request.IsRetrieveTagsAtLevel(ResourceType_Instance) &&
45 request.GetOrdering().empty() && 42 request.GetOrdering().empty() &&
46 request.GetLabels().empty()) 43 request.GetLabels().empty())
47 { 44 {
48 std::list<std::string> ids; 45 std::list<std::string> ids;
49 46
56 transaction_.GetAllPublicIds(ids, request.GetLevel()); 53 transaction_.GetAllPublicIds(ids, request.GetLevel());
57 } 54 }
58 55
59 for (std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it) 56 for (std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
60 { 57 {
61 response.Add(new FindResponse::Resource(request.GetLevel(), *it)); 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());
62 } 105 }
63 } 106 }
64 else 107 else
65 { 108 {
66 throw OrthancException(ErrorCode_NotImplemented); 109 throw OrthancException(ErrorCode_NotImplemented);
73 116
74 for (size_t i = 0; i < response.GetSize(); i++) 117 for (size_t i = 0; i < response.GetSize(); i++)
75 { 118 {
76 const FindResponse::Resource& resource = response.GetResource(i); 119 const FindResponse::Resource& resource = response.GetResource(i);
77 120
78 if (request.IsRetrieveTagsAtLevel(request.GetLevel())) 121 if (request.IsRetrieveMainDicomTags())
79 { 122 {
80 DicomMap tmp; 123 DicomMap tmp;
81 resource.GetDicomTagsAtLevel(tmp, request.GetLevel()); 124 resource.GetMainDicomTags(tmp);
82 if (tmp.GetSize() == 0) 125 if (tmp.GetSize() == 0)
83 { 126 {
84 throw OrthancException(ErrorCode_InternalError); 127 throw OrthancException(ErrorCode_InternalError);
85 } 128 }
86 } 129 }