annotate OrthancServer/ServerIndex.cpp @ 436:d51186bf7602

read access to metadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 15 May 2013 16:28:00 +0200
parents ccf3a0a43dac
children 7bbe77cb9e12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
399
4d5f0857ec9c copyright update
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 375
diff changeset
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "ServerIndex.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
35 #ifndef NOMINMAX
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
36 #define NOMINMAX
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
37 #endif
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
38
8
3a584803783e build with visual studio
jodogne
parents: 6
diff changeset
39 #include "EmbeddedResources.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "../Core/Toolbox.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include "../Core/Uuid.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include "../Core/DicomFormat/DicomArray.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include "../Core/SQLite/Transaction.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include "FromDcmtkBridge.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
45 #include "ServerContext.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #include <stdio.h>
108
a6e41de88a53 using glog
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
49 #include <glog/logging.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
51 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 namespace Internals
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
55 class ServerIndexListener : public IServerIndexListener
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
56 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
57 private:
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
58 ServerContext& context_;
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
59 bool hasRemainingLevel_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
60 ResourceType remainingType_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
61 std::string remainingPublicId_;
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
62 std::list<std::string> pendingFilesToRemove_;
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
63 uint64_t sizeOfFilesToRemove_;
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
64
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
65 public:
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
66 ServerIndexListener(ServerContext& context) :
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
67 context_(context)
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
68 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
69 Reset();
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
70 assert(ResourceType_Patient < ResourceType_Study &&
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
71 ResourceType_Study < ResourceType_Series &&
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
72 ResourceType_Series < ResourceType_Instance);
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
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
75 void Reset()
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
76 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
77 sizeOfFilesToRemove_ = 0;
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
78 hasRemainingLevel_ = false;
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
79 pendingFilesToRemove_.clear();
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
80 }
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
81
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
82 uint64_t GetSizeOfFilesToRemove()
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
83 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
84 return sizeOfFilesToRemove_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
85 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
86
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
87 void CommitFilesToRemove()
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
88 {
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
89 for (std::list<std::string>::iterator
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
90 it = pendingFilesToRemove_.begin();
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
91 it != pendingFilesToRemove_.end(); it++)
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
92 {
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
93 context_.RemoveFile(*it);
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
94 }
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
95 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
96
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
97 virtual void SignalRemainingAncestor(ResourceType parentType,
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
98 const std::string& publicId)
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 LOG(INFO) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
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 if (hasRemainingLevel_)
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
103 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
104 if (parentType < remainingType_)
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 remainingType_ = parentType;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
107 remainingPublicId_ = publicId;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
108 }
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 else
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
111 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
112 hasRemainingLevel_ = true;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
113 remainingType_ = parentType;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
114 remainingPublicId_ = publicId;
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
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
118 virtual void SignalFileDeleted(const FileInfo& info)
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
119 {
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
120 assert(Toolbox::IsUuid(info.GetUuid()));
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
121 pendingFilesToRemove_.push_back(info.GetUuid());
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
122 sizeOfFilesToRemove_ += info.GetCompressedSize();
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
123 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
124
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
125 bool HasRemainingLevel() const
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
126 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
127 return hasRemainingLevel_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
128 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
129
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
130 ResourceType GetRemainingType() const
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
131 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
132 assert(HasRemainingLevel());
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
133 return remainingType_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
134 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
135
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
136 const std::string& GetRemainingPublicId() const
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
137 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
138 assert(HasRemainingLevel());
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
139 return remainingPublicId_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
140 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
141 };
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
145 class ServerIndex::Transaction
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
146 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
147 private:
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
148 ServerIndex& index_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
149 std::auto_ptr<SQLite::Transaction> transaction_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
150 bool isCommitted_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
151
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
152 public:
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
153 Transaction(ServerIndex& index) :
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
154 index_(index),
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
155 isCommitted_(false)
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
156 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
157 assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize());
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
158
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
159 index_.listener_->Reset();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
160 transaction_.reset(index_.db_->StartTransaction());
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
161 transaction_->Begin();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
162 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
163
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
164 void Commit(uint64_t sizeOfAddedFiles)
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
165 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
166 if (!isCommitted_)
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
167 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
168 transaction_->Commit();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
169
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
170 // We can remove the files once the SQLite transaction has
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
171 // been successfully committed. Some files might have to be
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
172 // deleted because of recycling.
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
173 index_.listener_->CommitFilesToRemove();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
174
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
175 index_.currentStorageSize_ += sizeOfAddedFiles;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
176
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
177 assert(index_.currentStorageSize_ >= index_.listener_->GetSizeOfFilesToRemove());
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
178 index_.currentStorageSize_ -= index_.listener_->GetSizeOfFilesToRemove();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
179
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
180 assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize());
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
181
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
182 isCommitted_ = true;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
183 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
184 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
185 };
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
186
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
187
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
188 bool ServerIndex::DeleteResource(Json::Value& target,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 const std::string& uuid,
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
190 ResourceType expectedType)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
192 boost::mutex::scoped_lock lock(mutex_);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
193 listener_->Reset();
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
194
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
195 Transaction t(*this);
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
196
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
197 int64_t id;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
198 ResourceType type;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
199 if (!db_->LookupResource(uuid, id, type) ||
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
200 expectedType != type)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
204
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
205 db_->DeleteResource(id);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
207 if (listener_->HasRemainingLevel())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
209 ResourceType type = listener_->GetRemainingType();
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
210 const std::string& uuid = listener_->GetRemainingPublicId();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 target["RemainingAncestor"] = Json::Value(Json::objectValue);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 202
diff changeset
213 target["RemainingAncestor"]["Path"] = GetBasePath(type, uuid);
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 433
diff changeset
214 target["RemainingAncestor"]["Type"] = EnumerationToString(type);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 target["RemainingAncestor"]["ID"] = uuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 target["RemainingAncestor"] = Json::nullValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
222 t.Commit(0);
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
223
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
228 static void FlushThread(DatabaseWrapper* db,
220
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
229 boost::mutex* mutex,
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
230 unsigned int sleep)
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
231 {
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
232 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")";
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
233
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
234 while (1)
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
235 {
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
236 boost::this_thread::sleep(boost::posix_time::seconds(sleep));
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
237 boost::mutex::scoped_lock lock(*mutex);
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
238 db->FlushToDisk();
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
239 }
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
240 }
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
241
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
242
433
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
243 static void ComputeExpectedNumberOfInstances(DatabaseWrapper& db,
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
244 int64_t series,
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
245 const DicomMap& dicomSummary)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
246 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
247 const DicomValue* value;
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
248 const DicomValue* value2;
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
249
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
250 try
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
251 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
252 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL &&
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
253 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS)) != NULL)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
254 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
255 // Patch for series with temporal positions thanks to Will Ryder
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
256 int64_t imagesInAcquisition = boost::lexical_cast<int64_t>(value->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
257 int64_t countTemporalPositions = boost::lexical_cast<int64_t>(value2->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
258 std::string expected = boost::lexical_cast<std::string>(imagesInAcquisition * countTemporalPositions);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
259 db.SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, expected);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
260 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
261
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
262 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL &&
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
263 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TIME_SLICES)) != NULL)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
264 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
265 // Support of Cardio-PET images
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
266 int64_t numberOfSlices = boost::lexical_cast<int64_t>(value->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
267 int64_t numberOfTimeSlices = boost::lexical_cast<int64_t>(value2->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
268 std::string expected = boost::lexical_cast<std::string>(numberOfSlices * numberOfTimeSlices);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
269 db.SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, expected);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
270 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
271
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
272 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
273 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
274 db.SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, value->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
275 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
276 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
277 catch (boost::bad_lexical_cast)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
278 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
279 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
280 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
281
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
282
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
283 ServerIndex::ServerIndex(ServerContext& context,
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
284 const std::string& dbPath) :
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
285 maximumStorageSize_(0),
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
286 maximumPatients_(0)
186
f68c039b0571 preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
287 {
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
288 listener_.reset(new Internals::ServerIndexListener(context));
186
f68c039b0571 preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
289
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
290 if (dbPath == ":memory:")
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
291 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
292 db_.reset(new DatabaseWrapper(*listener_));
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
293 }
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
294 else
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
296 boost::filesystem::path p = dbPath;
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
297
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
298 try
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
299 {
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
300 boost::filesystem::create_directories(p);
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
301 }
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
302 catch (boost::filesystem::filesystem_error)
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
303 {
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
304 }
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
305
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
306 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
308
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
309 currentStorageSize_ = db_->GetTotalCompressedSize();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
310
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
311 // Initial recycling if the parameters have changed since the last
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
312 // execution of Orthanc
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
313 StandaloneRecycling();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
314
220
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
315 unsigned int sleep;
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
316 try
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
317 {
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
318 std::string sleepString = db_->GetGlobalProperty(GlobalProperty_FlushSleep);
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
319 sleep = boost::lexical_cast<unsigned int>(sleepString);
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
320 }
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
321 catch (boost::bad_lexical_cast&)
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
322 {
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
323 // By default, wait for 10 seconds before flushing
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
324 sleep = 10;
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
325 }
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
326
bb8c260c0092 fix for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
327 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_, sleep);
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
328 }
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
329
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
330
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
331 ServerIndex::~ServerIndex()
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
332 {
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
333 LOG(INFO) << "Stopping the database flushing thread";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 186
diff changeset
337 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary,
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
338 const Attachments& attachments,
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 186
diff changeset
339 const std::string& remoteAet)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
341 boost::mutex::scoped_lock lock(mutex_);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
342 listener_->Reset();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 147
diff changeset
344 DicomInstanceHasher hasher(dicomSummary);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
348 Transaction t(*this);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
350 // Do nothing if the instance already exists
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
352 ResourceType type;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
353 int64_t tmp;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
354 if (db_->LookupResource(hasher.HashInstance(), tmp, type))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
355 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
356 assert(type == ResourceType_Instance);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
357 return StoreStatus_AlreadyStored;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
358 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
361 // Ensure there is enough room in the storage for the new instance
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
362 uint64_t instanceSize = 0;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
363 for (Attachments::const_iterator it = attachments.begin();
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
364 it != attachments.end(); it++)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
365 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
366 instanceSize += it->GetCompressedSize();
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
367 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
368
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
369 Recycle(instanceSize, hasher.HashPatient());
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
370
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
371 // Create the instance
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
372 int64_t instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
373
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
374 DicomMap dicom;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
375 dicomSummary.ExtractInstanceInformation(dicom);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
376 db_->SetMainDicomTags(instance, dicom);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
377
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
378 // Detect up to which level the patient/study/series/instance
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
379 // hierarchy must be created
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
380 int64_t patient = -1, study = -1, series = -1;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
381 bool isNewPatient = false;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
382 bool isNewStudy = false;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
383 bool isNewSeries = false;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
384
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 {
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
386 ResourceType dummy;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
387
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
388 if (db_->LookupResource(hasher.HashSeries(), series, dummy))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
389 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
390 assert(dummy == ResourceType_Series);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
391 // The patient, the study and the series already exist
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
392
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
393 bool ok = (db_->LookupResource(hasher.HashPatient(), patient, dummy) &&
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
394 db_->LookupResource(hasher.HashStudy(), study, dummy));
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
395 assert(ok);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
396 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
397 else if (db_->LookupResource(hasher.HashStudy(), study, dummy))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
398 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
399 assert(dummy == ResourceType_Study);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
400
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
401 // New series: The patient and the study already exist
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
402 isNewSeries = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
403
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
404 bool ok = db_->LookupResource(hasher.HashPatient(), patient, dummy);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
405 assert(ok);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
406 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
407 else if (db_->LookupResource(hasher.HashPatient(), patient, dummy))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
408 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
409 assert(dummy == ResourceType_Patient);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
410
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
411 // New study and series: The patient already exist
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
412 isNewStudy = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
413 isNewSeries = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
414 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
415 else
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
416 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
417 // New patient, study and series: Nothing exists
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
418 isNewPatient = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
419 isNewStudy = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
420 isNewSeries = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
421 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
422 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
423
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
424 // Create the series if needed
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
425 if (isNewSeries)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
426 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
427 series = db_->CreateResource(hasher.HashSeries(), ResourceType_Series);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
428 dicomSummary.ExtractSeriesInformation(dicom);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
429 db_->SetMainDicomTags(series, dicom);
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
430 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
431
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
432 // Create the study if needed
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
433 if (isNewStudy)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
434 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
435 study = db_->CreateResource(hasher.HashStudy(), ResourceType_Study);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
436 dicomSummary.ExtractStudyInformation(dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
437 db_->SetMainDicomTags(study, dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
438 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
439
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
440 // Create the patient if needed
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
441 if (isNewPatient)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
442 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
443 patient = db_->CreateResource(hasher.HashPatient(), ResourceType_Patient);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
444 dicomSummary.ExtractPatientInformation(dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
445 db_->SetMainDicomTags(patient, dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
446 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
447
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
448 // Create the parent-to-child links
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
449 db_->AttachChild(series, instance);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
450
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
451 if (isNewSeries)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
452 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
453 db_->AttachChild(study, series);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
455
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
456 if (isNewStudy)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
458 db_->AttachChild(patient, study);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
461 // Sanity checks
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
462 assert(patient != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
463 assert(study != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
464 assert(series != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
465 assert(instance != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
466
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
467 // Attach the files to the newly created instance
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
468 for (Attachments::const_iterator it = attachments.begin();
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
469 it != attachments.end(); it++)
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
470 {
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
471 db_->AddAttachment(instance, *it);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
472 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
473
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
474 // Attach the metadata
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
475 std::string now = Toolbox::GetNowIsoString();
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
476 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, now);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
477 db_->SetMetadata(series, MetadataType_LastUpdate, now);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
478 db_->SetMetadata(study, MetadataType_LastUpdate, now);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
479 db_->SetMetadata(patient, MetadataType_LastUpdate, now);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
480
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
481 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
482
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
483 const DicomValue* value;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
484 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL ||
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
485 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
487 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
490 if (isNewSeries)
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
491 {
433
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
492 ComputeExpectedNumberOfInstances(*db_, series, dicomSummary);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
493 }
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
494
205
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
495 // 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
496 SeriesStatus seriesStatus = GetSeriesStatus(series);
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
497 if (seriesStatus == SeriesStatus_Complete)
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
498 {
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
499 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series);
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
500 }
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
501
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
502 t.Commit(instanceSize);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
503
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 return StoreStatus_Success;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
506 catch (OrthancException& e)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
508 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
509 << " (SQLite status: " << db_->GetErrorMessage() << ")";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 return StoreStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
516 void ServerIndex::ComputeStatistics(Json::Value& target)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 {
240
jodogne
parents: 239
diff changeset
518 static const uint64_t MB = 1024 * 1024;
jodogne
parents: 239
diff changeset
519
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
520 boost::mutex::scoped_lock lock(mutex_);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
521 target = Json::objectValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
523 uint64_t cs = currentStorageSize_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
524 assert(cs == db_->GetTotalCompressedSize());
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
525 uint64_t us = db_->GetTotalUncompressedSize();
239
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
526 target["TotalDiskSpace"] = boost::lexical_cast<std::string>(cs);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
527 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us);
240
jodogne
parents: 239
diff changeset
528 target["TotalDiskSpaceMB"] = boost::lexical_cast<unsigned int>(cs / MB);
jodogne
parents: 239
diff changeset
529 target["TotalUncompressedSizeMB"] = boost::lexical_cast<unsigned int>(us / MB);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
530
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
531 target["CountPatients"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Patient));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
532 target["CountStudies"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Study));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
533 target["CountSeries"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Series));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
534 target["CountInstances"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Instance));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
535 }
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
536
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 186
diff changeset
537
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 186
diff changeset
538
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
539 SeriesStatus ServerIndex::GetSeriesStatus(int id)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
540 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
541 // Get the expected number of instances in this series (from the metadata)
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
542 std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
543
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
544 size_t expected;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
545 try
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
546 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
547 expected = boost::lexical_cast<size_t>(s);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
548 if (expected < 0)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
549 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
550 return SeriesStatus_Unknown;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
551 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
552 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
553 catch (boost::bad_lexical_cast&)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
554 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
555 return SeriesStatus_Unknown;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
556 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
557
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
558 // Loop over the instances of this series
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
559 std::list<int64_t> children;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
560 db_->GetChildrenInternalId(children, id);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
561
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
562 std::set<size_t> instances;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
563 for (std::list<int64_t>::const_iterator
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
564 it = children.begin(); it != children.end(); it++)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
565 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
566 // Get the index of this instance in the series
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
567 s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
568 size_t index;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
569 try
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
570 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
571 index = boost::lexical_cast<size_t>(s);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
572 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
573 catch (boost::bad_lexical_cast&)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
574 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
575 return SeriesStatus_Unknown;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
576 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
577
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
578 if (index <= 0 || index > expected)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
579 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
580 // Out-of-range instance index
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
581 return SeriesStatus_Inconsistent;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
582 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
583
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
584 if (instances.find(index) != instances.end())
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
585 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
586 // Twice the same instance index
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
587 return SeriesStatus_Inconsistent;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
588 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
589
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
590 instances.insert(index);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
591 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
592
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
593 if (instances.size() == expected)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
594 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
595 return SeriesStatus_Complete;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
596 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
597 else
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
598 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
599 return SeriesStatus_Missing;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
600 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
601 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
602
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
603
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
604
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
605 void ServerIndex::MainDicomTagsToJson(Json::Value& target,
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
606 int64_t resourceId)
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
607 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
608 DicomMap tags;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
609 db_->GetMainDicomTags(tags, resourceId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
610 target["MainDicomTags"] = Json::objectValue;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
611 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
612 }
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 bool ServerIndex::LookupResource(Json::Value& result,
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
615 const std::string& publicId,
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
616 ResourceType expectedType)
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
617 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
618 result = Json::objectValue;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
619
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
620 boost::mutex::scoped_lock lock(mutex_);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
621
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
622 // Lookup for the requested resource
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
623 int64_t id;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
624 ResourceType type;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
625 if (!db_->LookupResource(publicId, id, type) ||
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
626 type != expectedType)
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
627 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
628 return false;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
629 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
630
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
631 // Find the parent resource (if it exists)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
632 if (type != ResourceType_Patient)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
633 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
634 int64_t parentId;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
635 if (!db_->LookupParent(parentId, id))
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
636 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
637 throw OrthancException(ErrorCode_InternalError);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
638 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
639
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
640 std::string parent = db_->GetPublicId(parentId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
641
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
642 switch (type)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
643 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
644 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
645 result["ParentPatient"] = parent;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
646 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
647
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
648 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
649 result["ParentStudy"] = parent;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
650 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
651
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
652 case ResourceType_Instance:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
653 result["ParentSeries"] = parent;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
654 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
655
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
656 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
657 throw OrthancException(ErrorCode_InternalError);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
658 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
659 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
660
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
661 // List the children resources
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
662 std::list<std::string> children;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
663 db_->GetChildrenPublicId(children, id);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
664
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
665 if (type != ResourceType_Instance)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
666 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
667 Json::Value c = Json::arrayValue;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
668
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
669 for (std::list<std::string>::const_iterator
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
670 it = children.begin(); it != children.end(); it++)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
671 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
672 c.append(*it);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
673 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
674
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
675 switch (type)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
676 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
677 case ResourceType_Patient:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
678 result["Studies"] = c;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
679 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
680
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
681 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
682 result["Series"] = c;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
683 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
684
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
685 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
686 result["Instances"] = c;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
687 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
688
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
689 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
690 throw OrthancException(ErrorCode_InternalError);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
691 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
692 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
693
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
694 // Set the resource type
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
695 switch (type)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
696 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
697 case ResourceType_Patient:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
698 result["Type"] = "Patient";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
699 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
700
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
701 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
702 result["Type"] = "Study";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
703 break;
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
704
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
705 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
706 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
707 result["Type"] = "Series";
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 433
diff changeset
708 result["Status"] = EnumerationToString(GetSeriesStatus(id));
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
709
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
710 int i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
711 if (db_->GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
712 result["ExpectedNumberOfInstances"] = i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
713 else
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
714 result["ExpectedNumberOfInstances"] = Json::nullValue;
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
715
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
716 break;
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
717 }
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
718
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
719 case ResourceType_Instance:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
720 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
721 result["Type"] = "Instance";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
722
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
723 FileInfo attachment;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
724 if (!db_->LookupAttachment(attachment, id, FileContentType_Dicom))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
725 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
726 throw OrthancException(ErrorCode_InternalError);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
727 }
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
728
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
729 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize());
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
730 result["FileUuid"] = attachment.GetUuid();
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
731
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
732 int i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
733 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
734 result["IndexInSeries"] = i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
735 else
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
736 result["IndexInSeries"] = Json::nullValue;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
737
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
738 break;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
739 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
740
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
741 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
742 throw OrthancException(ErrorCode_InternalError);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
743 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
744
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
745 // Record the remaining information
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
746 result["ID"] = publicId;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
747 MainDicomTagsToJson(result, id);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
748
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
749 std::string tmp;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
750
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
751 tmp = db_->GetMetadata(id, MetadataType_AnonymizedFrom);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
752 if (tmp.size() != 0)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
753 result["AnonymizedFrom"] = tmp;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
754
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
755 tmp = db_->GetMetadata(id, MetadataType_ModifiedFrom);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
756 if (tmp.size() != 0)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
757 result["ModifiedFrom"] = tmp;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
758
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
759 return true;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
760 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
761
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
763 bool ServerIndex::LookupAttachment(FileInfo& attachment,
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
764 const std::string& instanceUuid,
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
765 FileContentType contentType)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
767 boost::mutex::scoped_lock lock(mutex_);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
769 int64_t id;
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
770 ResourceType type;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
771 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
772 type != ResourceType_Instance)
192
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
773 {
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
774 throw OrthancException(ErrorCode_InternalError);
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
775 }
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
776
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
777 if (db_->LookupAttachment(attachment, id, contentType))
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
778 {
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
779 assert(attachment.GetContentType() == contentType);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
780 return true;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
781 }
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
782 else
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
783 {
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
784 return false;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
785 }
192
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
786 }
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
787
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
788
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
789
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 void ServerIndex::GetAllUuids(Json::Value& target,
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
791 ResourceType resourceType)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
793 boost::mutex::scoped_lock lock(mutex_);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
794 db_->GetAllPublicIds(target, resourceType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 bool ServerIndex::GetChanges(Json::Value& target,
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 202
diff changeset
799 int64_t since,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 unsigned int maxResults)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
802 boost::mutex::scoped_lock lock(mutex_);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
803 db_->GetChanges(target, since, maxResults);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
804 return true;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
805 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
807 bool ServerIndex::GetLastChange(Json::Value& target)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
808 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
809 boost::mutex::scoped_lock lock(mutex_);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
810 db_->GetLastChange(target);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 202
diff changeset
811 return true;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 }
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
813
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
814 void ServerIndex::LogExportedResource(const std::string& publicId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
815 const std::string& remoteModality)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
816 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
817 boost::mutex::scoped_lock lock(mutex_);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
818
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
819 int64_t id;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
820 ResourceType type;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
821 if (!db_->LookupResource(publicId, id, type))
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
822 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
823 throw OrthancException(ErrorCode_InternalError);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
824 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
825
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
826 std::string patientId;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
827 std::string studyInstanceUid;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
828 std::string seriesInstanceUid;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
829 std::string sopInstanceUid;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
830
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
831 int64_t currentId = id;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
832 ResourceType currentType = type;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
833
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
834 // Iteratively go up inside the patient/study/series/instance hierarchy
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
835 bool done = false;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
836 while (!done)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
837 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
838 DicomMap map;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
839 db_->GetMainDicomTags(map, currentId);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
840
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
841 switch (currentType)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
842 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
843 case ResourceType_Patient:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
844 patientId = map.GetValue(DICOM_TAG_PATIENT_ID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
845 done = true;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
846 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
847
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
848 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
849 studyInstanceUid = map.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
850 currentType = ResourceType_Patient;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
851 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
852
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
853 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
854 seriesInstanceUid = map.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
855 currentType = ResourceType_Study;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
856 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
857
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
858 case ResourceType_Instance:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
859 sopInstanceUid = map.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
860 currentType = ResourceType_Series;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
861 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
862
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
863 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
864 throw OrthancException(ErrorCode_InternalError);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
865 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
866
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
867 // If we have not reached the Patient level, find the parent of
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
868 // the current resource
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
869 if (!done)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
870 {
375
d1ea72f1c967 major fix of storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
871 bool ok = db_->LookupParent(currentId, currentId);
d1ea72f1c967 major fix of storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
872 assert(ok);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
873 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
874 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
875
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
876 // No need for a SQLite::Transaction here, as we only insert 1 record
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
877 db_->LogExportedResource(type,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
878 publicId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
879 remoteModality,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
880 patientId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
881 studyInstanceUid,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
882 seriesInstanceUid,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
883 sopInstanceUid);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
884 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
885
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
886
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
887 bool ServerIndex::GetExportedResources(Json::Value& target,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
888 int64_t since,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
889 unsigned int maxResults)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
890 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
891 boost::mutex::scoped_lock lock(mutex_);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
892 db_->GetExportedResources(target, since, maxResults);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
893 return true;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
894 }
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
895
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
896 bool ServerIndex::GetLastExportedResource(Json::Value& target)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
897 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
898 boost::mutex::scoped_lock lock(mutex_);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
899 db_->GetLastExportedResource(target);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
900 return true;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
901 }
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
902
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
903
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
904 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
905 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
906 if (maximumStorageSize_ != 0)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
907 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
908 uint64_t currentSize = currentStorageSize_ - listener_->GetSizeOfFilesToRemove();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
909 assert(db_->GetTotalCompressedSize() == currentSize);
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
910
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
911 if (currentSize + instanceSize > maximumStorageSize_)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
912 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
913 return true;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
914 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
915 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
916
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
917 if (maximumPatients_ != 0)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
918 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
919 uint64_t patientCount = db_->GetResourceCount(ResourceType_Patient);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
920 if (patientCount > maximumPatients_)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
921 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
922 return true;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
923 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
924 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
925
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
926 return false;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
927 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
928
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
929
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
930 void ServerIndex::Recycle(uint64_t instanceSize,
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
931 const std::string& newPatientId)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
932 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
933 if (!IsRecyclingNeeded(instanceSize))
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
934 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
935 return;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
936 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
937
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
938 // Check whether other DICOM instances from this patient are
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
939 // already stored
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
940 int64_t patientToAvoid;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
941 ResourceType type;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
942 bool hasPatientToAvoid = db_->LookupResource(newPatientId, patientToAvoid, type);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
943
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
944 if (hasPatientToAvoid && type != ResourceType_Patient)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
945 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
946 throw OrthancException(ErrorCode_InternalError);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
947 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
948
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
949 // Iteratively select patient to remove until there is enough
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
950 // space in the DICOM store
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
951 int64_t patientToRecycle;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
952 while (true)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
953 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
954 // If other instances of this patient are already in the store,
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
955 // we must avoid to recycle them
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
956 bool ok = hasPatientToAvoid ?
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
957 db_->SelectPatientToRecycle(patientToRecycle, patientToAvoid) :
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
958 db_->SelectPatientToRecycle(patientToRecycle);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
959
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
960 if (!ok)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
961 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
962 throw OrthancException(ErrorCode_FullStorage);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
963 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
964
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
965 LOG(INFO) << "Recycling one patient";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
966 db_->DeleteResource(patientToRecycle);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
967
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
968 if (!IsRecyclingNeeded(instanceSize))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
969 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
970 // OK, we're done
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
971 break;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
972 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
973 }
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
974 }
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
975
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
976 void ServerIndex::SetMaximumPatientCount(unsigned int count)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
977 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
978 boost::mutex::scoped_lock lock(mutex_);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
979 maximumPatients_ = count;
270
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
980
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
981 if (count == 0)
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
982 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
983 LOG(WARNING) << "No limit on the number of stored patients";
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
984 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
985 else
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
986 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
987 LOG(WARNING) << "At most " << count << " patients will be stored";
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
988 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
989
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
990 StandaloneRecycling();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
991 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
992
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
993 void ServerIndex::SetMaximumStorageSize(uint64_t size)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
994 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
995 boost::mutex::scoped_lock lock(mutex_);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
996 maximumStorageSize_ = size;
270
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
997
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
998 if (size == 0)
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
999 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1000 LOG(WARNING) << "No limit on the size of the storage area";
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1001 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1002 else
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1003 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1004 LOG(WARNING) << "At most " << (size / (1024 * 1024)) << "MB will be used for the storage area";
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1005 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1006
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1007 StandaloneRecycling();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1008 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1009
272
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1010 void ServerIndex::StandaloneRecycling()
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1011 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1012 // WARNING: No mutex here, do not include this as a public method
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
1013 Transaction t(*this);
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1014 Recycle(0, "");
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
1015 t.Commit(0);
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1016 }
272
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1017
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1018
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1019 bool ServerIndex::IsProtectedPatient(const std::string& publicId)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1020 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1021 boost::mutex::scoped_lock lock(mutex_);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1022
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1023 // Lookup for the requested resource
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1024 int64_t id;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1025 ResourceType type;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1026 if (!db_->LookupResource(publicId, id, type) ||
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1027 type != ResourceType_Patient)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1028 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1029 throw OrthancException(ErrorCode_ParameterOutOfRange);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1030 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1031
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1032 return db_->IsProtectedPatient(id);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1033 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1034
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1035
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1036 void ServerIndex::SetProtectedPatient(const std::string& publicId,
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1037 bool isProtected)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1038 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1039 boost::mutex::scoped_lock lock(mutex_);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1040
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1041 // Lookup for the requested resource
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1042 int64_t id;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1043 ResourceType type;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1044 if (!db_->LookupResource(publicId, id, type) ||
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1045 type != ResourceType_Patient)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1046 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1047 throw OrthancException(ErrorCode_ParameterOutOfRange);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1048 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1049
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1050 // No need for a SQLite::Transaction here, as we only make 1 write to the DB
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1051 db_->SetProtectedPatient(id, isProtected);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1052
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1053 if (isProtected)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1054 LOG(INFO) << "Patient " << publicId << " has been protected";
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1055 else
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1056 LOG(INFO) << "Patient " << publicId << " has been unprotected";
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1057 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1058
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1059
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1060 void ServerIndex::GetChildInstances(std::list<std::string>& result,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1061 const std::string& publicId)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1062 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1063 result.clear();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1064
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1065 boost::mutex::scoped_lock lock(mutex_);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1066
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1067 ResourceType type;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1068 int64_t top;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1069 if (!db_->LookupResource(publicId, top, type))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1070 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1071 throw OrthancException(ErrorCode_UnknownResource);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1072 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1073
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1074 if (type == ResourceType_Instance)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1075 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1076 // The resource is already an instance: Do not go down the hierarchy
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1077 result.push_back(publicId);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1078 return;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1079 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1080
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1081 std::stack<int64_t> toExplore;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1082 toExplore.push(top);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1083
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1084 std::list<int64_t> tmp;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1085
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1086 while (!toExplore.empty())
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1087 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1088 // Get the internal ID of the current resource
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1089 int64_t resource = toExplore.top();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1090 toExplore.pop();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1091
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1092 if (db_->GetResourceType(resource) == ResourceType_Instance)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1093 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1094 result.push_back(db_->GetPublicId(resource));
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1095 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1096 else
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1097 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1098 // Tag all the children of this resource as to be explored
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1099 db_->GetChildrenInternalId(tmp, resource);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1100 for (std::list<int64_t>::const_iterator
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1101 it = tmp.begin(); it != tmp.end(); it++)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1102 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1103 toExplore.push(*it);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1104 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1105 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1106 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1107 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1108
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1109
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1110 void ServerIndex::SetMetadata(const std::string& publicId,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1111 MetadataType type,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1112 const std::string& value)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1113 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1114 boost::mutex::scoped_lock lock(mutex_);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1115
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1116 ResourceType rtype;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1117 int64_t id;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1118 if (!db_->LookupResource(publicId, id, rtype))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1119 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1120 throw OrthancException(ErrorCode_UnknownResource);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1121 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1122
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1123 db_->SetMetadata(id, type, value);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1124 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1125
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1126 bool ServerIndex::LookupMetadata(std::string& target,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1127 const std::string& publicId,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1128 MetadataType type)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1129 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1130 boost::mutex::scoped_lock lock(mutex_);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1131
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1132 ResourceType rtype;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1133 int64_t id;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1134 if (!db_->LookupResource(publicId, id, rtype))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1135 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1136 throw OrthancException(ErrorCode_UnknownResource);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1137 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1138
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1139 return db_->LookupMetadata(target, id, type);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1140 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1141
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1142
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1143 bool ServerIndex::ListAvailableMetadata(std::list<MetadataType>& target,
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1144 const std::string& publicId)
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1145 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1146 boost::mutex::scoped_lock lock(mutex_);
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1147
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1148 ResourceType rtype;
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1149 int64_t id;
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1150 if (!db_->LookupResource(publicId, id, rtype))
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1151 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1152 throw OrthancException(ErrorCode_UnknownResource);
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1153 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1154
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1155 return db_->ListAvailableMetadata(target, id);
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1156 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1157
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1158
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1159 bool ServerIndex::LookupParent(std::string& target,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1160 const std::string& publicId)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1161 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1162 boost::mutex::scoped_lock lock(mutex_);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1163
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1164 ResourceType type;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1165 int64_t id;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1166 if (!db_->LookupResource(publicId, id, type))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1167 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1168 throw OrthancException(ErrorCode_UnknownResource);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1169 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1170
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1171 int64_t parentId;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1172 if (db_->LookupParent(parentId, id))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1173 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1174 target = db_->GetPublicId(parentId);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1175 return true;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1176 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1177 else
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1178 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1179 return false;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1180 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1181 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1182
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1183
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1184 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1185 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1186 boost::mutex::scoped_lock lock(mutex_);
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1187
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1188 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction());
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1189
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1190 transaction->Begin();
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1191 uint64_t seq = db_->IncrementGlobalSequence(sequence);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1192 transaction->Commit();
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1193
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1194 return seq;
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1195 }
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1196
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1197
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1198
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1199 void ServerIndex::LogChange(ChangeType changeType,
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1200 const std::string& publicId)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1201 {
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1202 boost::mutex::scoped_lock lock(mutex_);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1203 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction());
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1204 transaction->Begin();
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1205
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1206 int64_t id;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1207 ResourceType type;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1208 if (!db_->LookupResource(publicId, id, type))
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1209 {
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1210 throw OrthancException(ErrorCode_UnknownResource);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1211 }
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1212
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1213 db_->LogChange(changeType, id, type);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1214
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1215 transaction->Commit();
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1216 }
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1217
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1218
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1219 void ServerIndex::DeleteChanges()
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1220 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1221 boost::mutex::scoped_lock lock(mutex_);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1222 db_->ClearTable("Changes");
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1223 }
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1224
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1225 void ServerIndex::DeleteExportedResources()
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1226 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1227 boost::mutex::scoped_lock lock(mutex_);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1228 db_->ClearTable("ExportedResources");
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1229 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 }