annotate Framework/Plugins/IndexBackend.cpp @ 260:793bbbe11287

IDatabaseBackend::HasRevisionsSupport()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Apr 2021 16:45:15 +0200
parents e184dcadf163
children 34e2b93a7ac1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
193
3236894320d6 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "IndexBackend.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
24 #include "../../Resources/Orthanc/Databases/ISqlLookupFormatter.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../Common/BinaryStringValue.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Common/Integer64Value.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../Common/Utf8StringValue.h"
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
28 #include "DatabaseBackendAdapterV2.h"
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
29 #include "DatabaseBackendAdapterV3.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "GlobalProperties.h"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
32 #include <Compatibility.h> // For std::unique_ptr<>
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
33 #include <Logging.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
34 #include <OrthancException.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace OrthancDatabases
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 static std::string ConvertWildcardToLike(const std::string& query)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 std::string s = query;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 for (size_t i = 0; i < s.size(); i++)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 if (s[i] == '*')
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 s[i] = '%';
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 else if (s[i] == '?')
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 s[i] = '_';
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
65
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
55 // TODO Escape underscores and percents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
56
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 return s;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
61 int64_t IndexBackend::ReadInteger64(const DatabaseManager::StatementBase& statement,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 size_t field)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 const IValue& value = statement.GetResultField(field);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 switch (value.GetType())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 case ValueType_Integer64:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return dynamic_cast<const Integer64Value&>(value).GetValue();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 //LOG(ERROR) << value.Format();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
83 int32_t IndexBackend::ReadInteger32(const DatabaseManager::StatementBase& statement,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 size_t field)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 int64_t value = ReadInteger64(statement, field);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 if (value != static_cast<int64_t>(static_cast<int32_t>(value)))
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 LOG(ERROR) << "Integer overflow";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 return static_cast<int32_t>(value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
105 std::string IndexBackend::ReadString(const DatabaseManager::StatementBase& statement,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 size_t field)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const IValue& value = statement.GetResultField(field);
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
109
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 switch (value.GetType())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 case ValueType_BinaryString:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return dynamic_cast<const BinaryStringValue&>(value).GetContent();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 case ValueType_Utf8String:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return dynamic_cast<const Utf8StringValue&>(value).GetContent();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 //LOG(ERROR) << value.Format();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 template <typename T>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 void IndexBackend::ReadListOfIntegers(std::list<T>& target,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 DatabaseManager::CachedStatement& statement,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 const Dictionary& args)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 target.clear();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 if (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (statement.GetResultFieldsCount() != 1)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 statement.SetResultFieldType(0, ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 while (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 target.push_back(static_cast<T>(ReadInteger64(statement, 0)));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 void IndexBackend::ReadListOfStrings(std::list<std::string>& target,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 DatabaseManager::CachedStatement& statement,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 const Dictionary& args)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 target.clear();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 if (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 if (statement.GetResultFieldsCount() != 1)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 while (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 target.push_back(ReadString(statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
176 void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
177 bool& done,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
178 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 DatabaseManager::CachedStatement& statement,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 const Dictionary& args,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 uint32_t maxResults)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 uint32_t count = 0;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 while (count < maxResults &&
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 !statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
190 output.AnswerChange(
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ReadInteger64(statement, 0),
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ReadInteger32(statement, 1),
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 3)),
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
194 GetPublicId(manager, ReadInteger64(statement, 2)),
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 ReadString(statement, 4));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 count++;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 done = (count < maxResults ||
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 statement.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
206 void IndexBackend::ReadExportedResourcesInternal(IDatabaseBackendOutput& output,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
207 bool& done,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 DatabaseManager::CachedStatement& statement,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 const Dictionary& args,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 uint32_t maxResults)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 uint32_t count = 0;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 while (count < maxResults &&
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 !statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 int64_t seq = ReadInteger64(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 OrthancPluginResourceType resourceType =
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 std::string publicId = ReadString(statement, 2);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
224 output.AnswerExportedResource(seq,
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
225 resourceType,
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
226 publicId,
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
227 ReadString(statement, 3), // modality
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
228 ReadString(statement, 8), // date
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
229 ReadString(statement, 4), // patient ID
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
230 ReadString(statement, 5), // study instance UID
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
231 ReadString(statement, 6), // series instance UID
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
232 ReadString(statement, 7)); // sop instance UID
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
233
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 count++;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 done = (count < maxResults ||
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 statement.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
243 void IndexBackend::ClearDeletedFiles(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
246 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 "DELETE FROM DeletedFiles");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
253 void IndexBackend::ClearDeletedResources(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
256 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 "DELETE FROM DeletedResources");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
263 void IndexBackend::SignalDeletedFiles(IDatabaseBackendOutput& output,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
264 DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
267 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 "SELECT * FROM DeletedFiles");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 while (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 std::string a = ReadString(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 std::string b = ReadString(statement, 5);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 std::string c = ReadString(statement, 6);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
279 output.SignalDeletedAttachment(a.c_str(),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
280 ReadInteger32(statement, 1),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
281 ReadInteger64(statement, 3),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
282 b.c_str(),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
283 ReadInteger32(statement, 4),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
284 ReadInteger64(statement, 2),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
285 c.c_str());
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
286
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
292 void IndexBackend::SignalDeletedResources(IDatabaseBackendOutput& output,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
293 DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
296 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 "SELECT * FROM DeletedResources");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 while (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
304 output.SignalDeletedResource(
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 ReadString(statement, 1),
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0)));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
313 IndexBackend::IndexBackend(OrthancPluginContext* context) :
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
314 context_(context)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
318
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
319 void IndexBackend::SetOutputFactory(IDatabaseBackendOutput::IFactory* factory)
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
320 {
232
4e15eace9b90 reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
321 boost::unique_lock<boost::shared_mutex> lock(outputFactoryMutex_);
4e15eace9b90 reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
322
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
323 if (factory == NULL)
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
324 {
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
325 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
326 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
327 else if (outputFactory_.get() != NULL)
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
328 {
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
330 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
331 else
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
332 {
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
333 outputFactory_.reset(factory);
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
334 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
335 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
336
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
337
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
338 IDatabaseBackendOutput* IndexBackend::CreateOutput()
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
339 {
232
4e15eace9b90 reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
340 boost::shared_lock<boost::shared_mutex> lock(outputFactoryMutex_);
4e15eace9b90 reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
341
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
342 if (outputFactory_.get() == NULL)
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
343 {
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
345 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
346 else
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
347 {
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
348 return outputFactory_->CreateOutput();
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
349 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
350 }
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
351
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
352
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
353 void IndexBackend::AddAttachment(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
354 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 const OrthancPluginAttachment& attachment)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
358 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 "INSERT INTO AttachedFiles VALUES(${id}, ${type}, ${uuid}, "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 "${compressed}, ${uncompressed}, ${compression}, ${hash}, ${hash-compressed})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 statement.SetParameterType("uuid", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 statement.SetParameterType("compressed", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 statement.SetParameterType("uncompressed", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 statement.SetParameterType("compression", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 statement.SetParameterType("hash", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 statement.SetParameterType("hash-compressed", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 args.SetIntegerValue("type", attachment.contentType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 args.SetUtf8Value("uuid", attachment.uuid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 args.SetIntegerValue("compressed", attachment.compressedSize);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 args.SetIntegerValue("uncompressed", attachment.uncompressedSize);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 args.SetIntegerValue("compression", attachment.compressionType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 args.SetUtf8Value("hash", attachment.uncompressedHash);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 args.SetUtf8Value("hash-compressed", attachment.compressedHash);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
385 void IndexBackend::AttachChild(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
386 int64_t parent,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 int64_t child)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
390 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 "UPDATE Resources SET parentId = ${parent} WHERE internalId = ${child}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 statement.SetParameterType("parent", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 statement.SetParameterType("child", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 args.SetIntegerValue("parent", parent);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 args.SetIntegerValue("child", child);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
404 void IndexBackend::ClearChanges(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
407 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 "DELETE FROM Changes");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
414 void IndexBackend::ClearExportedResources(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
417 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 "DELETE FROM ExportedResources");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
424 void IndexBackend::DeleteAttachment(IDatabaseBackendOutput& output,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
425 DatabaseManager& manager,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
426 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 int32_t attachment)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
429 ClearDeletedFiles(manager);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
433 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 "DELETE FROM AttachedFiles WHERE id=${id} AND fileType=${type}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 args.SetIntegerValue("type", static_cast<int>(attachment));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
446 SignalDeletedFiles(output, manager);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
449
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
450 void IndexBackend::DeleteMetadata(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
451 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 int32_t metadataType)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
455 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 "DELETE FROM Metadata WHERE id=${id} and type=${type}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 args.SetIntegerValue("type", static_cast<int>(metadataType));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
468
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
469 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
470 DatabaseManager& manager,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
471 int64_t id)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
473 assert(manager.GetDialect() != Dialect_MySQL);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
475 ClearDeletedFiles(manager);
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
476 ClearDeletedResources(manager);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
480 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 "DELETE FROM RemainingAncestor");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
488 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 "DELETE FROM Resources WHERE internalId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
502 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 "SELECT * FROM RemainingAncestor");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 if (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
509 output.SignalRemainingAncestor(
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 ReadString(statement, 1),
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0)));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 // There is at most 1 remaining ancestor
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 assert((statement.Next(), statement.IsDone()));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
518 SignalDeletedFiles(output, manager);
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
519 SignalDeletedResources(output, manager);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 void IndexBackend::GetAllInternalIds(std::list<int64_t>& target,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
524 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 OrthancPluginResourceType resourceType)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
528 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 "SELECT internalId FROM Resources WHERE resourceType=${type}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 args.SetIntegerValue("type", static_cast<int>(resourceType));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 ReadListOfIntegers<int64_t>(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 void IndexBackend::GetAllPublicIds(std::list<std::string>& target,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
542 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 OrthancPluginResourceType resourceType)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
546 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 "SELECT publicId FROM Resources WHERE resourceType=${type}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 args.SetIntegerValue("type", static_cast<int>(resourceType));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 ReadListOfStrings(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 void IndexBackend::GetAllPublicIds(std::list<std::string>& target,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
560 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 OrthancPluginResourceType resourceType,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 uint64_t since,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 uint64_t limit)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
566 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 "SELECT publicId FROM (SELECT publicId FROM Resources "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 "WHERE resourceType=${type}) AS tmp "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 "ORDER BY tmp.publicId LIMIT ${limit} OFFSET ${since}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 statement.SetParameterType("limit", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 statement.SetParameterType("since", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 args.SetIntegerValue("type", static_cast<int>(resourceType));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 args.SetIntegerValue("limit", limit);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 args.SetIntegerValue("since", since);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 ReadListOfStrings(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 /* Use GetOutput().AnswerChange() */
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
586 void IndexBackend::GetChanges(IDatabaseBackendOutput& output,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
587 bool& done /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
588 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 int64_t since,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 uint32_t maxResults)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
593 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 "SELECT * FROM Changes WHERE seq>${since} ORDER BY seq LIMIT ${limit}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 statement.SetParameterType("limit", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 statement.SetParameterType("since", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 args.SetIntegerValue("limit", maxResults + 1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 args.SetIntegerValue("since", since);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
604 ReadChangesInternal(output, done, manager, statement, args, maxResults);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 void IndexBackend::GetChildrenInternalId(std::list<int64_t>& target /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
609 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 int64_t id)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
613 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 "SELECT a.internalId FROM Resources AS a, Resources AS b "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 "WHERE a.parentId = b.internalId AND b.internalId = ${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 ReadListOfIntegers<int64_t>(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 void IndexBackend::GetChildrenPublicId(std::list<std::string>& target /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
628 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 int64_t id)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
632 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 "SELECT a.publicId FROM Resources AS a, Resources AS b "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 "WHERE a.parentId = b.internalId AND b.internalId = ${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 ReadListOfStrings(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 /* Use GetOutput().AnswerExportedResource() */
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
647 void IndexBackend::GetExportedResources(IDatabaseBackendOutput& output,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
648 bool& done /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
649 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 int64_t since,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 uint32_t maxResults)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
654 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 "SELECT * FROM ExportedResources WHERE seq>${since} ORDER BY seq LIMIT ${limit}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 statement.SetParameterType("limit", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 statement.SetParameterType("since", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 args.SetIntegerValue("limit", maxResults + 1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 args.SetIntegerValue("since", since);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
665 ReadExportedResourcesInternal(output, done, statement, args, maxResults);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 /* Use GetOutput().AnswerChange() */
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
670 void IndexBackend::GetLastChange(IDatabaseBackendOutput& output,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
671 DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
674 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 bool done; // Ignored
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
682 ReadChangesInternal(output, done, manager, statement, args, 1);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 /* Use GetOutput().AnswerExportedResource() */
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
687 void IndexBackend::GetLastExportedResource(IDatabaseBackendOutput& output,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
688 DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
691 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 bool done; // Ignored
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
699 ReadExportedResourcesInternal(output, done, statement, args, 1);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 /* Use GetOutput().AnswerDicomTag() */
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
704 void IndexBackend::GetMainDicomTags(IDatabaseBackendOutput& output,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
705 DatabaseManager& manager,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
706 int64_t id)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
709 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 "SELECT * FROM MainDicomTags WHERE id=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 while (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
722 output.AnswerDicomTag(static_cast<uint16_t>(ReadInteger64(statement, 1)),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
723 static_cast<uint16_t>(ReadInteger64(statement, 2)),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
724 ReadString(statement, 3));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
730 std::string IndexBackend::GetPublicId(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
731 int64_t resourceId)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
734 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 "SELECT publicId FROM Resources WHERE internalId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 args.SetIntegerValue("id", resourceId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 return ReadString(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
756 uint64_t IndexBackend::GetResourcesCount(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
757 OrthancPluginResourceType resourceType)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
759 std::unique_ptr<DatabaseManager::CachedStatement> statement;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
761 switch (manager.GetDialect())
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 case Dialect_MySQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
765 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources WHERE resourceType=${type}"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 case Dialect_PostgreSQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
771 STATEMENT_FROM_HERE, manager,
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
772 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources WHERE resourceType=${type}"));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 case Dialect_SQLite:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
777 STATEMENT_FROM_HERE, manager,
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
778 "SELECT COUNT(*) FROM Resources WHERE resourceType=${type}"));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 statement->SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 statement->SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 args.SetIntegerValue("type", resourceType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 statement->Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 return static_cast<uint64_t>(ReadInteger64(*statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
797 OrthancPluginResourceType IndexBackend::GetResourceType(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
798 int64_t resourceId)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
801 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 "SELECT resourceType FROM Resources WHERE internalId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 args.SetIntegerValue("id", resourceId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 return static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
823 uint64_t IndexBackend::GetTotalCompressedSize(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
825 std::unique_ptr<DatabaseManager::CachedStatement> statement;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
829 switch (manager.GetDialect())
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 case Dialect_MySQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
833 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 case Dialect_PostgreSQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
839 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS BIGINT) FROM AttachedFiles"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 case Dialect_SQLite:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
845 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 "SELECT COALESCE(SUM(compressedSize), 0) FROM AttachedFiles"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 statement->SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 statement->Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 return static_cast<uint64_t>(ReadInteger64(*statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
860 uint64_t IndexBackend::GetTotalUncompressedSize(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
862 std::unique_ptr<DatabaseManager::CachedStatement> statement;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
866 switch (manager.GetDialect())
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 case Dialect_MySQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
870 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 case Dialect_PostgreSQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
876 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS BIGINT) FROM AttachedFiles"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 case Dialect_SQLite:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
882 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 "SELECT COALESCE(SUM(uncompressedSize), 0) FROM AttachedFiles"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 statement->SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 statement->Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 return static_cast<uint64_t>(ReadInteger64(*statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
897 bool IndexBackend::IsExistingResource(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
898 int64_t internalId)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
901 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 "SELECT * FROM Resources WHERE internalId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 args.SetIntegerValue("id", internalId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 return !statement.IsDone();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
916 bool IndexBackend::IsProtectedPatient(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
917 int64_t internalId)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
920 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 args.SetIntegerValue("id", internalId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 return statement.IsDone();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 void IndexBackend::ListAvailableMetadata(std::list<int32_t>& target /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
936 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 int64_t id)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
940 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 "SELECT type FROM Metadata WHERE id=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 ReadListOfIntegers<int32_t>(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 void IndexBackend::ListAvailableAttachments(std::list<int32_t>& target /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
954 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 int64_t id)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
958 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 "SELECT fileType FROM AttachedFiles WHERE id=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 ReadListOfIntegers<int32_t>(target, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
971 void IndexBackend::LogChange(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
972 int32_t changeType,
209
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
973 int64_t resourceId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
974 OrthancPluginResourceType resourceType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
975 const char* date)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
978 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 "INSERT INTO Changes VALUES(${}, ${changeType}, ${id}, ${resourceType}, ${date})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 statement.SetParameterType("changeType", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 statement.SetParameterType("resourceType", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 statement.SetParameterType("date", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 Dictionary args;
209
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
987 args.SetIntegerValue("changeType", changeType);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
988 args.SetIntegerValue("id", resourceId);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
989 args.SetIntegerValue("resourceType", resourceType);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
990 args.SetUtf8Value("date", date);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
996 void IndexBackend::LogExportedResource(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
997 const OrthancPluginExportedResource& resource)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1000 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001 "INSERT INTO ExportedResources VALUES(${}, ${type}, ${publicId}, "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 "${modality}, ${patient}, ${study}, ${series}, ${instance}, ${date})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 statement.SetParameterType("publicId", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 statement.SetParameterType("modality", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 statement.SetParameterType("patient", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 statement.SetParameterType("study", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 statement.SetParameterType("series", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 statement.SetParameterType("instance", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 statement.SetParameterType("date", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 args.SetIntegerValue("type", resource.resourceType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 args.SetUtf8Value("publicId", resource.publicId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 args.SetUtf8Value("modality", resource.modality);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 args.SetUtf8Value("patient", resource.patientId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 args.SetUtf8Value("study", resource.studyInstanceUid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 args.SetUtf8Value("series", resource.seriesInstanceUid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 args.SetUtf8Value("instance", resource.sopInstanceUid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 args.SetUtf8Value("date", resource.date);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 /* Use GetOutput().AnswerAttachment() */
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
1028 bool IndexBackend::LookupAttachment(IDatabaseBackendOutput& output,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1029 DatabaseManager& manager,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1030 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 int32_t contentType)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1034 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 "SELECT uuid, uncompressedSize, compressionType, compressedSize, "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 "uncompressedHash, compressedHash FROM AttachedFiles WHERE id=${id} AND fileType=${type}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 args.SetIntegerValue("type", static_cast<int>(contentType));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1054 output.AnswerAttachment(ReadString(statement, 0),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1055 contentType,
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1056 ReadInteger64(statement, 1),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1057 ReadString(statement, 4),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1058 ReadInteger32(statement, 2),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1059 ReadInteger64(statement, 3),
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1060 ReadString(statement, 5));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1065
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1066 static bool ReadGlobalProperty(std::string& target,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1067 DatabaseManager::CachedStatement& statement,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1068 const Dictionary& args)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 {
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1070 statement.Execute(args);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1071 statement.SetResultFieldType(0, ValueType_Utf8String);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1072
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1073 if (statement.IsDone())
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1074 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1075 return false;
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1076 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1077 else
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1078 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1079 ValueType type = statement.GetResultField(0).GetType();
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1080
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1081 if (type == ValueType_Null)
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1082 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1083 return false;
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1084 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1085 else if (type != ValueType_Utf8String)
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1086 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1087 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1088 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1089 else
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1090 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1091 target = dynamic_cast<const Utf8StringValue&>(statement.GetResultField(0)).GetContent();
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1092 return true;
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1093 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1094 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 }
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1096
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1097
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1098 bool IndexBackend::LookupGlobalProperty(std::string& target /*out*/,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1099 DatabaseManager& manager,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1100 const char* serverIdentifier,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1101 int32_t property)
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1102 {
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1103 if (serverIdentifier == NULL)
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1104 {
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1105 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1106 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1107 else
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1108 {
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1109 if (strlen(serverIdentifier) == 0)
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1110 {
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1111 DatabaseManager::CachedStatement statement(
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1112 STATEMENT_FROM_HERE, manager,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1113 "SELECT value FROM GlobalProperties WHERE property=${property}");
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1114
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1115 statement.SetReadOnly(true);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1116 statement.SetParameterType("property", ValueType_Integer64);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1117
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1118 Dictionary args;
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1119 args.SetIntegerValue("property", property);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1120
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1121 return ReadGlobalProperty(target, statement, args);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1122 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1123 else
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1124 {
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1125 DatabaseManager::CachedStatement statement(
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1126 STATEMENT_FROM_HERE, manager,
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1127 "SELECT value FROM ServerProperties WHERE server=${server} AND property=${property}");
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1128
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1129 statement.SetReadOnly(true);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1130 statement.SetParameterType("server", ValueType_Utf8String);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1131 statement.SetParameterType("property", ValueType_Integer64);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1132
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1133 Dictionary args;
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1134 args.SetUtf8Value("server", serverIdentifier);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1135 args.SetIntegerValue("property", property);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1136
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1137 return ReadGlobalProperty(target, statement, args);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1138 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1139 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1140 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 void IndexBackend::LookupIdentifier(std::list<int64_t>& target /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1144 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 OrthancPluginResourceType resourceType,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 uint16_t group,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 uint16_t element,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 OrthancPluginIdentifierConstraint constraint,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 const char* value)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
1151 std::unique_ptr<DatabaseManager::CachedStatement> statement;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 std::string header =
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 "AND d.tagElement=${element} AND ";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 switch (constraint)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 case OrthancPluginIdentifierConstraint_Equal:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 header += "d.value = ${value}";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1163 STATEMENT_FROM_HERE, manager, header.c_str()));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 case OrthancPluginIdentifierConstraint_SmallerOrEqual:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 header += "d.value <= ${value}";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1169 STATEMENT_FROM_HERE, manager, header.c_str()));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 case OrthancPluginIdentifierConstraint_GreaterOrEqual:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 header += "d.value >= ${value}";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1175 STATEMENT_FROM_HERE, manager, header.c_str()));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 case OrthancPluginIdentifierConstraint_Wildcard:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 header += "d.value LIKE ${value}";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1181 STATEMENT_FROM_HERE, manager, header.c_str()));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 statement->SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 statement->SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 statement->SetParameterType("group", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 statement->SetParameterType("element", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 statement->SetParameterType("value", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 args.SetIntegerValue("type", resourceType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 args.SetIntegerValue("group", group);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 args.SetIntegerValue("element", element);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 if (constraint == OrthancPluginIdentifierConstraint_Wildcard)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 args.SetUtf8Value("value", ConvertWildcardToLike(value));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 args.SetUtf8Value("value", value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 statement->Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 target.clear();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 while (!statement->IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 target.push_back(ReadInteger64(*statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 statement->Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 void IndexBackend::LookupIdentifierRange(std::list<int64_t>& target /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1220 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 OrthancPluginResourceType resourceType,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222 uint16_t group,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 uint16_t element,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 const char* start,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 const char* end)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1228 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 "AND d.tagElement=${element} AND d.value>=${start} AND d.value<=${end}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 statement.SetParameterType("group", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 statement.SetParameterType("element", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 statement.SetParameterType("start", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 statement.SetParameterType("end", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 args.SetIntegerValue("type", resourceType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 args.SetIntegerValue("group", group);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 args.SetIntegerValue("element", element);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 args.SetUtf8Value("start", start);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 args.SetUtf8Value("end", end);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 target.clear();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 while (!statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 target.push_back(ReadInteger64(statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 statement.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 bool IndexBackend::LookupMetadata(std::string& target /*out*/,
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1259 int64_t& revision /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1260 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 int64_t id,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 int32_t metadataType)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 {
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1264 std::unique_ptr<DatabaseManager::CachedStatement> statement;
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1265
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1266 switch (manager.GetDialect())
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1267 {
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1268 case Dialect_MySQL:
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1269 case Dialect_PostgreSQL:
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1270 statement.reset(new DatabaseManager::CachedStatement(
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1271 STATEMENT_FROM_HERE, manager,
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1272 "SELECT value FROM Metadata WHERE id=${id} and type=${type}"));
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1273 break;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1275 case Dialect_SQLite:
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1276 statement.reset(new DatabaseManager::CachedStatement(
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1277 STATEMENT_FROM_HERE, manager,
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1278 "SELECT value, revision FROM Metadata WHERE id=${id} and type=${type}"));
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1279 break;
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1280
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1281 default:
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1282 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1283 }
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1284
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1285
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1286 statement->SetReadOnly(true);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1287 statement->SetParameterType("id", ValueType_Integer64);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1288 statement->SetParameterType("type", ValueType_Integer64);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292 args.SetIntegerValue("type", metadataType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1294 statement->Execute(args);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1296 if (statement->IsDone())
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 {
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1302 target = ReadString(*statement, 0);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1303
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1304 if (manager.GetDialect() == Dialect_SQLite)
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1305 {
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1306 revision = ReadInteger64(*statement, 1);
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1307 }
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1308 else
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1309 {
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1310 revision = 0; // TODO - REVISIONS
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1311 }
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1312
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318 bool IndexBackend::LookupParent(int64_t& parentId /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1319 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 int64_t resourceId)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1323 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 "SELECT parentId FROM Resources WHERE internalId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 args.SetIntegerValue("id", resourceId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 if (statement.IsDone() ||
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 statement.GetResultField(0).GetType() == ValueType_Null)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 parentId = ReadInteger64(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347 bool IndexBackend::LookupResource(int64_t& id /*out*/,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 OrthancPluginResourceType& type /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1349 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 const char* publicId)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1353 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 "SELECT internalId, resourceType FROM Resources WHERE publicId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 statement.SetParameterType("id", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 args.SetUtf8Value("id", publicId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 id = ReadInteger64(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1377 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1378 DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1381 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 statement.Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 internalId = ReadInteger64(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1400 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 int64_t patientIdToAvoid)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1404 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 "SELECT patientId FROM PatientRecyclingOrder "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 "WHERE patientId != ${id} ORDER BY seq ASC LIMIT 1");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 args.SetIntegerValue("id", patientIdToAvoid);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1414 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422 internalId = ReadInteger64(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1426
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1427
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1428 static void RunSetGlobalPropertyStatement(DatabaseManager::CachedStatement& statement,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1429 bool hasServer,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1430 bool hasValue,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1431 const char* serverIdentifier,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1432 int32_t property,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1433 const char* utf8)
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1434 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1435 Dictionary args;
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1436
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1437 statement.SetParameterType("property", ValueType_Integer64);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1438 args.SetIntegerValue("property", static_cast<int>(property));
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1439
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1440 if (hasValue)
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1441 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1442 assert(utf8 != NULL);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1443 statement.SetParameterType("value", ValueType_Utf8String);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1444 args.SetUtf8Value("value", utf8);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1445 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1446 else
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1447 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1448 assert(utf8 == NULL);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1449 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1450
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1451 if (hasServer)
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1452 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1453 assert(serverIdentifier != NULL && strlen(serverIdentifier) > 0);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1454 statement.SetParameterType("server", ValueType_Utf8String);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1455 args.SetUtf8Value("server", serverIdentifier);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1456 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1457 else
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1458 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1459 assert(serverIdentifier == NULL);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1460 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1461
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1462 statement.Execute(args);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1463 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1464
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1466 void IndexBackend::SetGlobalProperty(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1467 const char* serverIdentifier,
221
73cc85f3d9c1 implementation of the "serverIdentifier" information for global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 220
diff changeset
1468 int32_t property,
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1469 const char* utf8)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 {
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1471 if (serverIdentifier == NULL)
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1472 {
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1473 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1474 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1475 else if (manager.GetDialect() == Dialect_SQLite)
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1476 {
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1477 bool hasServer = (strlen(serverIdentifier) != 0);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1478
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1479 if (hasServer)
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1480 {
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1481 DatabaseManager::CachedStatement statement(
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1482 STATEMENT_FROM_HERE, manager,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1483 "INSERT OR REPLACE INTO ServerProperties VALUES (${server}, ${property}, ${value})");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1484
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1485 RunSetGlobalPropertyStatement(statement, true, true, serverIdentifier, property, utf8);
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1486 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1487 else
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1488 {
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1489 DatabaseManager::CachedStatement statement(
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1490 STATEMENT_FROM_HERE, manager,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1491 "INSERT OR REPLACE INTO GlobalProperties VALUES (${property}, ${value})");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1492
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1493 RunSetGlobalPropertyStatement(statement, false, true, NULL, property, utf8);
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1494 }
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1495 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1496 else
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1497 {
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1498 bool hasServer = (strlen(serverIdentifier) != 0);
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1499
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1500 if (hasServer)
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1501 {
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1502 {
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1503 DatabaseManager::CachedStatement statement(
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1504 STATEMENT_FROM_HERE, manager,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1505 "DELETE FROM ServerProperties WHERE server=${server} AND property=${property}");
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1506
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1507 RunSetGlobalPropertyStatement(statement, true, false, serverIdentifier, property, NULL);
238
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1508 }
f033cc039264 new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
1509
239
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1510 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1511 DatabaseManager::CachedStatement statement(
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1512 STATEMENT_FROM_HERE, manager,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1513 "INSERT INTO ServerProperties VALUES (${server}, ${property}, ${value})");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1514
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1515 RunSetGlobalPropertyStatement(statement, true, true, serverIdentifier, property, utf8);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1516 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1517 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1518 else
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1519 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1520 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1521 DatabaseManager::CachedStatement statement(
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1522 STATEMENT_FROM_HERE, manager,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1523 "DELETE FROM GlobalProperties WHERE property=${property}");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1524
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1525 RunSetGlobalPropertyStatement(statement, false, false, NULL, property, NULL);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1526 }
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1527
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1528 {
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1529 DatabaseManager::CachedStatement statement(
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1530 STATEMENT_FROM_HERE, manager,
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1531 "INSERT INTO GlobalProperties VALUES (${property}, ${value})");
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1532
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1533 RunSetGlobalPropertyStatement(statement, false, true, NULL, property, utf8);
e9ba888f371b fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
1534 }
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1535 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
1536 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540 static void ExecuteSetTag(DatabaseManager::CachedStatement& statement,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 int64_t id,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 uint16_t group,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 uint16_t element,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 const char* value)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 statement.SetParameterType("group", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548 statement.SetParameterType("element", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 statement.SetParameterType("value", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 args.SetIntegerValue("group", group);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 args.SetIntegerValue("element", element);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 args.SetUtf8Value("value", value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1561 void IndexBackend::SetMainDicomTag(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1562 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 uint16_t group,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 uint16_t element,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 const char* value)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1568 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 "INSERT INTO MainDicomTags VALUES(${id}, ${group}, ${element}, ${value})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571 ExecuteSetTag(statement, id, group, element, value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1574
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1575 void IndexBackend::SetIdentifierTag(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1576 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 uint16_t group,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1578 uint16_t element,
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 const char* value)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1582 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583 "INSERT INTO DicomIdentifiers VALUES(${id}, ${group}, ${element}, ${value})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 ExecuteSetTag(statement, id, group, element, value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1589 void IndexBackend::SetMetadata(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1590 int64_t id,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1591 int32_t metadataType,
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1592 const char* value,
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1593 int64_t revision)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1594 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1595 if (manager.GetDialect() == Dialect_SQLite)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1596 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1597 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1598 STATEMENT_FROM_HERE, manager,
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1599 "INSERT OR REPLACE INTO Metadata VALUES (${id}, ${type}, ${value}, ${revision})");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1600
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1601 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603 statement.SetParameterType("value", ValueType_Utf8String);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1604 statement.SetParameterType("revision", ValueType_Integer64);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1605
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608 args.SetIntegerValue("type", metadataType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1609 args.SetUtf8Value("value", value);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1610 args.SetIntegerValue("revision", revision);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1613 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1614 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1615 {
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
1616 // TODO - REVISIONS
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1617 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1618 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1619 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1620 "DELETE FROM Metadata WHERE id=${id} AND type=${type}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1621
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1622 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1623 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1624
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1625 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1626 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1627 args.SetIntegerValue("type", metadataType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1628
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1629 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1630 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1634 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1635 "INSERT INTO Metadata VALUES (${id}, ${type}, ${value})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1636
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 statement.SetParameterType("type", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639 statement.SetParameterType("value", ValueType_Utf8String);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1640
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1641 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1642 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643 args.SetIntegerValue("type", metadataType);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644 args.SetUtf8Value("value", value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1650
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1651
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1652 void IndexBackend::SetProtectedPatient(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1653 int64_t internalId,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1654 bool isProtected)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1655 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1656 if (isProtected)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1659 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1660 "DELETE FROM PatientRecyclingOrder WHERE patientId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1661
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1662 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1663
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1665 args.SetIntegerValue("id", internalId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1666
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668 }
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1669 else if (IsProtectedPatient(manager, internalId))
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1670 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1671 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1672 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1673 "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1674
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1677 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1678 args.SetIntegerValue("id", internalId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1681 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684 // Nothing to do: The patient is already unprotected
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1685 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1689 uint32_t IndexBackend::GetDatabaseVersion(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690 {
220
492aa3edf572 use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 219
diff changeset
1691 // Create a read-only, explicit transaction to read the database
492aa3edf572 use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 219
diff changeset
1692 // version (this was a read-write, implicit transaction in
492aa3edf572 use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 219
diff changeset
1693 // PostgreSQL plugin <= 3.3 and MySQL plugin <= 3.0)
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1694 DatabaseManager::Transaction transaction(manager, TransactionType_ReadOnly);
220
492aa3edf572 use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 219
diff changeset
1695
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1696 std::string version = "unknown";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1697
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1698 if (LookupGlobalProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion))
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1699 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1700 try
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1701 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1702 return boost::lexical_cast<unsigned int>(version);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1703 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1704 catch (boost::bad_lexical_cast&)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1705 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1706 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1707 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1708
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1709 LOG(ERROR) << "The database is corrupted. Drop it manually for Orthanc to recreate it";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1710 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1711 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1712
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1713
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1714 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1715 * Upgrade the database to the specified version of the database
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1716 * schema. The upgrade script is allowed to make calls to
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1717 * OrthancPluginReconstructMainDicomTags().
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1718 **/
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1719 void IndexBackend::UpgradeDatabase(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1720 uint32_t targetVersion,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1721 OrthancPluginStorageArea* storageArea)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1722 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1723 LOG(ERROR) << "Upgrading database is not implemented by this plugin";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1724 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1725 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1726
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1727
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1728 void IndexBackend::ClearMainDicomTags(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1729 int64_t internalId)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1730 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1731 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1732 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1733 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1734 "DELETE FROM MainDicomTags WHERE id=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1735
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1736 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1737
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1738 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1739 args.SetIntegerValue("id", internalId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1740
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1741 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1742 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1743
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1744 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1745 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1746 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1747 "DELETE FROM DicomIdentifiers WHERE id=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1748
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1749 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1750
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1751 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1752 args.SetIntegerValue("id", internalId);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1753
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1754 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1755 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1756 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1757
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1758
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1759 // For unit testing only!
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1760 uint64_t IndexBackend::GetAllResourcesCount(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1761 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
1762 std::unique_ptr<DatabaseManager::CachedStatement> statement;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1763
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1764 switch (manager.GetDialect())
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1765 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766 case Dialect_MySQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1767 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1768 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1770 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1771
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1772 case Dialect_PostgreSQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1773 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1774 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1775 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1776 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1777
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1778 case Dialect_SQLite:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1779 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1780 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1781 "SELECT COUNT(*) FROM Resources"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1782 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1783
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1784 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1785 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1786 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1787
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1788 statement->SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1789 statement->Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1790
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1791 return static_cast<uint64_t>(ReadInteger64(*statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1792 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1793
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1794
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1795 // For unit testing only!
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1796 uint64_t IndexBackend::GetUnprotectedPatientsCount(DatabaseManager& manager)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1797 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
1798 std::unique_ptr<DatabaseManager::CachedStatement> statement;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1799
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1800 switch (manager.GetDialect())
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1801 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1802 case Dialect_MySQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1803 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1804 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1805 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM PatientRecyclingOrder"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1806 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1807
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1808 case Dialect_PostgreSQL:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1809 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1810 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1811 "SELECT CAST(COUNT(*) AS BIGINT) FROM PatientRecyclingOrder"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1812 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1813
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1814 case Dialect_SQLite:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1815 statement.reset(new DatabaseManager::CachedStatement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1816 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1817 "SELECT COUNT(*) FROM PatientRecyclingOrder"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1818 break;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1819
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1820 default:
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1821 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1822 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1823
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1824 statement->SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1825 statement->Execute();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1826
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1827 return static_cast<uint64_t>(ReadInteger64(*statement, 0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1828 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1829
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1830
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1831 // For unit testing only!
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1832 bool IndexBackend::GetParentPublicId(std::string& target,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1833 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1834 int64_t id)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1835 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1836 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1837 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1838 "SELECT a.publicId FROM Resources AS a, Resources AS b "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1839 "WHERE a.internalId = b.parentId AND b.internalId = ${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1842 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1843
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1844 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1845 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1846
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1847 statement.Execute(args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1848
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1849 if (statement.IsDone())
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1850 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1851 return false;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1852 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1853 else
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1854 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1855 target = ReadString(statement, 0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1856 return true;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1857 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1858 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1859
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1860
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1861 // For unit tests only!
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1862 void IndexBackend::GetChildren(std::list<std::string>& childrenPublicIds,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1863 DatabaseManager& manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1864 int64_t id)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1865 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1866 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1867 STATEMENT_FROM_HERE, manager,
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1868 "SELECT publicId FROM Resources WHERE parentId=${id}");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1869
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1870 statement.SetReadOnly(true);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1871 statement.SetParameterType("id", ValueType_Integer64);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1872
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1873 Dictionary args;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1874 args.SetIntegerValue("id", id);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1875
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1876 ReadListOfStrings(childrenPublicIds, statement, args);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1877 }
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1878
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1879
78
2ee166f77501 renamed macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 76
diff changeset
1880 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1881 class IndexBackend::LookupFormatter : public Orthanc::ISqlLookupFormatter
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1882 {
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1883 private:
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1884 Dialect dialect_;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1885 size_t count_;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1886 Dictionary dictionary_;
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1887
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1888 static std::string FormatParameter(size_t index)
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1889 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1890 return "p" + boost::lexical_cast<std::string>(index);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1891 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1892
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1893 public:
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1894 LookupFormatter(Dialect dialect) :
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1895 dialect_(dialect),
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1896 count_(0)
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1897 {
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1898 }
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1899
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1900 virtual std::string GenerateParameter(const std::string& value)
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1901 {
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1902 const std::string key = FormatParameter(count_);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1903
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1904 count_ ++;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1905 dictionary_.SetUtf8Value(key, value);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1906
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1907 return "${" + key + "}";
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1908 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1909
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1910 virtual std::string FormatResourceType(Orthanc::ResourceType level)
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1911 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1912 return boost::lexical_cast<std::string>(Orthanc::Plugins::Convert(level));
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1913 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1914
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1915 virtual std::string FormatWildcardEscape()
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1916 {
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1917 switch (dialect_)
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1918 {
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1919 case Dialect_SQLite:
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1920 case Dialect_PostgreSQL:
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1921 return "ESCAPE '\\'";
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1922
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1923 case Dialect_MySQL:
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1924 return "ESCAPE '\\\\'";
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1925
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1926 default:
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1927 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1928 }
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1929 }
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1930
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1931 void PrepareStatement(DatabaseManager::StandaloneStatement& statement) const
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1932 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1933 statement.SetReadOnly(true);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1934
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1935 for (size_t i = 0; i < count_; i++)
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1936 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1937 statement.SetParameterType(FormatParameter(i), ValueType_Utf8String);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1938 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1939 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1940
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1941 const Dictionary& GetDictionary() const
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1942 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1943 return dictionary_;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1944 }
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1945 };
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1946 #endif
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1947
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1948
78
2ee166f77501 renamed macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 76
diff changeset
1949 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1950 // New primitive since Orthanc 1.5.2
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
1951 void IndexBackend::LookupResources(IDatabaseBackendOutput& output,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1952 DatabaseManager& manager,
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
1953 const std::vector<Orthanc::DatabaseConstraint>& lookup,
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1954 OrthancPluginResourceType queryLevel,
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1955 uint32_t limit,
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1956 bool requestSomeInstance)
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1957 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1958 LookupFormatter formatter(manager.GetDialect());
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1959
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1960 std::string sql;
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1961 Orthanc::ISqlLookupFormatter::Apply(sql, formatter, lookup,
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1962 Orthanc::Plugins::Convert(queryLevel), limit);
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1963
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1964 if (requestSomeInstance)
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1965 {
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1966 // Composite query to find some instance if requested
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1967 switch (queryLevel)
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1968 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1969 case OrthancPluginResourceType_Patient:
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1970 sql = ("SELECT patients.publicId, MIN(instances.publicId) FROM (" + sql + ") patients "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1971 "INNER JOIN Resources studies ON studies.parentId = patients.internalId "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1972 "INNER JOIN Resources series ON series.parentId = studies.internalId "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1973 "INNER JOIN Resources instances ON instances.parentId = series.internalId "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1974 "GROUP BY patients.publicId");
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1975 break;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1976
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1977 case OrthancPluginResourceType_Study:
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1978 sql = ("SELECT studies.publicId, MIN(instances.publicId) FROM (" + sql + ") studies "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1979 "INNER JOIN Resources series ON series.parentId = studies.internalId "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1980 "INNER JOIN Resources instances ON instances.parentId = series.internalId "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1981 "GROUP BY studies.publicId");
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1982 break;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1983
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1984 case OrthancPluginResourceType_Series:
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1985 sql = ("SELECT series.publicId, MIN(instances.publicId) FROM (" + sql + ") series "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1986 "INNER JOIN Resources instances ON instances.parentId = series.internalId "
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1987 "GROUP BY series.publicId");
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1988 break;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1989
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1990 case OrthancPluginResourceType_Instance:
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1991 sql = ("SELECT instances.publicId, instances.publicId FROM (" + sql + ") instances");
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1992 break;
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1993
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1994 default:
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1995 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1996 }
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
1997 }
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
1998
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
1999 DatabaseManager::StandaloneStatement statement(manager, sql);
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2000 formatter.PrepareStatement(statement);
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2001
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2002 statement.Execute(formatter.GetDictionary());
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2003
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2004 while (!statement.IsDone())
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2005 {
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2006 if (requestSomeInstance)
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2007 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
2008 output.AnswerMatchingResource(ReadString(statement, 0), ReadString(statement, 1));
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2009 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2010 else
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2011 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
2012 output.AnswerMatchingResource(ReadString(statement, 0));
70
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2013 }
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2014
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2015 statement.Next();
e6c13ddd26d9 all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 69
diff changeset
2016 }
69
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
2017 }
19764fc60ade compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
2018 #endif
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2019
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2020
78
2ee166f77501 renamed macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 76
diff changeset
2021 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2022 static void ExecuteSetResourcesContentTags(
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2023 DatabaseManager& manager,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2024 const std::string& table,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2025 const std::string& variablePrefix,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2026 uint32_t count,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2027 const OrthancPluginResourcesContentTags* tags)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2028 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2029 std::string sql;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2030 Dictionary args;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2031
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2032 for (uint32_t i = 0; i < count; i++)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2033 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2034 std::string name = variablePrefix + boost::lexical_cast<std::string>(i);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2035
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2036 args.SetUtf8Value(name, tags[i].value);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2037
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2038 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " +
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2039 boost::lexical_cast<std::string>(tags[i].group) + ", " +
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2040 boost::lexical_cast<std::string>(tags[i].element) + ", " +
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2041 "${" + name + "})");
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2042
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2043 if (sql.empty())
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2044 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2045 sql = "INSERT INTO " + table + " VALUES " + insert;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2046 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2047 else
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2048 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2049 sql += ", " + insert;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2050 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2051 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2052
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2053 if (!sql.empty())
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2054 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2055 DatabaseManager::StandaloneStatement statement(manager, sql);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2056
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2057 for (uint32_t i = 0; i < count; i++)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2058 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2059 statement.SetParameterType(variablePrefix + boost::lexical_cast<std::string>(i),
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2060 ValueType_Utf8String);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2061 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2062
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2063 statement.Execute(args);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2064 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2065 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2066 #endif
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2067
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2068
78
2ee166f77501 renamed macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 76
diff changeset
2069 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2070 static void ExecuteSetResourcesContentMetadata(
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2071 DatabaseManager& manager,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2072 uint32_t count,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2073 const OrthancPluginResourcesContentMetadata* metadata)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2074 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2075 std::string sqlRemove; // To overwrite
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2076 std::string sqlInsert;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2077 Dictionary args;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2078
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2079 for (uint32_t i = 0; i < count; i++)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2080 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2081 std::string name = "m" + boost::lexical_cast<std::string>(i);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2082
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2083 args.SetUtf8Value(name, metadata[i].value);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2084
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2085 std::string revisionSuffix;
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2086 if (manager.GetDialect() == Dialect_SQLite)
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2087 {
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2088 revisionSuffix = ", 0"; // TODO - REVISIONS
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2089 }
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2090
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2091 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " +
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2092 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " +
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2093 "${" + name + "}" + revisionSuffix + ")");
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2094
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2095 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) +
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2096 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2097 + ")");
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2098
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2099 if (sqlInsert.empty())
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2100 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2101 sqlInsert = "INSERT INTO Metadata VALUES " + insert;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2102 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2103 else
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2104 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2105 sqlInsert += ", " + insert;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2106 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2107
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2108 if (sqlRemove.empty())
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2109 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2110 sqlRemove = "DELETE FROM Metadata WHERE " + remove;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2111 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2112 else
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2113 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2114 sqlRemove += " OR " + remove;
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2115 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2116 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2117
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2118 if (!sqlRemove.empty())
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2119 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2120 DatabaseManager::StandaloneStatement statement(manager, sqlRemove);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2121 statement.Execute();
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2122 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2123
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2124 if (!sqlInsert.empty())
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2125 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2126 DatabaseManager::StandaloneStatement statement(manager, sqlInsert);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2127
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2128 for (uint32_t i = 0; i < count; i++)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2129 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2130 statement.SetParameterType("m" + boost::lexical_cast<std::string>(i),
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2131 ValueType_Utf8String);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2132 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2133
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2134 statement.Execute(args);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2135 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2136 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2137 #endif
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2138
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2139
78
2ee166f77501 renamed macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 76
diff changeset
2140 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2141 // New primitive since Orthanc 1.5.2
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2142 void IndexBackend::SetResourcesContent(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2143 DatabaseManager& manager,
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2144 uint32_t countIdentifierTags,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2145 const OrthancPluginResourcesContentTags* identifierTags,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2146 uint32_t countMainDicomTags,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2147 const OrthancPluginResourcesContentTags* mainDicomTags,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2148 uint32_t countMetadata,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2149 const OrthancPluginResourcesContentMetadata* metadata)
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2150 {
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2151 /**
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2152 * TODO - PostgreSQL doesn't allow multiple commands in a prepared
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2153 * statement, so we execute 3 separate commands (for identifiers,
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2154 * main tags and metadata). Maybe MySQL does not suffer from the
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2155 * same limitation, to check.
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2156 **/
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2157
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2158 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i",
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2159 countIdentifierTags, identifierTags);
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2160
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2161 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t",
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2162 countMainDicomTags, mainDicomTags);
256
e184dcadf163 handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 255
diff changeset
2163
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2164 ExecuteSetResourcesContentMetadata(manager, countMetadata, metadata);
75
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2165 }
52c70007bb87 new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
2166 #endif
76
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2167
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2168
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2169 // New primitive since Orthanc 1.5.2
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2170 void IndexBackend::GetChildrenMetadata(std::list<std::string>& target,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2171 DatabaseManager& manager,
76
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2172 int64_t resourceId,
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2173 int32_t metadata)
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2174 {
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2175 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2176 STATEMENT_FROM_HERE, manager,
76
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2177 "SELECT value FROM Metadata WHERE type=${metadata} AND "
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2178 "id IN (SELECT internalId FROM Resources WHERE parentId=${id})");
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2179
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2180 statement.SetReadOnly(true);
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2181 statement.SetParameterType("id", ValueType_Integer64);
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2182 statement.SetParameterType("metadata", ValueType_Integer64);
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2183
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2184 Dictionary args;
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2185 args.SetIntegerValue("id", static_cast<int>(resourceId));
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2186 args.SetIntegerValue("metadata", static_cast<int>(metadata));
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2187
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2188 ReadListOfStrings(target, statement, args);
a1c6238b26f8 new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
2189 }
88
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2190
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2191
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2192 // New primitive since Orthanc 1.5.2
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2193 void IndexBackend::TagMostRecentPatient(DatabaseManager& manager,
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2194 int64_t patient)
88
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2195 {
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2196 int64_t seq;
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2197
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2198 {
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2199 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2200 STATEMENT_FROM_HERE, manager,
88
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2201 "SELECT * FROM PatientRecyclingOrder WHERE seq >= "
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2202 "(SELECT seq FROM PatientRecyclingOrder WHERE patientid=${id}) ORDER BY seq LIMIT 2");
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2203
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2204 statement.SetReadOnly(true);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2205 statement.SetParameterType("id", ValueType_Integer64);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2206
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2207 Dictionary args;
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2208 args.SetIntegerValue("id", patient);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2209
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2210 statement.Execute(args);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2211
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2212 if (statement.IsDone())
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2213 {
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2214 // The patient is protected, don't add it to the recycling order
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2215 return;
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2216 }
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2217
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2218 seq = ReadInteger64(statement, 0);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2219
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2220 statement.Next();
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2221
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2222 if (statement.IsDone())
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2223 {
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2224 // The patient is already at the end of the recycling order
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2225 // (because of the "LIMIT 2" above), no need to modify the table
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2226 return;
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2227 }
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2228 }
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2229
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2230 // Delete the old position of the patient in the recycling order
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2231
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2232 {
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2233 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2234 STATEMENT_FROM_HERE, manager,
88
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2235 "DELETE FROM PatientRecyclingOrder WHERE seq=${seq}");
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2236
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2237 statement.SetParameterType("seq", ValueType_Integer64);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2238
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2239 Dictionary args;
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2240 args.SetIntegerValue("seq", seq);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2241
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2242 statement.Execute(args);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2243 }
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2244
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2245 // Add the patient to the end of the recycling order
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2246
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2247 {
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2248 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2249 STATEMENT_FROM_HERE, manager,
88
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2250 "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})");
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2251
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2252 statement.SetParameterType("id", ValueType_Integer64);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2253
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2254 Dictionary args;
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2255 args.SetIntegerValue("id", patient);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2256
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2257 statement.Execute(args);
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2258 }
eb08ec14fb04 new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 85
diff changeset
2259 }
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2260
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2261
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2262 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2263 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2264 // New primitive since Orthanc 1.5.4
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2265 bool IndexBackend::LookupResourceAndParent(int64_t& id,
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2266 OrthancPluginResourceType& type,
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2267 std::string& parentPublicId,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2268 DatabaseManager& manager,
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2269 const char* publicId)
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2270 {
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2271 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2272 STATEMENT_FROM_HERE, manager,
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2273 "SELECT resource.internalId, resource.resourceType, parent.publicId "
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2274 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId "
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2275 "WHERE resource.publicId=${id}");
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2276
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2277 statement.SetParameterType("id", ValueType_Utf8String);
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2278
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2279 Dictionary args;
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2280 args.SetUtf8Value("id", publicId);
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2281
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2282 statement.Execute(args);
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2283
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2284 if (statement.IsDone())
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2285 {
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2286 return false;
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2287 }
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2288 else
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2289 {
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2290 if (statement.GetResultFieldsCount() != 3)
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2291 {
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2292 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2293 }
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2294
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2295 statement.SetResultFieldType(0, ValueType_Integer64);
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2296 statement.SetResultFieldType(1, ValueType_Integer64);
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2297 statement.SetResultFieldType(2, ValueType_Utf8String);
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2298
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2299 id = ReadInteger64(statement, 0);
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2300 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1));
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2301
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2302 const IValue& value = statement.GetResultField(2);
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2303
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2304 switch (value.GetType())
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2305 {
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2306 case ValueType_Null:
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2307 parentPublicId.clear();
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2308 break;
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2309
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2310 case ValueType_Utf8String:
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2311 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent();
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2312 break;
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2313
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2314 default:
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2315 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2316 }
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2317
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2318 assert((statement.Next(), statement.IsDone()));
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2319 return true;
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2320 }
203
2089d4071408 moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
2321 }
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2322 # endif
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2323 #endif
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2324
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2325
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2326 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2327 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4)
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2328 // New primitive since Orthanc 1.5.4
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2329 void IndexBackend::GetAllMetadata(std::map<int32_t, std::string>& result,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2330 DatabaseManager& manager,
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2331 int64_t id)
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2332 {
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2333 DatabaseManager::CachedStatement statement(
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2334 STATEMENT_FROM_HERE, manager,
117
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2335 "SELECT type, value FROM Metadata WHERE id=${id}");
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2336
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2337 statement.SetReadOnly(true);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2338 statement.SetParameterType("id", ValueType_Integer64);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2339
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2340 Dictionary args;
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2341 args.SetIntegerValue("id", id);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2342
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2343 statement.Execute(args);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2344
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2345 result.clear();
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2346
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2347 if (!statement.IsDone())
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2348 {
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2349 if (statement.GetResultFieldsCount() != 2)
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2350 {
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2351 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2352 }
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2353
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2354 statement.SetResultFieldType(0, ValueType_Integer64);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2355 statement.SetResultFieldType(1, ValueType_Utf8String);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2356
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2357 while (!statement.IsDone())
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2358 {
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2359 result[ReadInteger32(statement, 0)] = ReadString(statement, 1);
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2360 statement.Next();
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2361 }
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2362 }
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2363 }
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2364 # endif
ca0ecd412988 Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 88
diff changeset
2365 #endif
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2366
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2367
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2368 void IndexBackend::CreateInstanceGeneric(OrthancPluginCreateInstanceResult& result,
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2369 DatabaseManager& manager,
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2370 const char* hashPatient,
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2371 const char* hashStudy,
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2372 const char* hashSeries,
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2373 const char* hashInstance)
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2374 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2375 // Check out "OrthancServer/Sources/Database/Compatibility/ICreateInstance.cpp"
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2376
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2377 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2378 OrthancPluginResourceType type;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2379 int64_t tmp;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2380
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2381 if (LookupResource(tmp, type, manager, hashInstance))
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2382 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2383 // The instance already exists
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2384 assert(type == OrthancPluginResourceType_Instance);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2385 result.instanceId = tmp;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2386 result.isNewInstance = false;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2387 return;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2388 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2389 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2390
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2391 result.instanceId = CreateResource(manager, hashInstance, OrthancPluginResourceType_Instance);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2392 result.isNewInstance = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2393
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2394 result.isNewPatient = false;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2395 result.isNewStudy = false;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2396 result.isNewSeries = false;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2397 result.patientId = -1;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2398 result.studyId = -1;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2399 result.seriesId = -1;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2400
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2401 // Detect up to which level the patient/study/series/instance
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2402 // hierarchy must be created
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2403
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2404 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2405 OrthancPluginResourceType dummy;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2406
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2407 if (LookupResource(result.seriesId, dummy, manager, hashSeries))
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2408 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2409 assert(dummy == OrthancPluginResourceType_Series);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2410 // The patient, the study and the series already exist
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2411
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2412 bool ok = (LookupResource(result.patientId, dummy, manager, hashPatient) &&
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2413 LookupResource(result.studyId, dummy, manager, hashStudy));
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2414 (void) ok; // Remove warning about unused variable in release builds
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2415 assert(ok);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2416 }
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2417 else if (LookupResource(result.studyId, dummy, manager, hashStudy))
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2418 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2419 assert(dummy == OrthancPluginResourceType_Study);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2420
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2421 // New series: The patient and the study already exist
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2422 result.isNewSeries = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2423
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2424 bool ok = LookupResource(result.patientId, dummy, manager, hashPatient);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2425 (void) ok; // Remove warning about unused variable in release builds
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2426 assert(ok);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2427 }
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2428 else if (LookupResource(result.patientId, dummy, manager, hashPatient))
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2429 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2430 assert(dummy == OrthancPluginResourceType_Patient);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2431
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2432 // New study and series: The patient already exist
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2433 result.isNewStudy = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2434 result.isNewSeries = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2435 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2436 else
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2437 {
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2438 // New patient, study and series: Nothing exists
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2439 result.isNewPatient = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2440 result.isNewStudy = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2441 result.isNewSeries = true;
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2442 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2443 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2444
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2445 // Create the series if needed
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2446 if (result.isNewSeries)
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2447 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2448 result.seriesId = CreateResource(manager, hashSeries, OrthancPluginResourceType_Series);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2449 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2450
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2451 // Create the study if needed
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2452 if (result.isNewStudy)
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2453 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2454 result.studyId = CreateResource(manager, hashStudy, OrthancPluginResourceType_Study);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2455 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2456
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2457 // Create the patient if needed
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2458 if (result.isNewPatient)
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2459 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2460 result.patientId = CreateResource(manager, hashPatient, OrthancPluginResourceType_Patient);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2461 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2462
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2463 // Create the parent-to-child links
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2464 AttachChild(manager, result.seriesId, result.instanceId);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2465
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2466 if (result.isNewSeries)
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2467 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2468 AttachChild(manager, result.studyId, result.seriesId);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2469 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2470
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2471 if (result.isNewStudy)
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2472 {
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2473 AttachChild(manager, result.patientId, result.studyId);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2474 }
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2475
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
2476 TagMostRecentPatient(manager, result.patientId);
210
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2477
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2478 // Sanity checks
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2479 assert(result.patientId != -1);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2480 assert(result.studyId != -1);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2481 assert(result.seriesId != -1);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2482 assert(result.instanceId != -1);
a0c095a4ba7d all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
2483 }
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2484
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2485
234
d1b124d116c1 PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
2486 void IndexBackend::Register(IndexBackend* backend,
d1b124d116c1 PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
2487 size_t countConnections,
d1b124d116c1 PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
2488 unsigned int maxDatabaseRetries)
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2489 {
222
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2490 if (backend == NULL)
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2491 {
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2492 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2493 }
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2494
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2495 bool hasLoadedV3 = false;
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2496
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2497 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2498 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
222
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2499 if (OrthancPluginCheckVersionAdvanced(backend->GetContext(), 1, 9, 2) == 1)
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2500 {
253
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
2501 LOG(WARNING) << "The index plugin will use " << countConnections << " connection(s) to the database, "
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
2502 << "and will retry up to " << maxDatabaseRetries << " time(s) in the case of a collision";
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
2503
234
d1b124d116c1 PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
2504 OrthancDatabases::DatabaseBackendAdapterV3::Register(backend, countConnections, maxDatabaseRetries);
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2505 hasLoadedV3 = true;
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2506 }
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2507 # endif
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2508 #endif
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2509
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2510 if (!hasLoadedV3)
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2511 {
249
7f5ee2b42a86 better performance warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 239
diff changeset
2512 LOG(WARNING) << "Performance warning: Your version of the Orthanc SDK doesn't support multiple readers/writers";
213
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2513 OrthancDatabases::DatabaseBackendAdapterV2::Register(backend);
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2514 }
c2e4a909de0e added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
2515 }
222
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2516
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2517
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2518 bool IndexBackend::LookupGlobalIntegerProperty(int& target,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2519 DatabaseManager& manager,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2520 const char* serverIdentifier,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2521 int32_t property)
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2522 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2523 std::string value;
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2524
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2525 if (LookupGlobalProperty(value, manager, serverIdentifier, property))
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2526 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2527 try
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2528 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2529 target = boost::lexical_cast<int>(value);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2530 return true;
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2531 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2532 catch (boost::bad_lexical_cast&)
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2533 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2534 LOG(ERROR) << "Corrupted PostgreSQL database";
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2535 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2536 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2537 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2538 else
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2539 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2540 return false;
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2541 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2542 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2543
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2544
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2545 void IndexBackend::SetGlobalIntegerProperty(DatabaseManager& manager,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2546 const char* serverIdentifier,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2547 int32_t property,
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2548 int value)
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2549 {
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2550 std::string s = boost::lexical_cast<std::string>(value);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2551 SetGlobalProperty(manager, serverIdentifier, property, s.c_str());
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2552 }
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2553
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2554
222
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2555 void IndexBackend::Finalize()
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2556 {
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2557 OrthancDatabases::DatabaseBackendAdapterV2::Finalize();
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2558
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2559 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2560 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2)
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2561 OrthancDatabases::DatabaseBackendAdapterV3::Finalize();
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2562 # endif
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2563 #endif
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
2564 }
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
2565
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
2566
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
2567 DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend)
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
2568 {
255
d663d9e44f8d reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
2569 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend.CreateDatabaseFactory()));
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2570 backend.ConfigureDatabase(*manager);
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
2571 return manager.release();
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
2572 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2573 }