comparison OrthancServer/Search/Compatibility/SetOfResources.cpp @ 3050:d8a91acb7424 db-changes

working on a database compatibility layer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Dec 2018 16:42:35 +0100
parents Plugins/Engine/SetOfResources.cpp@1c095185074c
children c7db469bbe8e
comparison
equal deleted inserted replaced
3049:6a2c7e206ebb 3050:d8a91acb7424
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-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #include "../../OrthancServer/PrecompiledHeadersServer.h"
35 #include "SetOfResources.h"
36
37 #include "../../Core/OrthancException.h"
38
39
40 namespace Orthanc
41 {
42 void SetOfResources::Intersect(const std::list<int64_t>& resources)
43 {
44 if (resources_.get() == NULL)
45 {
46 resources_.reset(new Resources);
47
48 for (std::list<int64_t>::const_iterator
49 it = resources.begin(); it != resources.end(); ++it)
50 {
51 resources_->insert(*it);
52 }
53 }
54 else
55 {
56 std::auto_ptr<Resources> filtered(new Resources);
57
58 for (std::list<int64_t>::const_iterator
59 it = resources.begin(); it != resources.end(); ++it)
60 {
61 if (resources_->find(*it) != resources_->end())
62 {
63 filtered->insert(*it);
64 }
65 }
66
67 resources_ = filtered;
68 }
69 }
70
71
72 void SetOfResources::GoDown()
73 {
74 if (level_ == ResourceType_Instance)
75 {
76 throw OrthancException(ErrorCode_BadSequenceOfCalls);
77 }
78
79 if (resources_.get() != NULL)
80 {
81 std::auto_ptr<Resources> children(new Resources);
82
83 for (Resources::const_iterator it = resources_->begin();
84 it != resources_->end(); ++it)
85 {
86 std::list<int64_t> tmp;
87 database_.GetChildrenInternalId(tmp, *it);
88
89 for (std::list<int64_t>::const_iterator
90 child = tmp.begin(); child != tmp.end(); ++child)
91 {
92 children->insert(*child);
93 }
94 }
95
96 resources_ = children;
97 }
98
99 switch (level_)
100 {
101 case ResourceType_Patient:
102 level_ = ResourceType_Study;
103 break;
104
105 case ResourceType_Study:
106 level_ = ResourceType_Series;
107 break;
108
109 case ResourceType_Series:
110 level_ = ResourceType_Instance;
111 break;
112
113 default:
114 throw OrthancException(ErrorCode_InternalError);
115 }
116 }
117
118
119 void SetOfResources::Flatten(std::list<std::string>& result)
120 {
121 result.clear();
122
123 if (resources_.get() == NULL)
124 {
125 // All the resources of this level are part of the filter
126 database_.GetAllPublicIds(result, level_);
127 }
128 else
129 {
130 for (Resources::const_iterator it = resources_->begin();
131 it != resources_->end(); ++it)
132 {
133 result.push_back(database_.GetPublicId(*it));
134 }
135 }
136 }
137
138
139 void SetOfResources::Flatten(std::list<int64_t>& result)
140 {
141 result.clear();
142
143 if (resources_.get() == NULL)
144 {
145 // All the resources of this level are part of the filter
146 database_.GetAllInternalIds(result, level_);
147 }
148 else
149 {
150 for (Resources::const_iterator it = resources_->begin();
151 it != resources_->end(); ++it)
152 {
153 result.push_back(*it);
154 }
155 }
156 }
157 }