Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/Compatibility/SetOfResources.cpp @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | OrthancServer/Database/Compatibility/SetOfResources.cpp@2a170a8f1faf |
children | 05b8fd21089c |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
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-2020 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 "../../PrecompiledHeadersServer.h" | |
35 #include "SetOfResources.h" | |
36 | |
37 #include "../../../Core/OrthancException.h" | |
38 | |
39 | |
40 namespace Orthanc | |
41 { | |
42 namespace Compatibility | |
43 { | |
44 void SetOfResources::Intersect(const std::list<int64_t>& resources) | |
45 { | |
46 if (resources_.get() == NULL) | |
47 { | |
48 resources_.reset(new Resources); | |
49 | |
50 for (std::list<int64_t>::const_iterator | |
51 it = resources.begin(); it != resources.end(); ++it) | |
52 { | |
53 resources_->insert(*it); | |
54 } | |
55 } | |
56 else | |
57 { | |
58 std::unique_ptr<Resources> filtered(new Resources); | |
59 | |
60 for (std::list<int64_t>::const_iterator | |
61 it = resources.begin(); it != resources.end(); ++it) | |
62 { | |
63 if (resources_->find(*it) != resources_->end()) | |
64 { | |
65 filtered->insert(*it); | |
66 } | |
67 } | |
68 | |
69 #if __cplusplus < 201103L | |
70 resources_.reset(filtered.release()); | |
71 #else | |
72 resources_ = std::move(filtered); | |
73 #endif | |
74 } | |
75 } | |
76 | |
77 | |
78 void SetOfResources::GoDown() | |
79 { | |
80 if (level_ == ResourceType_Instance) | |
81 { | |
82 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
83 } | |
84 | |
85 if (resources_.get() != NULL) | |
86 { | |
87 std::unique_ptr<Resources> children(new Resources); | |
88 | |
89 for (Resources::const_iterator it = resources_->begin(); | |
90 it != resources_->end(); ++it) | |
91 { | |
92 std::list<int64_t> tmp; | |
93 database_.GetChildrenInternalId(tmp, *it); | |
94 | |
95 for (std::list<int64_t>::const_iterator | |
96 child = tmp.begin(); child != tmp.end(); ++child) | |
97 { | |
98 children->insert(*child); | |
99 } | |
100 } | |
101 | |
102 #if __cplusplus < 201103L | |
103 resources_.reset(children.release()); | |
104 #else | |
105 resources_ = std::move(children); | |
106 #endif | |
107 } | |
108 | |
109 switch (level_) | |
110 { | |
111 case ResourceType_Patient: | |
112 level_ = ResourceType_Study; | |
113 break; | |
114 | |
115 case ResourceType_Study: | |
116 level_ = ResourceType_Series; | |
117 break; | |
118 | |
119 case ResourceType_Series: | |
120 level_ = ResourceType_Instance; | |
121 break; | |
122 | |
123 default: | |
124 throw OrthancException(ErrorCode_InternalError); | |
125 } | |
126 } | |
127 | |
128 | |
129 void SetOfResources::Flatten(std::list<std::string>& result) | |
130 { | |
131 result.clear(); | |
132 | |
133 if (resources_.get() == NULL) | |
134 { | |
135 // All the resources of this level are part of the filter | |
136 database_.GetAllPublicIds(result, level_); | |
137 } | |
138 else | |
139 { | |
140 for (Resources::const_iterator it = resources_->begin(); | |
141 it != resources_->end(); ++it) | |
142 { | |
143 result.push_back(database_.GetPublicId(*it)); | |
144 } | |
145 } | |
146 } | |
147 | |
148 | |
149 void SetOfResources::Flatten(ILookupResources& compatibility, | |
150 std::list<int64_t>& result) | |
151 { | |
152 result.clear(); | |
153 | |
154 if (resources_.get() == NULL) | |
155 { | |
156 // All the resources of this level are part of the filter | |
157 compatibility.GetAllInternalIds(result, level_); | |
158 } | |
159 else | |
160 { | |
161 for (Resources::const_iterator it = resources_->begin(); | |
162 it != resources_->end(); ++it) | |
163 { | |
164 result.push_back(*it); | |
165 } | |
166 } | |
167 } | |
168 } | |
169 } |