annotate OrthancServer/ServerIndex.cpp @ 1102:ce6386b37afd

avoid unnecessary exceptions on Orthanc startup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Aug 2014 10:51:35 +0200
parents 649d47854314
children ba5c0908600c
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
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
3 * Copyright (C) 2012-2014 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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "PrecompiledHeadersServer.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ServerIndex.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
36 #ifndef NOMINMAX
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
37 #define NOMINMAX
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
38 #endif
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
39
8
3a584803783e build with visual studio
jodogne
parents: 6
diff changeset
40 #include "EmbeddedResources.h"
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
41 #include "OrthancInitialization.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include "../Core/Toolbox.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include "../Core/Uuid.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include "../Core/DicomFormat/DicomArray.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include "../Core/SQLite/Transaction.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #include "FromDcmtkBridge.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
47 #include "ServerContext.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 #include <stdio.h>
108
a6e41de88a53 using glog
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 84
diff changeset
51 #include <glog/logging.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
53 static const uint64_t MEGA_BYTES = 1024 * 1024;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
54
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
55 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 namespace Internals
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
59 class ServerIndexListener : public IServerIndexListener
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
60 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
61 private:
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
62 ServerContext& context_;
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
63 bool hasRemainingLevel_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
64 ResourceType remainingType_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
65 std::string remainingPublicId_;
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
66 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
67 uint64_t sizeOfFilesToRemove_;
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
68
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
69 public:
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
70 ServerIndexListener(ServerContext& context) :
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
71 context_(context)
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
72 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
73 Reset();
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
74 assert(ResourceType_Patient < ResourceType_Study &&
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
75 ResourceType_Study < ResourceType_Series &&
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
76 ResourceType_Series < ResourceType_Instance);
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
77 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
78
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
79 void Reset()
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
80 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
81 sizeOfFilesToRemove_ = 0;
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
82 hasRemainingLevel_ = false;
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
83 pendingFilesToRemove_.clear();
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
84 }
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
85
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
86 uint64_t GetSizeOfFilesToRemove()
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
87 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
88 return sizeOfFilesToRemove_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
89 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
90
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
91 void CommitFilesToRemove()
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 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
94 it = pendingFilesToRemove_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
95 it != pendingFilesToRemove_.end(); ++it)
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
96 {
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
97 context_.RemoveFile(*it);
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
98 }
201
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
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
101 virtual void SignalRemainingAncestor(ResourceType parentType,
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
102 const std::string& publicId)
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 LOG(INFO) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")";
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 if (hasRemainingLevel_)
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
107 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
108 if (parentType < remainingType_)
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 remainingType_ = parentType;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
111 remainingPublicId_ = publicId;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
112 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
113 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
114 else
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 hasRemainingLevel_ = true;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
117 remainingType_ = parentType;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
118 remainingPublicId_ = publicId;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
119 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
120 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
121
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
122 virtual void SignalFileDeleted(const FileInfo& info)
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
123 {
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
124 assert(Toolbox::IsUuid(info.GetUuid()));
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 272
diff changeset
125 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
126 sizeOfFilesToRemove_ += info.GetCompressedSize();
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
127 }
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 bool HasRemainingLevel() const
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
130 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
131 return hasRemainingLevel_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
132 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
133
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
134 ResourceType GetRemainingType() const
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 assert(HasRemainingLevel());
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
137 return remainingType_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
138 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
139
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
140 const std::string& GetRemainingPublicId() const
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
141 {
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
142 assert(HasRemainingLevel());
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
143 return remainingPublicId_;
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
144 }
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
145 };
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
149 class ServerIndex::Transaction
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
150 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
151 private:
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
152 ServerIndex& index_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
153 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
154 bool isCommitted_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
155
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
156 public:
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
157 Transaction(ServerIndex& index) :
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
158 index_(index),
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
159 isCommitted_(false)
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
160 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
161 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
162
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
163 index_.listener_->Reset();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
164 transaction_.reset(index_.db_->StartTransaction());
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
165 transaction_->Begin();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
166 }
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 void Commit(uint64_t sizeOfAddedFiles)
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 if (!isCommitted_)
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
171 {
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
172 transaction_->Commit();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
173
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
174 // 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
175 // 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
176 // deleted because of recycling.
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
177 index_.listener_->CommitFilesToRemove();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
178
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
179 index_.currentStorageSize_ += sizeOfAddedFiles;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
180
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
181 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
182 index_.currentStorageSize_ -= index_.listener_->GetSizeOfFilesToRemove();
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 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
185
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
186 isCommitted_ = true;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
187 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
188 }
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
189 };
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
190
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
191
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
192 struct ServerIndex::UnstableResourcePayload
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
193 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
194 Orthanc::ResourceType type_;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
195 boost::posix_time::ptime time_;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
196
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
197 UnstableResourcePayload() : type_(Orthanc::ResourceType_Instance)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
198 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
199 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
200
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
201 UnstableResourcePayload(Orthanc::ResourceType type) : type_(type)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
202 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
203 time_ = boost::posix_time::second_clock::local_time();
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
204 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
205
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
206 unsigned int GetAge() const
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
207 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
208 return (boost::posix_time::second_clock::local_time() - time_).total_seconds();
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
209 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
210 };
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
211
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
212
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
213 bool ServerIndex::DeleteResource(Json::Value& target,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 const std::string& uuid,
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
215 ResourceType expectedType)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
217 boost::mutex::scoped_lock lock(mutex_);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
218 listener_->Reset();
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
219
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
220 Transaction t(*this);
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
221
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
222 int64_t id;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
223 ResourceType type;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
224 if (!db_->LookupResource(uuid, id, type) ||
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
225 expectedType != type)
0
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 return false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
229
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
230 db_->DeleteResource(id);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
232 if (listener_->HasRemainingLevel())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
234 ResourceType type = listener_->GetRemainingType();
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
235 const std::string& uuid = listener_->GetRemainingPublicId();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 target["RemainingAncestor"] = Json::Value(Json::objectValue);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 202
diff changeset
238 target["RemainingAncestor"]["Path"] = GetBasePath(type, uuid);
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 433
diff changeset
239 target["RemainingAncestor"]["Type"] = EnumerationToString(type);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 target["RemainingAncestor"]["ID"] = uuid;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 target["RemainingAncestor"] = Json::nullValue;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
247 t.Commit(0);
264
5b8e8b74bc8b remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 240
diff changeset
248
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 return true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
253 void ServerIndex::FlushThread(ServerIndex* that)
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
254 {
1102
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
255 // By default, wait for 10 seconds before flushing
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
256 unsigned int sleep = 10;
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
257
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
258 try
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
259 {
744
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
260 boost::mutex::scoped_lock lock(that->mutex_);
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
261 std::string sleepString = that->db_->GetGlobalProperty(GlobalProperty_FlushSleep);
1102
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
262
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
263 if (Toolbox::IsInteger(sleepString))
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
264 {
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
265 sleep = boost::lexical_cast<unsigned int>(sleepString);
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
266 }
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
267 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
268 catch (boost::bad_lexical_cast&)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
269 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
270 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
271
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
272 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")";
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
273
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
274 unsigned int count = 0;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
275
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
276 while (!that->done_)
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
277 {
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
278 boost::this_thread::sleep(boost::posix_time::seconds(1));
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
279 count++;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
280 if (count < sleep)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
281 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
282 continue;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
283 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
284
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
285 boost::mutex::scoped_lock lock(that->mutex_);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
286 that->db_->FlushToDisk();
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
287 count = 0;
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
288 }
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
289
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
290 LOG(INFO) << "Stopping the database flushing thread";
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
291 }
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
292
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
293
433
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
294 static void ComputeExpectedNumberOfInstances(DatabaseWrapper& db,
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
295 int64_t series,
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
296 const DicomMap& dicomSummary)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
297 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
298 try
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
299 {
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
300 const DicomValue* value;
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
301 const DicomValue* value2;
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
302
433
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
303 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL &&
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
304 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS)) != NULL)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
305 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
306 // Patch for series with temporal positions thanks to Will Ryder
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
307 int64_t imagesInAcquisition = boost::lexical_cast<int64_t>(value->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
308 int64_t countTemporalPositions = boost::lexical_cast<int64_t>(value2->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
309 std::string expected = boost::lexical_cast<std::string>(imagesInAcquisition * countTemporalPositions);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
310 db.SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, expected);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
311 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
312
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
313 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL &&
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
314 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TIME_SLICES)) != NULL)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
315 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
316 // Support of Cardio-PET images
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
317 int64_t numberOfSlices = boost::lexical_cast<int64_t>(value->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
318 int64_t numberOfTimeSlices = boost::lexical_cast<int64_t>(value2->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
319 std::string expected = boost::lexical_cast<std::string>(numberOfSlices * numberOfTimeSlices);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
320 db.SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, expected);
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
321 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
322
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
323 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
324 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
325 db.SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, value->AsString());
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
326 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
327 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
328 catch (boost::bad_lexical_cast)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
329 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
330 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
331 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
332
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
333
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
334 ServerIndex::ServerIndex(ServerContext& context,
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
335 const std::string& dbPath) :
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
336 done_(false),
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
337 maximumStorageSize_(0),
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
338 maximumPatients_(0)
186
f68c039b0571 preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
339 {
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
340 listener_.reset(new Internals::ServerIndexListener(context));
186
f68c039b0571 preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 180
diff changeset
341
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
342 if (dbPath == ":memory:")
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
343 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
344 db_.reset(new DatabaseWrapper(*listener_));
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
345 }
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
346 else
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
348 boost::filesystem::path p = dbPath;
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
349
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
350 try
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
351 {
201
bee20e978835 refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
352 boost::filesystem::create_directories(p);
180
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
353 }
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
354 catch (boost::filesystem::filesystem_error)
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
355 {
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
356 }
626777d01dc4 use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 179
diff changeset
357
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
358 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
360
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
361 currentStorageSize_ = db_->GetTotalCompressedSize();
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
362
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
363 // 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
364 // execution of Orthanc
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
365 StandaloneRecycling();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
366
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
367 flushThread_ = boost::thread(FlushThread, this);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
368 unstableResourcesMonitorThread_ = boost::thread(UnstableResourcesMonitorThread, this);
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
369 }
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
370
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
371
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
372 ServerIndex::~ServerIndex()
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
373 {
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
374 done_ = true;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
375
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
376 if (flushThread_.joinable())
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
377 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
378 flushThread_.join();
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
379 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
380
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
381 if (unstableResourcesMonitorThread_.joinable())
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
382 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
383 unstableResourcesMonitorThread_.join();
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
384 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
388 StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata,
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
389 const DicomMap& dicomSummary,
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
390 const Attachments& attachments,
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
391 const std::string& remoteAet,
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
392 const MetadataMap& metadata)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
394 boost::mutex::scoped_lock lock(mutex_);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
395 listener_->Reset();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
397 instanceMetadata.clear();
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
398
178
5739b4d10a4b hashing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 147
diff changeset
399 DicomInstanceHasher hasher(dicomSummary);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
403 Transaction t(*this);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
405 // Do nothing if the instance already exists
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
407 ResourceType type;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
408 int64_t tmp;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
409 if (db_->LookupResource(hasher.HashInstance(), tmp, type))
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 assert(type == ResourceType_Instance);
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
412 db_->GetAllMetadata(instanceMetadata, tmp);
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
413 return StoreStatus_AlreadyStored;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
414 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
417 // 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
418 uint64_t instanceSize = 0;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
419 for (Attachments::const_iterator it = attachments.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
420 it != attachments.end(); ++it)
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
421 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
422 instanceSize += it->GetCompressedSize();
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
423 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
424
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
425 Recycle(instanceSize, hasher.HashPatient());
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
426
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
427 // Create the instance
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
428 int64_t instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
429
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
430 DicomMap dicom;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
431 dicomSummary.ExtractInstanceInformation(dicom);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
432 db_->SetMainDicomTags(instance, dicom);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
433
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
434 // Detect up to which level the patient/study/series/instance
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
435 // hierarchy must be created
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
436 int64_t patient = -1, study = -1, series = -1;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
437 bool isNewPatient = false;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
438 bool isNewStudy = false;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
439 bool isNewSeries = false;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
440
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 {
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
442 ResourceType dummy;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
443
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
444 if (db_->LookupResource(hasher.HashSeries(), series, dummy))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
445 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
446 assert(dummy == ResourceType_Series);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
447 // The patient, the study and the series already exist
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
448
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
449 bool ok = (db_->LookupResource(hasher.HashPatient(), patient, dummy) &&
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
450 db_->LookupResource(hasher.HashStudy(), study, dummy));
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
451 assert(ok);
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 else if (db_->LookupResource(hasher.HashStudy(), study, dummy))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
454 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
455 assert(dummy == ResourceType_Study);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
456
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
457 // New series: The patient and the study already exist
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
458 isNewSeries = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
459
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
460 bool ok = db_->LookupResource(hasher.HashPatient(), patient, dummy);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
461 assert(ok);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
462 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
463 else if (db_->LookupResource(hasher.HashPatient(), patient, dummy))
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
464 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
465 assert(dummy == ResourceType_Patient);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
466
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
467 // New study and series: The patient already exist
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
468 isNewStudy = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
469 isNewSeries = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
470 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
471 else
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
472 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
473 // New patient, study and series: Nothing exists
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
474 isNewPatient = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
475 isNewStudy = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
476 isNewSeries = true;
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
477 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
478 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
479
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
480 // Create the series if needed
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
481 if (isNewSeries)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
482 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
483 series = db_->CreateResource(hasher.HashSeries(), ResourceType_Series);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
484 dicomSummary.ExtractSeriesInformation(dicom);
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
485 db_->SetMainDicomTags(series, dicom);
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
486 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
487
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
488 // Create the study if needed
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
489 if (isNewStudy)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
490 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
491 study = db_->CreateResource(hasher.HashStudy(), ResourceType_Study);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
492 dicomSummary.ExtractStudyInformation(dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
493 db_->SetMainDicomTags(study, dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
494 }
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
495
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
496 // Create the patient if needed
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
497 if (isNewPatient)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
498 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
499 patient = db_->CreateResource(hasher.HashPatient(), ResourceType_Patient);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
500 dicomSummary.ExtractPatientInformation(dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
501 db_->SetMainDicomTags(patient, dicom);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
502 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
503
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
504 // Create the parent-to-child links
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
505 db_->AttachChild(series, instance);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
506
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
507 if (isNewSeries)
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
508 {
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
509 db_->AttachChild(study, series);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
511
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
512 if (isNewStudy)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
514 db_->AttachChild(patient, study);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
517 // Sanity checks
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
518 assert(patient != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
519 assert(study != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
520 assert(series != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
521 assert(instance != -1);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
522
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
523 // Attach the files to the newly created instance
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
524 for (Attachments::const_iterator it = attachments.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
525 it != attachments.end(); ++it)
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
526 {
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
527 db_->AddAttachment(instance, *it);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
528 }
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
529
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
530 // Attach the user-specified metadata
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
531 for (MetadataMap::const_iterator
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
532 it = metadata.begin(); it != metadata.end(); ++it)
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
533 {
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
534 switch (it->first.first)
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
535 {
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
536 case ResourceType_Patient:
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
537 db_->SetMetadata(patient, it->first.second, it->second);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
538 break;
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
539
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
540 case ResourceType_Study:
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
541 db_->SetMetadata(study, it->first.second, it->second);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
542 break;
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
543
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
544 case ResourceType_Series:
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
545 db_->SetMetadata(series, it->first.second, it->second);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
546 break;
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
547
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
548 case ResourceType_Instance:
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
549 db_->SetMetadata(instance, it->first.second, it->second);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
550 instanceMetadata[it->first.second] = it->second;
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
551 break;
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
552
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
553 default:
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
554 throw OrthancException(ErrorCode_ParameterOutOfRange);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
555 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
556 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
557
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
558 // Attach the auto-computed metadata for the patient/study/series levels
432
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
559 std::string now = Toolbox::GetNowIsoString();
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
560 db_->SetMetadata(series, MetadataType_LastUpdate, now);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
561 db_->SetMetadata(study, MetadataType_LastUpdate, now);
2b09d4ee86c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
562 db_->SetMetadata(patient, MetadataType_LastUpdate, now);
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
563
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
564 // Attach the auto-computed metadata for the instance level,
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
565 // reflecting these additions into the input metadata map
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
566 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, now);
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
567 instanceMetadata[MetadataType_Instance_ReceptionDate] = now;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
568
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
569 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
570 instanceMetadata[MetadataType_Instance_RemoteAet] = remoteAet;
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
571
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
572 const DicomValue* value;
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
573 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL ||
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
574 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 {
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
576 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString());
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1004
diff changeset
577 instanceMetadata[MetadataType_Instance_IndexInSeries] = value->AsString();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
580 // Check whether the series of this new instance is now completed
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
581 if (isNewSeries)
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
582 {
433
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
583 ComputeExpectedNumberOfInstances(*db_, series, dicomSummary);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
584 }
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
585
205
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
586 SeriesStatus seriesStatus = GetSeriesStatus(series);
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
587 if (seriesStatus == SeriesStatus_Complete)
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
588 {
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
589 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series);
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
590 }
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
591
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
592 // Mark the parent resources of this instance as unstable
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
593 MarkAsUnstable(patient, ResourceType_Patient);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
594 MarkAsUnstable(study, ResourceType_Study);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
595 MarkAsUnstable(series, ResourceType_Series);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
596
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
597 t.Commit(instanceSize);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
598
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 return StoreStatus_Success;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 }
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
601 catch (OrthancException& e)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 {
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
603 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
604 << " (SQLite status: " << db_->GetErrorMessage() << ")";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 return StoreStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
611 void ServerIndex::ComputeStatistics(Json::Value& target)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
613 boost::mutex::scoped_lock lock(mutex_);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
614 target = Json::objectValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
616 uint64_t cs = currentStorageSize_;
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
617 assert(cs == db_->GetTotalCompressedSize());
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
618 uint64_t us = db_->GetTotalUncompressedSize();
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
619 target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
620 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us);
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
621 target["TotalDiskSizeMB"] = boost::lexical_cast<unsigned int>(cs / MEGA_BYTES);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
622 target["TotalUncompressedSizeMB"] = boost::lexical_cast<unsigned int>(us / MEGA_BYTES);
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
623
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
624 target["CountPatients"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Patient));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
625 target["CountStudies"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Study));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
626 target["CountSeries"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Series));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
627 target["CountInstances"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Instance));
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
628 }
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
629
187
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 186
diff changeset
630
8e673a65564d refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 186
diff changeset
631
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
632 SeriesStatus ServerIndex::GetSeriesStatus(int64_t id)
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
633 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
634 // 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
635 std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
636
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
637 size_t expected;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
638 try
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
639 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
640 expected = boost::lexical_cast<size_t>(s);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
641 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
642 catch (boost::bad_lexical_cast&)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
643 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
644 return SeriesStatus_Unknown;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
645 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
646
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
647 // Loop over the instances of this series
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
648 std::list<int64_t> children;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
649 db_->GetChildrenInternalId(children, id);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
650
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
651 std::set<size_t> instances;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
652 for (std::list<int64_t>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
653 it = children.begin(); it != children.end(); ++it)
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
654 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
655 // Get the index of this instance in the series
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
656 s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
657 size_t index;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
658 try
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
659 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
660 index = boost::lexical_cast<size_t>(s);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
661 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
662 catch (boost::bad_lexical_cast&)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
663 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
664 return SeriesStatus_Unknown;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
665 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
666
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
667 if (!(index > 0 && index <= expected))
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
668 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
669 // Out-of-range instance index
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
670 return SeriesStatus_Inconsistent;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
671 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
672
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
673 if (instances.find(index) != instances.end())
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
674 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
675 // Twice the same instance index
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
676 return SeriesStatus_Inconsistent;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
677 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
678
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
679 instances.insert(index);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
680 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
681
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
682 if (instances.size() == expected)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
683 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
684 return SeriesStatus_Complete;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
685 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
686 else
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
687 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
688 return SeriesStatus_Missing;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
689 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
690 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
691
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
692
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
693
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
694 void ServerIndex::MainDicomTagsToJson(Json::Value& target,
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
695 int64_t resourceId)
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
696 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
697 DicomMap tags;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
698 db_->GetMainDicomTags(tags, resourceId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
699 target["MainDicomTags"] = Json::objectValue;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
700 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
701 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
702
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
703 bool ServerIndex::LookupResource(Json::Value& result,
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
704 const std::string& publicId,
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
705 ResourceType expectedType)
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
706 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
707 result = Json::objectValue;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
708
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
709 boost::mutex::scoped_lock lock(mutex_);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
710
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
711 // Lookup for the requested resource
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
712 int64_t id;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
713 ResourceType type;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
714 if (!db_->LookupResource(publicId, id, type) ||
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
715 type != expectedType)
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
716 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
717 return false;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
718 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
719
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
720 // Find the parent resource (if it exists)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
721 if (type != ResourceType_Patient)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
722 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
723 int64_t parentId;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
724 if (!db_->LookupParent(parentId, id))
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
725 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
726 throw OrthancException(ErrorCode_InternalError);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
727 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
728
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
729 std::string parent = db_->GetPublicId(parentId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
730
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
731 switch (type)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
732 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
733 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
734 result["ParentPatient"] = parent;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
735 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
736
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
737 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
738 result["ParentStudy"] = parent;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
739 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
740
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
741 case ResourceType_Instance:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
742 result["ParentSeries"] = parent;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
743 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
744
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
745 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
746 throw OrthancException(ErrorCode_InternalError);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
747 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
748 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
749
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
750 // List the children resources
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
751 std::list<std::string> children;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
752 db_->GetChildrenPublicId(children, id);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
753
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
754 if (type != ResourceType_Instance)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
755 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
756 Json::Value c = Json::arrayValue;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
757
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
758 for (std::list<std::string>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
759 it = children.begin(); it != children.end(); ++it)
198
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 c.append(*it);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
762 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
763
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
764 switch (type)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
765 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
766 case ResourceType_Patient:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
767 result["Studies"] = c;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
768 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
769
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
770 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
771 result["Series"] = c;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
772 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
773
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
774 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
775 result["Instances"] = c;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
776 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
777
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
778 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
779 throw OrthancException(ErrorCode_InternalError);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
780 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
781 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
782
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
783 // Set the resource type
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
784 switch (type)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
785 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
786 case ResourceType_Patient:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
787 result["Type"] = "Patient";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
788 break;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
789
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
790 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
791 result["Type"] = "Study";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
792 break;
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
793
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
794 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
795 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
796 result["Type"] = "Series";
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 433
diff changeset
797 result["Status"] = EnumerationToString(GetSeriesStatus(id));
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
798
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
799 int i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
800 if (db_->GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
801 result["ExpectedNumberOfInstances"] = i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
802 else
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
803 result["ExpectedNumberOfInstances"] = Json::nullValue;
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
804
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
805 break;
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
806 }
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
807
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
808 case ResourceType_Instance:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
809 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
810 result["Type"] = "Instance";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
811
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
812 FileInfo attachment;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
813 if (!db_->LookupAttachment(attachment, id, FileContentType_Dicom))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
814 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
815 throw OrthancException(ErrorCode_InternalError);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
816 }
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
817
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
818 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize());
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
819 result["FileUuid"] = attachment.GetUuid();
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
820
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
821 int i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
822 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
823 result["IndexInSeries"] = i;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
824 else
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
825 result["IndexInSeries"] = Json::nullValue;
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
826
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
827 break;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
828 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
829
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
830 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
831 throw OrthancException(ErrorCode_InternalError);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
832 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
833
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
834 // Record the remaining information
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
835 result["ID"] = publicId;
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
836 MainDicomTagsToJson(result, id);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
837
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
838 std::string tmp;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
839
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
840 tmp = db_->GetMetadata(id, MetadataType_AnonymizedFrom);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
841 if (tmp.size() != 0)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
842 result["AnonymizedFrom"] = tmp;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
843
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
844 tmp = db_->GetMetadata(id, MetadataType_ModifiedFrom);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
845 if (tmp.size() != 0)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
846 result["ModifiedFrom"] = tmp;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
847
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
848 if (type == ResourceType_Patient ||
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
849 type == ResourceType_Study ||
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
850 type == ResourceType_Series)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
851 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
852 result["IsStable"] = !unstableResources_.Contains(id);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
853 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
854
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
855 return true;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
856 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
857
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
859 bool ServerIndex::LookupAttachment(FileInfo& attachment,
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
860 const std::string& instanceUuid,
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
861 FileContentType contentType)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
863 boost::mutex::scoped_lock lock(mutex_);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
865 int64_t id;
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
866 ResourceType type;
701
f9052558eada fix attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
867 if (!db_->LookupResource(instanceUuid, id, type))
192
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
868 {
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
869 throw OrthancException(ErrorCode_InternalError);
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
870 }
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
871
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
872 if (db_->LookupAttachment(attachment, id, contentType))
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
873 {
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
874 assert(attachment.GetContentType() == contentType);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
875 return true;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
876 }
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
877 else
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
878 {
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
879 return false;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
880 }
192
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
881 }
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
882
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
883
c56dc32266e0 refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
884
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 void ServerIndex::GetAllUuids(Json::Value& target,
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
886 ResourceType resourceType)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
888 boost::mutex::scoped_lock lock(mutex_);
202
1650557bd81a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
889 db_->GetAllPublicIds(target, resourceType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 bool ServerIndex::GetChanges(Json::Value& target,
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 202
diff changeset
894 int64_t since,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 unsigned int maxResults)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 {
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
897 boost::mutex::scoped_lock lock(mutex_);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
898 db_->GetChanges(target, since, maxResults);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
899 return true;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
900 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
902 bool ServerIndex::GetLastChange(Json::Value& target)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
903 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
904 boost::mutex::scoped_lock lock(mutex_);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
905 db_->GetLastChange(target);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 202
diff changeset
906 return true;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 }
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
908
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
909 void ServerIndex::LogExportedResource(const std::string& publicId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
910 const std::string& remoteModality)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
911 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
912 boost::mutex::scoped_lock lock(mutex_);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
913
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
914 int64_t id;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
915 ResourceType type;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
916 if (!db_->LookupResource(publicId, id, type))
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
917 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
918 throw OrthancException(ErrorCode_InternalError);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
919 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
920
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
921 std::string patientId;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
922 std::string studyInstanceUid;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
923 std::string seriesInstanceUid;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
924 std::string sopInstanceUid;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
925
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
926 int64_t currentId = id;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
927 ResourceType currentType = type;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
928
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
929 // Iteratively go up inside the patient/study/series/instance hierarchy
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
930 bool done = false;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
931 while (!done)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
932 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
933 DicomMap map;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
934 db_->GetMainDicomTags(map, currentId);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
935
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
936 switch (currentType)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
937 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
938 case ResourceType_Patient:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
939 patientId = map.GetValue(DICOM_TAG_PATIENT_ID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
940 done = true;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
941 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
942
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
943 case ResourceType_Study:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
944 studyInstanceUid = map.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
945 currentType = ResourceType_Patient;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
946 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
947
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
948 case ResourceType_Series:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
949 seriesInstanceUid = map.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
950 currentType = ResourceType_Study;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
951 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
952
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
953 case ResourceType_Instance:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
954 sopInstanceUid = map.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
955 currentType = ResourceType_Series;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
956 break;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
957
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
958 default:
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
959 throw OrthancException(ErrorCode_InternalError);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
960 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
961
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
962 // 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
963 // the current resource
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
964 if (!done)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
965 {
375
d1ea72f1c967 major fix of storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
966 bool ok = db_->LookupParent(currentId, currentId);
d1ea72f1c967 major fix of storescu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 315
diff changeset
967 assert(ok);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
968 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
969 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
970
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
971 // 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
972 db_->LogExportedResource(type,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
973 publicId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
974 remoteModality,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
975 patientId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
976 studyInstanceUid,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
977 seriesInstanceUid,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
978 sopInstanceUid);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
979 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
980
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
981
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
982 bool ServerIndex::GetExportedResources(Json::Value& target,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
983 int64_t since,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
984 unsigned int maxResults)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
985 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
986 boost::mutex::scoped_lock lock(mutex_);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
987 db_->GetExportedResources(target, since, maxResults);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
988 return true;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
989 }
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
990
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
991 bool ServerIndex::GetLastExportedResource(Json::Value& target)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
992 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
993 boost::mutex::scoped_lock lock(mutex_);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
994 db_->GetLastExportedResource(target);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
995 return true;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
996 }
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
997
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
998
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
999 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1000 {
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1001 if (maximumStorageSize_ != 0)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1002 {
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
1003 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
1004 assert(db_->GetTotalCompressedSize() == currentSize);
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
1005
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1006 if (currentSize + instanceSize > maximumStorageSize_)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1007 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1008 return true;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1009 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1010 }
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 if (maximumPatients_ != 0)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1013 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1014 uint64_t patientCount = db_->GetResourceCount(ResourceType_Patient);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1015 if (patientCount > maximumPatients_)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1016 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1017 return true;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1018 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1019 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1020
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1021 return false;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1022 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1023
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1024
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1025 void ServerIndex::Recycle(uint64_t instanceSize,
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1026 const std::string& newPatientId)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1027 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1028 if (!IsRecyclingNeeded(instanceSize))
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1029 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1030 return;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1031 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1032
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1033 // Check whether other DICOM instances from this patient are
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1034 // already stored
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1035 int64_t patientToAvoid;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1036 ResourceType type;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1037 bool hasPatientToAvoid = db_->LookupResource(newPatientId, patientToAvoid, type);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1038
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1039 if (hasPatientToAvoid && type != ResourceType_Patient)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1040 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1041 throw OrthancException(ErrorCode_InternalError);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1042 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1043
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1044 // Iteratively select patient to remove until there is enough
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1045 // space in the DICOM store
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1046 int64_t patientToRecycle;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1047 while (true)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1048 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1049 // 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
1050 // we must avoid to recycle them
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1051 bool ok = hasPatientToAvoid ?
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1052 db_->SelectPatientToRecycle(patientToRecycle, patientToAvoid) :
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1053 db_->SelectPatientToRecycle(patientToRecycle);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1054
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1055 if (!ok)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1056 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1057 throw OrthancException(ErrorCode_FullStorage);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1058 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1059
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1060 LOG(INFO) << "Recycling one patient";
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1061 db_->DeleteResource(patientToRecycle);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1062
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1063 if (!IsRecyclingNeeded(instanceSize))
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1064 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1065 // OK, we're done
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1066 break;
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1067 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1068 }
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 264
diff changeset
1069 }
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1070
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1071 void ServerIndex::SetMaximumPatientCount(unsigned int count)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1072 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1073 boost::mutex::scoped_lock lock(mutex_);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1074 maximumPatients_ = count;
270
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1075
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1076 if (count == 0)
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1077 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1078 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
1079 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1080 else
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1081 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1082 LOG(WARNING) << "At most " << count << " patients will be stored";
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1083 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1084
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1085 StandaloneRecycling();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1086 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1087
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1088 void ServerIndex::SetMaximumStorageSize(uint64_t size)
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1089 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1090 boost::mutex::scoped_lock lock(mutex_);
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1091 maximumStorageSize_ = size;
270
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1092
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1093 if (size == 0)
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1094 {
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1095 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
1096 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1097 else
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1098 {
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1099 LOG(WARNING) << "At most " << (size / MEGA_BYTES) << "MB will be used for the storage area";
270
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1100 }
e6a4c4329481 parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
1101
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1102 StandaloneRecycling();
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1103 }
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1104
272
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1105 void ServerIndex::StandaloneRecycling()
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1106 {
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1107 // 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
1108 Transaction t(*this);
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1109 Recycle(0, "");
278
771f12042be9 more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
1110 t.Commit(0);
269
f6fdf5abe751 recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
1111 }
272
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1112
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1113
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1114 bool ServerIndex::IsProtectedPatient(const std::string& publicId)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1115 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1116 boost::mutex::scoped_lock lock(mutex_);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1117
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1118 // Lookup for the requested resource
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1119 int64_t id;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1120 ResourceType type;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1121 if (!db_->LookupResource(publicId, id, type) ||
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1122 type != ResourceType_Patient)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1123 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1124 throw OrthancException(ErrorCode_ParameterOutOfRange);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1125 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1126
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1127 return db_->IsProtectedPatient(id);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1128 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1129
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1130
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1131 void ServerIndex::SetProtectedPatient(const std::string& publicId,
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1132 bool isProtected)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1133 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1134 boost::mutex::scoped_lock lock(mutex_);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1135
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1136 // Lookup for the requested resource
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1137 int64_t id;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1138 ResourceType type;
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1139 if (!db_->LookupResource(publicId, id, type) ||
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1140 type != ResourceType_Patient)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1141 {
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1142 throw OrthancException(ErrorCode_ParameterOutOfRange);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1143 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1144
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1145 // 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
1146 db_->SetProtectedPatient(id, isProtected);
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1147
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1148 if (isProtected)
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1149 LOG(INFO) << "Patient " << publicId << " has been protected";
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1150 else
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1151 LOG(INFO) << "Patient " << publicId << " has been unprotected";
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1152 }
337c506461d2 protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 270
diff changeset
1153
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1154
714
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1155 void ServerIndex::GetChildren(std::list<std::string>& result,
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1156 const std::string& publicId)
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1157 {
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1158 result.clear();
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1159
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1160 boost::mutex::scoped_lock lock(mutex_);
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1161
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1162 ResourceType type;
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1163 int64_t resource;
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1164 if (!db_->LookupResource(publicId, resource, type))
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1165 {
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1166 throw OrthancException(ErrorCode_UnknownResource);
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1167 }
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1168
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1169 if (type == ResourceType_Instance)
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1170 {
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1171 // An instance cannot have a child
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1172 throw OrthancException(ErrorCode_BadParameterType);
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1173 }
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1174
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1175 std::list<int64_t> tmp;
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1176 db_->GetChildrenInternalId(tmp, resource);
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1177
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1178 for (std::list<int64_t>::const_iterator
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1179 it = tmp.begin(); it != tmp.end(); ++it)
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1180 {
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1181 result.push_back(db_->GetPublicId(*it));
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1182 }
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1183 }
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1184
6a1dbba0cca7 new implementation of C-Find handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 704
diff changeset
1185
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1186 void ServerIndex::GetChildInstances(std::list<std::string>& result,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1187 const std::string& publicId)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1188 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1189 result.clear();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1190
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1191 boost::mutex::scoped_lock lock(mutex_);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1192
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1193 ResourceType type;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1194 int64_t top;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1195 if (!db_->LookupResource(publicId, top, type))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1196 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1197 throw OrthancException(ErrorCode_UnknownResource);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1198 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1199
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1200 if (type == ResourceType_Instance)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1201 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1202 // The resource is already an instance: Do not go down the hierarchy
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1203 result.push_back(publicId);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1204 return;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1205 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1206
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1207 std::stack<int64_t> toExplore;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1208 toExplore.push(top);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1209
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1210 std::list<int64_t> tmp;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1211
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1212 while (!toExplore.empty())
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1213 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1214 // Get the internal ID of the current resource
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1215 int64_t resource = toExplore.top();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1216 toExplore.pop();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1217
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1218 if (db_->GetResourceType(resource) == ResourceType_Instance)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1219 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1220 result.push_back(db_->GetPublicId(resource));
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1221 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1222 else
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1223 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1224 // Tag all the children of this resource as to be explored
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1225 db_->GetChildrenInternalId(tmp, resource);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1226 for (std::list<int64_t>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
1227 it = tmp.begin(); it != tmp.end(); ++it)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1228 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1229 toExplore.push(*it);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1230 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1231 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1232 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1233 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 278
diff changeset
1234
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1235
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1236 void ServerIndex::SetMetadata(const std::string& publicId,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1237 MetadataType type,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1238 const std::string& value)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1239 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1240 boost::mutex::scoped_lock lock(mutex_);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1241
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1242 ResourceType rtype;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1243 int64_t id;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1244 if (!db_->LookupResource(publicId, id, rtype))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1245 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1246 throw OrthancException(ErrorCode_UnknownResource);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1247 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1248
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1249 db_->SetMetadata(id, type, value);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1250 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1251
438
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1252
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1253 void ServerIndex::DeleteMetadata(const std::string& publicId,
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1254 MetadataType type)
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1255 {
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1256 boost::mutex::scoped_lock lock(mutex_);
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1257
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1258 ResourceType rtype;
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1259 int64_t id;
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1260 if (!db_->LookupResource(publicId, id, rtype))
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1261 {
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1262 throw OrthancException(ErrorCode_UnknownResource);
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1263 }
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1264
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1265 db_->DeleteMetadata(id, type);
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1266 }
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1267
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
1268
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1269 bool ServerIndex::LookupMetadata(std::string& target,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1270 const std::string& publicId,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1271 MetadataType type)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1272 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1273 boost::mutex::scoped_lock lock(mutex_);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1274
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1275 ResourceType rtype;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1276 int64_t id;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1277 if (!db_->LookupResource(publicId, id, rtype))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1278 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1279 throw OrthancException(ErrorCode_UnknownResource);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1280 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1281
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1282 return db_->LookupMetadata(target, id, type);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1283 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1284
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1285
739
696dbb4fd390 api uniformization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 714
diff changeset
1286 void ServerIndex::ListAvailableMetadata(std::list<MetadataType>& target,
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1287 const std::string& publicId)
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1288 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1289 boost::mutex::scoped_lock lock(mutex_);
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1290
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1291 ResourceType rtype;
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1292 int64_t id;
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1293 if (!db_->LookupResource(publicId, id, rtype))
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1294 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1295 throw OrthancException(ErrorCode_UnknownResource);
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1296 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1297
739
696dbb4fd390 api uniformization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 714
diff changeset
1298 db_->ListAvailableMetadata(target, id);
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1299 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1300
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
1301
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1302 void ServerIndex::ListAvailableAttachments(std::list<FileContentType>& target,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1303 const std::string& publicId,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1304 ResourceType expectedType)
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1305 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1306 boost::mutex::scoped_lock lock(mutex_);
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1307
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1308 ResourceType type;
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1309 int64_t id;
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1310 if (!db_->LookupResource(publicId, id, type) ||
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1311 expectedType != type)
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1312 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1313 throw OrthancException(ErrorCode_UnknownResource);
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1314 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1315
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1316 db_->ListAvailableAttachments(target, id);
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1317 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1318
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
1319
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1320 bool ServerIndex::LookupParent(std::string& target,
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1321 const std::string& publicId)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1322 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1323 boost::mutex::scoped_lock lock(mutex_);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1324
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1325 ResourceType type;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1326 int64_t id;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1327 if (!db_->LookupResource(publicId, id, type))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1328 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1329 throw OrthancException(ErrorCode_UnknownResource);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1330 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1331
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1332 int64_t parentId;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1333 if (db_->LookupParent(parentId, id))
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1334 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1335 target = db_->GetPublicId(parentId);
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1336 return true;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1337 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1338 else
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1339 {
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1340 return false;
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1341 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1342 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1343
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1344
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1345 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1346 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1347 boost::mutex::scoped_lock lock(mutex_);
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1348
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1349 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction());
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1350
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1351 transaction->Begin();
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1352 uint64_t seq = db_->IncrementGlobalSequence(sequence);
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1353 transaction->Commit();
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1354
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
1355 return seq;
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 306
diff changeset
1356 }
315
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1357
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1358
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1359
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1360 void ServerIndex::LogChange(ChangeType changeType,
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1361 const std::string& publicId)
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1362 {
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1363 boost::mutex::scoped_lock lock(mutex_);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1364 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction());
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1365 transaction->Begin();
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1366
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1367 int64_t id;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1368 ResourceType type;
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1369 if (!db_->LookupResource(publicId, id, type))
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1370 {
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1371 throw OrthancException(ErrorCode_UnknownResource);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1372 }
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1373
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1374 db_->LogChange(changeType, id, type);
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1375
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1376 transaction->Commit();
fc856d175d18 modifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 311
diff changeset
1377 }
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1378
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1379
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1380 void ServerIndex::DeleteChanges()
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1381 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1382 boost::mutex::scoped_lock lock(mutex_);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1383 db_->ClearTable("Changes");
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1384 }
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1385
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1386 void ServerIndex::DeleteExportedResources()
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1387 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1388 boost::mutex::scoped_lock lock(mutex_);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1389 db_->ClearTable("ExportedResources");
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1390 }
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1391
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1392
646
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1393 void ServerIndex::GetStatisticsInternal(/* out */ uint64_t& compressedSize,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1394 /* out */ uint64_t& uncompressedSize,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1395 /* out */ unsigned int& countStudies,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1396 /* out */ unsigned int& countSeries,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1397 /* out */ unsigned int& countInstances,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1398 /* in */ int64_t id,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1399 /* in */ ResourceType type)
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1400 {
646
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1401 std::stack<int64_t> toExplore;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1402 toExplore.push(id);
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1403
646
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1404 countInstances = 0;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1405 countSeries = 0;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1406 countStudies = 0;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1407 compressedSize = 0;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1408 uncompressedSize = 0;
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1409
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1410 while (!toExplore.empty())
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1411 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1412 // Get the internal ID of the current resource
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1413 int64_t resource = toExplore.top();
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1414 toExplore.pop();
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1415
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1416 ResourceType thisType = db_->GetResourceType(resource);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1417
702
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1418 std::list<FileContentType> f;
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1419 db_->ListAvailableAttachments(f, resource);
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1420
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1421 for (std::list<FileContentType>::const_iterator
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1422 it = f.begin(); it != f.end(); ++it)
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1423 {
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1424 FileInfo attachment;
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1425 if (db_->LookupAttachment(attachment, resource, *it))
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1426 {
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1427 compressedSize += attachment.GetCompressedSize();
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1428 uncompressedSize += attachment.GetUncompressedSize();
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1429 }
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1430 }
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1431
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1432 if (thisType == ResourceType_Instance)
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1433 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1434 countInstances++;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1435 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1436 else
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1437 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1438 switch (thisType)
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1439 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1440 case ResourceType_Study:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1441 countStudies++;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1442 break;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1443
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1444 case ResourceType_Series:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1445 countSeries++;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1446 break;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1447
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1448 default:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1449 break;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1450 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1451
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1452 // Tag all the children of this resource as to be explored
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1453 std::list<int64_t> tmp;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1454 db_->GetChildrenInternalId(tmp, resource);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1455 for (std::list<int64_t>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
1456 it = tmp.begin(); it != tmp.end(); ++it)
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1457 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1458 toExplore.push(*it);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1459 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1460 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1461 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1462
646
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1463 if (countStudies == 0)
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1464 {
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1465 countStudies = 1;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1466 }
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1467
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1468 if (countSeries == 0)
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1469 {
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1470 countSeries = 1;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1471 }
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1472 }
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1473
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1474
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1475
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1476 void ServerIndex::GetStatistics(Json::Value& target,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1477 const std::string& publicId)
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1478 {
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1479 boost::mutex::scoped_lock lock(mutex_);
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1480
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1481 ResourceType type;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1482 int64_t top;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1483 if (!db_->LookupResource(publicId, top, type))
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1484 {
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1485 throw OrthancException(ErrorCode_UnknownResource);
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1486 }
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1487
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1488 uint64_t uncompressedSize;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1489 uint64_t compressedSize;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1490 unsigned int countStudies;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1491 unsigned int countSeries;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1492 unsigned int countInstances;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1493 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1494 countSeries, countInstances, top, type);
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1495
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1496 target = Json::objectValue;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1497 target["DiskSize"] = boost::lexical_cast<std::string>(compressedSize);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1498 target["DiskSizeMB"] = boost::lexical_cast<unsigned int>(compressedSize / MEGA_BYTES);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1499 target["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1500 target["UncompressedSizeMB"] = boost::lexical_cast<unsigned int>(uncompressedSize / MEGA_BYTES);
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1501
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1502 switch (type)
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1503 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1504 // Do NOT add "break" below this point!
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1505 case ResourceType_Patient:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1506 target["CountStudies"] = countStudies;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1507
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1508 case ResourceType_Study:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1509 target["CountSeries"] = countSeries;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1510
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1511 case ResourceType_Series:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1512 target["CountInstances"] = countInstances;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1513
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1514 case ResourceType_Instance:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1515 default:
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1516 break;
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1517 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
1518 }
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1519
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1520
646
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1521 void ServerIndex::GetStatistics(/* out */ uint64_t& compressedSize,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1522 /* out */ uint64_t& uncompressedSize,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1523 /* out */ unsigned int& countStudies,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1524 /* out */ unsigned int& countSeries,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1525 /* out */ unsigned int& countInstances,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1526 const std::string& publicId)
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1527 {
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1528 boost::mutex::scoped_lock lock(mutex_);
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1529
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1530 ResourceType type;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1531 int64_t top;
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1532 if (!db_->LookupResource(publicId, top, type))
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1533 {
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1534 throw OrthancException(ErrorCode_UnknownResource);
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1535 }
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1536
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1537 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies,
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1538 countSeries, countInstances, top, type);
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1539 }
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1540
fb49bf72ac2d fix issue 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 615
diff changeset
1541
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1542 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1543 {
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 744
diff changeset
1544 int stableAge = Configuration::GetGlobalIntegerParameter("StableAge", 60);
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1545 if (stableAge <= 0)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1546 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1547 stableAge = 60;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1548 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1549
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1550 LOG(INFO) << "Starting the monitor for stable resources (stable age = " << stableAge << ")";
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1551
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1552 while (!that->done_)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1553 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1554 // Check for stable resources each second
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1555 boost::this_thread::sleep(boost::posix_time::seconds(1));
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1556
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1557 boost::mutex::scoped_lock lock(that->mutex_);
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1558
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1559 while (!that->unstableResources_.IsEmpty() &&
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1560 that->unstableResources_.GetOldestPayload().GetAge() > static_cast<unsigned int>(stableAge))
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1561 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1562 // This DICOM resource has not received any new instance for
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1563 // some time. It can be considered as stable.
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1564
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1565 UnstableResourcePayload payload;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1566 int64_t id = that->unstableResources_.RemoveOldest(payload);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1567
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1568 // Ensure that the resource is still existing before logging the change
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1569 if (that->db_->IsExistingResource(id))
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1570 {
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1571 switch (payload.type_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1572 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1573 case Orthanc::ResourceType_Patient:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1574 that->db_->LogChange(ChangeType_StablePatient, id, ResourceType_Patient);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1575 break;
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1576
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1577 case Orthanc::ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1578 that->db_->LogChange(ChangeType_StableStudy, id, ResourceType_Study);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1579 break;
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1580
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1581 case Orthanc::ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1582 that->db_->LogChange(ChangeType_StableSeries, id, ResourceType_Series);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1583 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1584
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1585 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1586 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1587 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1588
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1589 //LOG(INFO) << "Stable resource: " << EnumerationToString(payload.type_) << " " << id;
511
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1590 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1591 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1592 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1593
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1594 LOG(INFO) << "Closing the monitor thread for stable resources";
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1595 }
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1596
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1597
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1598 void ServerIndex::MarkAsUnstable(int64_t id,
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1599 Orthanc::ResourceType type)
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1600 {
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1601 // WARNING: Before calling this method, "mutex_" must be locked.
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1602
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1603 assert(type == Orthanc::ResourceType_Patient ||
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1604 type == Orthanc::ResourceType_Study ||
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1605 type == Orthanc::ResourceType_Series);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1606
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1607 unstableResources_.AddOrMakeMostRecent(id, type);
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1608 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id;
3b735fdf320b monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1609 }
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1610
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1611
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1612
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1613 void ServerIndex::LookupTagValue(std::list<std::string>& result,
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1614 DicomTag tag,
615
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1615 const std::string& value,
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1616 ResourceType type)
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1617 {
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1618 result.clear();
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1619
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1620 boost::mutex::scoped_lock lock(mutex_);
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1621
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1622 std::list<int64_t> id;
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1623 db_->LookupTagValue(id, tag, value);
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1624
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1625 for (std::list<int64_t>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
1626 it = id.begin(); it != id.end(); ++it)
615
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1627 {
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1628 if (db_->GetResourceType(*it) == type)
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1629 {
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1630 result.push_back(db_->GetPublicId(*it));
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1631 }
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1632 }
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1633 }
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1634
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1635
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1636 void ServerIndex::LookupTagValue(std::list<std::string>& result,
ec0b7a51d7bd speed up find
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 585
diff changeset
1637 DicomTag tag,
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1638 const std::string& value)
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1639 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1640 result.clear();
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1641
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1642 boost::mutex::scoped_lock lock(mutex_);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1643
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1644 std::list<int64_t> id;
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1645 db_->LookupTagValue(id, tag, value);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1646
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1647 for (std::list<int64_t>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
1648 it = id.begin(); it != id.end(); ++it)
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1649 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1650 result.push_back(db_->GetPublicId(*it));
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1651 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1652 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1653
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1654
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1655 void ServerIndex::LookupTagValue(std::list<std::string>& result,
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1656 const std::string& value)
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1657 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1658 result.clear();
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1659
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1660 boost::mutex::scoped_lock lock(mutex_);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1661
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1662 std::list<int64_t> id;
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1663 db_->LookupTagValue(id, value);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1664
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1665 for (std::list<int64_t>::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
1666 it = id.begin(); it != id.end(); ++it)
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1667 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1668 result.push_back(db_->GetPublicId(*it));
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1669 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1670 }
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1671
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1672
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1673 StoreStatus ServerIndex::AddAttachment(const FileInfo& attachment,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1674 const std::string& publicId)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1675 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1676 boost::mutex::scoped_lock lock(mutex_);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1677
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1678 Transaction t(*this);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1679
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1680 ResourceType resourceType;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1681 int64_t resourceId;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1682 if (!db_->LookupResource(publicId, resourceId, resourceType))
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1683 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1684 return StoreStatus_Failure; // Inexistent resource
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1685 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1686
704
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1687 // Remove possible previous attachment
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1688 db_->DeleteAttachment(resourceId, attachment.GetContentType());
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1689
704
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1690 // Locate the patient of the target resource
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1691 int64_t patientId = resourceId;
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1692 for (;;)
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1693 {
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1694 int64_t parent;
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1695 if (db_->LookupParent(parent, patientId))
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1696 {
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1697 // We have not reached the patient level yet
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1698 patientId = parent;
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1699 }
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1700 else
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1701 {
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1702 // We have reached the patient level
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1703 break;
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1704 }
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1705 }
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1706
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1707 // Possibly apply the recycling mechanism while preserving this patient
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1708 assert(db_->GetResourceType(patientId) == ResourceType_Patient);
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1709 Recycle(attachment.GetCompressedSize(), db_->GetPublicId(patientId));
4789da60d655 recycling with custom attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 702
diff changeset
1710
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1711 db_->AddAttachment(resourceId, attachment);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1712
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1713 t.Commit(attachment.GetCompressedSize());
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1714
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1715 return StoreStatus_Success;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1716 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
1717
702
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1718
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1719 void ServerIndex::DeleteAttachment(const std::string& publicId,
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1720 FileContentType type)
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1721 {
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1722 boost::mutex::scoped_lock lock(mutex_);
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1723 listener_->Reset();
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1724
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1725 Transaction t(*this);
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1726
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1727 ResourceType rtype;
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1728 int64_t id;
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1729 if (!db_->LookupResource(publicId, id, rtype))
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1730 {
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1731 throw OrthancException(ErrorCode_UnknownResource);
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1732 }
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1733
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1734 db_->DeleteAttachment(id, type);
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1735
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1736 t.Commit(0);
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1737 }
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1738
7592a48e97e4 delete custom attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
1739
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1740 bool ServerIndex::GetMetadata(Json::Value& target,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1741 const std::string& publicId)
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1742 {
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1743 boost::mutex::scoped_lock lock(mutex_);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1744
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1745 target = Json::objectValue;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1746
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1747 ResourceType type;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1748 int64_t id;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1749 if (!db_->LookupResource(publicId, id, type))
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1750 {
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1751 return false;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1752 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1753
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1754 std::list<MetadataType> metadata;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1755 db_->ListAvailableMetadata(metadata, id);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1756
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1757 for (std::list<MetadataType>::const_iterator
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1758 it = metadata.begin(); it != metadata.end(); it++)
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1759 {
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1760 std::string key = EnumerationToString(*it);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1761 std::string value = db_->GetMetadata(id, *it);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1762 target[key] = value;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1763 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1764
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1765 return true;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1766 }
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1767
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1768
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769 }