Mercurial > hg > orthanc
annotate OrthancServer/Search/Compatibility/SetOfResources.cpp @ 3057:87f52703ebbc db-changes
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2018 14:12:14 +0100 |
parents | 6c5d4281da4a |
children | ce272138f15e |
rev | line source |
---|---|
1746 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1746 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1746 | 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 | |
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3050
diff
changeset
|
34 #include "../../PrecompiledHeadersServer.h" |
1746 | 35 #include "SetOfResources.h" |
36 | |
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3050
diff
changeset
|
37 #include "../../../Core/OrthancException.h" |
1746 | 38 |
39 | |
40 namespace Orthanc | |
41 { | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
42 namespace Compatibility |
1746 | 43 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
44 void SetOfResources::Intersect(const std::list<int64_t>& resources) |
1746 | 45 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
46 if (resources_.get() == NULL) |
1746 | 47 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
48 resources_.reset(new Resources); |
1746 | 49 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
50 for (std::list<int64_t>::const_iterator |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
51 it = resources.begin(); it != resources.end(); ++it) |
1746 | 52 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
53 resources_->insert(*it); |
1746 | 54 } |
55 } | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
56 else |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
57 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
58 std::auto_ptr<Resources> filtered(new Resources); |
1746 | 59 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
60 for (std::list<int64_t>::const_iterator |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
61 it = resources.begin(); it != resources.end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
62 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
63 if (resources_->find(*it) != resources_->end()) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
64 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
65 filtered->insert(*it); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
66 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
67 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
68 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
69 resources_ = filtered; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
70 } |
1746 | 71 } |
72 | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
73 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
74 void SetOfResources::GoDown() |
1753 | 75 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
76 if (level_ == ResourceType_Instance) |
1753 | 77 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
78 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1746 | 79 } |
1753 | 80 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
81 if (resources_.get() != NULL) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
82 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
83 std::auto_ptr<Resources> children(new Resources); |
1746 | 84 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
85 for (Resources::const_iterator it = resources_->begin(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
86 it != resources_->end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
87 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
88 std::list<int64_t> tmp; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
89 database_.GetChildrenInternalId(tmp, *it); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
90 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
91 for (std::list<int64_t>::const_iterator |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
92 child = tmp.begin(); child != tmp.end(); ++child) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
93 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
94 children->insert(*child); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
95 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
96 } |
1747 | 97 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
98 resources_ = children; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
99 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
100 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
101 switch (level_) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
102 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
103 case ResourceType_Patient: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
104 level_ = ResourceType_Study; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
105 break; |
1747 | 106 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
107 case ResourceType_Study: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
108 level_ = ResourceType_Series; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
109 break; |
1747 | 110 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
111 case ResourceType_Series: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
112 level_ = ResourceType_Instance; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
113 break; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
114 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
115 default: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
116 throw OrthancException(ErrorCode_InternalError); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
117 } |
1747 | 118 } |
1746 | 119 |
120 | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
121 void SetOfResources::Flatten(std::list<std::string>& result) |
1746 | 122 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
123 result.clear(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
124 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
125 if (resources_.get() == NULL) |
1746 | 126 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
127 // All the resources of this level are part of the filter |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
128 database_.GetAllPublicIds(result, level_); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
129 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
130 else |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
131 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
132 for (Resources::const_iterator it = resources_->begin(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
133 it != resources_->end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
134 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
135 result.push_back(database_.GetPublicId(*it)); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
136 } |
1746 | 137 } |
138 } | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
139 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
140 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
141 void SetOfResources::Flatten(std::list<int64_t>& result) |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
142 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
143 result.clear(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
144 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
145 if (resources_.get() == NULL) |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
146 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
147 // All the resources of this level are part of the filter |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
148 database_.GetAllInternalIds(result, level_); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
149 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
150 else |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
151 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
152 for (Resources::const_iterator it = resources_->begin(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
153 it != resources_->end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
154 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
155 result.push_back(*it); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
156 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
157 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
158 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
159 } |
1746 | 160 } |