comparison OrthancServer/Database/Compatibility/SetOfResources.cpp @ 3093:2e1808b6146a db-changes

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 05 Jan 2019 16:09:21 +0100
parents OrthancServer/Search/Compatibility/SetOfResources.cpp@c829758b9ca0
children 94f4a18a79cc
comparison
equal deleted inserted replaced
3092:fc57988dbfd8 3093:2e1808b6146a
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-2019 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::auto_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 resources_ = filtered;
70 }
71 }
72
73
74 void SetOfResources::GoDown()
75 {
76 if (level_ == ResourceType_Instance)
77 {
78 throw OrthancException(ErrorCode_BadSequenceOfCalls);
79 }
80
81 if (resources_.get() != NULL)
82 {
83 std::auto_ptr<Resources> children(new Resources);
84
85 for (Resources::const_iterator it = resources_->begin();
86 it != resources_->end(); ++it)
87 {
88 std::list<int64_t> tmp;
89 database_.GetChildrenInternalId(tmp, *it);
90
91 for (std::list<int64_t>::const_iterator
92 child = tmp.begin(); child != tmp.end(); ++child)
93 {
94 children->insert(*child);
95 }
96 }
97
98 resources_ = children;
99 }
100
101 switch (level_)
102 {
103 case ResourceType_Patient:
104 level_ = ResourceType_Study;
105 break;
106
107 case ResourceType_Study:
108 level_ = ResourceType_Series;
109 break;
110
111 case ResourceType_Series:
112 level_ = ResourceType_Instance;
113 break;
114
115 default:
116 throw OrthancException(ErrorCode_InternalError);
117 }
118 }
119
120
121 void SetOfResources::Flatten(std::list<std::string>& result)
122 {
123 result.clear();
124
125 if (resources_.get() == NULL)
126 {
127 // All the resources of this level are part of the filter
128 database_.GetAllPublicIds(result, level_);
129 }
130 else
131 {
132 for (Resources::const_iterator it = resources_->begin();
133 it != resources_->end(); ++it)
134 {
135 result.push_back(database_.GetPublicId(*it));
136 }
137 }
138 }
139
140
141 void SetOfResources::Flatten(ILookupResources& compatibility,
142 std::list<int64_t>& result)
143 {
144 result.clear();
145
146 if (resources_.get() == NULL)
147 {
148 // All the resources of this level are part of the filter
149 compatibility.GetAllInternalIds(result, level_);
150 }
151 else
152 {
153 for (Resources::const_iterator it = resources_->begin();
154 it != resources_->end(); ++it)
155 {
156 result.push_back(*it);
157 }
158 }
159 }
160 }
161 }