comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 90:e61587582cef db-changes

moved extension TagMostRecentPatient into stored procedure CreateInstance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 16 Jan 2019 18:14:28 +0100
parents eb08ec14fb04
children cc3dc759c989
comparison
equal deleted inserted replaced
89:3f917ed95daf 90:e61587582cef
173 } 173 }
174 174
175 { 175 {
176 PostgreSQLTransaction t(*db); 176 PostgreSQLTransaction t(*db);
177 177
178 int hasCreateInstance = 0; 178 int property = 0;
179 if (!LookupGlobalIntegerProperty(hasCreateInstance, *db, t, 179 if (!LookupGlobalIntegerProperty(property, *db, t,
180 Orthanc::GlobalProperty_HasCreateInstance) || 180 Orthanc::GlobalProperty_HasCreateInstance) ||
181 hasCreateInstance != 1) 181 property != 2)
182 { 182 {
183 LOG(INFO) << "Installing the CreateInstance extension"; 183 LOG(INFO) << "Installing the CreateInstance extension";
184 184
185 if (property == 1)
186 {
187 // Drop older, experimental versions of this extension
188 db->Execute("DROP FUNCTION CreateInstance("
189 "IN patient TEXT, IN study TEXT, IN series TEXT, in instance TEXT)");
190 }
191
185 std::string query; 192 std::string query;
186 Orthanc::EmbeddedResources::GetFileResource 193 Orthanc::EmbeddedResources::GetFileResource
187 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE); 194 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE);
188 db->Execute(query); 195 db->Execute(query);
189 196
190 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasCreateInstance, 1); 197 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasCreateInstance, 2);
191 } 198 }
192 199
193 t.Commit(); 200
194 } 201 if (!LookupGlobalIntegerProperty(property, *db, t,
195
196 {
197 PostgreSQLTransaction t(*db);
198
199 int hasFastTotalSize = 0;
200 if (!LookupGlobalIntegerProperty(hasFastTotalSize, *db, t,
201 Orthanc::GlobalProperty_GetTotalSizeIsFast) || 202 Orthanc::GlobalProperty_GetTotalSizeIsFast) ||
202 hasFastTotalSize != 1) 203 property != 1)
203 { 204 {
204 LOG(INFO) << "Installing the FastTotalSize extension"; 205 LOG(INFO) << "Installing the FastTotalSize extension";
205 206
206 std::string query; 207 std::string query;
207 Orthanc::EmbeddedResources::GetFileResource 208 Orthanc::EmbeddedResources::GetFileResource
209 db->Execute(query); 210 db->Execute(query);
210 211
211 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1); 212 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1);
212 } 213 }
213 214
214 t.Commit();
215 }
216
217 {
218 PostgreSQLTransaction t(*db);
219 215
220 // Installing this extension requires the "GlobalIntegers" table 216 // Installing this extension requires the "GlobalIntegers" table
221 // created by the "FastTotalSize" extension 217 // created by the "FastTotalSize" extension
222 int property = 0; 218 property = 0;
223 if (!LookupGlobalIntegerProperty(property, *db, t, 219 if (!LookupGlobalIntegerProperty(property, *db, t,
224 Orthanc::GlobalProperty_HasFastCountResources) || 220 Orthanc::GlobalProperty_HasFastCountResources) ||
225 property != 1) 221 property != 1)
226 { 222 {
227 LOG(INFO) << "Installing the FastCountResources extension"; 223 LOG(INFO) << "Installing the FastCountResources extension";
232 db->Execute(query); 228 db->Execute(query);
233 229
234 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasFastCountResources, 1); 230 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_HasFastCountResources, 1);
235 } 231 }
236 232
237 t.Commit();
238 }
239
240 {
241 PostgreSQLTransaction t(*db);
242 233
243 // Installing this extension requires the "GlobalIntegers" table 234 // Installing this extension requires the "GlobalIntegers" table
244 // created by the "GetLastChangeIndex" extension 235 // created by the "GetLastChangeIndex" extension
245 int property = 0; 236 property = 0;
246 if (!LookupGlobalIntegerProperty(property, *db, t, 237 if (!LookupGlobalIntegerProperty(property, *db, t,
247 Orthanc::GlobalProperty_GetLastChangeIndex) || 238 Orthanc::GlobalProperty_GetLastChangeIndex) ||
248 property != 1) 239 property != 1)
249 { 240 {
250 LOG(INFO) << "Installing the GetLastChangeIndex extension"; 241 LOG(INFO) << "Installing the GetLastChangeIndex extension";
379 result.isNewStudy = (ReadInteger64(statement, 1) == 1); 370 result.isNewStudy = (ReadInteger64(statement, 1) == 1);
380 result.isNewSeries = (ReadInteger64(statement, 2) == 1); 371 result.isNewSeries = (ReadInteger64(statement, 2) == 1);
381 result.patientId = ReadInteger64(statement, 4); 372 result.patientId = ReadInteger64(statement, 4);
382 result.studyId = ReadInteger64(statement, 5); 373 result.studyId = ReadInteger64(statement, 5);
383 result.seriesId = ReadInteger64(statement, 6); 374 result.seriesId = ReadInteger64(statement, 6);
384
385 // TODO - Move this to the stored procedure
386 TagMostRecentPatient(result.patientId);
387 } 375 }
388 } 376 }
389 #endif 377 #endif
390 378
391 379
432 statement.SetReadOnly(true); 420 statement.SetReadOnly(true);
433 statement.Execute(); 421 statement.Execute();
434 422
435 return ReadInteger64(statement, 0); 423 return ReadInteger64(statement, 0);
436 } 424 }
425
426
427 void PostgreSQLIndex::TagMostRecentPatient(int64_t patient)
428 {
429 // This behavior is implemented in "CreateInstance()", and no
430 // backward compatibility is necessary
431 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
432 }
437 } 433 }