comparison OrthancServer/Sources/Database/Compatibility/GenericFind.cpp @ 5554:12d8a1a266e9 find-refactoring

introduction of FindRequest and FindResponse
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Apr 2024 16:13:24 +0200
parents
children def06a42e5ef
comparison
equal deleted inserted replaced
5549:dcbf0c776945 5554:12d8a1a266e9
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #include "GenericFind.h"
24
25 #include "../../../../OrthancFramework/Sources/OrthancException.h"
26
27
28 namespace Orthanc
29 {
30 namespace Compatibility
31 {
32 void GenericFind::Execute(FindResponse& response,
33 const FindRequest& request)
34 {
35 if (request.GetResponseType() == FindRequest::ResponseType_OrthancIdentifiers &&
36 !request.GetOrthancIdentifiers().HasPatientId() &&
37 !request.GetOrthancIdentifiers().HasStudyId() &&
38 !request.GetOrthancIdentifiers().HasSeriesId() &&
39 !request.GetOrthancIdentifiers().HasInstanceId() &&
40 request.GetTagConstraintsCount() == 0 &&
41 request.GetMetadataMode() == FindRequest::MetadataMode_None &&
42 !request.IsRetrieveTagsAtLevel(ResourceType_Patient) &&
43 !request.IsRetrieveTagsAtLevel(ResourceType_Study) &&
44 !request.IsRetrieveTagsAtLevel(ResourceType_Series) &&
45 !request.IsRetrieveTagsAtLevel(ResourceType_Instance) &&
46 request.GetTagOrdering().empty() &&
47 request.GetLabels().empty() &&
48 request.GetMetadataConstraints().empty())
49 {
50 std::list<std::string> ids;
51
52 if (request.HasLimits())
53 {
54 transaction_.GetAllPublicIds(ids, request.GetLevel(), request.GetLimitsSince(), request.GetLimitsCount());
55 }
56 else
57 {
58 transaction_.GetAllPublicIds(ids, request.GetLevel());
59 }
60
61 for (std::list<std::string>::const_iterator it = ids.begin(); it != ids.end(); ++it)
62 {
63 OrthancIdentifiers identifiers;
64 identifiers.SetLevel(request.GetLevel(), *it);
65
66 response.Add(new FindResponse::Item(request.GetLevel(), identifiers));
67 }
68 }
69 else
70 {
71 throw OrthancException(ErrorCode_NotImplemented);
72 }
73
74
75 /**
76 * Sanity checks
77 **/
78
79 for (size_t i = 0; i < response.GetSize(); i++)
80 {
81 const FindResponse::Item& item = response.GetItem(i);
82
83 if (item.GetLevel() != request.GetLevel())
84 {
85 throw OrthancException(ErrorCode_InternalError);
86 }
87
88 switch (request.GetResponseType())
89 {
90 case FindRequest::ResponseType_OrthancIdentifiers:
91 break;
92
93 case FindRequest::ResponseType_DicomMap:
94 if (!item.HasDicomMap())
95 {
96 throw OrthancException(ErrorCode_InternalError);
97 }
98 break;
99
100 default:
101 throw OrthancException(ErrorCode_NotImplemented);
102 }
103 }
104 }
105 }
106 }