Mercurial > hg > orthanc
annotate OrthancServer/ServerIndex.cpp @ 224:4eb0c7ce86c9
refactoring for store
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 22:22:00 +0100 |
parents | bb8c260c0092 |
children | 8a26a8e85edf |
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, |
220 | 169 boost::mutex* mutex, |
170 unsigned int sleep) | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
171 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
172 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; |
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 while (1) |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
175 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
176 boost::this_thread::sleep(boost::posix_time::seconds(sleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
177 boost::mutex::scoped_lock lock(*mutex); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
178 db->FlushToDisk(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
179 } |
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 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
182 |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
183 ServerIndex::ServerIndex(FileStorage& fileStorage, |
220 | 184 const std::string& dbPath) : mutex_() |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
185 { |
202 | 186 listener_.reset(new Internals::ServerIndexListener(fileStorage)); |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
187 |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
188 if (dbPath == ":memory:") |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
189 { |
202 | 190 db_.reset(new DatabaseWrapper(*listener_)); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
191 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
192 else |
0 | 193 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
194 boost::filesystem::path p = dbPath; |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
195 |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
196 try |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
197 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
198 boost::filesystem::create_directories(p); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
199 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
200 catch (boost::filesystem::filesystem_error) |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
201 { |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
202 } |
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(p.string() + "/index", *listener_)); |
0 | 205 } |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
206 |
220 | 207 unsigned int sleep; |
208 try | |
209 { | |
210 std::string sleepString = db_->GetGlobalProperty(GlobalProperty_FlushSleep); | |
211 sleep = boost::lexical_cast<unsigned int>(sleepString); | |
212 } | |
213 catch (boost::bad_lexical_cast&) | |
214 { | |
215 // By default, wait for 10 seconds before flushing | |
216 sleep = 10; | |
217 } | |
218 | |
219 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_, sleep); | |
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 |
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 ServerIndex::~ServerIndex() |
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 LOG(INFO) << "Stopping the database flushing thread"; |
220 | 226 /*flushThread_.terminate(); |
227 flushThread_.join();*/ | |
0 | 228 } |
229 | |
230 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
231 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, |
0 | 232 const std::string& fileUuid, |
233 uint64_t uncompressedFileSize, | |
234 const std::string& jsonUuid, | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
235 const std::string& remoteAet) |
0 | 236 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
237 boost::mutex::scoped_lock lock(mutex_); |
0 | 238 |
178 | 239 DicomInstanceHasher hasher(dicomSummary); |
0 | 240 |
241 try | |
242 { | |
202 | 243 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); |
244 t->Begin(); | |
0 | 245 |
202 | 246 int64_t patient, study, series, instance; |
247 ResourceType type; | |
248 bool isNewSeries = false; | |
249 | |
250 // Do nothing if the instance already exists | |
251 if (db_->LookupResource(hasher.HashInstance(), patient, type)) | |
0 | 252 { |
202 | 253 assert(type == ResourceType_Instance); |
0 | 254 return StoreStatus_AlreadyStored; |
255 } | |
256 | |
202 | 257 // Create the instance |
258 instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance); | |
259 | |
260 DicomMap dicom; | |
261 dicomSummary.ExtractInstanceInformation(dicom); | |
262 db_->SetMainDicomTags(instance, dicom); | |
263 | |
264 // Create the patient/study/series/instance hierarchy | |
265 if (!db_->LookupResource(hasher.HashSeries(), series, type)) | |
0 | 266 { |
202 | 267 // This is a new series |
268 isNewSeries = true; | |
269 series = db_->CreateResource(hasher.HashSeries(), ResourceType_Series); | |
270 dicomSummary.ExtractSeriesInformation(dicom); | |
271 db_->SetMainDicomTags(series, dicom); | |
272 db_->AttachChild(series, instance); | |
273 | |
274 if (!db_->LookupResource(hasher.HashStudy(), study, type)) | |
275 { | |
276 // This is a new study | |
277 study = db_->CreateResource(hasher.HashStudy(), ResourceType_Study); | |
278 dicomSummary.ExtractStudyInformation(dicom); | |
279 db_->SetMainDicomTags(study, dicom); | |
280 db_->AttachChild(study, series); | |
281 | |
282 if (!db_->LookupResource(hasher.HashPatient(), patient, type)) | |
283 { | |
284 // This is a new patient | |
285 patient = db_->CreateResource(hasher.HashPatient(), ResourceType_Patient); | |
286 dicomSummary.ExtractPatientInformation(dicom); | |
287 db_->SetMainDicomTags(patient, dicom); | |
288 db_->AttachChild(patient, study); | |
289 } | |
290 else | |
291 { | |
292 assert(type == ResourceType_Patient); | |
293 db_->AttachChild(patient, study); | |
294 } | |
295 } | |
296 else | |
297 { | |
298 assert(type == ResourceType_Study); | |
299 db_->AttachChild(study, series); | |
300 } | |
0 | 301 } |
302 else | |
303 { | |
202 | 304 assert(type == ResourceType_Series); |
305 db_->AttachChild(series, instance); | |
0 | 306 } |
307 | |
202 | 308 // Attach the files to the newly created instance |
309 db_->AttachFile(instance, AttachedFileType_Dicom, fileUuid, uncompressedFileSize); | |
310 db_->AttachFile(instance, AttachedFileType_Json, jsonUuid, 0); // TODO "0" | |
311 | |
312 // Attach the metadata | |
313 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString()); | |
314 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); | |
315 | |
316 const DicomValue* value; | |
317 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || | |
318 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) | |
0 | 319 { |
202 | 320 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString()); |
0 | 321 } |
322 | |
202 | 323 if (isNewSeries) |
324 { | |
325 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL || | |
326 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL || | |
327 (value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL) | |
328 { | |
329 db_->SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, value->AsString()); | |
330 } | |
331 } | |
332 | |
205
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
333 // 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
|
334 SeriesStatus seriesStatus = GetSeriesStatus(series); |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
335 if (seriesStatus == SeriesStatus_Complete) |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
336 { |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
337 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series); |
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 |
202 | 340 t->Commit(); |
341 | |
0 | 342 return StoreStatus_Success; |
343 } | |
62 | 344 catch (OrthancException& e) |
0 | 345 { |
202 | 346 LOG(ERROR) << "EXCEPTION2 [" << e.What() << "]" << " " << db_->GetErrorMessage(); |
0 | 347 } |
348 | |
349 return StoreStatus_Failure; | |
350 } | |
351 | |
352 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
353 uint64_t ServerIndex::GetTotalCompressedSize() |
0 | 354 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
355 boost::mutex::scoped_lock lock(mutex_); |
202 | 356 return db_->GetTotalCompressedSize(); |
0 | 357 } |
358 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
359 uint64_t ServerIndex::GetTotalUncompressedSize() |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
360 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
361 boost::mutex::scoped_lock lock(mutex_); |
202 | 362 return db_->GetTotalUncompressedSize(); |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
363 } |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
364 |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
365 |
199 | 366 SeriesStatus ServerIndex::GetSeriesStatus(int id) |
367 { | |
368 // Get the expected number of instances in this series (from the metadata) | |
202 | 369 std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances); |
199 | 370 |
371 size_t expected; | |
372 try | |
373 { | |
374 expected = boost::lexical_cast<size_t>(s); | |
375 if (expected < 0) | |
376 { | |
377 return SeriesStatus_Unknown; | |
378 } | |
379 } | |
380 catch (boost::bad_lexical_cast&) | |
381 { | |
382 return SeriesStatus_Unknown; | |
383 } | |
384 | |
385 // Loop over the instances of this series | |
386 std::list<int64_t> children; | |
202 | 387 db_->GetChildrenInternalId(children, id); |
199 | 388 |
389 std::set<size_t> instances; | |
390 for (std::list<int64_t>::const_iterator | |
391 it = children.begin(); it != children.end(); it++) | |
392 { | |
393 // Get the index of this instance in the series | |
202 | 394 s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries); |
199 | 395 size_t index; |
396 try | |
397 { | |
398 index = boost::lexical_cast<size_t>(s); | |
399 } | |
400 catch (boost::bad_lexical_cast&) | |
401 { | |
402 return SeriesStatus_Unknown; | |
403 } | |
404 | |
405 if (index <= 0 || index > expected) | |
406 { | |
407 // Out-of-range instance index | |
408 return SeriesStatus_Inconsistent; | |
409 } | |
410 | |
411 if (instances.find(index) != instances.end()) | |
412 { | |
413 // Twice the same instance index | |
414 return SeriesStatus_Inconsistent; | |
415 } | |
416 | |
417 instances.insert(index); | |
418 } | |
419 | |
420 if (instances.size() == expected) | |
421 { | |
422 return SeriesStatus_Complete; | |
423 } | |
424 else | |
425 { | |
426 return SeriesStatus_Missing; | |
427 } | |
428 } | |
429 | |
430 | |
431 | |
202 | 432 void ServerIndex::MainDicomTagsToJson(Json::Value& target, |
433 int64_t resourceId) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
434 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
435 DicomMap tags; |
202 | 436 db_->GetMainDicomTags(tags, resourceId); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
437 target["MainDicomTags"] = Json::objectValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
438 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
439 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
440 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
441 bool ServerIndex::LookupResource(Json::Value& result, |
199 | 442 const std::string& publicId, |
443 ResourceType expectedType) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
444 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
445 result = Json::objectValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
446 |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
447 boost::mutex::scoped_lock lock(mutex_); |
199 | 448 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
449 // Lookup for the requested resource |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
450 int64_t id; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
451 ResourceType type; |
202 | 452 if (!db_->LookupResource(publicId, id, type) || |
199 | 453 type != expectedType) |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
454 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
455 return false; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
456 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
457 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
458 // Find the parent resource (if it exists) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
459 if (type != ResourceType_Patient) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
460 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
461 int64_t parentId; |
202 | 462 if (!db_->LookupParent(parentId, id)) |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
463 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
464 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
465 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
466 |
202 | 467 std::string parent = db_->GetPublicId(parentId); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
468 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
469 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
470 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
471 case ResourceType_Study: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
472 result["ParentPatient"] = parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
473 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
474 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
475 case ResourceType_Series: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
476 result["ParentStudy"] = parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
477 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
478 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
479 case ResourceType_Instance: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
480 result["ParentSeries"] = parent; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
481 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
482 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
483 default: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
484 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
485 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
486 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
487 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
488 // List the children resources |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
489 std::list<std::string> children; |
202 | 490 db_->GetChildrenPublicId(children, id); |
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 if (type != ResourceType_Instance) |
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 Json::Value c = Json::arrayValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
495 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
496 for (std::list<std::string>::const_iterator |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
497 it = children.begin(); it != children.end(); it++) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
498 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
499 c.append(*it); |
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 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
502 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
503 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
504 case ResourceType_Patient: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
505 result["Studies"] = c; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
506 break; |
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["Series"] = c; |
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["Instances"] = c; |
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 default: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
517 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
518 } |
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 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
521 // Set the resource type |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
522 switch (type) |
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 case ResourceType_Patient: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
525 result["Type"] = "Patient"; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
526 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
527 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
528 case ResourceType_Study: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
529 result["Type"] = "Study"; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
530 break; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
531 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
532 case ResourceType_Series: |
199 | 533 { |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
534 result["Type"] = "Series"; |
199 | 535 result["Status"] = ToString(GetSeriesStatus(id)); |
536 | |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
537 int i; |
202 | 538 if (db_->GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances)) |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
539 result["ExpectedNumberOfInstances"] = i; |
202 | 540 else |
199 | 541 result["ExpectedNumberOfInstances"] = Json::nullValue; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
542 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
543 break; |
199 | 544 } |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
545 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
546 case ResourceType_Instance: |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
547 { |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
548 result["Type"] = "Instance"; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
549 |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
550 std::string fileUuid; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
551 uint64_t uncompressedSize; |
202 | 552 if (!db_->LookupFile(id, AttachedFileType_Dicom, fileUuid, uncompressedSize)) |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
553 { |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
554 throw OrthancException(ErrorCode_InternalError); |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
555 } |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
556 |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
557 result["FileSize"] = static_cast<unsigned int>(uncompressedSize); |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
558 result["FileUuid"] = fileUuid; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
559 |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
560 int i; |
202 | 561 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
562 result["IndexInSeries"] = i; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
563 else |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
564 result["IndexInSeries"] = Json::nullValue; |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
565 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
566 break; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
567 } |
198
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 default: |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
570 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
571 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
572 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
573 // Record the remaining information |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
574 result["ID"] = publicId; |
202 | 575 MainDicomTagsToJson(result, id); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
576 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
577 return true; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
578 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
579 |
0 | 580 |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
581 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
|
582 CompressionType& compressionType, |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
583 const std::string& instanceUuid, |
197
530a25320461
removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
194
diff
changeset
|
584 AttachedFileType contentType) |
0 | 585 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
586 boost::mutex::scoped_lock lock(mutex_); |
0 | 587 |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
588 int64_t id; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
589 ResourceType type; |
202 | 590 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
|
591 type != ResourceType_Instance) |
192
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
592 { |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
593 throw OrthancException(ErrorCode_InternalError); |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
594 } |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
595 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
596 uint64_t compressedSize, uncompressedSize; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
597 |
202 | 598 return db_->LookupFile(id, contentType, fileUuid, compressedSize, uncompressedSize, compressionType); |
192
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
599 } |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
600 |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
601 |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
602 |
0 | 603 void ServerIndex::GetAllUuids(Json::Value& target, |
190 | 604 ResourceType resourceType) |
0 | 605 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
606 boost::mutex::scoped_lock lock(mutex_); |
202 | 607 db_->GetAllPublicIds(target, resourceType); |
0 | 608 } |
609 | |
610 | |
611 bool ServerIndex::GetChanges(Json::Value& target, | |
204 | 612 int64_t since, |
0 | 613 unsigned int maxResults) |
614 { | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
615 boost::mutex::scoped_lock lock(mutex_); |
0 | 616 |
204 | 617 db_->GetChanges(target, since, maxResults); |
0 | 618 |
204 | 619 return true; |
0 | 620 } |
621 } |