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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1898
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
11 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
12 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
13 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
16 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
20 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
21 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 108
diff changeset
22 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
34 #include "PrecompiledHeadersServer.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ServerIndex.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
37 #ifndef NOMINMAX
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
38 #define NOMINMAX
6
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
39 #endif
9d483cf71d17 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
40
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
41 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
42 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
43 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
44 #include "../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
62 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
90 explicit FileToRemove(const FileInfo& info) :
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
91 uuid_(info.GetUuid()),
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
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
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
127 explicit Listener(ServerContext& context) :
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1148
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4575
diff changeset
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
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
326 publicId_(publicId),
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4140
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
348 class ServerIndex::MainDicomTagsRegistry : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
349 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
350 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
351 class TagInfo
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
352 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
353 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
354 ResourceType level_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
355 DicomTagType type_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
356
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
357 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
358 TagInfo()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
359 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
360 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
361
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
362 TagInfo(ResourceType level,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
363 DicomTagType type) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
364 level_(level),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
365 type_(type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
366 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
367 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
368
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
369 ResourceType GetLevel() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
370 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
371 return level_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
372 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
373
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
374 DicomTagType GetType() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
375 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
376 return type_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
377 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
378 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
379
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
380 typedef std::map<DicomTag, TagInfo> Registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
381
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
382
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
383 Registry registry_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
384
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
385 void LoadTags(ResourceType level)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
390
3650
e5811a9f8df0 removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
391 ServerToolbox::LoadIdentifiers(tags, size, level);
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
407 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
408 }
3650
e5811a9f8df0 removing DicomMap::LoadMainDicomTags()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
409
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
421 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
422 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
423 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
424
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
425 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
426 MainDicomTagsRegistry()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
427 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
428 LoadTags(ResourceType_Patient);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
429 LoadTags(ResourceType_Study);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
430 LoadTags(ResourceType_Series);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
431 LoadTags(ResourceType_Instance);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
432 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
433
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
434 void LookupTag(ResourceType& level,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
435 DicomTagType& type,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
436 const DicomTag& tag) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
437 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
438 Registry::const_iterator it = registry_.find(tag);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
439
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
440 if (it == registry_.end())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
441 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
442 // Default values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
443 level = ResourceType_Instance;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
444 type = DicomTagType_Generic;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
445 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
446 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
447 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
448 level = it->second.GetLevel();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
449 type = it->second.GetType();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
450 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
451 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
452 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
453
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
465 std::string sleepString;
1102
ce6386b37afd avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
466
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
467 if (that->db_.LookupGlobalProperty(sleepString, GlobalProperty_FlushSleep) &&
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2209
diff changeset
490 Logging::Flush();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2209
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
511 const DicomMap& dicomSummary)
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
512 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
513 try
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
514 {
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
515 const DicomValue* value;
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
516 const DicomValue* value2;
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 646
diff changeset
517
433
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
524 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
530 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
531
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
538 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
544 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
552 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
558 {
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
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
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
562 }
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
563
aa50783f9550 cardiopet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 432
diff changeset
564
1237
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
565
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
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
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
588 {
1238
6c07108ff1e2 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1237
diff changeset
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
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
591 {
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
592 return false;
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
593 }
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
594
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
595 try
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
596 {
1238
6c07108ff1e2 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1237
diff changeset
597 result = boost::lexical_cast<int64_t>(s);
1237
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
598 return true;
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
599 }
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
600 catch (boost::bad_lexical_cast&)
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
601 {
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
602 return false;
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
603 }
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
604 }
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
605
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
606
1297
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
607 void ServerIndex::LogChange(int64_t internalId,
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
608 ChangeType changeType,
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
609 ResourceType resourceType,
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
610 const std::string& publicId)
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
611 {
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
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
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
621 }
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
622
1237
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
623
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
624 bool ServerIndex::IsUnstableResource(int64_t id)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
625 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
626 return unstableResources_.Contains(id);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
627 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
628
1237
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
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
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
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
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
695
1238
6c07108ff1e2 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1237
diff changeset
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
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
700 {
1238
6c07108ff1e2 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1237
diff changeset
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
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
708 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
709 return SeriesStatus_Unknown;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
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
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
713 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
714 // Out-of-range instance index
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
715 return SeriesStatus_Inconsistent;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
716 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
717
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
718 if (instances.find(index) != instances.end())
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
719 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
720 // Twice the same instance index
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
721 return SeriesStatus_Inconsistent;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
722 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
723
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
724 instances.insert(index);
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
725 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
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
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
728 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
729 return SeriesStatus_Complete;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
730 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
731 else
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
732 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
733 return SeriesStatus_Missing;
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
734 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
735 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
736
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
737
4578
710748828b6a simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4577
diff changeset
738 void ServerIndex::ReadOnlyTransaction::MainDicomTagsToJson(Json::Value& target,
710748828b6a simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4577
diff changeset
739 int64_t resourceId,
710748828b6a simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4577
diff changeset
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
710748828b6a simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4577
diff changeset
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
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
765 template <typename T>
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
766 static void FormatLog(Json::Value& target,
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
767 const std::list<T>& log,
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
768 const std::string& name,
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
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
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
773 {
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
774 Json::Value items = Json::arrayValue;
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
775 for (typename std::list<T>::const_iterator
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
776 it = log.begin(); it != log.end(); ++it)
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
777 {
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
778 Json::Value item;
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
779 it->Format(item);
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
780 items.append(item);
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
781 }
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
782
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
783 target = Json::objectValue;
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
784 target[name] = items;
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
785 target["Done"] = done;
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
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
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
800 target["Last"] = static_cast<int>(last);
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
801 }
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
802
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
876 // Ensure that the resource is still existing before logging the change
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
880 {
1177
5b2d8c280ac2 Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1162
diff changeset
881 case ResourceType_Patient:
1237
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
882 that->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId());
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
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
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
886 that->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId());
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
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
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
890 that->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId());
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
891 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
892
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
893 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
894 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
895 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
896
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
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
0f3716b88af7 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1236
diff changeset
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
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
922
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
923
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
926 const DatabaseLookup& source,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
927 ResourceType queryLevel) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
928 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
933
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
934 for (size_t i = 0; i < source.GetConstraintsCount(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
935 {
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
936 ResourceType level;
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
937 DicomTagType type;
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
938
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
939 mainDicomTagsRegistry_->LookupTag(level, type, source.GetConstraint(i).GetTag());
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
940
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
941 if (type == DicomTagType_Identifier ||
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
942 type == DicomTagType_Main)
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
945 if (level == ResourceType_Patient &&
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
946 queryLevel != ResourceType_Patient)
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
947 {
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
948 level = ResourceType_Study;
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
952 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
953 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
954 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1096
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1097
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1098 template <typename T1,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1099 typename T2,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1100 typename T3,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1101 typename T4,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1102 typename T5>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1103 class ReadOnlyOperationsT5 : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1104 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1105 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1106 typedef typename boost::tuple<T1, T2, T3, T4, T5> Tuple;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1108 virtual ~ReadOnlyOperationsT5()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1109 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1110 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1111
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1112 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1113 const Tuple& tuple) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1114
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1121 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1122 const Tuple tuple(t1, t2, t3, t4, t5);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1123 TupleOperationsWrapper<ReadOnlyOperationsT5, Tuple> wrapper(*this, tuple);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1124 index.Apply(wrapper);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1125 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1126 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1127
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1128
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1129 template <typename T1,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1130 typename T2,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1131 typename T3,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1132 typename T4,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1133 typename T5,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1134 typename T6>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1135 class ReadOnlyOperationsT6 : public boost::noncopyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1136 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1137 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1138 typedef typename boost::tuple<T1, T2, T3, T4, T5, T6> Tuple;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1139
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1140 virtual ~ReadOnlyOperationsT6()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1141 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1142 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1143
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1144 virtual void ApplyTuple(ServerIndex::ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1145 const Tuple& tuple) = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1146
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1154 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1155 const Tuple tuple(t1, t2, t3, t4, t5, t6);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1156 TupleOperationsWrapper<ReadOnlyOperationsT6, Tuple> wrapper(*this, tuple);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1157 index.Apply(wrapper);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1158 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4575
diff changeset
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
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
1201 assert(listener_.get() != NULL);
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
1202 ReadWriteTransaction t(db_, *listener_, *this);
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
1203 writeOperations->Apply(t);
4570
648defffc8cc new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4569
diff changeset
1204 }
4576
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4575
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1256
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1257 bool ServerIndex::ExpandResource(Json::Value& target,
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1258 const std::string& publicId,
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1259 ResourceType level)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1262 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1263 private:
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
1264 ServerIndex& index_; // TODO - REMOVE
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1265
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1266 public:
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1267 explicit Operations(ServerIndex& index) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1268 index_(index)
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1269 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1270 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1275 // Lookup for the requested resource
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1276 int64_t internalId; // unused
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1277 ResourceType type;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1278 std::string parent;
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1279 if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1280 type != tuple.get<3>())
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1283 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1284 else
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1288
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1289 // Set information about the parent resource (if it exists)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1290 if (type == ResourceType_Patient)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1291 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1292 if (!parent.empty())
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1293 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1294 throw OrthancException(ErrorCode_DatabasePlugin);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1295 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1296 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1297 else
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1298 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1299 if (parent.empty())
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1300 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1301 throw OrthancException(ErrorCode_DatabasePlugin);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1302 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1303
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1304 switch (type)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1305 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1308 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1309
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1312 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1313
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1316 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1317
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1318 default:
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1319 throw OrthancException(ErrorCode_InternalError);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1320 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1321 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1322
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1323 // List the children resources
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1324 std::list<std::string> children;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1325 transaction.GetChildrenPublicId(children, internalId);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1326
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1327 if (type != ResourceType_Instance)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1328 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1329 Json::Value c = Json::arrayValue;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1330
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1331 for (std::list<std::string>::const_iterator
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1332 it = children.begin(); it != children.end(); ++it)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1333 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1334 c.append(*it);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1335 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1336
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1337 switch (type)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1338 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1341 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1342
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1345 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1346
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1349 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1350
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1351 default:
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1352 throw OrthancException(ErrorCode_InternalError);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1353 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1354 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1355
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1356 // Extract the metadata
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1357 std::map<MetadataType, std::string> metadata;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1358 transaction.GetAllMetadata(metadata, internalId);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1359
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1360 // Set the resource type
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1361 switch (type)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1362 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1365 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1366
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1369 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1370
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1371 case ResourceType_Series:
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1374
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1375 int64_t i;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1376 if (LookupIntegerMetadata(i, metadata, MetadataType_Series_ExpectedNumberOfInstances))
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1380 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1381 else
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1385 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1386
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1387 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1388 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1389
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1390 case ResourceType_Instance:
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1393
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1394 FileInfo attachment;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1395 if (!transaction.LookupAttachment(attachment, internalId, FileContentType_Dicom))
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1396 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1397 throw OrthancException(ErrorCode_InternalError);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1398 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1402
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1403 int64_t i;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1404 if (LookupIntegerMetadata(i, metadata, MetadataType_Instance_IndexInSeries))
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1407 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1408 else
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1411 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1412
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1413 break;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1414 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1415
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1416 default:
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1417 throw OrthancException(ErrorCode_InternalError);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1418 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1419
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1420 // Record the remaining information
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1423
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1424 std::string tmp;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1425
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1426 if (LookupStringMetadata(tmp, metadata, MetadataType_AnonymizedFrom))
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1429 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1430
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1431 if (LookupStringMetadata(tmp, metadata, MetadataType_ModifiedFrom))
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1434 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1435
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1436 if (type == ResourceType_Patient ||
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1437 type == ResourceType_Study ||
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1438 type == ResourceType_Series)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1441
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1442 if (LookupStringMetadata(tmp, metadata, MetadataType_LastUpdate))
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1445 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1446 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1449 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1450 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1451 };
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1452
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1456 return found;
4554
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1457 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1458
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1459
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1460 void ServerIndex::GetAllMetadata(std::map<MetadataType, std::string>& target,
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1461 const std::string& publicId,
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1462 ResourceType level)
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1465 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1469 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1470 ResourceType type;
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1474 {
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1475 throw OrthancException(ErrorCode_UnknownResource);
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1476 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1477 else
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1480 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1481 }
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1482 };
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
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
efd90f778cd2 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4551
diff changeset
1486 }
4555
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1487
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1488
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1489 bool ServerIndex::LookupAttachment(FileInfo& attachment,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1490 const std::string& instancePublicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1491 FileContentType contentType)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1494 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1498 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1499 int64_t internalId;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1500 ResourceType type;
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1501 if (!transaction.LookupResource(internalId, type, tuple.get<2>()))
4555
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1502 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1503 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1509 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1510 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1513 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1514 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1515 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1516
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1520 return found;
4555
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1521 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1522
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1523
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1524 void ServerIndex::GetAllUuids(std::list<std::string>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1525 ResourceType resourceType)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1528 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1535 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1536 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1540 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1541
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1542
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1543 void ServerIndex::GetAllUuids(std::list<std::string>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1544 ResourceType resourceType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1545 size_t since,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1546 size_t limit)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1547 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1548 if (limit == 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1549 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1550 target.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1551 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1552 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1555 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1562 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1563 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1567 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4554
diff changeset
1568 }
4558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1569
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1570
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1571 void ServerIndex::GetGlobalStatistics(/* out */ uint64_t& diskSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1572 /* out */ uint64_t& uncompressedSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1573 /* out */ uint64_t& countPatients,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1574 /* out */ uint64_t& countStudies,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1575 /* out */ uint64_t& countSeries,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1576 /* out */ uint64_t& countInstances)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1579 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1580 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1581 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1582 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1590 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1591 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1592
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1596 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1597
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1598
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1599 void ServerIndex::GetChanges(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1600 int64_t since,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1601 unsigned int maxResults)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1604 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1605 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1606 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1607 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1608 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1609 // NB: In Orthanc <= 1.3.2, a transaction was missing, as
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1610 // "GetLastChange()" involves calls to "GetPublicId()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1611
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1612 std::list<ServerIndexChange> changes;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1613 bool done;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1614 bool hasLast = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1615 int64_t last = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1616
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1617 transaction.GetChanges(changes, done, tuple.get<1>(), tuple.get<2>());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1618 if (changes.empty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1619 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1620 last = transaction.GetLastChangeIndex();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1621 hasLast = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1622 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1625 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1626 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1627
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1630 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1631
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1632
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1633 void ServerIndex::GetLastChange(Json::Value& target)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1636 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1637 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1638 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1639 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1640 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1641 // NB: In Orthanc <= 1.3.2, a transaction was missing, as
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1642 // "GetLastChange()" involves calls to "GetPublicId()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1643
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1644 std::list<ServerIndexChange> changes;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1645 bool hasLast = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1646 int64_t last = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1647
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1648 transaction.GetLastChange(changes);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1649 if (changes.empty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1650 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1651 last = transaction.GetLastChangeIndex();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1652 hasLast = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1653 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1656 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1657 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1658
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1661 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1662
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1663
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1664 void ServerIndex::GetExportedResources(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1665 int64_t since,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1666 unsigned int maxResults)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1669 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1670 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1671 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1672 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1673 {
4570
648defffc8cc new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4569
diff changeset
1674 // TODO - CANDIDATE FOR "TransactionType_Implicit"
4558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1675
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1676 std::list<ExportedResource> exported;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1677 bool done;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1680 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1681 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1682
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1685 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1686
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1687
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1688 void ServerIndex::GetLastExportedResource(Json::Value& target)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1691 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1692 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1693 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1694 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1695 {
4570
648defffc8cc new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4569
diff changeset
1696 // TODO - CANDIDATE FOR "TransactionType_Implicit"
4558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1697
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1698 std::list<ExportedResource> exported;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1701 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1702 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1703
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4557
diff changeset
1706 }
4559
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1707
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1708
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1709 bool ServerIndex::IsProtectedPatient(const std::string& publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1712 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1713 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1714 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1715 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1716 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1717 // Lookup for the requested resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1718 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1719 ResourceType type;
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1720 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
4559
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1721 type != ResourceType_Patient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1722 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1723 throw OrthancException(ErrorCode_ParameterOutOfRange);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1724 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1725 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1728 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1729 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1730 };
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1731
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1732 bool isProtected;
4559
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1735 return isProtected;
4559
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1736 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1737
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1738
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1739 void ServerIndex::GetChildren(std::list<std::string>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1740 const std::string& publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1743 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1744 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1745 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1746 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1747 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1748 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1749 int64_t resource;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1750 if (!transaction.LookupResource(resource, type, tuple.get<1>()))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1751 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1752 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1753 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1754 else if (type == ResourceType_Instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1755 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1756 // An instance cannot have a child
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1757 throw OrthancException(ErrorCode_BadParameterType);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1758 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1759 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1760 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1761 std::list<int64_t> tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1762 transaction.GetChildrenInternalId(tmp, resource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1765
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1766 for (std::list<int64_t>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1767 it = tmp.begin(); it != tmp.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1770 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1771 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1772 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1773 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1774
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1777 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1778
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1779
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1780 void ServerIndex::GetChildInstances(std::list<std::string>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1781 const std::string& publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1784 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1785 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1786 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1787 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1790
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1791 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1792 int64_t top;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1793 if (!transaction.LookupResource(top, type, tuple.get<1>()))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1794 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1795 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1796 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1797 else if (type == ResourceType_Instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1798 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1801 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1802 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1803 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1804 std::stack<int64_t> toExplore;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1805 toExplore.push(top);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1806
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1807 std::list<int64_t> tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1808 while (!toExplore.empty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1809 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1810 // Get the internal ID of the current resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1811 int64_t resource = toExplore.top();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1812 toExplore.pop();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1813
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1814 // TODO - This could be optimized by seeing how many
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1815 // levels "type == transaction.GetResourceType(top)" is
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1816 // above the "instances level"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1817 if (transaction.GetResourceType(resource) == ResourceType_Instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1820 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1821 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1822 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1823 // Tag all the children of this resource as to be explored
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1824 transaction.GetChildrenInternalId(tmp, resource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1825 for (std::list<int64_t>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1826 it = tmp.begin(); it != tmp.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1827 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1828 toExplore.push(*it);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1829 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1830 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1831 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1832 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1833 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1834 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1835
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4558
diff changeset
1838 }
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1839
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1840
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1841 bool ServerIndex::LookupMetadata(std::string& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1842 const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1843 ResourceType expectedType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1844 MetadataType type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1847 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1848 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1849 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1850 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1851 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1852 ResourceType rtype;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1853 int64_t id;
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1854 if (!transaction.LookupResource(id, rtype, tuple.get<2>()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1855 rtype != tuple.get<3>())
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1856 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1857 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1858 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1859 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1862 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1863 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1864 };
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1865
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1866 bool found;
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1869 return found;
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1870 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1871
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1872
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1873 void ServerIndex::ListAvailableAttachments(std::set<FileContentType>& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1874 const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1875 ResourceType expectedType)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1878 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1879 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1880 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1881 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1882 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1883 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1884 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1885 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1886 tuple.get<2>() != type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1887 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1888 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1889 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1890 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1893 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1894 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1895 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1896
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1899 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1901
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1902 bool ServerIndex::LookupParent(std::string& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1903 const std::string& publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1906 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1907 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1908 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1909 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1910 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1911 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1912 int64_t id;
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1913 if (!transaction.LookupResource(id, type, tuple.get<2>()))
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1914 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1915 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1916 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1917 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1918 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1919 int64_t parentId;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
1920 if (transaction.LookupParent(parentId, id))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1924 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1925 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1928 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1929 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1930 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1931 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1932
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1933 bool found;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1936 return found;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1937 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1938
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1939
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1940 void ServerIndex::GetResourceStatistics(/* out */ ResourceType& type,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1941 /* out */ uint64_t& diskSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1942 /* out */ uint64_t& uncompressedSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1943 /* out */ unsigned int& countStudies,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1944 /* out */ unsigned int& countSeries,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1945 /* out */ unsigned int& countInstances,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1946 /* out */ uint64_t& dicomDiskSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1947 /* out */ uint64_t& dicomUncompressedSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1948 const std::string& publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1949 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1950 class Operations : public ServerIndex::IReadOnlyOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1951 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1952 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1953 ResourceType& type_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1954 uint64_t& diskSize_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1955 uint64_t& uncompressedSize_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1956 unsigned int& countStudies_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1957 unsigned int& countSeries_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1958 unsigned int& countInstances_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1959 uint64_t& dicomDiskSize_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1960 uint64_t& dicomUncompressedSize_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1961 const std::string& publicId_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1962
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1963 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1964 explicit Operations(ResourceType& type,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1965 uint64_t& diskSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1966 uint64_t& uncompressedSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1967 unsigned int& countStudies,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1968 unsigned int& countSeries,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1969 unsigned int& countInstances,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1970 uint64_t& dicomDiskSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1971 uint64_t& dicomUncompressedSize,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1972 const std::string& publicId) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1973 type_(type),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1974 diskSize_(diskSize),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1975 uncompressedSize_(uncompressedSize),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1976 countStudies_(countStudies),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1977 countSeries_(countSeries),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1978 countInstances_(countInstances),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1979 dicomDiskSize_(dicomDiskSize),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1980 dicomUncompressedSize_(dicomUncompressedSize),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1981 publicId_(publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1982 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1983 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1984
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1985 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1986 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1987 int64_t top;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1988 if (!transaction.LookupResource(top, type_, publicId_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1989 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1990 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1991 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1992 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1993 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1994 countInstances_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1995 countSeries_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1996 countStudies_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1997 diskSize_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1998 uncompressedSize_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
1999 dicomDiskSize_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2000 dicomUncompressedSize_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2001
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2002 std::stack<int64_t> toExplore;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2003 toExplore.push(top);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2004
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2005 while (!toExplore.empty())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2006 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2007 // Get the internal ID of the current resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2008 int64_t resource = toExplore.top();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2009 toExplore.pop();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2010
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2011 ResourceType thisType = transaction.GetResourceType(resource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2012
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2013 std::set<FileContentType> f;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2014 transaction.ListAvailableAttachments(f, resource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2016 for (std::set<FileContentType>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2017 it = f.begin(); it != f.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2018 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2019 FileInfo attachment;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2020 if (transaction.LookupAttachment(attachment, resource, *it))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2021 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2022 if (attachment.GetContentType() == FileContentType_Dicom)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2023 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2024 dicomDiskSize_ += attachment.GetCompressedSize();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2025 dicomUncompressedSize_ += attachment.GetUncompressedSize();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2026 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2028 diskSize_ += attachment.GetCompressedSize();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2029 uncompressedSize_ += attachment.GetUncompressedSize();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2030 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2031 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2032
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2033 if (thisType == ResourceType_Instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2034 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2035 countInstances_++;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2036 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2037 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2038 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2039 switch (thisType)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2040 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2041 case ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2042 countStudies_++;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2043 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2044
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2045 case ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2046 countSeries_++;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2047 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2048
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2049 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2050 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2051 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2052
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2053 // Tag all the children of this resource as to be explored
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2054 std::list<int64_t> tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2055 transaction.GetChildrenInternalId(tmp, resource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2056 for (std::list<int64_t>::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2057 it = tmp.begin(); it != tmp.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2058 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2059 toExplore.push(*it);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2060 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2061 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2062 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2063
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2064 if (countStudies_ == 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2065 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2066 countStudies_ = 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2067 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2068
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2069 if (countSeries_ == 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2070 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2071 countSeries_ = 1;
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
2072 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
2073 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
2074 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
2075 };
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2076
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2077 Operations operations(type, diskSize, uncompressedSize, countStudies, countSeries,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2078 countInstances, dicomDiskSize, dicomUncompressedSize, publicId);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2079 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2080 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2081
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2082
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2083 void ServerIndex::LookupIdentifierExact(std::vector<std::string>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2084 ResourceType level,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2085 const DicomTag& tag,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2086 const std::string& value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2087 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2088 assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2089 (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2090 (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2091 (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2092 (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID));
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
2093
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2094 result.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2095
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2096 DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2097
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2098 std::vector<DatabaseConstraint> query;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2099 query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2100
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2101
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2102 class Operations : public ServerIndex::IReadOnlyOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2103 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2104 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2105 std::vector<std::string>& result_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2106 const std::vector<DatabaseConstraint>& query_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2107 ResourceType level_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2108
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2109 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2110 Operations(std::vector<std::string>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2111 const std::vector<DatabaseConstraint>& query,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2112 ResourceType level) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2113 result_(result),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2114 query_(query),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2115 level_(level)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2116 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2117 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2118
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2119 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2120 {
4570
648defffc8cc new enum: TransactionType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4569
diff changeset
2121 // TODO - CANDIDATE FOR "TransactionType_Implicit"
4562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2122 std::list<std::string> tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2123 transaction.ApplyLookupResources(tmp, NULL, query_, level_, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2124 CopyListToVector(result_, tmp);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2125 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2126 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2127
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2128 Operations operations(result, query, level);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2129 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2130 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2131
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2132
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2133 bool ServerIndex::LookupGlobalProperty(std::string& value,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2134 GlobalProperty property)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2137 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2138 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2139 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2140 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2144 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2145 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2146
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2147 bool found;
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2150 return found;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2151 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2153
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2154 std::string ServerIndex::GetGlobalProperty(GlobalProperty property,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2155 const std::string& defaultValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2166 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2167
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2168
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2169 bool ServerIndex::GetMainDicomTags(DicomMap& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2170 const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2171 ResourceType expectedType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2172 ResourceType levelOfInterest)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2173 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2174 // Yes, the following test could be shortened, but we wish to make it as clear as possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2175 if (!(expectedType == ResourceType_Patient && levelOfInterest == ResourceType_Patient) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2176 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Patient) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2177 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Study) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2178 !(expectedType == ResourceType_Series && levelOfInterest == ResourceType_Series) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2179 !(expectedType == ResourceType_Instance && levelOfInterest == ResourceType_Instance))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2180 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2181 throw OrthancException(ErrorCode_ParameterOutOfRange);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2182 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2183
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2186 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2187 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2188 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2189 const Tuple& tuple) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2190 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2191 // Lookup for the requested resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2192 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2193 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2194 if (!transaction.LookupResource(id, type, tuple.get<2>()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2195 type != tuple.get<3>())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2198 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2199 else if (type == ResourceType_Study)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2200 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2201 DicomMap tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2202 transaction.GetMainDicomTags(tmp, id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2203
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2204 switch (tuple.get<4>())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2205 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2209 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2210
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2214 break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2215
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2216 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2217 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2218 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2219 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2220 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2224 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2225 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2226 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2227
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2228 result.Clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2229
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2230 bool found;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4561
diff changeset
2233 return found;
4560
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4559
diff changeset
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
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
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
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2502 if (transaction.GetListener().HasRemainingLevel())
4565
3495a3d97ab6 start of read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4564
diff changeset
2503 {
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2504 ResourceType remainingType = transaction.GetListener().GetRemainingType();
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
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
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2632
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2633
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2634 void ServerIndex::SetProtectedPatient(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2635 bool isProtected)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2636 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2637 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2638 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2639 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2640 const std::string& publicId_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2641 bool isProtected_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2642
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2643 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2644 Operations(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2645 bool isProtected) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2646 publicId_(publicId),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2647 isProtected_(isProtected)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2648 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2649 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2650
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2651 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2652 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2653 // Lookup for the requested resource
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2654 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2655 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2656 if (!transaction.LookupResource(id, type, publicId_) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2657 type != ResourceType_Patient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2658 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2659 throw OrthancException(ErrorCode_ParameterOutOfRange);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2660 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2661 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2662 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2663 transaction.SetProtectedPatient(id, isProtected_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2664 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2665 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2666 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2667
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2668 Operations operations(publicId, isProtected);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2669 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2670
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2671 if (isProtected)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2672 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2673 LOG(INFO) << "Patient " << publicId << " has been protected";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2674 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2675 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2676 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2677 LOG(INFO) << "Patient " << publicId << " has been unprotected";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2678 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2679 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2680
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2681
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2682 void ServerIndex::SetMetadata(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2683 MetadataType type,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2684 const std::string& value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2685 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2686 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2687 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2688 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2689 const std::string& publicId_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2690 MetadataType type_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2691 const std::string& value_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2692
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2693 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2694 Operations(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2695 MetadataType type,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2696 const std::string& value) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2697 publicId_(publicId),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2698 type_(type),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2699 value_(value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2700 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2701 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2702
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2703 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2704 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2705 ResourceType rtype;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2706 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2707 if (!transaction.LookupResource(id, rtype, publicId_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2708 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2709 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2710 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2711 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2712 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2713 transaction.SetMetadata(id, type_, value_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2714
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2715 if (IsUserMetadata(type_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2716 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2717 transaction.LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2718 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2719 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2720 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2721 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2722
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2723 Operations operations(publicId, type, value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2724 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2725 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2726
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2727
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2728 void ServerIndex::DeleteMetadata(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2729 MetadataType type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2730 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2731 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2732 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2733 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2734 const std::string& publicId_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2735 MetadataType type_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2736
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2737 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2738 Operations(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2739 MetadataType type) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2740 publicId_(publicId),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2741 type_(type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2742 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2743 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2744
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2745 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2746 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2747 ResourceType rtype;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2748 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2749 if (!transaction.LookupResource(id, rtype, publicId_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2750 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2751 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2752 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2753 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2754 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2755 transaction.DeleteMetadata(id, type_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2756
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2757 if (IsUserMetadata(type_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2758 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2759 transaction.LogChange(id, ChangeType_UpdatedMetadata, rtype, publicId_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2760 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2761 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2762 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2763 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2764
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2765 Operations operations(publicId, type);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2766 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2767 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2768
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2769
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2770 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2771 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2772 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2773 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2774 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2775 uint64_t newValue_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2776 GlobalProperty sequence_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2777
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2778 public:
4569
19ea4ecd6d9a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4568
diff changeset
2779 explicit Operations(GlobalProperty sequence) :
19ea4ecd6d9a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4568
diff changeset
2780 newValue_(0), // Dummy initialization
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2781 sequence_(sequence)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2782 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2783 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2784
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2785 uint64_t GetNewValue() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2786 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2787 return newValue_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2788 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2789
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2790 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2791 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2792 std::string oldString;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2793
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2794 if (transaction.LookupGlobalProperty(oldString, sequence_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2795 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2796 uint64_t oldValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2797
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2798 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2799 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2800 oldValue = boost::lexical_cast<uint64_t>(oldString);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2801 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2802 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2803 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2804 LOG(ERROR) << "Cannot read the global sequence "
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2805 << boost::lexical_cast<std::string>(sequence_) << ", resetting it";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2806 oldValue = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2807 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2808
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2809 newValue_ = oldValue + 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2810 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2811 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2812 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2813 // Initialize the sequence at "1"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2814 newValue_ = 1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2815 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2816
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2817 transaction.SetGlobalProperty(sequence_, boost::lexical_cast<std::string>(newValue_));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2818 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2819 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2820
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2821 Operations operations(sequence);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2822 Apply(operations);
4569
19ea4ecd6d9a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4568
diff changeset
2823 assert(operations.GetNewValue() != 0);
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2824 return operations.GetNewValue();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2825 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2826
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2827
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2828 void ServerIndex::DeleteChanges()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2829 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2830 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2831 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2832 public:
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2833 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2834 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2835 transaction.ClearChanges();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2836 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2837 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2838
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2839 Operations operations;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2840 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2841 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2842
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2843
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2844 void ServerIndex::DeleteExportedResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2845 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2846 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2847 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2848 public:
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2849 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2850 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2851 transaction.ClearExportedResources();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2852 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2853 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2854
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2855 Operations operations;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2856 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2857 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2858
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2859
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2860 void ServerIndex::SetGlobalProperty(GlobalProperty property,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2861 const std::string& value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2862 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2863 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2864 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2865 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2866 GlobalProperty property_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2867 const std::string& value_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2868
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2869 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2870 Operations(GlobalProperty property,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2871 const std::string& value) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2872 property_(property),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2873 value_(value)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2874 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2875 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2876
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2877 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2878 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2879 transaction.SetGlobalProperty(property_, value_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2880 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2881 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2882
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2883 Operations operations(property, value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2884 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4566
diff changeset
2885 }
4568
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2886
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2887
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2888 void ServerIndex::DeleteAttachment(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2889 FileContentType type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2890 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2891 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2892 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2893 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2894 const std::string& publicId_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2895 FileContentType type_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2896
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2897 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2898 Operations(const std::string& publicId,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2899 FileContentType type) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2900 publicId_(publicId),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2901 type_(type)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2902 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2903 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2904
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2905 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4568
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2906 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2907 ResourceType rtype;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2908 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2909 if (!transaction.LookupResource(id, rtype, publicId_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2910 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2911 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2912 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2913 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2914 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2915 transaction.DeleteAttachment(id, type_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2916
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2917 if (IsUserContentType(type_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2918 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2919 transaction.LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2920 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2921 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2922 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2923 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2924
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2925 Operations operations(publicId, type);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2926 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2927 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2928
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2929
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2930 void ServerIndex::LogChange(ChangeType changeType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2931 const std::string& publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2932 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2933 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2934 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2935 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2936 ChangeType changeType_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2937 const std::string& publicId_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2938
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2939 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2940 Operations(ChangeType changeType,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2941 const std::string& publicId) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2942 changeType_(changeType),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2943 publicId_(publicId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2944 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2945 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2946
4573
f6bd5563b5df simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4572
diff changeset
2947 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
4568
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2948 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2949 int64_t id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2950 ResourceType type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2951 if (!transaction.LookupResource(id, type, publicId_))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2952 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2953 throw OrthancException(ErrorCode_UnknownResource);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2954 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2955 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2956 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2957 transaction.LogChange(id, changeType_, type, publicId_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2958 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2959 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2960 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2961
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2962 Operations operations(changeType, publicId);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2963 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4567
diff changeset
2964 }
4574
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2965
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2966
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2967 void ServerIndex::ReconstructInstance(const ParsedDicomFile& dicom)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2968 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2969 class Operations : public IReadWriteOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2970 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2971 private:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2972 DicomMap summary_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2973 std::unique_ptr<DicomInstanceHasher> hasher_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2974 bool hasTransferSyntax_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2975 DicomTransferSyntax transferSyntax_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2976
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2977 public:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2978 Operations(const ParsedDicomFile& dicom)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2979 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2980 OrthancConfiguration::DefaultExtractDicomSummary(summary_, dicom);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2981 hasher_.reset(new DicomInstanceHasher(summary_));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2982 hasTransferSyntax_ = dicom.LookupTransferSyntax(transferSyntax_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2983 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2984
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2985 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2986 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2987 int64_t patient = -1, study = -1, series = -1, instance = -1;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2988
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2989 ResourceType type1, type2, type3, type4;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2990 if (!transaction.LookupResource(patient, type1, hasher_->HashPatient()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2991 !transaction.LookupResource(study, type2, hasher_->HashStudy()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2992 !transaction.LookupResource(series, type3, hasher_->HashSeries()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2993 !transaction.LookupResource(instance, type4, hasher_->HashInstance()) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2994 type1 != ResourceType_Patient ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2995 type2 != ResourceType_Study ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2996 type3 != ResourceType_Series ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2997 type4 != ResourceType_Instance ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2998 patient == -1 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
2999 study == -1 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3000 series == -1 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3001 instance == -1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3002 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3003 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3004 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3005
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3006 transaction.ClearMainDicomTags(patient);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3007 transaction.ClearMainDicomTags(study);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3008 transaction.ClearMainDicomTags(series);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3009 transaction.ClearMainDicomTags(instance);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3010
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3011 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3012 ResourcesContent content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3013 content.AddResource(patient, ResourceType_Patient, summary_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3014 content.AddResource(study, ResourceType_Study, summary_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3015 content.AddResource(series, ResourceType_Series, summary_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3016 content.AddResource(instance, ResourceType_Instance, summary_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3017 transaction.SetResourcesContent(content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3018 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3020 if (hasTransferSyntax_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3021 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3022 transaction.SetMetadata(instance, MetadataType_Instance_TransferSyntax, GetTransferSyntaxUid(transferSyntax_));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3023 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3025 const DicomValue* value;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3026 if ((value = summary_.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3027 !value->IsNull() &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3028 !value->IsBinary())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3029 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3030 transaction.SetMetadata(instance, MetadataType_Instance_SopClassUid, value->GetContent());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3031 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3032 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3033 };
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3034
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3035 Operations operations(dicom);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
3036 Apply(operations);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4573
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3618 }