Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerIndex.cpp @ 4578:710748828b6a db-changes
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Mar 2021 11:55:08 +0100 |
parents | a114a5db2afe |
children | 5ee9a4f8a0f0 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1286
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4371
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
136 | 11 * |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
0 | 23 * |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "PrecompiledHeadersServer.h" |
0 | 35 #include "ServerIndex.h" |
36 | |
6 | 37 #ifndef NOMINMAX |
2 | 38 #define NOMINMAX |
6 | 39 #endif |
40 | |
4045 | 41 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h" |
42 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
43 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h" | |
44 #include "../../OrthancFramework/Sources/Logging.h" | |
45 #include "../../OrthancFramework/Sources/Toolbox.h" | |
3094
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
46 |
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
47 #include "Database/ResourcesContent.h" |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
48 #include "OrthancConfiguration.h" |
3094
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
49 #include "Search/DatabaseLookup.h" |
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
50 #include "Search/DicomTagConstraint.h" |
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
51 #include "ServerContext.h" |
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
52 #include "ServerIndexChange.h" |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
53 #include "ServerToolbox.h" |
0 | 54 |
55 #include <boost/lexical_cast.hpp> | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
56 #include <boost/tuple/tuple.hpp> |
0 | 57 #include <stdio.h> |
4488
50b3f4c8107e
fix missing include for Debian unstable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4460
diff
changeset
|
58 #include <stack> |
0 | 59 |
440
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
60 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
|
61 |
62 | 62 namespace Orthanc |
0 | 63 { |
3075
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
64 static void CopyListToVector(std::vector<std::string>& target, |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
65 const std::list<std::string>& source) |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
66 { |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
67 target.resize(source.size()); |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
68 |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
69 size_t pos = 0; |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
70 |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
71 for (std::list<std::string>::const_iterator |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
72 it = source.begin(); it != source.end(); ++it) |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
73 { |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
74 target[pos] = *it; |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
75 pos ++; |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
76 } |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
77 } |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
78 |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3073
diff
changeset
|
79 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
80 class ServerIndex::Listener : public IDatabaseListener |
0 | 81 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
82 private: |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
83 struct FileToRemove |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
84 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
85 private: |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
86 std::string uuid_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
87 FileContentType type_; |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
88 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
89 public: |
4205 | 90 explicit FileToRemove(const FileInfo& info) : |
91 uuid_(info.GetUuid()), | |
92 type_(info.GetContentType()) | |
1191
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
93 { |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
94 } |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
95 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
96 const std::string& GetUuid() const |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
97 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
98 return uuid_; |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
99 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
100 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
101 FileContentType GetContentType() const |
264
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
102 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
103 return type_; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
104 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
105 }; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
106 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
107 ServerContext& context_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
108 bool hasRemainingLevel_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
109 ResourceType remainingType_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
110 std::string remainingPublicId_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
111 std::list<FileToRemove> pendingFilesToRemove_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
112 std::list<ServerIndexChange> pendingChanges_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
113 uint64_t sizeOfFilesToRemove_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
114 bool insideTransaction_; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
115 uint64_t sizeOfAddedAttachments_; |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
116 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
117 void Reset() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
118 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
119 sizeOfFilesToRemove_ = 0; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
120 hasRemainingLevel_ = false; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
121 pendingFilesToRemove_.clear(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
122 pendingChanges_.clear(); |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
123 sizeOfAddedAttachments_ = 0; |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
124 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
125 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
126 public: |
4205 | 127 explicit Listener(ServerContext& context) : |
128 context_(context), | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
129 insideTransaction_(false), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
130 sizeOfAddedAttachments_(0) |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
131 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
132 Reset(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
133 assert(ResourceType_Patient < ResourceType_Study && |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
134 ResourceType_Study < ResourceType_Series && |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
135 ResourceType_Series < ResourceType_Instance); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
136 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
137 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
138 void StartTransaction() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
139 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
140 Reset(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
141 insideTransaction_ = true; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
142 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
143 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
144 void EndTransaction() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
145 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
146 insideTransaction_ = false; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
147 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
148 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
149 uint64_t GetSizeOfFilesToRemove() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
150 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
151 return sizeOfFilesToRemove_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
152 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
153 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
154 void CommitFilesToRemove() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
155 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
156 for (std::list<FileToRemove>::const_iterator |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
157 it = pendingFilesToRemove_.begin(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
158 it != pendingFilesToRemove_.end(); ++it) |
1189
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
159 { |
3702
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
160 try |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
161 { |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
162 context_.RemoveFile(it->GetUuid(), it->GetContentType()); |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
163 } |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
164 catch (OrthancException& e) |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
165 { |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
166 LOG(ERROR) << "Unable to remove an attachment from the storage area: " |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
167 << it->GetUuid() << " (type: " << EnumerationToString(it->GetContentType()) << ")"; |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
168 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
169 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
170 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
171 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
172 void CommitChanges() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
173 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
174 for (std::list<ServerIndexChange>::const_iterator |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
175 it = pendingChanges_.begin(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
176 it != pendingChanges_.end(); ++it) |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
177 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
178 context_.SignalChange(*it); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
179 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
180 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
181 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
182 virtual void SignalRemainingAncestor(ResourceType parentType, |
4571
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
183 const std::string& publicId) ORTHANC_OVERRIDE |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
184 { |
4268
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
185 LOG(TRACE) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")"; |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
186 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
187 if (hasRemainingLevel_) |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
188 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
189 if (parentType < remainingType_) |
1189
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
190 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
191 remainingType_ = parentType; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
192 remainingPublicId_ = publicId; |
1191
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
193 } |
1158 | 194 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
195 else |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
196 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
197 hasRemainingLevel_ = true; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
198 remainingType_ = parentType; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
199 remainingPublicId_ = publicId; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
200 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
201 } |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
202 |
4571
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
203 virtual void SignalAttachmentDeleted(const FileInfo& info) ORTHANC_OVERRIDE |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
204 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
205 assert(Toolbox::IsUuid(info.GetUuid())); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
206 pendingFilesToRemove_.push_back(FileToRemove(info)); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
207 sizeOfFilesToRemove_ += info.GetCompressedSize(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
208 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
209 |
4571
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
210 virtual void SignalResourceDeleted(ResourceType type, |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
211 const std::string& publicId) ORTHANC_OVERRIDE |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
212 { |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
213 SignalChange(ServerIndexChange(ChangeType_Deleted, type, publicId)); |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
214 } |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
215 |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
216 void SignalChange(const ServerIndexChange& change) |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
217 { |
4268
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
218 LOG(TRACE) << "Change related to resource " << change.GetPublicId() << " of type " |
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
219 << EnumerationToString(change.GetResourceType()) << ": " |
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
220 << EnumerationToString(change.GetChangeType()); |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
221 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
222 if (insideTransaction_) |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
223 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
224 pendingChanges_.push_back(change); |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
225 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
226 else |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
227 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
228 context_.SignalChange(change); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
229 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
230 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
231 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
232 void SignalAttachmentsAdded(uint64_t compressedSize) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
233 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
234 sizeOfAddedAttachments_ += compressedSize; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
235 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
236 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
237 bool HasRemainingLevel() const |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
238 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
239 return hasRemainingLevel_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
240 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
241 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
242 ResourceType GetRemainingType() const |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
243 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
244 assert(HasRemainingLevel()); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
245 return remainingType_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
246 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
247 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
248 const std::string& GetRemainingPublicId() const |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
249 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
250 assert(HasRemainingLevel()); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
251 return remainingPublicId_; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
252 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
253 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
254 uint64_t GetSizeOfAddedAttachments() const |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
255 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
256 return sizeOfAddedAttachments_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
257 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
258 }; |
0 | 259 |
260 | |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
261 class ServerIndex::Transaction |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
262 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
263 private: |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
264 ServerIndex& index_; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3702
diff
changeset
|
265 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_; |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
266 bool isCommitted_; |
4205 | 267 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
268 public: |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
269 explicit Transaction(ServerIndex& index, |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
270 TransactionType type) : |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
271 index_(index), |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
272 isCommitted_(false) |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
273 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
274 transaction_.reset(index_.db_.StartTransaction(type)); |
1191
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
275 index_.listener_->StartTransaction(); |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
276 } |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
277 |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
278 ~Transaction() |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
279 { |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
280 index_.listener_->EndTransaction(); |
1310
61ce8147f30d
custom database back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
281 |
61ce8147f30d
custom database back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
282 if (!isCommitted_) |
61ce8147f30d
custom database back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
283 { |
61ce8147f30d
custom database back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
284 transaction_->Rollback(); |
61ce8147f30d
custom database back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
285 } |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
286 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
287 |
4576 | 288 void Commit() |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
289 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
290 if (!isCommitted_) |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
291 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
292 int64_t delta = (static_cast<int64_t>(index_.listener_->GetSizeOfAddedAttachments()) - |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3006
diff
changeset
|
293 static_cast<int64_t>(index_.listener_->GetSizeOfFilesToRemove())); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3006
diff
changeset
|
294 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3006
diff
changeset
|
295 transaction_->Commit(delta); |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
296 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
297 // 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
|
298 // 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
|
299 // deleted because of recycling. |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
300 index_.listener_->CommitFilesToRemove(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
301 |
1189
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
302 // Send all the pending changes to the Orthanc plugins |
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
303 index_.listener_->CommitChanges(); |
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
304 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
305 isCommitted_ = true; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
306 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
307 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
308 }; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
309 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
310 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
311 class ServerIndex::UnstableResourcePayload |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
312 { |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
313 private: |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
314 ResourceType type_; |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
315 std::string publicId_; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
316 boost::posix_time::ptime time_; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
317 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
318 public: |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
319 UnstableResourcePayload() : type_(ResourceType_Instance) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
320 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
321 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
322 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
323 UnstableResourcePayload(Orthanc::ResourceType type, |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
324 const std::string& publicId) : |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
325 type_(type), |
4205 | 326 publicId_(publicId), |
327 time_(boost::posix_time::second_clock::local_time()) | |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
328 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
329 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
330 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
331 unsigned int GetAge() const |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
332 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
333 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
|
334 } |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
335 |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
336 ResourceType GetResourceType() const |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
337 { |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
338 return type_; |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
339 } |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
340 |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
341 const std::string& GetPublicId() const |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
342 { |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
343 return publicId_; |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
344 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
345 }; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
346 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
347 |
3027 | 348 class ServerIndex::MainDicomTagsRegistry : public boost::noncopyable |
349 { | |
350 private: | |
351 class TagInfo | |
352 { | |
353 private: | |
354 ResourceType level_; | |
355 DicomTagType type_; | |
356 | |
357 public: | |
358 TagInfo() | |
359 { | |
360 } | |
361 | |
362 TagInfo(ResourceType level, | |
363 DicomTagType type) : | |
364 level_(level), | |
365 type_(type) | |
366 { | |
367 } | |
368 | |
369 ResourceType GetLevel() const | |
370 { | |
371 return level_; | |
372 } | |
373 | |
374 DicomTagType GetType() const | |
375 { | |
376 return type_; | |
377 } | |
378 }; | |
379 | |
380 typedef std::map<DicomTag, TagInfo> Registry; | |
381 | |
382 | |
383 Registry registry_; | |
384 | |
385 void LoadTags(ResourceType level) | |
386 { | |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
387 { |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
388 const DicomTag* tags = NULL; |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
389 size_t size; |
3027 | 390 |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
391 ServerToolbox::LoadIdentifiers(tags, size, level); |
3027 | 392 |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
393 for (size_t i = 0; i < size; i++) |
3027 | 394 { |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
395 if (registry_.find(tags[i]) == registry_.end()) |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
396 { |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
397 registry_[tags[i]] = TagInfo(level, DicomTagType_Identifier); |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
398 } |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
399 else |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
400 { |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
401 // These patient-level tags are copied in the study level |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
402 assert(level == ResourceType_Study && |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
403 (tags[i] == DICOM_TAG_PATIENT_ID || |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
404 tags[i] == DICOM_TAG_PATIENT_NAME || |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
405 tags[i] == DICOM_TAG_PATIENT_BIRTH_DATE)); |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
406 } |
3027 | 407 } |
408 } | |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
409 |
3027 | 410 { |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
411 std::set<DicomTag> tags; |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
412 DicomMap::GetMainDicomTags(tags, level); |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
413 |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
414 for (std::set<DicomTag>::const_iterator |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
415 tag = tags.begin(); tag != tags.end(); ++tag) |
3027 | 416 { |
3650
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
417 if (registry_.find(*tag) == registry_.end()) |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
418 { |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
419 registry_[*tag] = TagInfo(level, DicomTagType_Main); |
e5811a9f8df0
removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
420 } |
3027 | 421 } |
422 } | |
423 } | |
424 | |
425 public: | |
426 MainDicomTagsRegistry() | |
427 { | |
428 LoadTags(ResourceType_Patient); | |
429 LoadTags(ResourceType_Study); | |
430 LoadTags(ResourceType_Series); | |
431 LoadTags(ResourceType_Instance); | |
432 } | |
433 | |
434 void LookupTag(ResourceType& level, | |
435 DicomTagType& type, | |
436 const DicomTag& tag) const | |
437 { | |
438 Registry::const_iterator it = registry_.find(tag); | |
439 | |
440 if (it == registry_.end()) | |
441 { | |
442 // Default values | |
443 level = ResourceType_Instance; | |
444 type = DicomTagType_Generic; | |
445 } | |
446 else | |
447 { | |
448 level = it->second.GetLevel(); | |
449 type = it->second.GetType(); | |
450 } | |
451 } | |
452 }; | |
453 | |
454 | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
455 void ServerIndex::FlushThread(ServerIndex* that, |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
456 unsigned int threadSleep) |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
457 { |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1006
diff
changeset
|
458 // 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
|
459 unsigned int sleep = 10; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
460 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
461 // TODO - REMOVE THIS |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
462 try |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
463 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
464 boost::mutex::scoped_lock lock(that->monitoringMutex_); |
1239 | 465 std::string sleepString; |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1006
diff
changeset
|
466 |
1247 | 467 if (that->db_.LookupGlobalProperty(sleepString, GlobalProperty_FlushSleep) && |
1239 | 468 Toolbox::IsInteger(sleepString)) |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1006
diff
changeset
|
469 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1006
diff
changeset
|
470 sleep = boost::lexical_cast<unsigned int>(sleepString); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1006
diff
changeset
|
471 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
472 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
473 catch (boost::bad_lexical_cast&) |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
474 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
475 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
476 |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
477 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
478 |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
479 unsigned int count = 0; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
480 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
481 while (!that->done_) |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
482 { |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
483 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleep)); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
484 count++; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
485 if (count < sleep) |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
486 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
487 continue; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
488 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
489 |
2217 | 490 Logging::Flush(); |
491 | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
492 boost::mutex::scoped_lock lock(that->monitoringMutex_); |
3698
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
493 |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
494 try |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
495 { |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
496 that->db_.FlushToDisk(); |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
497 } |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
498 catch (OrthancException&) |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
499 { |
3699
efa815dd2c20
additional logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3698
diff
changeset
|
500 LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; |
3698
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
501 } |
356ebef2cd95
prevent crash on full disk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3650
diff
changeset
|
502 |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
503 count = 0; |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
504 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
505 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
506 LOG(INFO) << "Stopping the database flushing thread"; |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
507 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
508 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
509 |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
510 static bool ComputeExpectedNumberOfInstances(int64_t& target, |
433 | 511 const DicomMap& dicomSummary) |
512 { | |
513 try | |
514 { | |
656 | 515 const DicomValue* value; |
516 const DicomValue* value2; | |
517 | |
433 | 518 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL && |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
519 !value->IsNull() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
520 !value->IsBinary() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
521 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS)) != NULL && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
522 !value2->IsNull() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
523 !value2->IsBinary()) |
433 | 524 { |
525 // Patch for series with temporal positions thanks to Will Ryder | |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
526 int64_t imagesInAcquisition = boost::lexical_cast<int64_t>(value->GetContent()); |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
527 int64_t countTemporalPositions = boost::lexical_cast<int64_t>(value2->GetContent()); |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
528 target = imagesInAcquisition * countTemporalPositions; |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
529 return (target > 0); |
433 | 530 } |
531 | |
532 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL && | |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
533 !value->IsNull() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
534 !value->IsBinary() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
535 (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TIME_SLICES)) != NULL && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
536 !value2->IsBinary() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
537 !value2->IsNull()) |
433 | 538 { |
539 // Support of Cardio-PET images | |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
540 int64_t numberOfSlices = boost::lexical_cast<int64_t>(value->GetContent()); |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
541 int64_t numberOfTimeSlices = boost::lexical_cast<int64_t>(value2->GetContent()); |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
542 target = numberOfSlices * numberOfTimeSlices; |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
543 return (target > 0); |
433 | 544 } |
545 | |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
546 else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
547 !value->IsNull() && |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
548 !value->IsBinary()) |
433 | 549 { |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
550 target = boost::lexical_cast<int64_t>(value->GetContent()); |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
551 return (target > 0); |
433 | 552 } |
553 } | |
1737
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
554 catch (OrthancException&) |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
555 { |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
556 } |
ec66a16aa398
removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1725
diff
changeset
|
557 catch (boost::bad_lexical_cast&) |
433 | 558 { |
559 } | |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
560 |
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
561 return false; |
433 | 562 } |
563 | |
564 | |
1237 | 565 |
566 | |
3187
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
567 static bool LookupStringMetadata(std::string& result, |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
568 const std::map<MetadataType, std::string>& metadata, |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
569 MetadataType type) |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
570 { |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
571 std::map<MetadataType, std::string>::const_iterator found = metadata.find(type); |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
572 |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
573 if (found == metadata.end()) |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
574 { |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
575 return false; |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
576 } |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
577 else |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
578 { |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
579 result = found->second; |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
580 return true; |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
581 } |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
582 } |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
583 |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
584 |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
585 static bool LookupIntegerMetadata(int64_t& result, |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
586 const std::map<MetadataType, std::string>& metadata, |
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
587 MetadataType type) |
1237 | 588 { |
1238 | 589 std::string s; |
3187
4bbadcd03966
refactoring retrieval of metadata from database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
590 if (!LookupStringMetadata(s, metadata, type)) |
1237 | 591 { |
592 return false; | |
593 } | |
594 | |
595 try | |
596 { | |
1238 | 597 result = boost::lexical_cast<int64_t>(s); |
1237 | 598 return true; |
599 } | |
600 catch (boost::bad_lexical_cast&) | |
601 { | |
602 return false; | |
603 } | |
604 } | |
605 | |
606 | |
1297 | 607 void ServerIndex::LogChange(int64_t internalId, |
608 ChangeType changeType, | |
609 ResourceType resourceType, | |
610 const std::string& publicId) | |
611 { | |
612 ServerIndexChange change(changeType, resourceType, publicId); | |
1300
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
613 |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
614 if (changeType <= ChangeType_INTERNAL_LastLogged) |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
615 { |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
616 db_.LogChange(internalId, change); |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
617 } |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
618 |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
619 assert(listener_.get() != NULL); |
919dfb2fb3fe
DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1299
diff
changeset
|
620 listener_->SignalChange(change); |
1297 | 621 } |
622 | |
1237 | 623 |
4554 | 624 bool ServerIndex::IsUnstableResource(int64_t id) |
625 { | |
626 return unstableResources_.Contains(id); | |
627 } | |
628 | |
1237 | 629 |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
630 ServerIndex::ServerIndex(ServerContext& context, |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
631 IDatabaseWrapper& db, |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
632 unsigned int threadSleep) : |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
633 done_(false), |
1247 | 634 db_(db), |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
635 maximumStorageSize_(0), |
2826
c277e0421200
unit testing of overwriting
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
636 maximumPatients_(0), |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
637 mainDicomTagsRegistry_(new MainDicomTagsRegistry), |
4554 | 638 maxRetries_(10) |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
639 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
640 listener_.reset(new Listener(context)); |
1247 | 641 db_.SetListener(*listener_); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
642 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
643 // 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
|
644 // execution of Orthanc |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
645 StandaloneRecycling(maximumStorageSize_, maximumPatients_); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
646 |
1306
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
647 if (db.HasFlushToDisk()) |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
648 { |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
649 flushThread_ = boost::thread(FlushThread, this, threadSleep); |
1306
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
650 } |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
651 |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
652 unstableResourcesMonitorThread_ = boost::thread |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
653 (UnstableResourcesMonitorThread, this, threadSleep); |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
654 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
655 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
656 |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
657 |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
658 ServerIndex::~ServerIndex() |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
659 { |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
660 if (!done_) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
661 { |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
662 LOG(ERROR) << "INTERNAL ERROR: ServerIndex::Stop() should be invoked manually to avoid mess in the destruction order!"; |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
663 Stop(); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
664 } |
0 | 665 } |
666 | |
667 | |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
668 |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
669 void ServerIndex::Stop() |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
670 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
671 if (!done_) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
672 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
673 done_ = true; |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
674 |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
675 if (db_.HasFlushToDisk() && |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
676 flushThread_.joinable()) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
677 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
678 flushThread_.join(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
679 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
680 |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
681 if (unstableResourcesMonitorThread_.joinable()) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
682 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
683 unstableResourcesMonitorThread_.join(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
684 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
685 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
686 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
687 |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
688 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
689 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
690 SeriesStatus ServerIndex::ReadOnlyTransaction::GetSeriesStatus(int64_t id, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
691 int64_t expectedNumberOfInstances) |
199 | 692 { |
3091
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
693 std::list<std::string> values; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
694 db_.GetChildrenMetadata(values, id, MetadataType_Instance_IndexInSeries); |
199 | 695 |
1238 | 696 std::set<int64_t> instances; |
3091
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
697 |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
698 for (std::list<std::string>::const_iterator |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
699 it = values.begin(); it != values.end(); ++it) |
199 | 700 { |
1238 | 701 int64_t index; |
3091
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
702 |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
703 try |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
704 { |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
705 index = boost::lexical_cast<int64_t>(*it); |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
706 } |
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
707 catch (boost::bad_lexical_cast&) |
199 | 708 { |
709 return SeriesStatus_Unknown; | |
710 } | |
3091
476cba12c2b0
IDatabaseWrapper::GetChildrenMetadata()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3090
diff
changeset
|
711 |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
712 if (!(index > 0 && index <= expectedNumberOfInstances)) |
199 | 713 { |
714 // Out-of-range instance index | |
715 return SeriesStatus_Inconsistent; | |
716 } | |
717 | |
718 if (instances.find(index) != instances.end()) | |
719 { | |
720 // Twice the same instance index | |
721 return SeriesStatus_Inconsistent; | |
722 } | |
723 | |
724 instances.insert(index); | |
725 } | |
726 | |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
727 if (static_cast<int64_t>(instances.size()) == expectedNumberOfInstances) |
199 | 728 { |
729 return SeriesStatus_Complete; | |
730 } | |
731 else | |
732 { | |
733 return SeriesStatus_Missing; | |
734 } | |
735 } | |
736 | |
737 | |
4578 | 738 void ServerIndex::ReadOnlyTransaction::MainDicomTagsToJson(Json::Value& target, |
739 int64_t resourceId, | |
740 ResourceType resourceType) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
741 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
742 DicomMap tags; |
4578 | 743 db_.GetMainDicomTags(tags, resourceId); |
1676
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
744 |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
745 if (resourceType == ResourceType_Study) |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
746 { |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
747 DicomMap t1, t2; |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
748 tags.ExtractStudyInformation(t1); |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
749 tags.ExtractPatientInformation(t2); |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
750 |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
751 target["MainDicomTags"] = Json::objectValue; |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
752 FromDcmtkBridge::ToJson(target["MainDicomTags"], t1, true); |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
753 |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
754 target["PatientMainDicomTags"] = Json::objectValue; |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
755 FromDcmtkBridge::ToJson(target["PatientMainDicomTags"], t2, true); |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
756 } |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
757 else |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
758 { |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
759 target["MainDicomTags"] = Json::objectValue; |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
760 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags, true); |
f079f3efe33b
patient tags reported in studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
761 } |
198
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 |
3090
31244604f617
starting optimization of SeriesIndex::GetSeriesStatus()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3087
diff
changeset
|
764 |
1244 | 765 template <typename T> |
766 static void FormatLog(Json::Value& target, | |
767 const std::list<T>& log, | |
768 const std::string& name, | |
769 bool done, | |
3105
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
770 int64_t since, |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
771 bool hasLast, |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
772 int64_t last) |
1240 | 773 { |
774 Json::Value items = Json::arrayValue; | |
1244 | 775 for (typename std::list<T>::const_iterator |
1304 | 776 it = log.begin(); it != log.end(); ++it) |
1240 | 777 { |
778 Json::Value item; | |
779 it->Format(item); | |
780 items.append(item); | |
781 } | |
782 | |
783 target = Json::objectValue; | |
1244 | 784 target[name] = items; |
1240 | 785 target["Done"] = done; |
786 | |
3105
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
787 if (!hasLast) |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
788 { |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
789 // Best-effort guess of the last index in the sequence |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
790 if (log.empty()) |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
791 { |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
792 last = since; |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
793 } |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
794 else |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
795 { |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
796 last = log.back().GetSeq(); |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
797 } |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
798 } |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3094
diff
changeset
|
799 |
1240 | 800 target["Last"] = static_cast<int>(last); |
801 } | |
802 | |
803 | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
804 void ServerIndex::SetMaximumPatientCount(unsigned int count) |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
805 { |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
806 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
807 boost::mutex::scoped_lock lock(monitoringMutex_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
808 maximumPatients_ = count; |
3020
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
809 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
810 if (count == 0) |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
811 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
812 LOG(WARNING) << "No limit on the number of stored patients"; |
4575
e23bacd4fffc
clarifications in ServerIndex::Recycle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4574
diff
changeset
|
813 } |
e23bacd4fffc
clarifications in ServerIndex::Recycle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4574
diff
changeset
|
814 else |
e23bacd4fffc
clarifications in ServerIndex::Recycle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4574
diff
changeset
|
815 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
816 LOG(WARNING) << "At most " << count << " patients will be stored"; |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
817 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
818 } |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
819 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
820 StandaloneRecycling(maximumStorageSize_, maximumPatients_); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
821 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
822 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
823 void ServerIndex::SetMaximumStorageSize(uint64_t size) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
824 { |
270
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
825 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
826 boost::mutex::scoped_lock lock(monitoringMutex_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
827 maximumStorageSize_ = size; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
828 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
829 if (size == 0) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
830 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
831 LOG(WARNING) << "No limit on the size of the storage area"; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
832 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
833 else |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
834 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
835 LOG(WARNING) << "At most " << (size / MEGA_BYTES) << "MB will be used for the storage area"; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
836 } |
270
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
837 } |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
838 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
839 StandaloneRecycling(maximumStorageSize_, maximumPatients_); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
840 } |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
841 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
842 |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
843 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
844 unsigned int threadSleep) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
845 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
846 int stableAge; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
847 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
848 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
849 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
850 stableAge = lock.GetConfiguration().GetUnsignedIntegerParameter("StableAge", 60); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
851 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
852 |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
853 if (stableAge <= 0) |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
854 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
855 stableAge = 60; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
856 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
857 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
858 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
|
859 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
860 while (!that->done_) |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
861 { |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
862 // Check for stable resources each few seconds |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
863 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleep)); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
864 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
865 boost::mutex::scoped_lock lock(that->monitoringMutex_); |
513 | 866 |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
867 while (!that->unstableResources_.IsEmpty() && |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
868 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
|
869 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
870 // 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
|
871 // 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
|
872 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
873 UnstableResourcePayload payload; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
874 int64_t id = that->unstableResources_.RemoveOldest(payload); |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
875 |
513 | 876 // Ensure that the resource is still existing before logging the change |
1247 | 877 if (that->db_.IsExistingResource(id)) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
878 { |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
879 switch (payload.GetResourceType()) |
513 | 880 { |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
881 case ResourceType_Patient: |
1237 | 882 that->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId()); |
513 | 883 break; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
884 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
885 case ResourceType_Study: |
1237 | 886 that->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId()); |
513 | 887 break; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
888 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
889 case ResourceType_Series: |
1237 | 890 that->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId()); |
513 | 891 break; |
892 | |
893 default: | |
894 throw OrthancException(ErrorCode_InternalError); | |
895 } | |
896 | |
897 //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
|
898 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
899 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
900 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
901 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
902 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
|
903 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
904 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
905 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
906 void ServerIndex::MarkAsUnstable(int64_t id, |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
907 Orthanc::ResourceType type, |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
908 const std::string& publicId) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
909 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
910 // WARNING: Before calling this method, "monitoringMutex_" must be locked. |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
911 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
912 assert(type == Orthanc::ResourceType_Patient || |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
913 type == Orthanc::ResourceType_Study || |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
914 type == Orthanc::ResourceType_Series); |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
915 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
916 UnstableResourcePayload payload(type, publicId); |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
917 unstableResources_.AddOrMakeMostRecent(id, payload); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
918 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; |
1189
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
919 |
1237 | 920 LogChange(id, ChangeType_NewChildInstance, type, publicId); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
921 } |
521 | 922 |
923 | |
924 | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
925 void ServerIndex::NormalizeLookup(std::vector<DatabaseConstraint>& target, |
3027 | 926 const DatabaseLookup& source, |
927 ResourceType queryLevel) const | |
928 { | |
929 assert(mainDicomTagsRegistry_.get() != NULL); | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
930 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
931 target.clear(); |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
932 target.reserve(source.GetConstraintsCount()); |
3031 | 933 |
3027 | 934 for (size_t i = 0; i < source.GetConstraintsCount(); i++) |
935 { | |
3031 | 936 ResourceType level; |
937 DicomTagType type; | |
3027 | 938 |
3031 | 939 mainDicomTagsRegistry_->LookupTag(level, type, source.GetConstraint(i).GetTag()); |
940 | |
941 if (type == DicomTagType_Identifier || | |
942 type == DicomTagType_Main) | |
3027 | 943 { |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
944 // Use the fact that patient-level tags are copied at the study level |
3031 | 945 if (level == ResourceType_Patient && |
946 queryLevel != ResourceType_Patient) | |
3027 | 947 { |
3031 | 948 level = ResourceType_Study; |
3027 | 949 } |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
950 |
3073
0e9d1731b1b0
refactoring to reuse DatabaseConstraint in separate projects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
951 target.push_back(source.GetConstraint(i).ConvertToDatabaseConstraint(level, type)); |
3027 | 952 } |
953 } | |
954 } | |
955 | |
956 | |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
957 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
958 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
959 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
960 /*** |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
961 ** PROTOTYPING FOR DB REFACTORING BELOW |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
962 ***/ |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
963 |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
964 namespace |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
965 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
966 /** |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
967 * Some handy templates to reduce the verbosity in the definitions |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
968 * of the internal classes. |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
969 **/ |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
970 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
971 template <typename Operations, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
972 typename Tuple> |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
973 class TupleOperationsWrapper : public ServerIndex::IReadOnlyOperations |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
974 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
975 protected: |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
976 Operations& operations_; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
977 const Tuple& tuple_; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
978 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
979 public: |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
980 TupleOperationsWrapper(Operations& operations, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
981 const Tuple& tuple) : |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
982 operations_(operations), |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
983 tuple_(tuple) |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
984 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
985 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
986 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
987 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
988 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
989 operations_.ApplyTuple(transaction, tuple_); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
990 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
991 }; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
992 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
993 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
994 template <typename T1> |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
995 class ReadOnlyOperationsT1 : public boost::noncopyable |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
996 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
997 public: |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
998 typedef typename boost::tuple<T1> Tuple; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
999 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1000 virtual ~ReadOnlyOperationsT1() |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1001 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1002 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1003 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1004 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1005 const Tuple& tuple) = 0; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1006 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1007 void Apply(ServerIndex& index, |
4566
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1008 T1 t1) |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1009 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1010 const Tuple tuple(t1); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1011 TupleOperationsWrapper<ReadOnlyOperationsT1, Tuple> wrapper(*this, tuple); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1012 index.Apply(wrapper); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1013 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1014 }; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1015 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1016 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1017 template <typename T1, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1018 typename T2> |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1019 class ReadOnlyOperationsT2 : public boost::noncopyable |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1020 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1021 public: |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1022 typedef typename boost::tuple<T1, T2> Tuple; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1023 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1024 virtual ~ReadOnlyOperationsT2() |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1025 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1026 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1027 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1028 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1029 const Tuple& tuple) = 0; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1030 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1031 void Apply(ServerIndex& index, |
4566
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1032 T1 t1, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1033 T2 t2) |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1034 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1035 const Tuple tuple(t1, t2); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1036 TupleOperationsWrapper<ReadOnlyOperationsT2, Tuple> wrapper(*this, tuple); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1037 index.Apply(wrapper); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1038 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1039 }; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1040 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1041 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1042 template <typename T1, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1043 typename T2, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1044 typename T3> |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1045 class ReadOnlyOperationsT3 : public boost::noncopyable |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1046 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1047 public: |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1048 typedef typename boost::tuple<T1, T2, T3> Tuple; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1049 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1050 virtual ~ReadOnlyOperationsT3() |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1051 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1052 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1053 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1054 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1055 const Tuple& tuple) = 0; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1056 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1057 void Apply(ServerIndex& index, |
4566
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1058 T1 t1, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1059 T2 t2, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1060 T3 t3) |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1061 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1062 const Tuple tuple(t1, t2, t3); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1063 TupleOperationsWrapper<ReadOnlyOperationsT3, Tuple> wrapper(*this, tuple); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1064 index.Apply(wrapper); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1065 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1066 }; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1067 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1068 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1069 template <typename T1, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1070 typename T2, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1071 typename T3, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1072 typename T4> |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1073 class ReadOnlyOperationsT4 : public boost::noncopyable |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1074 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1075 public: |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1076 typedef typename boost::tuple<T1, T2, T3, T4> Tuple; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1077 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1078 virtual ~ReadOnlyOperationsT4() |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1079 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1080 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1081 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1082 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1083 const Tuple& tuple) = 0; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1084 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1085 void Apply(ServerIndex& index, |
4566
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1086 T1 t1, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1087 T2 t2, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1088 T3 t3, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1089 T4 t4) |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1090 { |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1091 const Tuple tuple(t1, t2, t3, t4); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1092 TupleOperationsWrapper<ReadOnlyOperationsT4, Tuple> wrapper(*this, tuple); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1093 index.Apply(wrapper); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1094 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1095 }; |
4558 | 1096 |
1097 | |
1098 template <typename T1, | |
1099 typename T2, | |
1100 typename T3, | |
1101 typename T4, | |
1102 typename T5> | |
1103 class ReadOnlyOperationsT5 : public boost::noncopyable | |
1104 { | |
1105 public: | |
1106 typedef typename boost::tuple<T1, T2, T3, T4, T5> Tuple; | |
1107 | |
1108 virtual ~ReadOnlyOperationsT5() | |
1109 { | |
1110 } | |
1111 | |
1112 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, | |
1113 const Tuple& tuple) = 0; | |
1114 | |
1115 void Apply(ServerIndex& index, | |
4566
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1116 T1 t1, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1117 T2 t2, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1118 T3 t3, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1119 T4 t4, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1120 T5 t5) |
4558 | 1121 { |
1122 const Tuple tuple(t1, t2, t3, t4, t5); | |
1123 TupleOperationsWrapper<ReadOnlyOperationsT5, Tuple> wrapper(*this, tuple); | |
1124 index.Apply(wrapper); | |
1125 } | |
1126 }; | |
1127 | |
1128 | |
1129 template <typename T1, | |
1130 typename T2, | |
1131 typename T3, | |
1132 typename T4, | |
1133 typename T5, | |
1134 typename T6> | |
1135 class ReadOnlyOperationsT6 : public boost::noncopyable | |
1136 { | |
1137 public: | |
1138 typedef typename boost::tuple<T1, T2, T3, T4, T5, T6> Tuple; | |
1139 | |
1140 virtual ~ReadOnlyOperationsT6() | |
1141 { | |
1142 } | |
1143 | |
1144 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction, | |
1145 const Tuple& tuple) = 0; | |
1146 | |
1147 void Apply(ServerIndex& index, | |
4566
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1148 T1 t1, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1149 T2 t2, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1150 T3 t3, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1151 T4 t4, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1152 T5 t5, |
f52d0bc19e07
fix build for msvc2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4565
diff
changeset
|
1153 T6 t6) |
4558 | 1154 { |
1155 const Tuple tuple(t1, t2, t3, t4, t5, t6); | |
1156 TupleOperationsWrapper<ReadOnlyOperationsT6, Tuple> wrapper(*this, tuple); | |
1157 index.Apply(wrapper); | |
1158 } | |
1159 }; | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1160 } |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1161 |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1162 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1163 void ServerIndex::ApplyInternal(IReadOnlyOperations* readOperations, |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1164 IReadWriteOperations* writeOperations) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1165 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1166 if ((readOperations == NULL && writeOperations == NULL) || |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1167 (readOperations != NULL && writeOperations != NULL)) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1168 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1169 throw OrthancException(ErrorCode_InternalError); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1170 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1171 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1172 unsigned int count = 0; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1173 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1174 for (;;) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1175 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1176 try |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1177 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
1178 boost::mutex::scoped_lock lock(monitoringMutex_); // TODO - REMOVE |
4554 | 1179 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1180 if (readOperations != NULL) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1181 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1182 /** |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1183 * IMPORTANT: In Orthanc <= 1.9.1, there was no transaction |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1184 * in this case. This was OK because of the presence of the |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1185 * global mutex protecting the database. |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1186 **/ |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1187 |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1188 Transaction transaction(*this, TransactionType_ReadOnly); // TODO - Only if not "TransactionType_Implicit" |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1189 { |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1190 ReadOnlyTransaction t(db_); |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1191 readOperations->Apply(t); |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1192 } |
4576 | 1193 transaction.Commit(); |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1194 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1195 else |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1196 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1197 assert(writeOperations != NULL); |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1198 |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1199 Transaction transaction(*this, TransactionType_ReadWrite); |
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1200 { |
4573 | 1201 assert(listener_.get() != NULL); |
1202 ReadWriteTransaction t(db_, *listener_, *this); | |
1203 writeOperations->Apply(t); | |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1204 } |
4576 | 1205 transaction.Commit(); |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1206 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1207 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1208 return; // Success |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1209 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1210 catch (OrthancException& e) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1211 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1212 if (e.GetErrorCode() == ErrorCode_DatabaseCannotSerialize) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1213 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1214 if (count == maxRetries_) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1215 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1216 throw; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1217 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1218 else |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1219 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1220 count++; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1221 boost::this_thread::sleep(boost::posix_time::milliseconds(100 * count)); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1222 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1223 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1224 else if (e.GetErrorCode() == ErrorCode_DatabaseUnavailable) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1225 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1226 if (count == maxRetries_) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1227 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1228 throw; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1229 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1230 else |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1231 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1232 count++; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1233 boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1234 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1235 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1236 else |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1237 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1238 throw; |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1239 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1240 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1241 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1242 } |
4561
02510325d869
removed function wrappers for transactions in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4560
diff
changeset
|
1243 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1244 |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1245 void ServerIndex::Apply(IReadOnlyOperations& operations) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1246 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1247 ApplyInternal(&operations, NULL); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1248 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1249 |
4561
02510325d869
removed function wrappers for transactions in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4560
diff
changeset
|
1250 |
4551
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1251 void ServerIndex::Apply(IReadWriteOperations& operations) |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1252 { |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1253 ApplyInternal(NULL, &operations); |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1254 } |
350a22c094f2
testing replay of transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4514
diff
changeset
|
1255 |
4554 | 1256 |
1257 bool ServerIndex::ExpandResource(Json::Value& target, | |
1258 const std::string& publicId, | |
1259 ResourceType level) | |
1260 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1261 class Operations : public ReadOnlyOperationsT4<bool&, Json::Value&, const std::string&, ResourceType> |
4554 | 1262 { |
1263 private: | |
4567 | 1264 ServerIndex& index_; // TODO - REMOVE |
4554 | 1265 |
1266 public: | |
4562 | 1267 explicit Operations(ServerIndex& index) : |
1268 index_(index) | |
4554 | 1269 { |
1270 } | |
1271 | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1272 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1273 const Tuple& tuple) ORTHANC_OVERRIDE |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1274 { |
4554 | 1275 // Lookup for the requested resource |
1276 int64_t internalId; // unused | |
1277 ResourceType type; | |
1278 std::string parent; | |
4562 | 1279 if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) || |
1280 type != tuple.get<3>()) | |
4554 | 1281 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1282 tuple.get<0>() = false; |
4554 | 1283 } |
1284 else | |
1285 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1286 Json::Value& target = tuple.get<1>(); |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1287 target = Json::objectValue; |
4554 | 1288 |
1289 // Set information about the parent resource (if it exists) | |
1290 if (type == ResourceType_Patient) | |
1291 { | |
1292 if (!parent.empty()) | |
1293 { | |
1294 throw OrthancException(ErrorCode_DatabasePlugin); | |
1295 } | |
1296 } | |
1297 else | |
1298 { | |
1299 if (parent.empty()) | |
1300 { | |
1301 throw OrthancException(ErrorCode_DatabasePlugin); | |
1302 } | |
1303 | |
1304 switch (type) | |
1305 { | |
1306 case ResourceType_Study: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1307 target["ParentPatient"] = parent; |
4554 | 1308 break; |
1309 | |
1310 case ResourceType_Series: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1311 target["ParentStudy"] = parent; |
4554 | 1312 break; |
1313 | |
1314 case ResourceType_Instance: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1315 target["ParentSeries"] = parent; |
4554 | 1316 break; |
1317 | |
1318 default: | |
1319 throw OrthancException(ErrorCode_InternalError); | |
1320 } | |
1321 } | |
1322 | |
1323 // List the children resources | |
1324 std::list<std::string> children; | |
1325 transaction.GetChildrenPublicId(children, internalId); | |
1326 | |
1327 if (type != ResourceType_Instance) | |
1328 { | |
1329 Json::Value c = Json::arrayValue; | |
1330 | |
1331 for (std::list<std::string>::const_iterator | |
1332 it = children.begin(); it != children.end(); ++it) | |
1333 { | |
1334 c.append(*it); | |
1335 } | |
1336 | |
1337 switch (type) | |
1338 { | |
1339 case ResourceType_Patient: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1340 target["Studies"] = c; |
4554 | 1341 break; |
1342 | |
1343 case ResourceType_Study: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1344 target["Series"] = c; |
4554 | 1345 break; |
1346 | |
1347 case ResourceType_Series: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1348 target["Instances"] = c; |
4554 | 1349 break; |
1350 | |
1351 default: | |
1352 throw OrthancException(ErrorCode_InternalError); | |
1353 } | |
1354 } | |
1355 | |
1356 // Extract the metadata | |
1357 std::map<MetadataType, std::string> metadata; | |
1358 transaction.GetAllMetadata(metadata, internalId); | |
1359 | |
1360 // Set the resource type | |
1361 switch (type) | |
1362 { | |
1363 case ResourceType_Patient: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1364 target["Type"] = "Patient"; |
4554 | 1365 break; |
1366 | |
1367 case ResourceType_Study: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1368 target["Type"] = "Study"; |
4554 | 1369 break; |
1370 | |
1371 case ResourceType_Series: | |
1372 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1373 target["Type"] = "Series"; |
4554 | 1374 |
1375 int64_t i; | |
1376 if (LookupIntegerMetadata(i, metadata, MetadataType_Series_ExpectedNumberOfInstances)) | |
1377 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1378 target["ExpectedNumberOfInstances"] = static_cast<int>(i); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1379 target["Status"] = EnumerationToString(transaction.GetSeriesStatus(internalId, i)); |
4554 | 1380 } |
1381 else | |
1382 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1383 target["ExpectedNumberOfInstances"] = Json::nullValue; |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1384 target["Status"] = EnumerationToString(SeriesStatus_Unknown); |
4554 | 1385 } |
1386 | |
1387 break; | |
1388 } | |
1389 | |
1390 case ResourceType_Instance: | |
1391 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1392 target["Type"] = "Instance"; |
4554 | 1393 |
1394 FileInfo attachment; | |
1395 if (!transaction.LookupAttachment(attachment, internalId, FileContentType_Dicom)) | |
1396 { | |
1397 throw OrthancException(ErrorCode_InternalError); | |
1398 } | |
1399 | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1400 target["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize()); |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1401 target["FileUuid"] = attachment.GetUuid(); |
4554 | 1402 |
1403 int64_t i; | |
1404 if (LookupIntegerMetadata(i, metadata, MetadataType_Instance_IndexInSeries)) | |
1405 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1406 target["IndexInSeries"] = static_cast<int>(i); |
4554 | 1407 } |
1408 else | |
1409 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1410 target["IndexInSeries"] = Json::nullValue; |
4554 | 1411 } |
1412 | |
1413 break; | |
1414 } | |
1415 | |
1416 default: | |
1417 throw OrthancException(ErrorCode_InternalError); | |
1418 } | |
1419 | |
1420 // Record the remaining information | |
4562 | 1421 target["ID"] = tuple.get<2>(); |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1422 transaction.MainDicomTagsToJson(target, internalId, type); |
4554 | 1423 |
1424 std::string tmp; | |
1425 | |
1426 if (LookupStringMetadata(tmp, metadata, MetadataType_AnonymizedFrom)) | |
1427 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1428 target["AnonymizedFrom"] = tmp; |
4554 | 1429 } |
1430 | |
1431 if (LookupStringMetadata(tmp, metadata, MetadataType_ModifiedFrom)) | |
1432 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1433 target["ModifiedFrom"] = tmp; |
4554 | 1434 } |
1435 | |
1436 if (type == ResourceType_Patient || | |
1437 type == ResourceType_Study || | |
1438 type == ResourceType_Series) | |
1439 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1440 target["IsStable"] = !index_.IsUnstableResource(internalId); |
4554 | 1441 |
1442 if (LookupStringMetadata(tmp, metadata, MetadataType_LastUpdate)) | |
1443 { | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1444 target["LastUpdate"] = tmp; |
4554 | 1445 } |
1446 } | |
1447 | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1448 tuple.get<0>() = true; |
4554 | 1449 } |
1450 } | |
1451 }; | |
1452 | |
4562 | 1453 bool found; |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1454 Operations operations(*this); |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1455 operations.Apply(*this, found, target, publicId, level); |
4562 | 1456 return found; |
4554 | 1457 } |
1458 | |
1459 | |
1460 void ServerIndex::GetAllMetadata(std::map<MetadataType, std::string>& target, | |
1461 const std::string& publicId, | |
1462 ResourceType level) | |
1463 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1464 class Operations : public ReadOnlyOperationsT3<std::map<MetadataType, std::string>&, const std::string&, ResourceType> |
4554 | 1465 { |
1466 public: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1467 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1468 const Tuple& tuple) ORTHANC_OVERRIDE |
4554 | 1469 { |
1470 ResourceType type; | |
1471 int64_t id; | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1472 if (!transaction.LookupResource(id, type, tuple.get<1>()) || |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1473 tuple.get<2>() != type) |
4554 | 1474 { |
1475 throw OrthancException(ErrorCode_UnknownResource); | |
1476 } | |
1477 else | |
1478 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1479 transaction.GetAllMetadata(tuple.get<0>(), id); |
4554 | 1480 } |
1481 } | |
1482 }; | |
1483 | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1484 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1485 operations.Apply(*this, target, publicId, level); |
4554 | 1486 } |
4555 | 1487 |
1488 | |
1489 bool ServerIndex::LookupAttachment(FileInfo& attachment, | |
1490 const std::string& instancePublicId, | |
1491 FileContentType contentType) | |
1492 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1493 class Operations : public ReadOnlyOperationsT4<bool&, FileInfo&, const std::string&, FileContentType> |
4555 | 1494 { |
1495 public: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1496 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1497 const Tuple& tuple) ORTHANC_OVERRIDE |
4555 | 1498 { |
1499 int64_t internalId; | |
1500 ResourceType type; | |
4562 | 1501 if (!transaction.LookupResource(internalId, type, tuple.get<2>())) |
4555 | 1502 { |
1503 throw OrthancException(ErrorCode_UnknownResource); | |
1504 } | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1505 else if (transaction.LookupAttachment(tuple.get<1>(), internalId, tuple.get<3>())) |
4555 | 1506 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1507 assert(tuple.get<1>().GetContentType() == tuple.get<3>()); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1508 tuple.get<0>() = true; |
4555 | 1509 } |
1510 else | |
1511 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1512 tuple.get<0>() = false; |
4555 | 1513 } |
1514 } | |
1515 }; | |
1516 | |
4562 | 1517 bool found; |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1518 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1519 operations.Apply(*this, found, attachment, instancePublicId, contentType); |
4562 | 1520 return found; |
4555 | 1521 } |
1522 | |
1523 | |
1524 void ServerIndex::GetAllUuids(std::list<std::string>& target, | |
1525 ResourceType resourceType) | |
1526 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1527 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, ResourceType> |
4555 | 1528 { |
1529 public: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1530 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1531 const Tuple& tuple) ORTHANC_OVERRIDE |
4555 | 1532 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1533 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1534 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>()); |
4555 | 1535 } |
1536 }; | |
1537 | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1538 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1539 operations.Apply(*this, target, resourceType); |
4555 | 1540 } |
1541 | |
1542 | |
1543 void ServerIndex::GetAllUuids(std::list<std::string>& target, | |
1544 ResourceType resourceType, | |
1545 size_t since, | |
1546 size_t limit) | |
1547 { | |
1548 if (limit == 0) | |
1549 { | |
1550 target.clear(); | |
1551 } | |
1552 else | |
1553 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1554 class Operations : public ReadOnlyOperationsT4<std::list<std::string>&, ResourceType, size_t, size_t> |
4555 | 1555 { |
1556 public: | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1557 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1558 const Tuple& tuple) ORTHANC_OVERRIDE |
4555 | 1559 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1560 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1561 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); |
4555 | 1562 } |
1563 }; | |
1564 | |
4557
b6d4b735eb4d
templates to reduce verbosity in ServerIndex implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4556
diff
changeset
|
1565 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1566 operations.Apply(*this, target, resourceType, since, limit); |
4555 | 1567 } |
1568 } | |
4558 | 1569 |
1570 | |
1571 void ServerIndex::GetGlobalStatistics(/* out */ uint64_t& diskSize, | |
1572 /* out */ uint64_t& uncompressedSize, | |
1573 /* out */ uint64_t& countPatients, | |
1574 /* out */ uint64_t& countStudies, | |
1575 /* out */ uint64_t& countSeries, | |
1576 /* out */ uint64_t& countInstances) | |
1577 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1578 class Operations : public ReadOnlyOperationsT6<uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&> |
4558 | 1579 { |
1580 public: | |
1581 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1582 const Tuple& tuple) ORTHANC_OVERRIDE | |
1583 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1584 tuple.get<0>() = transaction.GetTotalCompressedSize(); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1585 tuple.get<1>() = transaction.GetTotalUncompressedSize(); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1586 tuple.get<2>() = transaction.GetResourceCount(ResourceType_Patient); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1587 tuple.get<3>() = transaction.GetResourceCount(ResourceType_Study); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1588 tuple.get<4>() = transaction.GetResourceCount(ResourceType_Series); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1589 tuple.get<5>() = transaction.GetResourceCount(ResourceType_Instance); |
4558 | 1590 } |
1591 }; | |
1592 | |
1593 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1594 operations.Apply(*this, diskSize, uncompressedSize, countPatients, |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1595 countStudies, countSeries, countInstances); |
4558 | 1596 } |
1597 | |
1598 | |
1599 void ServerIndex::GetChanges(Json::Value& target, | |
1600 int64_t since, | |
1601 unsigned int maxResults) | |
1602 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1603 class Operations : public ReadOnlyOperationsT3<Json::Value&, int64_t, unsigned int> |
4558 | 1604 { |
1605 public: | |
1606 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1607 const Tuple& tuple) ORTHANC_OVERRIDE | |
1608 { | |
1609 // NB: In Orthanc <= 1.3.2, a transaction was missing, as | |
1610 // "GetLastChange()" involves calls to "GetPublicId()" | |
1611 | |
1612 std::list<ServerIndexChange> changes; | |
1613 bool done; | |
1614 bool hasLast = false; | |
1615 int64_t last = 0; | |
1616 | |
1617 transaction.GetChanges(changes, done, tuple.get<1>(), tuple.get<2>()); | |
1618 if (changes.empty()) | |
1619 { | |
1620 last = transaction.GetLastChangeIndex(); | |
1621 hasLast = true; | |
1622 } | |
1623 | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1624 FormatLog(tuple.get<0>(), changes, "Changes", done, tuple.get<1>(), hasLast, last); |
4558 | 1625 } |
1626 }; | |
1627 | |
1628 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1629 operations.Apply(*this, target, since, maxResults); |
4558 | 1630 } |
1631 | |
1632 | |
1633 void ServerIndex::GetLastChange(Json::Value& target) | |
1634 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1635 class Operations : public ReadOnlyOperationsT1<Json::Value&> |
4558 | 1636 { |
1637 public: | |
1638 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1639 const Tuple& tuple) ORTHANC_OVERRIDE | |
1640 { | |
1641 // NB: In Orthanc <= 1.3.2, a transaction was missing, as | |
1642 // "GetLastChange()" involves calls to "GetPublicId()" | |
1643 | |
1644 std::list<ServerIndexChange> changes; | |
1645 bool hasLast = false; | |
1646 int64_t last = 0; | |
1647 | |
1648 transaction.GetLastChange(changes); | |
1649 if (changes.empty()) | |
1650 { | |
1651 last = transaction.GetLastChangeIndex(); | |
1652 hasLast = true; | |
1653 } | |
1654 | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1655 FormatLog(tuple.get<0>(), changes, "Changes", true, 0, hasLast, last); |
4558 | 1656 } |
1657 }; | |
1658 | |
1659 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1660 operations.Apply(*this, target); |
4558 | 1661 } |
1662 | |
1663 | |
1664 void ServerIndex::GetExportedResources(Json::Value& target, | |
1665 int64_t since, | |
1666 unsigned int maxResults) | |
1667 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1668 class Operations : public ReadOnlyOperationsT3<Json::Value&, int64_t, unsigned int> |
4558 | 1669 { |
1670 public: | |
1671 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1672 const Tuple& tuple) ORTHANC_OVERRIDE | |
1673 { | |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1674 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4558 | 1675 |
1676 std::list<ExportedResource> exported; | |
1677 bool done; | |
1678 transaction.GetExportedResources(exported, done, tuple.get<1>(), tuple.get<2>()); | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1679 FormatLog(tuple.get<0>(), exported, "Exports", done, tuple.get<1>(), false, -1); |
4558 | 1680 } |
1681 }; | |
1682 | |
1683 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1684 operations.Apply(*this, target, since, maxResults); |
4558 | 1685 } |
1686 | |
1687 | |
1688 void ServerIndex::GetLastExportedResource(Json::Value& target) | |
1689 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1690 class Operations : public ReadOnlyOperationsT1<Json::Value&> |
4558 | 1691 { |
1692 public: | |
1693 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1694 const Tuple& tuple) ORTHANC_OVERRIDE | |
1695 { | |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
1696 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4558 | 1697 |
1698 std::list<ExportedResource> exported; | |
1699 transaction.GetLastExportedResource(exported); | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1700 FormatLog(tuple.get<0>(), exported, "Exports", true, 0, false, -1); |
4558 | 1701 } |
1702 }; | |
1703 | |
1704 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1705 operations.Apply(*this, target); |
4558 | 1706 } |
4559 | 1707 |
1708 | |
1709 bool ServerIndex::IsProtectedPatient(const std::string& publicId) | |
1710 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1711 class Operations : public ReadOnlyOperationsT2<bool&, const std::string&> |
4559 | 1712 { |
1713 public: | |
1714 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1715 const Tuple& tuple) ORTHANC_OVERRIDE | |
1716 { | |
1717 // Lookup for the requested resource | |
1718 int64_t id; | |
1719 ResourceType type; | |
4562 | 1720 if (!transaction.LookupResource(id, type, tuple.get<1>()) || |
4559 | 1721 type != ResourceType_Patient) |
1722 { | |
1723 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1724 } | |
1725 else | |
1726 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1727 tuple.get<0>() = transaction.IsProtectedPatient(id); |
4559 | 1728 } |
1729 } | |
1730 }; | |
4562 | 1731 |
1732 bool isProtected; | |
4559 | 1733 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1734 operations.Apply(*this, isProtected, publicId); |
4562 | 1735 return isProtected; |
4559 | 1736 } |
1737 | |
1738 | |
1739 void ServerIndex::GetChildren(std::list<std::string>& result, | |
1740 const std::string& publicId) | |
1741 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1742 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, const std::string&> |
4559 | 1743 { |
1744 public: | |
1745 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1746 const Tuple& tuple) ORTHANC_OVERRIDE | |
1747 { | |
1748 ResourceType type; | |
1749 int64_t resource; | |
1750 if (!transaction.LookupResource(resource, type, tuple.get<1>())) | |
1751 { | |
1752 throw OrthancException(ErrorCode_UnknownResource); | |
1753 } | |
1754 else if (type == ResourceType_Instance) | |
1755 { | |
1756 // An instance cannot have a child | |
1757 throw OrthancException(ErrorCode_BadParameterType); | |
1758 } | |
1759 else | |
1760 { | |
1761 std::list<int64_t> tmp; | |
1762 transaction.GetChildrenInternalId(tmp, resource); | |
1763 | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1764 tuple.get<0>().clear(); |
4559 | 1765 |
1766 for (std::list<int64_t>::const_iterator | |
1767 it = tmp.begin(); it != tmp.end(); ++it) | |
1768 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1769 tuple.get<0>().push_back(transaction.GetPublicId(*it)); |
4559 | 1770 } |
1771 } | |
1772 } | |
1773 }; | |
1774 | |
1775 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1776 operations.Apply(*this, result, publicId); |
4559 | 1777 } |
1778 | |
1779 | |
1780 void ServerIndex::GetChildInstances(std::list<std::string>& result, | |
1781 const std::string& publicId) | |
1782 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1783 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, const std::string&> |
4559 | 1784 { |
1785 public: | |
1786 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1787 const Tuple& tuple) ORTHANC_OVERRIDE | |
1788 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1789 tuple.get<0>().clear(); |
4559 | 1790 |
1791 ResourceType type; | |
1792 int64_t top; | |
1793 if (!transaction.LookupResource(top, type, tuple.get<1>())) | |
1794 { | |
1795 throw OrthancException(ErrorCode_UnknownResource); | |
1796 } | |
1797 else if (type == ResourceType_Instance) | |
1798 { | |
1799 // The resource is already an instance: Do not go down the hierarchy | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1800 tuple.get<0>().push_back(tuple.get<1>()); |
4559 | 1801 } |
1802 else | |
1803 { | |
1804 std::stack<int64_t> toExplore; | |
1805 toExplore.push(top); | |
1806 | |
1807 std::list<int64_t> tmp; | |
1808 while (!toExplore.empty()) | |
1809 { | |
1810 // Get the internal ID of the current resource | |
1811 int64_t resource = toExplore.top(); | |
1812 toExplore.pop(); | |
1813 | |
1814 // TODO - This could be optimized by seeing how many | |
1815 // levels "type == transaction.GetResourceType(top)" is | |
1816 // above the "instances level" | |
1817 if (transaction.GetResourceType(resource) == ResourceType_Instance) | |
1818 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1819 tuple.get<0>().push_back(transaction.GetPublicId(resource)); |
4559 | 1820 } |
1821 else | |
1822 { | |
1823 // Tag all the children of this resource as to be explored | |
1824 transaction.GetChildrenInternalId(tmp, resource); | |
1825 for (std::list<int64_t>::const_iterator | |
1826 it = tmp.begin(); it != tmp.end(); ++it) | |
1827 { | |
1828 toExplore.push(*it); | |
1829 } | |
1830 } | |
1831 } | |
1832 } | |
1833 } | |
1834 }; | |
1835 | |
1836 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1837 operations.Apply(*this, result, publicId); |
4559 | 1838 } |
4560 | 1839 |
1840 | |
1841 bool ServerIndex::LookupMetadata(std::string& target, | |
1842 const std::string& publicId, | |
1843 ResourceType expectedType, | |
1844 MetadataType type) | |
1845 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1846 class Operations : public ReadOnlyOperationsT5<bool&, std::string&, const std::string&, ResourceType, MetadataType> |
4560 | 1847 { |
1848 public: | |
1849 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1850 const Tuple& tuple) ORTHANC_OVERRIDE | |
1851 { | |
1852 ResourceType rtype; | |
1853 int64_t id; | |
4562 | 1854 if (!transaction.LookupResource(id, rtype, tuple.get<2>()) || |
1855 rtype != tuple.get<3>()) | |
4560 | 1856 { |
1857 throw OrthancException(ErrorCode_UnknownResource); | |
1858 } | |
1859 else | |
1860 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1861 tuple.get<0>() = transaction.LookupMetadata(tuple.get<1>(), id, tuple.get<4>()); |
4560 | 1862 } |
1863 } | |
1864 }; | |
4562 | 1865 |
1866 bool found; | |
4560 | 1867 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1868 operations.Apply(*this, found, target, publicId, expectedType, type); |
4562 | 1869 return found; |
4560 | 1870 } |
1871 | |
1872 | |
1873 void ServerIndex::ListAvailableAttachments(std::set<FileContentType>& target, | |
1874 const std::string& publicId, | |
1875 ResourceType expectedType) | |
1876 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1877 class Operations : public ReadOnlyOperationsT3<std::set<FileContentType>&, const std::string&, ResourceType> |
4560 | 1878 { |
1879 public: | |
1880 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1881 const Tuple& tuple) ORTHANC_OVERRIDE | |
1882 { | |
1883 ResourceType type; | |
1884 int64_t id; | |
1885 if (!transaction.LookupResource(id, type, tuple.get<1>()) || | |
1886 tuple.get<2>() != type) | |
1887 { | |
1888 throw OrthancException(ErrorCode_UnknownResource); | |
1889 } | |
1890 else | |
1891 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1892 transaction.ListAvailableAttachments(tuple.get<0>(), id); |
4560 | 1893 } |
1894 } | |
1895 }; | |
1896 | |
1897 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1898 operations.Apply(*this, target, publicId, expectedType); |
4560 | 1899 } |
1900 | |
1901 | |
1902 bool ServerIndex::LookupParent(std::string& target, | |
1903 const std::string& publicId) | |
1904 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1905 class Operations : public ReadOnlyOperationsT3<bool&, std::string&, const std::string&> |
4560 | 1906 { |
1907 public: | |
1908 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
1909 const Tuple& tuple) ORTHANC_OVERRIDE | |
1910 { | |
1911 ResourceType type; | |
1912 int64_t id; | |
4562 | 1913 if (!transaction.LookupResource(id, type, tuple.get<2>())) |
4560 | 1914 { |
1915 throw OrthancException(ErrorCode_UnknownResource); | |
1916 } | |
1917 else | |
1918 { | |
1919 int64_t parentId; | |
1920 if (transaction.LookupParent(parentId, id)) | |
1921 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1922 tuple.get<1>() = transaction.GetPublicId(parentId); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1923 tuple.get<0>() = true; |
4562 | 1924 } |
1925 else | |
1926 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1927 tuple.get<0>() = false; |
4562 | 1928 } |
1929 } | |
1930 } | |
1931 }; | |
1932 | |
1933 bool found; | |
1934 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
1935 operations.Apply(*this, found, target, publicId); |
4562 | 1936 return found; |
1937 } | |
1938 | |
1939 | |
1940 void ServerIndex::GetResourceStatistics(/* out */ ResourceType& type, | |
1941 /* out */ uint64_t& diskSize, | |
1942 /* out */ uint64_t& uncompressedSize, | |
1943 /* out */ unsigned int& countStudies, | |
1944 /* out */ unsigned int& countSeries, | |
1945 /* out */ unsigned int& countInstances, | |
1946 /* out */ uint64_t& dicomDiskSize, | |
1947 /* out */ uint64_t& dicomUncompressedSize, | |
1948 const std::string& publicId) | |
1949 { | |
1950 class Operations : public ServerIndex::IReadOnlyOperations | |
1951 { | |
1952 private: | |
1953 ResourceType& type_; | |
1954 uint64_t& diskSize_; | |
1955 uint64_t& uncompressedSize_; | |
1956 unsigned int& countStudies_; | |
1957 unsigned int& countSeries_; | |
1958 unsigned int& countInstances_; | |
1959 uint64_t& dicomDiskSize_; | |
1960 uint64_t& dicomUncompressedSize_; | |
1961 const std::string& publicId_; | |
1962 | |
1963 public: | |
1964 explicit Operations(ResourceType& type, | |
1965 uint64_t& diskSize, | |
1966 uint64_t& uncompressedSize, | |
1967 unsigned int& countStudies, | |
1968 unsigned int& countSeries, | |
1969 unsigned int& countInstances, | |
1970 uint64_t& dicomDiskSize, | |
1971 uint64_t& dicomUncompressedSize, | |
1972 const std::string& publicId) : | |
1973 type_(type), | |
1974 diskSize_(diskSize), | |
1975 uncompressedSize_(uncompressedSize), | |
1976 countStudies_(countStudies), | |
1977 countSeries_(countSeries), | |
1978 countInstances_(countInstances), | |
1979 dicomDiskSize_(dicomDiskSize), | |
1980 dicomUncompressedSize_(dicomUncompressedSize), | |
1981 publicId_(publicId) | |
1982 { | |
1983 } | |
1984 | |
1985 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | |
1986 { | |
1987 int64_t top; | |
1988 if (!transaction.LookupResource(top, type_, publicId_)) | |
1989 { | |
1990 throw OrthancException(ErrorCode_UnknownResource); | |
1991 } | |
1992 else | |
1993 { | |
1994 countInstances_ = 0; | |
1995 countSeries_ = 0; | |
1996 countStudies_ = 0; | |
1997 diskSize_ = 0; | |
1998 uncompressedSize_ = 0; | |
1999 dicomDiskSize_ = 0; | |
2000 dicomUncompressedSize_ = 0; | |
2001 | |
2002 std::stack<int64_t> toExplore; | |
2003 toExplore.push(top); | |
2004 | |
2005 while (!toExplore.empty()) | |
2006 { | |
2007 // Get the internal ID of the current resource | |
2008 int64_t resource = toExplore.top(); | |
2009 toExplore.pop(); | |
2010 | |
2011 ResourceType thisType = transaction.GetResourceType(resource); | |
2012 | |
2013 std::set<FileContentType> f; | |
2014 transaction.ListAvailableAttachments(f, resource); | |
2015 | |
2016 for (std::set<FileContentType>::const_iterator | |
2017 it = f.begin(); it != f.end(); ++it) | |
2018 { | |
2019 FileInfo attachment; | |
2020 if (transaction.LookupAttachment(attachment, resource, *it)) | |
2021 { | |
2022 if (attachment.GetContentType() == FileContentType_Dicom) | |
2023 { | |
2024 dicomDiskSize_ += attachment.GetCompressedSize(); | |
2025 dicomUncompressedSize_ += attachment.GetUncompressedSize(); | |
2026 } | |
2027 | |
2028 diskSize_ += attachment.GetCompressedSize(); | |
2029 uncompressedSize_ += attachment.GetUncompressedSize(); | |
2030 } | |
2031 } | |
2032 | |
2033 if (thisType == ResourceType_Instance) | |
2034 { | |
2035 countInstances_++; | |
2036 } | |
2037 else | |
2038 { | |
2039 switch (thisType) | |
2040 { | |
2041 case ResourceType_Study: | |
2042 countStudies_++; | |
2043 break; | |
2044 | |
2045 case ResourceType_Series: | |
2046 countSeries_++; | |
2047 break; | |
2048 | |
2049 default: | |
2050 break; | |
2051 } | |
2052 | |
2053 // Tag all the children of this resource as to be explored | |
2054 std::list<int64_t> tmp; | |
2055 transaction.GetChildrenInternalId(tmp, resource); | |
2056 for (std::list<int64_t>::const_iterator | |
2057 it = tmp.begin(); it != tmp.end(); ++it) | |
2058 { | |
2059 toExplore.push(*it); | |
2060 } | |
2061 } | |
2062 } | |
2063 | |
2064 if (countStudies_ == 0) | |
2065 { | |
2066 countStudies_ = 1; | |
2067 } | |
2068 | |
2069 if (countSeries_ == 0) | |
2070 { | |
2071 countSeries_ = 1; | |
4560 | 2072 } |
2073 } | |
2074 } | |
2075 }; | |
4562 | 2076 |
2077 Operations operations(type, diskSize, uncompressedSize, countStudies, countSeries, | |
2078 countInstances, dicomDiskSize, dicomUncompressedSize, publicId); | |
2079 Apply(operations); | |
2080 } | |
2081 | |
2082 | |
2083 void ServerIndex::LookupIdentifierExact(std::vector<std::string>& result, | |
2084 ResourceType level, | |
2085 const DicomTag& tag, | |
2086 const std::string& value) | |
2087 { | |
2088 assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) || | |
2089 (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) || | |
2090 (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) || | |
2091 (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) || | |
2092 (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID)); | |
4560 | 2093 |
4562 | 2094 result.clear(); |
2095 | |
2096 DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true); | |
2097 | |
2098 std::vector<DatabaseConstraint> query; | |
2099 query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier)); | |
2100 | |
2101 | |
2102 class Operations : public ServerIndex::IReadOnlyOperations | |
2103 { | |
2104 private: | |
2105 std::vector<std::string>& result_; | |
2106 const std::vector<DatabaseConstraint>& query_; | |
2107 ResourceType level_; | |
2108 | |
2109 public: | |
2110 Operations(std::vector<std::string>& result, | |
2111 const std::vector<DatabaseConstraint>& query, | |
2112 ResourceType level) : | |
2113 result_(result), | |
2114 query_(query), | |
2115 level_(level) | |
2116 { | |
2117 } | |
2118 | |
2119 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | |
2120 { | |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
2121 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4562 | 2122 std::list<std::string> tmp; |
2123 transaction.ApplyLookupResources(tmp, NULL, query_, level_, 0); | |
2124 CopyListToVector(result_, tmp); | |
2125 } | |
2126 }; | |
2127 | |
2128 Operations operations(result, query, level); | |
2129 Apply(operations); | |
2130 } | |
2131 | |
2132 | |
2133 bool ServerIndex::LookupGlobalProperty(std::string& value, | |
2134 GlobalProperty property) | |
2135 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2136 class Operations : public ReadOnlyOperationsT3<bool&, std::string&, GlobalProperty> |
4562 | 2137 { |
2138 public: | |
2139 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
2140 const Tuple& tuple) ORTHANC_OVERRIDE | |
2141 { | |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
2142 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2143 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>()); |
4562 | 2144 } |
2145 }; | |
2146 | |
2147 bool found; | |
4560 | 2148 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2149 operations.Apply(*this, found, value, property); |
4562 | 2150 return found; |
2151 } | |
2152 | |
2153 | |
2154 std::string ServerIndex::GetGlobalProperty(GlobalProperty property, | |
2155 const std::string& defaultValue) | |
2156 { | |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2157 std::string s; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2158 if (LookupGlobalProperty(s, property)) |
4562 | 2159 { |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2160 return s; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2161 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2162 else |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2163 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2164 return defaultValue; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2165 } |
4562 | 2166 } |
2167 | |
2168 | |
2169 bool ServerIndex::GetMainDicomTags(DicomMap& result, | |
2170 const std::string& publicId, | |
2171 ResourceType expectedType, | |
2172 ResourceType levelOfInterest) | |
2173 { | |
2174 // Yes, the following test could be shortened, but we wish to make it as clear as possible | |
2175 if (!(expectedType == ResourceType_Patient && levelOfInterest == ResourceType_Patient) && | |
2176 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Patient) && | |
2177 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Study) && | |
2178 !(expectedType == ResourceType_Series && levelOfInterest == ResourceType_Series) && | |
2179 !(expectedType == ResourceType_Instance && levelOfInterest == ResourceType_Instance)) | |
2180 { | |
2181 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
2182 } | |
2183 | |
2184 | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2185 class Operations : public ReadOnlyOperationsT5<bool&, DicomMap&, const std::string&, ResourceType, ResourceType> |
4562 | 2186 { |
2187 public: | |
2188 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
2189 const Tuple& tuple) ORTHANC_OVERRIDE | |
2190 { | |
2191 // Lookup for the requested resource | |
2192 int64_t id; | |
2193 ResourceType type; | |
2194 if (!transaction.LookupResource(id, type, tuple.get<2>()) || | |
2195 type != tuple.get<3>()) | |
2196 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2197 tuple.get<0>() = false; |
4562 | 2198 } |
2199 else if (type == ResourceType_Study) | |
2200 { | |
2201 DicomMap tmp; | |
2202 transaction.GetMainDicomTags(tmp, id); | |
2203 | |
2204 switch (tuple.get<4>()) | |
2205 { | |
2206 case ResourceType_Patient: | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2207 tmp.ExtractPatientInformation(tuple.get<1>()); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2208 tuple.get<0>() = true; |
4562 | 2209 break; |
2210 | |
2211 case ResourceType_Study: | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2212 tmp.ExtractStudyInformation(tuple.get<1>()); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2213 tuple.get<0>() = true; |
4562 | 2214 break; |
2215 | |
2216 default: | |
2217 throw OrthancException(ErrorCode_InternalError); | |
2218 } | |
2219 } | |
2220 else | |
2221 { | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2222 transaction.GetMainDicomTags(tuple.get<1>(), id); |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2223 tuple.get<0>() = true; |
4562 | 2224 } |
2225 } | |
2226 }; | |
2227 | |
2228 result.Clear(); | |
2229 | |
2230 bool found; | |
2231 Operations operations; | |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2232 operations.Apply(*this, found, result, publicId, expectedType, levelOfInterest); |
4562 | 2233 return found; |
4560 | 2234 } |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2235 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2236 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2237 bool ServerIndex::GetAllMainDicomTags(DicomMap& result, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2238 const std::string& instancePublicId) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2239 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2240 class Operations : public ReadOnlyOperationsT3<bool&, DicomMap&, const std::string&> |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2241 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2242 public: |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2243 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2244 const Tuple& tuple) ORTHANC_OVERRIDE |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2245 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2246 // Lookup for the requested resource |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2247 int64_t instance; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2248 ResourceType type; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2249 if (!transaction.LookupResource(instance, type, tuple.get<2>()) || |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2250 type != ResourceType_Instance) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2251 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2252 tuple.get<0>() = false; |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2253 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2254 else |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2255 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2256 DicomMap tmp; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2257 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2258 transaction.GetMainDicomTags(tmp, instance); |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2259 tuple.get<1>().Merge(tmp); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2260 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2261 int64_t series; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2262 if (!transaction.LookupParent(series, instance)) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2263 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2264 throw OrthancException(ErrorCode_InternalError); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2265 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2266 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2267 tmp.Clear(); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2268 transaction.GetMainDicomTags(tmp, series); |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2269 tuple.get<1>().Merge(tmp); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2270 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2271 int64_t study; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2272 if (!transaction.LookupParent(study, series)) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2273 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2274 throw OrthancException(ErrorCode_InternalError); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2275 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2276 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2277 tmp.Clear(); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2278 transaction.GetMainDicomTags(tmp, study); |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2279 tuple.get<1>().Merge(tmp); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2280 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2281 #ifndef NDEBUG |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2282 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2283 // Sanity test to check that all the main DICOM tags from the |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2284 // patient level are copied at the study level |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2285 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2286 int64_t patient; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2287 if (!transaction.LookupParent(patient, study)) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2288 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2289 throw OrthancException(ErrorCode_InternalError); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2290 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2291 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2292 tmp.Clear(); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2293 transaction.GetMainDicomTags(tmp, study); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2294 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2295 std::set<DicomTag> patientTags; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2296 tmp.GetTags(patientTags); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2297 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2298 for (std::set<DicomTag>::const_iterator |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2299 it = patientTags.begin(); it != patientTags.end(); ++it) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2300 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2301 assert(tuple.get<1>().HasTag(*it)); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2302 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2303 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2304 #endif |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2305 |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2306 tuple.get<0>() = true; |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2307 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2308 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2309 }; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2310 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2311 result.Clear(); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2312 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2313 bool found; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2314 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2315 operations.Apply(*this, found, result, instancePublicId); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2316 return found; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2317 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2318 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2319 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2320 bool ServerIndex::LookupResourceType(ResourceType& type, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2321 const std::string& publicId) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2322 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2323 class Operations : public ReadOnlyOperationsT3<bool&, ResourceType&, const std::string&> |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2324 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2325 public: |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2326 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2327 const Tuple& tuple) ORTHANC_OVERRIDE |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2328 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
2329 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2330 int64_t id; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2331 tuple.get<0>() = transaction.LookupResource(id, tuple.get<1>(), tuple.get<2>()); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2332 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2333 }; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2334 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2335 bool found; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2336 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2337 operations.Apply(*this, found, type, publicId); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2338 return found; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2339 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2340 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2341 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2342 unsigned int ServerIndex::GetDatabaseVersion() |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2343 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2344 class Operations : public ReadOnlyOperationsT1<unsigned int&> |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2345 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2346 public: |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2347 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2348 const Tuple& tuple) ORTHANC_OVERRIDE |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2349 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
2350 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2351 tuple.get<0>() = transaction.GetDatabaseVersion(); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2352 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2353 }; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2354 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2355 unsigned int version; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2356 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2357 operations.Apply(*this, version); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2358 return version; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2359 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2360 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2361 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2362 bool ServerIndex::LookupParent(std::string& target, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2363 const std::string& publicId, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2364 ResourceType parentType) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2365 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2366 class Operations : public ReadOnlyOperationsT4<bool&, std::string&, const std::string&, ResourceType> |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2367 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2368 public: |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2369 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2370 const Tuple& tuple) ORTHANC_OVERRIDE |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2371 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2372 ResourceType type; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2373 int64_t id; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2374 if (!transaction.LookupResource(id, type, tuple.get<2>())) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2375 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2376 throw OrthancException(ErrorCode_UnknownResource); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2377 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2378 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2379 while (type != tuple.get<3>()) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2380 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2381 int64_t parentId; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2382 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2383 if (type == ResourceType_Patient || // Cannot further go up in hierarchy |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2384 !transaction.LookupParent(parentId, id)) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2385 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2386 tuple.get<0>() = false; |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2387 return; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2388 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2389 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2390 id = parentId; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2391 type = GetParentResourceType(type); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2392 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2393 |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2394 tuple.get<0>() = true; |
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2395 tuple.get<1>() = transaction.GetPublicId(id); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2396 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2397 }; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2398 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2399 bool found; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2400 Operations operations; |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2401 operations.Apply(*this, found, target, publicId, parentType); |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2402 return found; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2403 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2404 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2405 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2406 void ServerIndex::ApplyLookupResources(std::vector<std::string>& resourcesId, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2407 std::vector<std::string>* instancesId, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2408 const DatabaseLookup& lookup, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2409 ResourceType queryLevel, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2410 size_t limit) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2411 { |
4564
5a0adc1c19a9
avoid copy of objects in ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4563
diff
changeset
|
2412 class Operations : public ReadOnlyOperationsT4<bool, const std::vector<DatabaseConstraint>&, ResourceType, size_t> |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2413 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2414 private: |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2415 std::list<std::string> resourcesList_; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2416 std::list<std::string> instancesList_; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2417 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2418 public: |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2419 const std::list<std::string>& GetResourcesList() const |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2420 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2421 return resourcesList_; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2422 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2423 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2424 const std::list<std::string>& GetInstancesList() const |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2425 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2426 return instancesList_; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2427 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2428 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2429 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2430 const Tuple& tuple) ORTHANC_OVERRIDE |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2431 { |
4570
648defffc8cc
new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4569
diff
changeset
|
2432 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
4563
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2433 if (tuple.get<0>()) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2434 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2435 transaction.ApplyLookupResources(resourcesList_, &instancesList_, tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2436 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2437 else |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2438 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2439 transaction.ApplyLookupResources(resourcesList_, NULL, tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2440 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2441 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2442 }; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2443 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2444 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2445 std::vector<DatabaseConstraint> normalized; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2446 NormalizeLookup(normalized, lookup, queryLevel); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2447 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2448 Operations operations; |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2449 operations.Apply(*this, (instancesId != NULL), normalized, queryLevel, limit); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2450 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2451 CopyListToVector(resourcesId, operations.GetResourcesList()); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2452 |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2453 if (instancesId != NULL) |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2454 { |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2455 CopyListToVector(*instancesId, operations.GetInstancesList()); |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2456 } |
bb1c365f9e44
end of refactoring read-only transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4562
diff
changeset
|
2457 } |
4565
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2458 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2459 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2460 bool ServerIndex::DeleteResource(Json::Value& target, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2461 const std::string& uuid, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2462 ResourceType expectedType) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2463 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2464 class Operations : public IReadWriteOperations |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2465 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2466 private: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2467 bool found_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2468 Json::Value& target_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2469 const std::string& uuid_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2470 ResourceType expectedType_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2471 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2472 public: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2473 Operations(Json::Value& target, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2474 const std::string& uuid, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2475 ResourceType expectedType) : |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2476 found_(false), |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2477 target_(target), |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2478 uuid_(uuid), |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2479 expectedType_(expectedType) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2480 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2481 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2482 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2483 bool IsFound() const |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2484 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2485 return found_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2486 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2487 |
4573 | 2488 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4565
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2489 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2490 int64_t id; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2491 ResourceType type; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2492 if (!transaction.LookupResource(id, type, uuid_) || |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2493 expectedType_ != type) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2494 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2495 found_ = false; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2496 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2497 else |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2498 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2499 found_ = true; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2500 transaction.DeleteResource(id); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2501 |
4573 | 2502 if (transaction.GetListener().HasRemainingLevel()) |
4565
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2503 { |
4573 | 2504 ResourceType remainingType = transaction.GetListener().GetRemainingType(); |
2505 const std::string& remainingUuid = transaction.GetListener().GetRemainingPublicId(); | |
4565
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2506 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2507 target_["RemainingAncestor"] = Json::Value(Json::objectValue); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2508 target_["RemainingAncestor"]["Path"] = GetBasePath(remainingType, remainingUuid); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2509 target_["RemainingAncestor"]["Type"] = EnumerationToString(remainingType); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2510 target_["RemainingAncestor"]["ID"] = remainingUuid; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2511 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2512 else |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2513 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2514 target_["RemainingAncestor"] = Json::nullValue; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2515 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2516 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2517 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2518 }; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2519 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2520 Operations operations(target, uuid, expectedType); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2521 Apply(operations); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2522 return operations.IsFound(); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2523 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2524 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2525 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2526 void ServerIndex::LogExportedResource(const std::string& publicId, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2527 const std::string& remoteModality) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2528 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2529 class Operations : public IReadWriteOperations |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2530 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2531 private: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2532 const std::string& publicId_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2533 const std::string& remoteModality_; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2534 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2535 public: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2536 Operations(const std::string& publicId, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2537 const std::string& remoteModality) : |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2538 publicId_(publicId), |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2539 remoteModality_(remoteModality) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2540 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2541 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2542 |
4573 | 2543 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4565
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2544 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2545 int64_t id; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2546 ResourceType type; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2547 if (!transaction.LookupResource(id, type, publicId_)) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2548 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2549 throw OrthancException(ErrorCode_InexistentItem); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2550 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2551 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2552 std::string patientId; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2553 std::string studyInstanceUid; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2554 std::string seriesInstanceUid; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2555 std::string sopInstanceUid; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2556 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2557 int64_t currentId = id; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2558 ResourceType currentType = type; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2559 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2560 // Iteratively go up inside the patient/study/series/instance hierarchy |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2561 bool done = false; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2562 while (!done) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2563 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2564 DicomMap map; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2565 transaction.GetMainDicomTags(map, currentId); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2566 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2567 switch (currentType) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2568 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2569 case ResourceType_Patient: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2570 if (map.HasTag(DICOM_TAG_PATIENT_ID)) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2571 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2572 patientId = map.GetValue(DICOM_TAG_PATIENT_ID).GetContent(); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2573 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2574 done = true; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2575 break; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2576 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2577 case ResourceType_Study: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2578 if (map.HasTag(DICOM_TAG_STUDY_INSTANCE_UID)) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2579 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2580 studyInstanceUid = map.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).GetContent(); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2581 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2582 currentType = ResourceType_Patient; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2583 break; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2584 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2585 case ResourceType_Series: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2586 if (map.HasTag(DICOM_TAG_SERIES_INSTANCE_UID)) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2587 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2588 seriesInstanceUid = map.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).GetContent(); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2589 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2590 currentType = ResourceType_Study; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2591 break; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2592 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2593 case ResourceType_Instance: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2594 if (map.HasTag(DICOM_TAG_SOP_INSTANCE_UID)) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2595 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2596 sopInstanceUid = map.GetValue(DICOM_TAG_SOP_INSTANCE_UID).GetContent(); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2597 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2598 currentType = ResourceType_Series; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2599 break; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2600 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2601 default: |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2602 throw OrthancException(ErrorCode_InternalError); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2603 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2604 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2605 // If we have not reached the Patient level, find the parent of |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2606 // the current resource |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2607 if (!done) |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2608 { |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2609 bool ok = transaction.LookupParent(currentId, currentId); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2610 (void) ok; // Remove warning about unused variable in release builds |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2611 assert(ok); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2612 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2613 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2614 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2615 ExportedResource resource(-1, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2616 type, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2617 publicId_, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2618 remoteModality_, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2619 SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */), |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2620 patientId, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2621 studyInstanceUid, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2622 seriesInstanceUid, |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2623 sopInstanceUid); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2624 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2625 transaction.LogExportedResource(resource); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2626 } |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2627 }; |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2628 |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2629 Operations operations(publicId, remoteModality); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2630 Apply(operations); |
3495a3d97ab6
start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4564
diff
changeset
|
2631 } |
4567 | 2632 |
2633 | |
2634 void ServerIndex::SetProtectedPatient(const std::string& publicId, | |
2635 bool isProtected) | |
2636 { | |
2637 class Operations : public IReadWriteOperations | |
2638 { | |
2639 private: | |
2640 const std::string& publicId_; | |
2641 bool isProtected_; | |
2642 | |
2643 public: | |
2644 Operations(const std::string& publicId, | |
2645 bool isProtected) : | |
2646 publicId_(publicId), | |
2647 isProtected_(isProtected) | |
2648 { | |
2649 } | |
2650 | |
4573 | 2651 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2652 { |
2653 // Lookup for the requested resource | |
2654 int64_t id; | |
2655 ResourceType type; | |
2656 if (!transaction.LookupResource(id, type, publicId_) || | |
2657 type != ResourceType_Patient) | |
2658 { | |
2659 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
2660 } | |
2661 else | |
2662 { | |
2663 transaction.SetProtectedPatient(id, isProtected_); | |
2664 } | |
2665 } | |
2666 }; | |
2667 | |
2668 Operations operations(publicId, isProtected); | |
2669 Apply(operations); | |
2670 | |
2671 if (isProtected) | |
2672 { | |
2673 LOG(INFO) << "Patient " << publicId << " has been protected"; | |
2674 } | |
2675 else | |
2676 { | |
2677 LOG(INFO) << "Patient " << publicId << " has been unprotected"; | |
2678 } | |
2679 } | |
2680 | |
2681 | |
2682 void ServerIndex::SetMetadata(const std::string& publicId, | |
2683 MetadataType type, | |
2684 const std::string& value) | |
2685 { | |
2686 class Operations : public IReadWriteOperations | |
2687 { | |
2688 private: | |
2689 const std::string& publicId_; | |
2690 MetadataType type_; | |
2691 const std::string& value_; | |
2692 | |
2693 public: | |
2694 Operations(const std::string& publicId, | |
2695 MetadataType type, | |
2696 const std::string& value) : | |
2697 publicId_(publicId), | |
2698 type_(type), | |
2699 value_(value) | |
2700 { | |
2701 } | |
2702 | |
4573 | 2703 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2704 { |
2705 ResourceType rtype; | |
2706 int64_t id; | |
2707 if (!transaction.LookupResource(id, rtype, publicId_)) | |
2708 { | |
2709 throw OrthancException(ErrorCode_UnknownResource); | |
2710 } | |
2711 else | |
2712 { | |
2713 transaction.SetMetadata(id, type_, value_); | |
2714 | |
2715 if (IsUserMetadata(type_)) | |
2716 { | |
2717 transaction.LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId_); | |
2718 } | |
2719 } | |
2720 } | |
2721 }; | |
2722 | |
2723 Operations operations(publicId, type, value); | |
2724 Apply(operations); | |
2725 } | |
2726 | |
2727 | |
2728 void ServerIndex::DeleteMetadata(const std::string& publicId, | |
2729 MetadataType type) | |
2730 { | |
2731 class Operations : public IReadWriteOperations | |
2732 { | |
2733 private: | |
2734 const std::string& publicId_; | |
2735 MetadataType type_; | |
2736 | |
2737 public: | |
2738 Operations(const std::string& publicId, | |
2739 MetadataType type) : | |
2740 publicId_(publicId), | |
2741 type_(type) | |
2742 { | |
2743 } | |
2744 | |
4573 | 2745 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2746 { |
2747 ResourceType rtype; | |
2748 int64_t id; | |
2749 if (!transaction.LookupResource(id, rtype, publicId_)) | |
2750 { | |
2751 throw OrthancException(ErrorCode_UnknownResource); | |
2752 } | |
2753 else | |
2754 { | |
2755 transaction.DeleteMetadata(id, type_); | |
2756 | |
2757 if (IsUserMetadata(type_)) | |
2758 { | |
2759 transaction.LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId_); | |
2760 } | |
2761 } | |
2762 } | |
2763 }; | |
2764 | |
2765 Operations operations(publicId, type); | |
2766 Apply(operations); | |
2767 } | |
2768 | |
2769 | |
2770 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) | |
2771 { | |
2772 class Operations : public IReadWriteOperations | |
2773 { | |
2774 private: | |
2775 uint64_t newValue_; | |
2776 GlobalProperty sequence_; | |
2777 | |
2778 public: | |
4569 | 2779 explicit Operations(GlobalProperty sequence) : |
2780 newValue_(0), // Dummy initialization | |
4567 | 2781 sequence_(sequence) |
2782 { | |
2783 } | |
2784 | |
2785 uint64_t GetNewValue() const | |
2786 { | |
2787 return newValue_; | |
2788 } | |
2789 | |
4573 | 2790 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2791 { |
2792 std::string oldString; | |
2793 | |
2794 if (transaction.LookupGlobalProperty(oldString, sequence_)) | |
2795 { | |
2796 uint64_t oldValue; | |
2797 | |
2798 try | |
2799 { | |
2800 oldValue = boost::lexical_cast<uint64_t>(oldString); | |
2801 } | |
2802 catch (boost::bad_lexical_cast&) | |
2803 { | |
2804 LOG(ERROR) << "Cannot read the global sequence " | |
2805 << boost::lexical_cast<std::string>(sequence_) << ", resetting it"; | |
2806 oldValue = 0; | |
2807 } | |
2808 | |
2809 newValue_ = oldValue + 1; | |
2810 } | |
2811 else | |
2812 { | |
2813 // Initialize the sequence at "1" | |
2814 newValue_ = 1; | |
2815 } | |
2816 | |
2817 transaction.SetGlobalProperty(sequence_, boost::lexical_cast<std::string>(newValue_)); | |
2818 } | |
2819 }; | |
2820 | |
2821 Operations operations(sequence); | |
2822 Apply(operations); | |
4569 | 2823 assert(operations.GetNewValue() != 0); |
4567 | 2824 return operations.GetNewValue(); |
2825 } | |
2826 | |
2827 | |
2828 void ServerIndex::DeleteChanges() | |
2829 { | |
2830 class Operations : public IReadWriteOperations | |
2831 { | |
2832 public: | |
4573 | 2833 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2834 { |
2835 transaction.ClearChanges(); | |
2836 } | |
2837 }; | |
2838 | |
2839 Operations operations; | |
2840 Apply(operations); | |
2841 } | |
2842 | |
2843 | |
2844 void ServerIndex::DeleteExportedResources() | |
2845 { | |
2846 class Operations : public IReadWriteOperations | |
2847 { | |
2848 public: | |
4573 | 2849 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2850 { |
2851 transaction.ClearExportedResources(); | |
2852 } | |
2853 }; | |
2854 | |
2855 Operations operations; | |
2856 Apply(operations); | |
2857 } | |
2858 | |
2859 | |
2860 void ServerIndex::SetGlobalProperty(GlobalProperty property, | |
2861 const std::string& value) | |
2862 { | |
2863 class Operations : public IReadWriteOperations | |
2864 { | |
2865 private: | |
2866 GlobalProperty property_; | |
2867 const std::string& value_; | |
2868 | |
2869 public: | |
2870 Operations(GlobalProperty property, | |
2871 const std::string& value) : | |
2872 property_(property), | |
2873 value_(value) | |
2874 { | |
2875 } | |
2876 | |
4573 | 2877 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4567 | 2878 { |
2879 transaction.SetGlobalProperty(property_, value_); | |
2880 } | |
2881 }; | |
2882 | |
2883 Operations operations(property, value); | |
2884 Apply(operations); | |
2885 } | |
4568 | 2886 |
2887 | |
2888 void ServerIndex::DeleteAttachment(const std::string& publicId, | |
2889 FileContentType type) | |
2890 { | |
2891 class Operations : public IReadWriteOperations | |
2892 { | |
2893 private: | |
2894 const std::string& publicId_; | |
2895 FileContentType type_; | |
2896 | |
2897 public: | |
2898 Operations(const std::string& publicId, | |
2899 FileContentType type) : | |
2900 publicId_(publicId), | |
2901 type_(type) | |
2902 { | |
2903 } | |
2904 | |
4573 | 2905 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4568 | 2906 { |
2907 ResourceType rtype; | |
2908 int64_t id; | |
2909 if (!transaction.LookupResource(id, rtype, publicId_)) | |
2910 { | |
2911 throw OrthancException(ErrorCode_UnknownResource); | |
2912 } | |
2913 else | |
2914 { | |
2915 transaction.DeleteAttachment(id, type_); | |
2916 | |
2917 if (IsUserContentType(type_)) | |
2918 { | |
2919 transaction.LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId_); | |
2920 } | |
2921 } | |
2922 } | |
2923 }; | |
2924 | |
2925 Operations operations(publicId, type); | |
2926 Apply(operations); | |
2927 } | |
2928 | |
2929 | |
2930 void ServerIndex::LogChange(ChangeType changeType, | |
2931 const std::string& publicId) | |
2932 { | |
2933 class Operations : public IReadWriteOperations | |
2934 { | |
2935 private: | |
2936 ChangeType changeType_; | |
2937 const std::string& publicId_; | |
2938 | |
2939 public: | |
2940 Operations(ChangeType changeType, | |
2941 const std::string& publicId) : | |
2942 changeType_(changeType), | |
2943 publicId_(publicId) | |
2944 { | |
2945 } | |
2946 | |
4573 | 2947 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
4568 | 2948 { |
2949 int64_t id; | |
2950 ResourceType type; | |
2951 if (!transaction.LookupResource(id, type, publicId_)) | |
2952 { | |
2953 throw OrthancException(ErrorCode_UnknownResource); | |
2954 } | |
2955 else | |
2956 { | |
2957 transaction.LogChange(id, changeType_, type, publicId_); | |
2958 } | |
2959 } | |
2960 }; | |
2961 | |
2962 Operations operations(changeType, publicId); | |
2963 Apply(operations); | |
2964 } | |
4574 | 2965 |
2966 | |
2967 void ServerIndex::ReconstructInstance(const ParsedDicomFile& dicom) | |
2968 { | |
2969 class Operations : public IReadWriteOperations | |
2970 { | |
2971 private: | |
2972 DicomMap summary_; | |
2973 std::unique_ptr<DicomInstanceHasher> hasher_; | |
2974 bool hasTransferSyntax_; | |
2975 DicomTransferSyntax transferSyntax_; | |
2976 | |
2977 public: | |
2978 Operations(const ParsedDicomFile& dicom) | |
2979 { | |
2980 OrthancConfiguration::DefaultExtractDicomSummary(summary_, dicom); | |
2981 hasher_.reset(new DicomInstanceHasher(summary_)); | |
2982 hasTransferSyntax_ = dicom.LookupTransferSyntax(transferSyntax_); | |
2983 } | |
2984 | |
2985 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE | |
2986 { | |
2987 int64_t patient = -1, study = -1, series = -1, instance = -1; | |
2988 | |
2989 ResourceType type1, type2, type3, type4; | |
2990 if (!transaction.LookupResource(patient, type1, hasher_->HashPatient()) || | |
2991 !transaction.LookupResource(study, type2, hasher_->HashStudy()) || | |
2992 !transaction.LookupResource(series, type3, hasher_->HashSeries()) || | |
2993 !transaction.LookupResource(instance, type4, hasher_->HashInstance()) || | |
2994 type1 != ResourceType_Patient || | |
2995 type2 != ResourceType_Study || | |
2996 type3 != ResourceType_Series || | |
2997 type4 != ResourceType_Instance || | |
2998 patient == -1 || | |
2999 study == -1 || | |
3000 series == -1 || | |
3001 instance == -1) | |
3002 { | |
3003 throw OrthancException(ErrorCode_InternalError); | |
3004 } | |
3005 | |
3006 transaction.ClearMainDicomTags(patient); | |
3007 transaction.ClearMainDicomTags(study); | |
3008 transaction.ClearMainDicomTags(series); | |
3009 transaction.ClearMainDicomTags(instance); | |
3010 | |
3011 { | |
3012 ResourcesContent content; | |
3013 content.AddResource(patient, ResourceType_Patient, summary_); | |
3014 content.AddResource(study, ResourceType_Study, summary_); | |
3015 content.AddResource(series, ResourceType_Series, summary_); | |
3016 content.AddResource(instance, ResourceType_Instance, summary_); | |
3017 transaction.SetResourcesContent(content); | |
3018 } | |
3019 | |
3020 if (hasTransferSyntax_) | |
3021 { | |
3022 transaction.SetMetadata(instance, MetadataType_Instance_TransferSyntax, GetTransferSyntaxUid(transferSyntax_)); | |
3023 } | |
3024 | |
3025 const DicomValue* value; | |
3026 if ((value = summary_.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL && | |
3027 !value->IsNull() && | |
3028 !value->IsBinary()) | |
3029 { | |
3030 transaction.SetMetadata(instance, MetadataType_Instance_SopClassUid, value->GetContent()); | |
3031 } | |
3032 } | |
3033 }; | |
3034 | |
3035 Operations operations(dicom); | |
3036 Apply(operations); | |
3037 } | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3038 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3039 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3040 static bool IsRecyclingNeeded(IDatabaseWrapper& db, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3041 uint64_t maximumStorageSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3042 unsigned int maximumPatients, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3043 uint64_t addedInstanceSize) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3044 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3045 if (maximumStorageSize != 0) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3046 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3047 if (maximumStorageSize < addedInstanceSize) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3048 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3049 throw OrthancException(ErrorCode_FullStorage, "Cannot store an instance of size " + |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3050 boost::lexical_cast<std::string>(addedInstanceSize) + |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3051 " bytes in a storage area limited to " + |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3052 boost::lexical_cast<std::string>(maximumStorageSize)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3053 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3054 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3055 if (db.IsDiskSizeAbove(maximumStorageSize - addedInstanceSize)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3056 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3057 return true; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3058 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3059 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3060 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3061 if (maximumPatients != 0) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3062 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3063 uint64_t patientCount = db.GetResourceCount(ResourceType_Patient); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3064 if (patientCount > maximumPatients) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3065 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3066 return true; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3067 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3068 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3069 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3070 return false; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3071 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3072 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3073 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3074 void ServerIndex::ReadWriteTransaction::Recycle(uint64_t maximumStorageSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3075 unsigned int maximumPatients, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3076 uint64_t addedInstanceSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3077 const std::string& newPatientId) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3078 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3079 // TODO - Performance: Avoid calls to "IsRecyclingNeeded()" |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3080 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3081 if (IsRecyclingNeeded(db_, maximumStorageSize, maximumPatients, addedInstanceSize)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3082 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3083 // Check whether other DICOM instances from this patient are |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3084 // already stored |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3085 int64_t patientToAvoid; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3086 bool hasPatientToAvoid; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3087 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3088 if (newPatientId.empty()) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3089 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3090 hasPatientToAvoid = false; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3091 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3092 else |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3093 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3094 ResourceType type; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3095 hasPatientToAvoid = db_.LookupResource(patientToAvoid, type, newPatientId); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3096 if (type != ResourceType_Patient) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3097 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3098 throw OrthancException(ErrorCode_InternalError); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3099 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3100 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3101 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3102 // Iteratively select patient to remove until there is enough |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3103 // space in the DICOM store |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3104 int64_t patientToRecycle; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3105 while (true) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3106 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3107 // If other instances of this patient are already in the store, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3108 // we must avoid to recycle them |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3109 bool ok = (hasPatientToAvoid ? |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3110 db_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) : |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3111 db_.SelectPatientToRecycle(patientToRecycle)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3112 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3113 if (!ok) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3114 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3115 throw OrthancException(ErrorCode_FullStorage); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3116 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3117 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3118 LOG(TRACE) << "Recycling one patient"; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3119 db_.DeleteResource(patientToRecycle); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3120 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3121 if (!IsRecyclingNeeded(db_, maximumStorageSize, maximumPatients, addedInstanceSize)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3122 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3123 // OK, we're done |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3124 return; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3125 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3126 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3127 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3128 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3129 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3130 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3131 void ServerIndex::StandaloneRecycling(uint64_t maximumStorageSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3132 unsigned int maximumPatientCount) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3133 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3134 class Operations : public IReadWriteOperations |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3135 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3136 private: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3137 uint64_t maximumStorageSize_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3138 unsigned int maximumPatientCount_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3139 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3140 public: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3141 Operations(uint64_t maximumStorageSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3142 unsigned int maximumPatientCount) : |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3143 maximumStorageSize_(maximumStorageSize), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3144 maximumPatientCount_(maximumPatientCount) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3145 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3146 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3147 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3148 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3149 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3150 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, 0, ""); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3151 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3152 }; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3153 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3154 Operations operations(maximumStorageSize, maximumPatientCount); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3155 Apply(operations); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3156 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3157 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3158 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3159 static void SetInstanceMetadata(ResourcesContent& content, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3160 std::map<MetadataType, std::string>& instanceMetadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3161 int64_t instance, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3162 MetadataType metadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3163 const std::string& value) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3164 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3165 content.AddMetadata(instance, metadata, value); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3166 instanceMetadata[metadata] = value; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3167 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3168 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3169 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3170 StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3171 const DicomMap& dicomSummary, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3172 const Attachments& attachments, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3173 const MetadataMap& metadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3174 const DicomInstanceOrigin& origin, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3175 bool overwrite, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3176 bool hasTransferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3177 DicomTransferSyntax transferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3178 bool hasPixelDataOffset, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3179 uint64_t pixelDataOffset) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3180 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3181 class Operations : public IReadWriteOperations |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3182 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3183 private: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3184 StoreStatus storeStatus_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3185 std::map<MetadataType, std::string>& instanceMetadata_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3186 ServerIndex& index_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3187 const DicomMap& dicomSummary_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3188 const Attachments& attachments_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3189 const MetadataMap& metadata_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3190 const DicomInstanceOrigin& origin_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3191 bool overwrite_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3192 bool hasTransferSyntax_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3193 DicomTransferSyntax transferSyntax_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3194 bool hasPixelDataOffset_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3195 uint64_t pixelDataOffset_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3196 uint64_t maximumStorageSize_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3197 unsigned int maximumPatientCount_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3198 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3199 // Auto-computed fields |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3200 bool hasExpectedInstances_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3201 int64_t expectedInstances_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3202 std::string hashPatient_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3203 std::string hashStudy_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3204 std::string hashSeries_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3205 std::string hashInstance_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3206 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3207 public: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3208 Operations(std::map<MetadataType, std::string>& instanceMetadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3209 ServerIndex& index, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3210 const DicomMap& dicomSummary, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3211 const Attachments& attachments, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3212 const MetadataMap& metadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3213 const DicomInstanceOrigin& origin, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3214 bool overwrite, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3215 bool hasTransferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3216 DicomTransferSyntax transferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3217 bool hasPixelDataOffset, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3218 uint64_t pixelDataOffset, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3219 uint64_t maximumStorageSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3220 unsigned int maximumPatientCount) : |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3221 storeStatus_(StoreStatus_Failure), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3222 instanceMetadata_(instanceMetadata), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3223 index_(index), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3224 dicomSummary_(dicomSummary), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3225 attachments_(attachments), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3226 metadata_(metadata), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3227 origin_(origin), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3228 overwrite_(overwrite), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3229 hasTransferSyntax_(hasTransferSyntax), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3230 transferSyntax_(transferSyntax), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3231 hasPixelDataOffset_(hasPixelDataOffset), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3232 pixelDataOffset_(pixelDataOffset), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3233 maximumStorageSize_(maximumStorageSize), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3234 maximumPatientCount_(maximumPatientCount) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3235 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3236 hasExpectedInstances_ = ComputeExpectedNumberOfInstances(expectedInstances_, dicomSummary); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3237 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3238 instanceMetadata_.clear(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3239 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3240 DicomInstanceHasher hasher(dicomSummary); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3241 hashPatient_ = hasher.HashPatient(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3242 hashStudy_ = hasher.HashStudy(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3243 hashSeries_ = hasher.HashSeries(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3244 hashInstance_ = hasher.HashInstance(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3245 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3246 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3247 StoreStatus GetStoreStatus() const |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3248 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3249 return storeStatus_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3250 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3251 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3252 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3253 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3254 try |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3255 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3256 IDatabaseWrapper::CreateInstanceResult status; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3257 int64_t instanceId; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3258 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3259 // Check whether this instance is already stored |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3260 if (!transaction.CreateInstance(status, instanceId, hashPatient_, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3261 hashStudy_, hashSeries_, hashInstance_)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3262 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3263 // The instance already exists |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3264 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3265 if (overwrite_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3266 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3267 // Overwrite the old instance |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3268 LOG(INFO) << "Overwriting instance: " << hashInstance_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3269 transaction.DeleteResource(instanceId); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3270 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3271 // Re-create the instance, now that the old one is removed |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3272 if (!transaction.CreateInstance(status, instanceId, hashPatient_, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3273 hashStudy_, hashSeries_, hashInstance_)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3274 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3275 throw OrthancException(ErrorCode_InternalError); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3276 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3277 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3278 else |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3279 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3280 // Do nothing if the instance already exists and overwriting is disabled |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3281 transaction.GetAllMetadata(instanceMetadata_, instanceId); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3282 storeStatus_ = StoreStatus_AlreadyStored; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3283 return; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3284 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3285 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3286 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3287 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3288 // Warn about the creation of new resources. The order must be |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3289 // from instance to patient. |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3290 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3291 // NB: In theory, could be sped up by grouping the underlying |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3292 // calls to "transaction.LogChange()". However, this would only have an |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3293 // impact when new patient/study/series get created, which |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3294 // occurs far less often that creating new instances. The |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3295 // positive impact looks marginal in practice. |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3296 transaction.LogChange(instanceId, ChangeType_NewInstance, ResourceType_Instance, hashInstance_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3297 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3298 if (status.isNewSeries_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3299 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3300 transaction.LogChange(status.seriesId_, ChangeType_NewSeries, ResourceType_Series, hashSeries_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3301 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3302 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3303 if (status.isNewStudy_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3304 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3305 transaction.LogChange(status.studyId_, ChangeType_NewStudy, ResourceType_Study, hashStudy_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3306 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3307 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3308 if (status.isNewPatient_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3309 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3310 transaction.LogChange(status.patientId_, ChangeType_NewPatient, ResourceType_Patient, hashPatient_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3311 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3312 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3313 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3314 // Ensure there is enough room in the storage for the new instance |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3315 uint64_t instanceSize = 0; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3316 for (Attachments::const_iterator it = attachments_.begin(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3317 it != attachments_.end(); ++it) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3318 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3319 instanceSize += it->GetCompressedSize(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3320 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3321 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3322 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3323 instanceSize, hashPatient_ /* don't consider the current patient for recycling */); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3324 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3325 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3326 // Attach the files to the newly created instance |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3327 for (Attachments::const_iterator it = attachments_.begin(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3328 it != attachments_.end(); ++it) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3329 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3330 transaction.AddAttachment(instanceId, *it); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3331 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3332 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3333 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3334 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3335 ResourcesContent content; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3336 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3337 // Populate the tags of the newly-created resources |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3338 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3339 content.AddResource(instanceId, ResourceType_Instance, dicomSummary_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3340 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3341 if (status.isNewSeries_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3342 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3343 content.AddResource(status.seriesId_, ResourceType_Series, dicomSummary_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3344 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3345 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3346 if (status.isNewStudy_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3347 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3348 content.AddResource(status.studyId_, ResourceType_Study, dicomSummary_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3349 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3350 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3351 if (status.isNewPatient_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3352 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3353 content.AddResource(status.patientId_, ResourceType_Patient, dicomSummary_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3354 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3355 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3356 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3357 // Attach the user-specified metadata |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3358 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3359 for (MetadataMap::const_iterator |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3360 it = metadata_.begin(); it != metadata_.end(); ++it) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3361 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3362 switch (it->first.first) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3363 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3364 case ResourceType_Patient: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3365 content.AddMetadata(status.patientId_, it->first.second, it->second); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3366 break; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3367 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3368 case ResourceType_Study: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3369 content.AddMetadata(status.studyId_, it->first.second, it->second); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3370 break; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3371 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3372 case ResourceType_Series: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3373 content.AddMetadata(status.seriesId_, it->first.second, it->second); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3374 break; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3375 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3376 case ResourceType_Instance: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3377 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3378 it->first.second, it->second); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3379 break; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3380 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3381 default: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3382 throw OrthancException(ErrorCode_ParameterOutOfRange); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3383 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3384 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3385 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3386 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3387 // Attach the auto-computed metadata for the patient/study/series levels |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3388 std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3389 content.AddMetadata(status.seriesId_, MetadataType_LastUpdate, now); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3390 content.AddMetadata(status.studyId_, MetadataType_LastUpdate, now); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3391 content.AddMetadata(status.patientId_, MetadataType_LastUpdate, now); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3392 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3393 if (status.isNewSeries_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3394 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3395 if (hasExpectedInstances_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3396 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3397 content.AddMetadata(status.seriesId_, MetadataType_Series_ExpectedNumberOfInstances, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3398 boost::lexical_cast<std::string>(expectedInstances_)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3399 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3400 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3401 // New in Orthanc 1.9.0 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3402 content.AddMetadata(status.seriesId_, MetadataType_RemoteAet, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3403 origin_.GetRemoteAetC()); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3404 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3405 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3406 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3407 // Attach the auto-computed metadata for the instance level, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3408 // reflecting these additions into the input metadata map |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3409 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3410 MetadataType_Instance_ReceptionDate, now); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3411 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_RemoteAet, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3412 origin_.GetRemoteAetC()); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3413 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_Instance_Origin, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3414 EnumerationToString(origin_.GetRequestOrigin())); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3415 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3416 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3417 if (hasTransferSyntax_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3418 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3419 // New in Orthanc 1.2.0 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3420 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3421 MetadataType_Instance_TransferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3422 GetTransferSyntaxUid(transferSyntax_)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3423 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3424 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3425 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3426 std::string s; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3427 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3428 if (origin_.LookupRemoteIp(s)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3429 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3430 // New in Orthanc 1.4.0 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3431 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3432 MetadataType_Instance_RemoteIp, s); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3433 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3434 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3435 if (origin_.LookupCalledAet(s)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3436 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3437 // New in Orthanc 1.4.0 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3438 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3439 MetadataType_Instance_CalledAet, s); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3440 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3441 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3442 if (origin_.LookupHttpUsername(s)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3443 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3444 // New in Orthanc 1.4.0 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3445 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3446 MetadataType_Instance_HttpUsername, s); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3447 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3448 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3449 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3450 if (hasPixelDataOffset_) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3451 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3452 // New in Orthanc 1.9.1 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3453 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3454 MetadataType_Instance_PixelDataOffset, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3455 boost::lexical_cast<std::string>(pixelDataOffset_)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3456 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3457 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3458 const DicomValue* value; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3459 if ((value = dicomSummary_.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL && |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3460 !value->IsNull() && |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3461 !value->IsBinary()) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3462 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3463 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3464 MetadataType_Instance_SopClassUid, value->GetContent()); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3465 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3466 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3467 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3468 if ((value = dicomSummary_.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3469 (value = dicomSummary_.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3470 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3471 if (!value->IsNull() && |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3472 !value->IsBinary()) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3473 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3474 SetInstanceMetadata(content, instanceMetadata_, instanceId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3475 MetadataType_Instance_IndexInSeries, Toolbox::StripSpaces(value->GetContent())); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3476 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3477 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3478 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3479 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3480 transaction.SetResourcesContent(content); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3481 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3482 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3483 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3484 // Check whether the series of this new instance is now completed |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3485 int64_t expectedNumberOfInstances; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3486 if (ComputeExpectedNumberOfInstances(expectedNumberOfInstances, dicomSummary_)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3487 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3488 SeriesStatus seriesStatus = transaction.GetSeriesStatus(status.seriesId_, expectedNumberOfInstances); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3489 if (seriesStatus == SeriesStatus_Complete) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3490 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3491 transaction.LogChange(status.seriesId_, ChangeType_CompletedSeries, ResourceType_Series, hashSeries_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3492 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3493 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3494 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3495 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3496 // Mark the parent resources of this instance as unstable |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3497 index_.MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3498 index_.MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3499 index_.MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3500 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3501 transaction.GetListener().SignalAttachmentsAdded(instanceSize); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3502 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3503 storeStatus_ = StoreStatus_Success; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3504 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3505 catch (OrthancException& e) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3506 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3507 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3508 storeStatus_ = StoreStatus_Failure; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3509 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3510 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3511 }; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3512 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3513 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3514 std::unique_ptr<Operations> operations; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3515 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3516 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3517 boost::mutex::scoped_lock lock(monitoringMutex_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3518 operations.reset(new Operations(instanceMetadata, *this, dicomSummary, attachments, metadata, origin, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3519 overwrite, hasTransferSyntax, transferSyntax, hasPixelDataOffset, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3520 pixelDataOffset, maximumStorageSize_, maximumPatients_)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3521 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3522 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3523 Apply(*operations); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3524 return operations->GetStoreStatus(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3525 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3526 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3527 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3528 StoreStatus ServerIndex::AddAttachment(const FileInfo& attachment, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3529 const std::string& publicId) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3530 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3531 class Operations : public IReadWriteOperations |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3532 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3533 private: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3534 StoreStatus status_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3535 const FileInfo& attachment_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3536 const std::string& publicId_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3537 uint64_t maximumStorageSize_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3538 unsigned int maximumPatientCount_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3539 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3540 public: |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3541 Operations(const FileInfo& attachment, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3542 const std::string& publicId, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3543 uint64_t maximumStorageSize, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3544 unsigned int maximumPatientCount) : |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3545 status_(StoreStatus_Failure), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3546 attachment_(attachment), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3547 publicId_(publicId), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3548 maximumStorageSize_(maximumStorageSize), |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3549 maximumPatientCount_(maximumPatientCount) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3550 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3551 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3552 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3553 StoreStatus GetStatus() const |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3554 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3555 return status_; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3556 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3557 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3558 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3559 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3560 ResourceType resourceType; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3561 int64_t resourceId; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3562 if (!transaction.LookupResource(resourceId, resourceType, publicId_)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3563 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3564 status_ = StoreStatus_Failure; // Inexistent resource |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3565 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3566 else |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3567 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3568 // Remove possible previous attachment |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3569 transaction.DeleteAttachment(resourceId, attachment_.GetContentType()); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3570 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3571 // Locate the patient of the target resource |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3572 int64_t patientId = resourceId; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3573 for (;;) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3574 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3575 int64_t parent; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3576 if (transaction.LookupParent(parent, patientId)) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3577 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3578 // We have not reached the patient level yet |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3579 patientId = parent; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3580 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3581 else |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3582 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3583 // We have reached the patient level |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3584 break; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3585 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3586 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3587 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3588 // Possibly apply the recycling mechanism while preserving this patient |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3589 assert(transaction.GetResourceType(patientId) == ResourceType_Patient); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3590 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3591 attachment_.GetCompressedSize(), transaction.GetPublicId(patientId)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3592 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3593 transaction.AddAttachment(resourceId, attachment_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3594 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3595 if (IsUserContentType(attachment_.GetContentType())) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3596 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3597 transaction.LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3598 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3599 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3600 transaction.GetListener().SignalAttachmentsAdded(attachment_.GetCompressedSize()); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3601 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3602 status_ = StoreStatus_Success; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3603 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3604 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3605 }; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3606 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3607 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3608 std::unique_ptr<Operations> operations; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3609 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3610 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3611 boost::mutex::scoped_lock lock(monitoringMutex_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3612 operations.reset(new Operations(attachment, publicId, maximumStorageSize_, maximumPatients_)); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3613 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3614 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3615 Apply(*operations); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3616 return operations->GetStatus(); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
3617 } |
0 | 3618 } |