Mercurial > hg > orthanc
annotate OrthancServer/ServerIndex.cpp @ 212:f276b175dcaf
delete resources
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 10:13:49 +0100 |
parents | 4453a010d0db |
children | bb8c260c0092 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "ServerIndex.h" | |
34 | |
62 | 35 using namespace Orthanc; |
0 | 36 |
6 | 37 #ifndef NOMINMAX |
2 | 38 #define NOMINMAX |
6 | 39 #endif |
40 | |
8 | 41 #include "EmbeddedResources.h" |
0 | 42 #include "../Core/Toolbox.h" |
43 #include "../Core/Uuid.h" | |
44 #include "../Core/DicomFormat/DicomArray.h" | |
45 #include "../Core/SQLite/Transaction.h" | |
46 #include "FromDcmtkBridge.h" | |
47 | |
48 #include <boost/lexical_cast.hpp> | |
49 #include <stdio.h> | |
108 | 50 #include <glog/logging.h> |
0 | 51 |
62 | 52 namespace Orthanc |
0 | 53 { |
54 namespace Internals | |
55 { | |
202 | 56 class ServerIndexListener : public IServerIndexListener |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
57 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
58 private: |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
59 FileStorage& fileStorage_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
60 bool hasRemainingLevel_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
61 ResourceType remainingType_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
62 std::string remainingPublicId_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
63 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
64 public: |
202 | 65 ServerIndexListener(FileStorage& fileStorage) : |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
66 fileStorage_(fileStorage), |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
67 hasRemainingLevel_(false) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
68 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
69 assert(ResourceType_Patient < ResourceType_Study && |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
70 ResourceType_Study < ResourceType_Series && |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
71 ResourceType_Series < ResourceType_Instance); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
72 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
73 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
74 void Reset() |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
75 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
76 hasRemainingLevel_ = false; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
77 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
78 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
79 virtual void SignalRemainingAncestor(ResourceType parentType, |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
80 const std::string& publicId) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
81 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
82 LOG(INFO) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")"; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
83 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
84 if (hasRemainingLevel_) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
85 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
86 if (parentType < remainingType_) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
87 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
88 remainingType_ = parentType; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
89 remainingPublicId_ = publicId; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
90 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
91 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
92 else |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
93 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
94 hasRemainingLevel_ = true; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
95 remainingType_ = parentType; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
96 remainingPublicId_ = publicId; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
97 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
98 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
99 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
100 virtual void SignalFileDeleted(const std::string& fileUuid) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
101 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
102 assert(Toolbox::IsUuid(fileUuid)); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
103 fileStorage_.Remove(fileUuid); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
104 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
105 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
106 bool HasRemainingLevel() const |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
107 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
108 return hasRemainingLevel_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
109 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
110 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
111 ResourceType GetRemainingType() const |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
112 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
113 assert(HasRemainingLevel()); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
114 return remainingType_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
115 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
116 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
117 const std::string& GetRemainingPublicId() const |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
118 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
119 assert(HasRemainingLevel()); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
120 return remainingPublicId_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
121 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
122 }; |
0 | 123 } |
124 | |
125 | |
212 | 126 bool ServerIndex::DeleteResource(Json::Value& target, |
0 | 127 const std::string& uuid, |
202 | 128 ResourceType expectedType) |
0 | 129 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
130 boost::mutex::scoped_lock lock(mutex_); |
0 | 131 |
202 | 132 listener_->Reset(); |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
133 |
202 | 134 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); |
135 t->Begin(); | |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
136 |
202 | 137 int64_t id; |
138 ResourceType type; | |
139 if (!db_->LookupResource(uuid, id, type) || | |
140 expectedType != type) | |
0 | 141 { |
142 return false; | |
143 } | |
202 | 144 |
145 db_->DeleteResource(id); | |
0 | 146 |
202 | 147 if (listener_->HasRemainingLevel()) |
0 | 148 { |
202 | 149 ResourceType type = listener_->GetRemainingType(); |
150 const std::string& uuid = listener_->GetRemainingPublicId(); | |
0 | 151 |
152 target["RemainingAncestor"] = Json::Value(Json::objectValue); | |
204 | 153 target["RemainingAncestor"]["Path"] = GetBasePath(type, uuid); |
202 | 154 target["RemainingAncestor"]["Type"] = ToString(type); |
0 | 155 target["RemainingAncestor"]["ID"] = uuid; |
156 } | |
157 else | |
158 { | |
159 target["RemainingAncestor"] = Json::nullValue; | |
160 } | |
161 | |
202 | 162 t->Commit(); |
163 | |
0 | 164 return true; |
165 } | |
166 | |
167 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
168 static void FlushThread(DatabaseWrapper* db, |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
169 boost::mutex* mutex) |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
170 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
171 // By default, wait for 10 seconds before flushing |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
172 unsigned int sleep = 10; |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
173 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
174 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
175 boost::mutex::scoped_lock lock(*mutex); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
176 std::string s = db->GetGlobalProperty(GlobalProperty_FlushSleep); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
177 try |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
178 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
179 sleep = boost::lexical_cast<unsigned int>(s); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
180 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
181 catch (boost::bad_lexical_cast&) |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
182 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
183 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
184 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
185 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
186 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
187 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
188 while (1) |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
189 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
190 boost::this_thread::sleep(boost::posix_time::seconds(sleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
191 boost::mutex::scoped_lock lock(*mutex); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
192 db->FlushToDisk(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
193 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
194 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
195 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
196 |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
197 ServerIndex::ServerIndex(FileStorage& fileStorage, |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
198 const std::string& dbPath) |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
199 { |
202 | 200 listener_.reset(new Internals::ServerIndexListener(fileStorage)); |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
201 |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
202 if (dbPath == ":memory:") |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
203 { |
202 | 204 db_.reset(new DatabaseWrapper(*listener_)); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
205 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
206 else |
0 | 207 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
208 boost::filesystem::path p = dbPath; |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
209 |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
210 try |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
211 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
212 boost::filesystem::create_directories(p); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
213 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
214 catch (boost::filesystem::filesystem_error) |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
215 { |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
216 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
217 |
202 | 218 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_)); |
0 | 219 } |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
220 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
221 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
222 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
223 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
224 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
225 ServerIndex::~ServerIndex() |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
226 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
227 LOG(INFO) << "Stopping the database flushing thread"; |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
228 flushThread_.interrupt(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
229 flushThread_.join(); |
0 | 230 } |
231 | |
232 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
233 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, |
0 | 234 const std::string& fileUuid, |
235 uint64_t uncompressedFileSize, | |
236 const std::string& jsonUuid, | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
237 const std::string& remoteAet) |
0 | 238 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
239 boost::mutex::scoped_lock lock(mutex_); |
0 | 240 |
178 | 241 DicomInstanceHasher hasher(dicomSummary); |
0 | 242 |
243 try | |
244 { | |
202 | 245 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); |
246 t->Begin(); | |
0 | 247 |
202 | 248 int64_t patient, study, series, instance; |
249 ResourceType type; | |
250 bool isNewSeries = false; | |
251 | |
252 // Do nothing if the instance already exists | |
253 if (db_->LookupResource(hasher.HashInstance(), patient, type)) | |
0 | 254 { |
202 | 255 assert(type == ResourceType_Instance); |
0 | 256 return StoreStatus_AlreadyStored; |
257 } | |
258 | |
202 | 259 // Create the instance |
260 instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance); | |
261 | |
262 DicomMap dicom; | |
263 dicomSummary.ExtractInstanceInformation(dicom); | |
264 db_->SetMainDicomTags(instance, dicom); | |
265 | |
266 // Create the patient/study/series/instance hierarchy | |
267 if (!db_->LookupResource(hasher.HashSeries(), series, type)) | |
0 | 268 { |
202 | 269 // This is a new series |
270 isNewSeries = true; | |
271 series = db_->CreateResource(hasher.HashSeries(), ResourceType_Series); | |
272 dicomSummary.ExtractSeriesInformation(dicom); | |
273 db_->SetMainDicomTags(series, dicom); | |
274 db_->AttachChild(series, instance); | |
275 | |
276 if (!db_->LookupResource(hasher.HashStudy(), study, type)) | |
277 { | |
278 // This is a new study | |
279 study = db_->CreateResource(hasher.HashStudy(), ResourceType_Study); | |
280 dicomSummary.ExtractStudyInformation(dicom); | |
281 db_->SetMainDicomTags(study, dicom); | |
282 db_->AttachChild(study, series); | |
283 | |
284 if (!db_->LookupResource(hasher.HashPatient(), patient, type)) | |
285 { | |
286 // This is a new patient | |
287 patient = db_->CreateResource(hasher.HashPatient(), ResourceType_Patient); | |
288 dicomSummary.ExtractPatientInformation(dicom); | |
289 db_->SetMainDicomTags(patient, dicom); | |
290 db_->AttachChild(patient, study); | |
291 } | |
292 else | |
293 { | |
294 assert(type == ResourceType_Patient); | |
295 db_->AttachChild(patient, study); | |
296 } | |
297 } | |
298 else | |
299 { | |
300 assert(type == ResourceType_Study); | |
301 db_->AttachChild(study, series); | |
302 } | |
0 | 303 } |
304 else | |
305 { | |
202 | 306 assert(type == ResourceType_Series); |
307 db_->AttachChild(series, instance); | |
0 | 308 } |
309 | |
202 | 310 // Attach the files to the newly created instance |
311 db_->AttachFile(instance, AttachedFileType_Dicom, fileUuid, uncompressedFileSize); | |
312 db_->AttachFile(instance, AttachedFileType_Json, jsonUuid, 0); // TODO "0" | |
313 | |
314 // Attach the metadata | |
315 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString()); | |
316 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); | |
317 | |
318 const DicomValue* value; | |
319 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || | |
320 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) | |
0 | 321 { |
202 | 322 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString()); |
0 | 323 } |
324 | |
202 | 325 if (isNewSeries) |
326 { | |
327 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL || | |
328 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL || | |
329 (value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL) | |
330 { | |
331 db_->SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, value->AsString()); | |
332 } | |
333 } | |
334 | |
205
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
335 // Check whether the series of this new instance is now completed |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
336 SeriesStatus seriesStatus = GetSeriesStatus(series); |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
337 if (seriesStatus == SeriesStatus_Complete) |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
338 { |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
339 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series); |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
340 } |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
341 |
202 | 342 t->Commit(); |
343 | |
0 | 344 return StoreStatus_Success; |
345 } | |
62 | 346 catch (OrthancException& e) |
0 | 347 { |
202 | 348 LOG(ERROR) << "EXCEPTION2 [" << e.What() << "]" << " " << db_->GetErrorMessage(); |
0 | 349 } |
350 | |
351 return StoreStatus_Failure; | |
352 } | |
353 | |
354 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
355 StoreStatus ServerIndex::Store(FileStorage& storage, |
0 | 356 const char* dicomFile, |
357 size_t dicomSize, | |
358 const DicomMap& dicomSummary, | |
359 const Json::Value& dicomJson, | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
360 const std::string& remoteAet) |
0 | 361 { |
362 std::string fileUuid = storage.Create(dicomFile, dicomSize); | |
363 std::string jsonUuid = storage.Create(dicomJson.toStyledString()); | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
364 StoreStatus status = Store(dicomSummary, fileUuid, dicomSize, jsonUuid, remoteAet); |
0 | 365 |
366 if (status != StoreStatus_Success) | |
367 { | |
147 | 368 storage.Remove(fileUuid); |
369 storage.Remove(jsonUuid); | |
0 | 370 } |
371 | |
372 switch (status) | |
373 { | |
374 case StoreStatus_Success: | |
194
0186ac92810c
fixes for Ubuntu 10.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
375 LOG(INFO) << "New instance stored"; |
0 | 376 break; |
377 | |
378 case StoreStatus_AlreadyStored: | |
194
0186ac92810c
fixes for Ubuntu 10.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
379 LOG(INFO) << "Already stored"; |
0 | 380 break; |
381 | |
382 case StoreStatus_Failure: | |
138 | 383 LOG(ERROR) << "Store failure"; |
0 | 384 break; |
385 } | |
386 | |
387 return status; | |
388 } | |
389 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
390 uint64_t ServerIndex::GetTotalCompressedSize() |
0 | 391 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
392 boost::mutex::scoped_lock lock(mutex_); |
202 | 393 return db_->GetTotalCompressedSize(); |
0 | 394 } |
395 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
396 uint64_t ServerIndex::GetTotalUncompressedSize() |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
397 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
398 boost::mutex::scoped_lock lock(mutex_); |
202 | 399 return db_->GetTotalUncompressedSize(); |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
400 } |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
401 |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
402 |
199 | 403 SeriesStatus ServerIndex::GetSeriesStatus(int id) |
404 { | |
405 // Get the expected number of instances in this series (from the metadata) | |
202 | 406 std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances); |
199 | 407 |
408 size_t expected; | |
409 try | |
410 { | |
411 expected = boost::lexical_cast<size_t>(s); | |
412 if (expected < 0) | |
413 { | |
414 return SeriesStatus_Unknown; | |
415 } | |
416 } | |
417 catch (boost::bad_lexical_cast&) | |
418 { | |
419 return SeriesStatus_Unknown; | |
420 } | |
421 | |
422 // Loop over the instances of this series | |
423 std::list<int64_t> children; | |
202 | 424 db_->GetChildrenInternalId(children, id); |
199 | 425 |
426 std::set<size_t> instances; | |
427 for (std::list<int64_t>::const_iterator | |
428 it = children.begin(); it != children.end(); it++) | |
429 { | |
430 // Get the index of this instance in the series | |
202 | 431 s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries); |
199 | 432 size_t index; |
433 try | |
434 { | |
435 index = boost::lexical_cast<size_t>(s); | |
436 } | |
437 catch (boost::bad_lexical_cast&) | |
438 { | |
439 return SeriesStatus_Unknown; | |
440 } | |
441 | |
442 if (index <= 0 || index > expected) | |
443 { | |
444 // Out-of-range instance index | |
445 return SeriesStatus_Inconsistent; | |
446 } | |
447 | |
448 if (instances.find(index) != instances.end()) | |
449 { | |
450 // Twice the same instance index | |
451 return SeriesStatus_Inconsistent; | |
452 } | |
453 | |
454 instances.insert(index); | |
455 } | |
456 | |
457 if (instances.size() == expected) | |
458 { | |
459 return SeriesStatus_Complete; | |
460 } | |
461 else | |
462 { | |
463 return SeriesStatus_Missing; | |
464 } | |
465 } | |
466 | |
467 | |
468 | |
202 | 469 void ServerIndex::MainDicomTagsToJson(Json::Value& target, |
470 int64_t resourceId) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
471 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
472 DicomMap tags; |
202 | 473 db_->GetMainDicomTags(tags, resourceId); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
474 target["MainDicomTags"] = Json::objectValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
475 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
476 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
477 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
478 bool ServerIndex::LookupResource(Json::Value& result, |
199 | 479 const std::string& publicId, |
480 ResourceType expectedType) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
481 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
482 result = Json::objectValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
483 |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
484 boost::mutex::scoped_lock lock(mutex_); |
199 | 485 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
486 // Lookup for the requested resource |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
487 int64_t id; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
488 ResourceType type; |
202 | 489 if (!db_->LookupResource(publicId, id, type) || |
199 | 490 type != expectedType) |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
491 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
492 return false; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
493 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
494 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
495 // Find the parent resource (if it exists) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
496 if (type != ResourceType_Patient) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
497 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
498 int64_t parentId; |
202 | 499 if (!db_->LookupParent(parentId, id)) |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
500 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
501 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
502 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
503 |
202 | 504 std::string parent = db_->GetPublicId(parentId); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
505 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
506 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
507 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
508 case ResourceType_Study: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
509 result["ParentPatient"] = parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
510 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
511 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
512 case ResourceType_Series: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
513 result["ParentStudy"] = parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
514 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
515 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
516 case ResourceType_Instance: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
517 result["ParentSeries"] = parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
518 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
519 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
520 default: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
521 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
522 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
523 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
524 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
525 // List the children resources |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
526 std::list<std::string> children; |
202 | 527 db_->GetChildrenPublicId(children, id); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
528 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
529 if (type != ResourceType_Instance) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
530 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
531 Json::Value c = Json::arrayValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
532 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
533 for (std::list<std::string>::const_iterator |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
534 it = children.begin(); it != children.end(); it++) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
535 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
536 c.append(*it); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
537 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
538 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
539 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
540 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
541 case ResourceType_Patient: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
542 result["Studies"] = c; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
543 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
544 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
545 case ResourceType_Study: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
546 result["Series"] = c; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
547 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
548 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
549 case ResourceType_Series: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
550 result["Instances"] = c; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
551 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
552 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
553 default: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
554 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
555 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
556 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
557 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
558 // Set the resource type |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
559 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
560 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
561 case ResourceType_Patient: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
562 result["Type"] = "Patient"; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
563 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
564 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
565 case ResourceType_Study: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
566 result["Type"] = "Study"; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
567 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
568 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
569 case ResourceType_Series: |
199 | 570 { |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
571 result["Type"] = "Series"; |
199 | 572 result["Status"] = ToString(GetSeriesStatus(id)); |
573 | |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
574 int i; |
202 | 575 if (db_->GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances)) |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
576 result["ExpectedNumberOfInstances"] = i; |
202 | 577 else |
199 | 578 result["ExpectedNumberOfInstances"] = Json::nullValue; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
579 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
580 break; |
199 | 581 } |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
582 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
583 case ResourceType_Instance: |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
584 { |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
585 result["Type"] = "Instance"; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
586 |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
587 std::string fileUuid; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
588 uint64_t uncompressedSize; |
202 | 589 if (!db_->LookupFile(id, AttachedFileType_Dicom, fileUuid, uncompressedSize)) |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
590 { |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
591 throw OrthancException(ErrorCode_InternalError); |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
592 } |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
593 |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
594 result["FileSize"] = static_cast<unsigned int>(uncompressedSize); |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
595 result["FileUuid"] = fileUuid; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
596 |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
597 int i; |
202 | 598 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
599 result["IndexInSeries"] = i; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
600 else |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
601 result["IndexInSeries"] = Json::nullValue; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
602 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
603 break; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
604 } |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
605 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
606 default: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
607 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
608 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
609 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
610 // Record the remaining information |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
611 result["ID"] = publicId; |
202 | 612 MainDicomTagsToJson(result, id); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
613 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
614 return true; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
615 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
616 |
0 | 617 |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
618 bool ServerIndex::GetFile(std::string& fileUuid, |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
619 CompressionType& compressionType, |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
620 const std::string& instanceUuid, |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
621 AttachedFileType contentType) |
0 | 622 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
623 boost::mutex::scoped_lock lock(mutex_); |
0 | 624 |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
625 int64_t id; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
626 ResourceType type; |
202 | 627 if (!db_->LookupResource(instanceUuid, id, type) || |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
628 type != ResourceType_Instance) |
192
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
629 { |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
630 throw OrthancException(ErrorCode_InternalError); |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
631 } |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
632 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
633 uint64_t compressedSize, uncompressedSize; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
634 |
202 | 635 return db_->LookupFile(id, contentType, fileUuid, compressedSize, uncompressedSize, compressionType); |
192
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
636 } |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
637 |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
638 |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
639 |
0 | 640 void ServerIndex::GetAllUuids(Json::Value& target, |
190 | 641 ResourceType resourceType) |
0 | 642 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
643 boost::mutex::scoped_lock lock(mutex_); |
202 | 644 db_->GetAllPublicIds(target, resourceType); |
0 | 645 } |
646 | |
647 | |
648 bool ServerIndex::GetChanges(Json::Value& target, | |
204 | 649 int64_t since, |
0 | 650 unsigned int maxResults) |
651 { | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
652 boost::mutex::scoped_lock lock(mutex_); |
0 | 653 |
204 | 654 db_->GetChanges(target, since, maxResults); |
0 | 655 |
204 | 656 return true; |
0 | 657 } |
658 } |