annotate OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 4586:1d96fe7e054e db-changes

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