annotate OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5042:120945ce48b6

fix
author Alain Mazy <am@osimis.io>
date Mon, 27 Jun 2022 14:09:17 +0200
parents 28db9663fc2d
children ec5c203a97ea
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
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * License, or (at your option) any later version.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * 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
16 * General Public License for more details.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * 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
19 * 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
20 **/
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeadersServer.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "StatelessDatabaseOperations.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #ifndef NOMINMAX
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #define NOMINMAX
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "../../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../../../OrthancFramework/Sources/Logging.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "../../../OrthancFramework/Sources/OrthancException.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../OrthancConfiguration.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../Search/DatabaseLookup.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../ServerIndexChange.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../ServerToolbox.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "ResourcesContent.h"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <boost/lexical_cast.hpp>
4633
37357df3dc27 fix mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4627
diff changeset
41 #include <boost/thread.hpp>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <boost/tuple/tuple.hpp>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <stack>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Orthanc
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
48 // copy all tags from Json (used to read from metadata)
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
49 void DicomSequencesMap::Deserialize(const Json::Value& serialized)
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
50 {
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
51 Json::Value::Members members = serialized.getMemberNames();
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
52 for (size_t i = 0; i < members.size(); i++)
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
53 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
54 DicomTag tag = FromDcmtkBridge::ParseTag(members[i].c_str());
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
55 sequences_[tag] = serialized[members[i]];
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
56 }
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
57 }
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
58
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
59 // serialize a subet of tags (used to store in the metadata)
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
60 void DicomSequencesMap::Serialize(Json::Value& target, const std::set<DicomTag>& tags) const
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
61 {
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
62 // add the sequences to "target"
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
63 for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin();
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
64 it != sequences_.end(); ++it)
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
65 {
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
66 if (tags.find(it->first) != tags.end())
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
67 {
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
68 target[it->first.Format()] = it->second;
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
69 }
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
70 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
71 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
72
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
73 // copy a subset of tags from Json
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
74 void DicomSequencesMap::FromDicomAsJson(const Json::Value& dicomAsJson, const std::set<DicomTag>& tags)
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
75 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
76 for (std::set<DicomTag>::const_iterator it = tags.begin();
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
77 it != tags.end(); ++it)
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
78 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
79 std::string tag = it->Format();
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
80 if (dicomAsJson.isMember(tag))
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
81 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
82 sequences_[*it] = dicomAsJson[tag];
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
83 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
84 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
85 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
86
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
87 void DicomSequencesMap::ToJson(Json::Value& target, DicomToJsonFormat format) const
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
88 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
89 // add the sequences to "target"
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
90 for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin();
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
91 it != sequences_.end(); ++it)
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
92 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
93 Json::Value sequenceForConversion = Json::objectValue;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
94 sequenceForConversion[it->first.Format()] = it->second;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
95
5042
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
96 Json::Value& requestedFormatJson = sequenceForConversion;
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
97 Json::Value convertedJson;
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
98
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
99 if (format != DicomToJsonFormat_Full)
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
100 {
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
101 Toolbox::SimplifyDicomAsJson(convertedJson, sequenceForConversion, format);
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
102 requestedFormatJson = convertedJson;
Alain Mazy <am@osimis.io>
parents: 5039
diff changeset
103 }
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
104
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
105 Json::Value::Members keys = requestedFormatJson.getMemberNames();
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
106 for (size_t i = 0; i < keys.size(); i++) // there should always be only one member in this JSON
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
107 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
108 target[keys[i]] = requestedFormatJson[keys[i]];
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
109 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
110 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
111 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
112
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 namespace
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 /**
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 * 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
117 * of the internal classes.
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 **/
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 template <typename Operations,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 typename Tuple>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 class TupleOperationsWrapper : public StatelessDatabaseOperations::IReadOnlyOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 protected:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 Operations& operations_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 const Tuple& tuple_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 TupleOperationsWrapper(Operations& operations,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 const Tuple& tuple) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 operations_(operations),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 tuple_(tuple)
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 virtual void Apply(StatelessDatabaseOperations::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 operations_.ApplyTuple(transaction, tuple_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 template <typename T1>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 class ReadOnlyOperationsT1 : public boost::noncopyable
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 typedef typename boost::tuple<T1> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 virtual ~ReadOnlyOperationsT1()
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 const Tuple& tuple) = 0;
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 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 T1 t1)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 const Tuple tuple(t1);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 TupleOperationsWrapper<ReadOnlyOperationsT1, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 index.Apply(wrapper);
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 typename T2>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 class ReadOnlyOperationsT2 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 typedef typename boost::tuple<T1, T2> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 virtual ~ReadOnlyOperationsT2()
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 T2 t2)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 const Tuple tuple(t1, t2);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 TupleOperationsWrapper<ReadOnlyOperationsT2, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
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 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 typename T3>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 class ReadOnlyOperationsT3 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 typedef typename boost::tuple<T1, T2, T3> Tuple;
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 virtual ~ReadOnlyOperationsT3()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 const Tuple& tuple) = 0;
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 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 T3 t3)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 const Tuple tuple(t1, t2, t3);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 TupleOperationsWrapper<ReadOnlyOperationsT3, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 typename T3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 typename T4>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 class ReadOnlyOperationsT4 : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 typedef typename boost::tuple<T1, T2, T3, T4> Tuple;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 virtual ~ReadOnlyOperationsT4()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
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 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 const Tuple& tuple) = 0;
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 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 T3 t3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 T4 t4)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 const Tuple tuple(t1, t2, t3, t4);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 TupleOperationsWrapper<ReadOnlyOperationsT4, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 typename T3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 typename T4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 typename T5>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 class ReadOnlyOperationsT5 : public boost::noncopyable
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 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
256
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 virtual ~ReadOnlyOperationsT5()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 const Tuple& tuple) = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 T3 t3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 T4 t4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 T5 t5)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 const Tuple tuple(t1, t2, t3, t4, t5);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 TupleOperationsWrapper<ReadOnlyOperationsT5, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 index.Apply(wrapper);
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 template <typename T1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 typename T2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 typename T3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 typename T4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 typename T5,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 typename T6>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 class ReadOnlyOperationsT6 : public boost::noncopyable
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 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
288
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 virtual ~ReadOnlyOperationsT6()
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 virtual void ApplyTuple(StatelessDatabaseOperations::ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 const Tuple& tuple) = 0;
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 void Apply(StatelessDatabaseOperations& index,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 T1 t1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 T2 t2,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 T3 t3,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 T4 t4,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 T5 t5,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 T6 t6)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 const Tuple tuple(t1, t2, t3, t4, t5, t6);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 TupleOperationsWrapper<ReadOnlyOperationsT6, Tuple> wrapper(*this, tuple);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 index.Apply(wrapper);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
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 template <typename T>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 static void FormatLog(Json::Value& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 const std::list<T>& log,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 const std::string& name,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 bool done,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 int64_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 bool hasLast,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 int64_t last)
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 Json::Value items = Json::arrayValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 for (typename std::list<T>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 it = log.begin(); it != log.end(); ++it)
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 Json::Value item;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 it->Format(item);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 items.append(item);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 target = Json::objectValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 target[name] = items;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 target["Done"] = done;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 if (!hasLast)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 // 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
337 if (log.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 last = since;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 else
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 last = log.back().GetSeq();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
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 target["Last"] = static_cast<int>(last);
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
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 static void CopyListToVector(std::vector<std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 const std::list<std::string>& source)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 target.resize(source.size());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 size_t pos = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 for (std::list<std::string>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 it = source.begin(); it != source.end(); ++it)
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 target[pos] = *it;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 pos ++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 class StatelessDatabaseOperations::MainDicomTagsRegistry : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 class TagInfo
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 ResourceType level_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 DicomTagType type_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 TagInfo()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
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 TagInfo(ResourceType level,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 DicomTagType type) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 level_(level),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 type_(type)
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 ResourceType GetLevel() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 return level_;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 DicomTagType GetType() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 return type_;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 typedef std::map<DicomTag, TagInfo> Registry;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
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 registry_;
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 void LoadTags(ResourceType level)
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 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 const DicomTag* tags = NULL;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 size_t size;
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 ServerToolbox::LoadIdentifiers(tags, size, level);
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 for (size_t i = 0; i < size; i++)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 if (registry_.find(tags[i]) == registry_.end())
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 registry_[tags[i]] = TagInfo(level, DicomTagType_Identifier);
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 // 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
421 assert(level == ResourceType_Study &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 (tags[i] == DICOM_TAG_PATIENT_ID ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 tags[i] == DICOM_TAG_PATIENT_NAME ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 tags[i] == DICOM_TAG_PATIENT_BIRTH_DATE));
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 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 {
4932
b7ce2bb6b881 refactored the list of MainDicomTags to be able to change it dynamicaly. Unit tests and Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4892
diff changeset
430 const std::set<DicomTag>& tags = DicomMap::GetMainDicomTags(level);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 for (std::set<DicomTag>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 tag = tags.begin(); tag != tags.end(); ++tag)
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 if (registry_.find(*tag) == registry_.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 registry_[*tag] = TagInfo(level, DicomTagType_Main);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 }
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 }
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 MainDicomTagsRegistry()
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 LoadTags(ResourceType_Patient);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 LoadTags(ResourceType_Study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 LoadTags(ResourceType_Series);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 LoadTags(ResourceType_Instance);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 }
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 void LookupTag(ResourceType& level,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 DicomTagType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 const DicomTag& tag) const
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 Registry::const_iterator it = registry_.find(tag);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 if (it == registry_.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 // Default values
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 level = ResourceType_Instance;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 type = DicomTagType_Generic;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 level = it->second.GetLevel();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 type = it->second.GetType();
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 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 void StatelessDatabaseOperations::ReadWriteTransaction::LogChange(int64_t internalId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 ChangeType changeType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 ResourceType resourceType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 const std::string& publicId)
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 ServerIndexChange change(changeType, resourceType, publicId);
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 if (changeType <= ChangeType_INTERNAL_LastLogged)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 {
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
482 transaction_.LogChange(internalId, change);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 GetTransactionContext().SignalChange(change);
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
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 SeriesStatus StatelessDatabaseOperations::ReadOnlyTransaction::GetSeriesStatus(int64_t id,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 int64_t expectedNumberOfInstances)
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 std::list<std::string> values;
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
493 transaction_.GetChildrenMetadata(values, id, MetadataType_Instance_IndexInSeries);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 std::set<int64_t> instances;
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 for (std::list<std::string>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 it = values.begin(); it != values.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 int64_t index;
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 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 index = boost::lexical_cast<int64_t>(*it);
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 catch (boost::bad_lexical_cast&)
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 return SeriesStatus_Unknown;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
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 if (!(index > 0 && index <= expectedNumberOfInstances))
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 // Out-of-range instance index
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 return SeriesStatus_Inconsistent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
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 if (instances.find(index) != instances.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 // Twice the same instance index
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 return SeriesStatus_Inconsistent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }
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 instances.insert(index);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 if (static_cast<int64_t>(instances.size()) == expectedNumberOfInstances)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 return SeriesStatus_Complete;
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 return SeriesStatus_Missing;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 void StatelessDatabaseOperations::NormalizeLookup(std::vector<DatabaseConstraint>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 const DatabaseLookup& source,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 ResourceType queryLevel) const
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 assert(mainDicomTagsRegistry_.get() != NULL);
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 target.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 target.reserve(source.GetConstraintsCount());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 for (size_t i = 0; i < source.GetConstraintsCount(); i++)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 ResourceType level;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 DicomTagType type;
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 mainDicomTagsRegistry_->LookupTag(level, type, source.GetConstraint(i).GetTag());
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 if (type == DicomTagType_Identifier ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 type == DicomTagType_Main)
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 // 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
557 if (level == ResourceType_Patient &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 queryLevel != ResourceType_Patient)
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 level = ResourceType_Study;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 target.push_back(source.GetConstraint(i).ConvertToDatabaseConstraint(level, type));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 }
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 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 class StatelessDatabaseOperations::Transaction : public boost::noncopyable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 IDatabaseWrapper& db_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 std::unique_ptr<ITransactionContext> context_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 bool isCommitted_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 Transaction(IDatabaseWrapper& db,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 ITransactionContextFactory& factory,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 TransactionType type) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 db_(db),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 isCommitted_(false)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 context_.reset(factory.Create());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 if (context_.get() == NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 throw OrthancException(ErrorCode_NullPointer);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589
4589
bec74e29f86b attaching the listener to transactions in IDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4587
diff changeset
590 transaction_.reset(db_.StartTransaction(type, *context_));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 if (transaction_.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_NullPointer);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 ~Transaction()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 if (!isCommitted_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 try
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 transaction_->Rollback();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 catch (OrthancException& e)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 {
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
607 LOG(INFO) << "Cannot rollback transaction: " << e.What();
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 }
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
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
612 IDatabaseWrapper::ITransaction& GetDatabaseTransaction()
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
613 {
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
614 assert(transaction_.get() != NULL);
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
615 return *transaction_;
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
616 }
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
617
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 void Commit()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 if (isCommitted_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 throw OrthancException(ErrorCode_BadSequenceOfCalls);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 int64_t delta = context_->GetCompressedSizeDelta();
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(delta);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 context_->Commit();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 isCommitted_ = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 ITransactionContext& GetContext() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 assert(context_.get() != NULL);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 return *context_;
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 };
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 void StatelessDatabaseOperations::ApplyInternal(IReadOnlyOperations* readOperations,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 IReadWriteOperations* writeOperations)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
645 boost::shared_lock<boost::shared_mutex> lock(mutex_); // To protect "factory_" and "maxRetries_"
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
646
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 if ((readOperations == NULL && writeOperations == NULL) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 (readOperations != NULL && writeOperations != NULL))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
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 if (factory_.get() == NULL)
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 throw OrthancException(ErrorCode_BadSequenceOfCalls, "No transaction context was provided");
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
658 unsigned int attempt = 0;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 for (;;)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 try
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 if (readOperations != NULL)
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 * 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
668 * in this case. This was OK because of the presence of the
4594
d494b4f1103e removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4591
diff changeset
669 * global mutex that was protecting the database.
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 **/
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 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
673 {
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
674 ReadOnlyTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 readOperations->Apply(t);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 transaction.Commit();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 assert(writeOperations != NULL);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 Transaction transaction(db_, *factory_, TransactionType_ReadWrite);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 {
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
685 ReadWriteTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 writeOperations->Apply(t);
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 transaction.Commit();
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 return; // Success
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 catch (OrthancException& e)
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 if (e.GetErrorCode() == ErrorCode_DatabaseCannotSerialize)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
697 if (attempt >= maxRetries_)
4586
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 throw;
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
703 attempt++;
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
704
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
705 // The "rand()" adds some jitter to de-synchronize writers
4619
fda80844b920 separate db retries by 100ms instead of 50ms to simplify documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4613
diff changeset
706 boost::this_thread::sleep(boost::posix_time::milliseconds(100 * attempt + 5 * (rand() % 10)));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 }
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 else
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 throw;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 StatelessDatabaseOperations::StatelessDatabaseOperations(IDatabaseWrapper& db) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 db_(db),
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
720 mainDicomTagsRegistry_(new MainDicomTagsRegistry),
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
721 hasFlushToDisk_(db.HasFlushToDisk()),
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
722 maxRetries_(0)
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
723 {
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
724 }
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
725
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
726
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
727 void StatelessDatabaseOperations::FlushToDisk()
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 {
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
729 try
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
730 {
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
731 db_.FlushToDisk();
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
732 }
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
733 catch (OrthancException&)
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
734 {
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
735 LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)";
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
736 }
4586
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 void StatelessDatabaseOperations::SetTransactionContextFactory(ITransactionContextFactory* factory)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 {
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
742 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
743
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 if (factory == NULL)
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 throw OrthancException(ErrorCode_NullPointer);
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 else if (factory_.get() != NULL)
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 throw OrthancException(ErrorCode_BadSequenceOfCalls);
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 factory_.reset(factory);
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
4613
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
759 void StatelessDatabaseOperations::SetMaxDatabaseRetries(unsigned int maxRetries)
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
760 {
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
761 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
762 maxRetries_ = maxRetries;
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
763 }
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
764
2684544ff03c maximum number of database retries for writer collisions is now set by the plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4612
diff changeset
765
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 void StatelessDatabaseOperations::Apply(IReadOnlyOperations& operations)
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 ApplyInternal(&operations, NULL);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 void StatelessDatabaseOperations::Apply(IReadWriteOperations& operations)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 ApplyInternal(NULL, &operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 }
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
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
778 bool StatelessDatabaseOperations::ExpandResource(ExpandedResource& target,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 const std::string& publicId,
4697
569d9ef165b1 Added "short", "simplify" and/or "full" options to control the format of DICOM tags wherever possible
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4694
diff changeset
780 ResourceType level,
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
781 const std::set<DicomTag>& requestedTags,
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
782 ExpandResourceDbFlags expandFlags)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
784 class Operations : public ReadOnlyOperationsT6<
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
785 bool&, ExpandedResource&, const std::string&, ResourceType, const std::set<DicomTag>&, ExpandResourceDbFlags>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 static bool LookupStringMetadata(std::string& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 const std::map<MetadataType, std::string>& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 MetadataType type)
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 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
794
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 if (found == metadata.end())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 else
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 result = found->second;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 return true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 static bool LookupIntegerMetadata(int64_t& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 const std::map<MetadataType, std::string>& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 MetadataType type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 std::string s;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 if (!LookupStringMetadata(s, metadata, type))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 try
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 result = boost::lexical_cast<int64_t>(s);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 return true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 catch (boost::bad_lexical_cast&)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 // Lookup for the requested resource
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
834 int64_t internalId;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 std::string parent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 if (!transaction.LookupResourceAndParent(internalId, type, parent, tuple.get<2>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 type != tuple.get<3>())
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 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
844 ExpandedResource& target = tuple.get<1>();
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
845 ExpandResourceDbFlags expandFlags = tuple.get<5>();
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
846
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 // Set information about the parent resource (if it exists)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 if (type == ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 if (!parent.empty())
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 throw OrthancException(ErrorCode_DatabasePlugin);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 if (parent.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 throw OrthancException(ErrorCode_DatabasePlugin);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
862 target.parentId_ = parent;
4586
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
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
865 target.type_ = type;
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
866 target.id_ = tuple.get<2>();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
867
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
868 if (expandFlags & ExpandResourceDbFlags_IncludeChildren)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
870 // List the children resources
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
871 transaction.GetChildrenPublicId(target.childrenIds_, internalId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
872 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
873
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
874 if (expandFlags & ExpandResourceDbFlags_IncludeMetadata)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
875 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
876 // Extract the metadata
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
877 transaction.GetAllMetadata(target.metadata_, internalId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
878
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
879 switch (type)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
881 case ResourceType_Patient:
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
882 case ResourceType_Study:
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
883 break;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
884
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
885 case ResourceType_Series:
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
887 int64_t i;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
888 if (LookupIntegerMetadata(i, target.metadata_, MetadataType_Series_ExpectedNumberOfInstances))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
889 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
890 target.expectedNumberOfInstances_ = static_cast<int>(i);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
891 target.status_ = EnumerationToString(transaction.GetSeriesStatus(internalId, i));
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
892 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
893 else
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
894 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
895 target.expectedNumberOfInstances_ = -1;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
896 target.status_ = EnumerationToString(SeriesStatus_Unknown);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
897 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
898
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
899 break;
4586
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
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
902 case ResourceType_Instance:
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
903 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
904 FileInfo attachment;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
905 int64_t revision; // ignored
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
906 if (!transaction.LookupAttachment(attachment, revision, internalId, FileContentType_Dicom))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
907 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
908 throw OrthancException(ErrorCode_InternalError);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
909 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
910
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
911 target.fileSize_ = static_cast<unsigned int>(attachment.GetUncompressedSize());
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
912 target.fileUuid_ = attachment.GetUuid();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
913
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
914 int64_t i;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
915 if (LookupIntegerMetadata(i, target.metadata_, MetadataType_Instance_IndexInSeries))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
916 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
917 target.indexInSeries_ = static_cast<int>(i);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
918 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
919 else
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
920 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
921 target.indexInSeries_ = -1;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
922 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
923
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
924 break;
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
925 }
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
926
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
927 default:
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
928 throw OrthancException(ErrorCode_InternalError);
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
929 }
4938
f630796a59b1 ExpandResource now able to return computed tags (like ModalitiesInStudies)
Alain Mazy <am@osimis.io>
parents: 4936
diff changeset
930
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
931 // check the main dicom tags list has not changed since the resource was stored
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
932 target.mainDicomTagsSignature_ = DicomMap::GetDefaultMainDicomTagsSignature(type);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
933 LookupStringMetadata(target.mainDicomTagsSignature_, target.metadata_, MetadataType_MainDicomTagsSignature);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
934 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
935
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
936 if (expandFlags & ExpandResourceDbFlags_IncludeMainDicomTags)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
937 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
938 // read all tags from DB
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
939 transaction.GetMainDicomTags(target.tags_, internalId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
940
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
941 // read all main sequences from DB
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
942 std::string serializedSequences;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
943 if (LookupStringMetadata(serializedSequences, target.metadata_, MetadataType_MainDicomSequences))
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
944 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
945 Json::Value jsonMetadata;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
946 Toolbox::ReadJson(jsonMetadata, serializedSequences);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
947
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
948 assert(jsonMetadata["Version"].asInt() == 1);
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
949 target.sequences_.Deserialize(jsonMetadata["Sequences"]);
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
950 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
951
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
952 // check if we have access to all requestedTags or if we must get tags from parents
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
953 const std::set<DicomTag>& requestedTags = tuple.get<4>();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
954
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
955 if (requestedTags.size() > 0)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
956 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
957 std::set<DicomTag> savedMainDicomTags;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
958
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
959 FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, target.mainDicomTagsSignature_);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
960
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
961 // read parent main dicom tags as long as we have not gathered all requested tags
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
962 ResourceType currentLevel = target.type_;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
963 int64_t currentInternalId = internalId;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
964 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
965
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
966 while ((target.missingRequestedTags_.size() > 0)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
967 && currentLevel != ResourceType_Patient)
4938
f630796a59b1 ExpandResource now able to return computed tags (like ModalitiesInStudies)
Alain Mazy <am@osimis.io>
parents: 4936
diff changeset
968 {
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
969 currentLevel = GetParentResourceType(currentLevel);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
970
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
971 int64_t currentParentId;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
972 if (!transaction.LookupParent(currentParentId, currentInternalId))
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
973 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
974 break;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
975 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
976
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
977 std::map<MetadataType, std::string> parentMetadata;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
978 transaction.GetAllMetadata(parentMetadata, currentParentId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
979
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
980 std::string parentMainDicomTagsSignature = DicomMap::GetDefaultMainDicomTagsSignature(currentLevel);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
981 LookupStringMetadata(parentMainDicomTagsSignature, parentMetadata, MetadataType_MainDicomTagsSignature);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
982
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
983 std::set<DicomTag> parentSavedMainDicomTags;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
984 FromDcmtkBridge::ParseListOfTags(parentSavedMainDicomTags, parentMainDicomTagsSignature);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
985
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
986 size_t previousMissingCount = target.missingRequestedTags_.size();
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
987 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
988 Toolbox::GetMissingsFromSet(target.missingRequestedTags_, requestedTags, savedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
989
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
990 // read the parent tags from DB only if it reduces the number of missing tags
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
991 if (target.missingRequestedTags_.size() < previousMissingCount)
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
992 {
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
993 Toolbox::AppendSets(savedMainDicomTags, parentSavedMainDicomTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
994
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
995 DicomMap parentTags;
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
996 transaction.GetMainDicomTags(parentTags, currentParentId);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
997
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
998 target.tags_.Merge(parentTags);
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
999 }
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
1000
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
1001 currentInternalId = currentParentId;
4938
f630796a59b1 ExpandResource now able to return computed tags (like ModalitiesInStudies)
Alain Mazy <am@osimis.io>
parents: 4936
diff changeset
1002 }
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
1003 }
4936
8422e4f99a18 Handling RequestedTags in ExpandResource -> read parent main dicom tags if required. Not yet getting missing tags from file. Integration tests ok
Alain Mazy <am@osimis.io>
parents: 4935
diff changeset
1004 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 std::string tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1008 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_AnonymizedFrom))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1010 target.anonymizedFrom_ = tmp;
4586
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
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1013 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_ModifiedFrom))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1015 target.modifiedFrom_ = tmp;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 if (type == ResourceType_Patient ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 type == ResourceType_Study ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 type == ResourceType_Series)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1022 target.isStable_ = !transaction.GetTransactionContext().IsUnstableResource(internalId);
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1023
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1024 if (LookupStringMetadata(tmp, target.metadata_, MetadataType_LastUpdate))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 {
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1026 target.lastUpdate_ = tmp;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 }
4935
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1029 else
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1030 {
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1031 target.isStable_ = false;
acd3f72e2a21 split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
Alain Mazy <am@osimis.io>
parents: 4934
diff changeset
1032 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 tuple.get<0>() = true;
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 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 Operations operations;
4940
304514ce84ee tools/find + C-Find + list-resources now all using the same code (ExpandResource) to build 'computed tags'
Alain Mazy <am@osimis.io>
parents: 4939
diff changeset
1041 operations.Apply(*this, found, target, publicId, level, requestedTags, expandFlags);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 }
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 void StatelessDatabaseOperations::GetAllMetadata(std::map<MetadataType, std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 ResourceType level)
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 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
1051 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 tuple.get<2>() != type)
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 throw OrthancException(ErrorCode_UnknownResource);
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 else
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 transaction.GetAllMetadata(tuple.get<0>(), id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 operations.Apply(*this, target, publicId, level);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 bool StatelessDatabaseOperations::LookupAttachment(FileInfo& attachment,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1076 int64_t& revision,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 const std::string& instancePublicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 FileContentType contentType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1080 class Operations : public ReadOnlyOperationsT5<bool&, FileInfo&, int64_t&, const std::string&, FileContentType>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 int64_t internalId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087 ResourceType type;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1088 if (!transaction.LookupResource(internalId, type, tuple.get<3>()))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 }
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1092 else if (transaction.LookupAttachment(tuple.get<1>(), tuple.get<2>(), internalId, tuple.get<4>()))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1094 assert(tuple.get<1>().GetContentType() == tuple.get<4>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 tuple.get<0>() = false;
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 Operations operations;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1106 operations.Apply(*this, found, attachment, revision, instancePublicId, contentType);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 ResourceType resourceType)
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 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, ResourceType>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 operations.Apply(*this, target, resourceType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 ResourceType resourceType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 size_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 size_t limit)
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 if (limit == 0)
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 target.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 else
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 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
1142 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 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
1149 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 operations.Apply(*this, target, resourceType, since, limit);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 void StatelessDatabaseOperations::GetGlobalStatistics(/* out */ uint64_t& diskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 /* out */ uint64_t& uncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 /* out */ uint64_t& countPatients,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 /* out */ uint64_t& countStudies,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 /* out */ uint64_t& countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 /* out */ uint64_t& countInstances)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 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
1166 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 const Tuple& tuple) ORTHANC_OVERRIDE
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 tuple.get<0>() = transaction.GetTotalCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 tuple.get<1>() = transaction.GetTotalUncompressedSize();
4595
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1173 tuple.get<2>() = transaction.GetResourcesCount(ResourceType_Patient);
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1174 tuple.get<3>() = transaction.GetResourcesCount(ResourceType_Study);
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1175 tuple.get<4>() = transaction.GetResourcesCount(ResourceType_Series);
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
1176 tuple.get<5>() = transaction.GetResourcesCount(ResourceType_Instance);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181 operations.Apply(*this, diskSize, uncompressedSize, countPatients,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182 countStudies, countSeries, countInstances);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 void StatelessDatabaseOperations::GetChanges(Json::Value& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 int64_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 unsigned int maxResults)
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 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
1191 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 const Tuple& tuple) ORTHANC_OVERRIDE
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 // 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
1197 // "GetLastChange()" involves calls to "GetPublicId()"
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 std::list<ServerIndexChange> changes;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 bool done;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 bool hasLast = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 int64_t last = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 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
1205 if (changes.empty())
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 last = transaction.GetLastChangeIndex();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 hasLast = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 }
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 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
1212 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 operations.Apply(*this, target, since, maxResults);
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
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 void StatelessDatabaseOperations::GetLastChange(Json::Value& target)
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 class Operations : public ReadOnlyOperationsT1<Json::Value&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 // 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
1229 // "GetLastChange()" involves calls to "GetPublicId()"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 std::list<ServerIndexChange> changes;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 bool hasLast = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 int64_t last = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 transaction.GetLastChange(changes);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 if (changes.empty())
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 last = transaction.GetLastChangeIndex();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 hasLast = true;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 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
1243 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 };
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 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 operations.Apply(*this, target);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249
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 void StatelessDatabaseOperations::GetExportedResources(Json::Value& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 int64_t since,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 unsigned int maxResults)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 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
1256 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259 const Tuple& tuple) ORTHANC_OVERRIDE
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 // TODO - CANDIDATE FOR "TransactionType_Implicit"
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 std::list<ExportedResource> exported;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 bool done;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 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
1266 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
1267 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 };
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 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271 operations.Apply(*this, target, since, maxResults);
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
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 void StatelessDatabaseOperations::GetLastExportedResource(Json::Value& target)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277 class Operations : public ReadOnlyOperationsT1<Json::Value&>
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 const Tuple& tuple) ORTHANC_OVERRIDE
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 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 std::list<ExportedResource> exported;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 transaction.GetLastExportedResource(exported);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287 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
1288 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292 operations.Apply(*this, target);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 bool StatelessDatabaseOperations::IsProtectedPatient(const std::string& publicId)
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 class Operations : public ReadOnlyOperationsT2<bool&, const std::string&>
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 const Tuple& tuple) ORTHANC_OVERRIDE
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 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308 type != ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1309 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 throw OrthancException(ErrorCode_ParameterOutOfRange);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 tuple.get<0>() = transaction.IsProtectedPatient(id);
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317 };
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 bool isProtected;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 operations.Apply(*this, isProtected, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 return isProtected;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326 void StatelessDatabaseOperations::GetChildren(std::list<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 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
1330 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 int64_t resource;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 if (!transaction.LookupResource(resource, type, tuple.get<1>()))
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 throw OrthancException(ErrorCode_UnknownResource);
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 else if (type == ResourceType_Instance)
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 // An instance cannot have a child
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 throw OrthancException(ErrorCode_BadParameterType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 else
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 std::list<int64_t> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349 transaction.GetChildrenInternalId(tmp, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 tuple.get<0>().clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 for (std::list<int64_t>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 it = tmp.begin(); it != tmp.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 tuple.get<0>().push_back(transaction.GetPublicId(*it));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363 operations.Apply(*this, result, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 void StatelessDatabaseOperations::GetChildInstances(std::list<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 const std::string& publicId)
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 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
1371 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376 tuple.get<0>().clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 int64_t top;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 if (!transaction.LookupResource(top, type, tuple.get<1>()))
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 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 else if (type == ResourceType_Instance)
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 // 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
1387 tuple.get<0>().push_back(tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 std::stack<int64_t> toExplore;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 toExplore.push(top);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 std::list<int64_t> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395 while (!toExplore.empty())
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 // Get the internal ID of the current resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 int64_t resource = toExplore.top();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 toExplore.pop();
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 // TODO - This could be optimized by seeing how many
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 // levels "type == transaction.GetResourceType(top)" is
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403 // above the "instances level"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 if (transaction.GetResourceType(resource) == ResourceType_Instance)
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 tuple.get<0>().push_back(transaction.GetPublicId(resource));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 else
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 // 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
1411 transaction.GetChildrenInternalId(tmp, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 for (std::list<int64_t>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413 it = tmp.begin(); it != tmp.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1414 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415 toExplore.push(*it);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 }
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424 operations.Apply(*this, result, publicId);
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
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 bool StatelessDatabaseOperations::LookupMetadata(std::string& target,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1429 int64_t& revision,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1430 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1431 ResourceType expectedType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1432 MetadataType type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1433 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1434 class Operations : public ReadOnlyOperationsT6<bool&, std::string&, int64_t&,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1435 const std::string&, ResourceType, MetadataType>
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1436 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1438 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1440 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1441 ResourceType resourceType;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1442 int64_t id;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1443 if (!transaction.LookupResource(id, resourceType, tuple.get<3>()) ||
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1444 resourceType != tuple.get<4>())
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446 throw OrthancException(ErrorCode_UnknownResource);
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1449 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1450 tuple.get<0>() = transaction.LookupMetadata(tuple.get<1>(), tuple.get<2>(), id, tuple.get<5>());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1451 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1454
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 Operations operations;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
1457 operations.Apply(*this, found, target, revision, publicId, expectedType, type);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462 void StatelessDatabaseOperations::ListAvailableAttachments(std::set<FileContentType>& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464 ResourceType expectedType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466 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
1467 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 const Tuple& tuple) ORTHANC_OVERRIDE
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 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474 if (!transaction.LookupResource(id, type, tuple.get<1>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 tuple.get<2>() != type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481 transaction.ListAvailableAttachments(tuple.get<0>(), id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 operations.Apply(*this, target, publicId, expectedType);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1488 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 bool StatelessDatabaseOperations::LookupParent(std::string& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 const std::string& publicId)
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 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
1495 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1498 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 if (!transaction.LookupResource(id, type, tuple.get<2>()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1503 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1504 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508 int64_t parentId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 if (transaction.LookupParent(parentId, id))
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 tuple.get<1>() = transaction.GetPublicId(parentId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 tuple.get<0>() = true;
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 else
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 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 }
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 };
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 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524 operations.Apply(*this, found, target, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529 void StatelessDatabaseOperations::GetResourceStatistics(/* out */ ResourceType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 /* out */ uint64_t& diskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 /* out */ uint64_t& uncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 /* out */ unsigned int& countStudies,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 /* out */ unsigned int& countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 /* out */ unsigned int& countInstances,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 /* out */ uint64_t& dicomDiskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536 /* out */ uint64_t& dicomUncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 const std::string& publicId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 class Operations : public IReadOnlyOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 ResourceType& type_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 uint64_t& diskSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 uint64_t& uncompressedSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 unsigned int& countStudies_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 unsigned int& countSeries_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 unsigned int& countInstances_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548 uint64_t& dicomDiskSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 uint64_t& dicomUncompressedSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 explicit Operations(ResourceType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 uint64_t& diskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 uint64_t& uncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 unsigned int& countStudies,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 unsigned int& countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 unsigned int& countInstances,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559 uint64_t& dicomDiskSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 uint64_t& dicomUncompressedSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 const std::string& publicId) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 type_(type),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 diskSize_(diskSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 uncompressedSize_(uncompressedSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 countStudies_(countStudies),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 countSeries_(countSeries),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 countInstances_(countInstances),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 dicomDiskSize_(dicomDiskSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 dicomUncompressedSize_(dicomUncompressedSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570 publicId_(publicId)
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1574 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1575 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1576 int64_t top;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 if (!transaction.LookupResource(top, type_, publicId_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1578 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 else
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 countInstances_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584 countSeries_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 countStudies_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 diskSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587 uncompressedSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588 dicomDiskSize_ = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1589 dicomUncompressedSize_ = 0;
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 std::stack<int64_t> toExplore;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1592 toExplore.push(top);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1593
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1594 while (!toExplore.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1595 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1596 // Get the internal ID of the current resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1597 int64_t resource = toExplore.top();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1598 toExplore.pop();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1599
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1600 ResourceType thisType = transaction.GetResourceType(resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1601
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 std::set<FileContentType> f;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603 transaction.ListAvailableAttachments(f, resource);
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 for (std::set<FileContentType>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606 it = f.begin(); it != f.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608 FileInfo attachment;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1609 int64_t revision; // ignored
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
1610 if (transaction.LookupAttachment(attachment, revision, resource, *it))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612 if (attachment.GetContentType() == FileContentType_Dicom)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1613 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1614 dicomDiskSize_ += attachment.GetCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1615 dicomUncompressedSize_ += attachment.GetUncompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1616 }
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 diskSize_ += attachment.GetCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1619 uncompressedSize_ += attachment.GetUncompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1620 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1621 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1622
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1623 if (thisType == ResourceType_Instance)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1624 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1625 countInstances_++;
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1628 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1629 switch (thisType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1630 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632 countStudies_++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 break;
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 case ResourceType_Series:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1636 countSeries_++;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1640 break;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643 // 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
1644 std::list<int64_t> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645 transaction.GetChildrenInternalId(tmp, resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 for (std::list<int64_t>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 it = tmp.begin(); it != tmp.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649 toExplore.push(*it);
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1652 }
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 if (countStudies_ == 0)
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 countStudies_ = 1;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1659 if (countSeries_ == 0)
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 countSeries_ = 1;
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667 Operations operations(type, diskSize, uncompressedSize, countStudies, countSeries,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668 countInstances, dicomDiskSize, dicomUncompressedSize, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1669 Apply(operations);
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
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 void StatelessDatabaseOperations::LookupIdentifierExact(std::vector<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1674 ResourceType level,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 const DicomTag& tag,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676 const std::string& value)
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 assert((level == ResourceType_Patient && tag == DICOM_TAG_PATIENT_ID) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679 (level == ResourceType_Study && tag == DICOM_TAG_STUDY_INSTANCE_UID) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680 (level == ResourceType_Study && tag == DICOM_TAG_ACCESSION_NUMBER) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1681 (level == ResourceType_Series && tag == DICOM_TAG_SERIES_INSTANCE_UID) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 (level == ResourceType_Instance && tag == DICOM_TAG_SOP_INSTANCE_UID));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684 result.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1685
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686 DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688 std::vector<DatabaseConstraint> query;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1689 query.push_back(c.ConvertToDatabaseConstraint(level, DicomTagType_Identifier));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690
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 class Operations : public IReadOnlyOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1695 std::vector<std::string>& result_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1696 const std::vector<DatabaseConstraint>& query_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1697 ResourceType level_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1698
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1699 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1700 Operations(std::vector<std::string>& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1701 const std::vector<DatabaseConstraint>& query,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1702 ResourceType level) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1703 result_(result),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1704 query_(query),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1705 level_(level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1706 {
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1709 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1710 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1711 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1712 std::list<std::string> tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1713 transaction.ApplyLookupResources(tmp, NULL, query_, level_, 0);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1714 CopyListToVector(result_, tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1715 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1716 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1717
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1718 Operations operations(result, query, level);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1719 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1720 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1721
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1722
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1723 bool StatelessDatabaseOperations::LookupGlobalProperty(std::string& value,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1724 GlobalProperty property,
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1725 bool shared)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1726 {
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1727 class Operations : public ReadOnlyOperationsT4<bool&, std::string&, GlobalProperty, bool>
4586
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1730 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1731 const Tuple& tuple) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1732 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1733 // TODO - CANDIDATE FOR "TransactionType_Implicit"
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1734 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>(), tuple.get<3>());
4586
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1738 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1739 Operations operations;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1740 operations.Apply(*this, found, value, property, shared);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1741 return found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1742 }
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 std::string StatelessDatabaseOperations::GetGlobalProperty(GlobalProperty property,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1746 bool shared,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1747 const std::string& defaultValue)
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 std::string s;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
1750 if (LookupGlobalProperty(s, property, shared))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1751 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1752 return s;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1753 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1754 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1755 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1756 return defaultValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1757 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1758 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1759
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 bool StatelessDatabaseOperations::GetMainDicomTags(DicomMap& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1762 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1763 ResourceType expectedType,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1764 ResourceType levelOfInterest)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1765 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766 // 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
1767 if (!(expectedType == ResourceType_Patient && levelOfInterest == ResourceType_Patient) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1768 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Patient) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769 !(expectedType == ResourceType_Study && levelOfInterest == ResourceType_Study) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1770 !(expectedType == ResourceType_Series && levelOfInterest == ResourceType_Series) &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1771 !(expectedType == ResourceType_Instance && levelOfInterest == ResourceType_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_ParameterOutOfRange);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1777 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
1778 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1779 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1780 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1781 const Tuple& tuple) ORTHANC_OVERRIDE
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 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1784 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1785 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1786 if (!transaction.LookupResource(id, type, tuple.get<2>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1787 type != tuple.get<3>())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1788 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1789 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1790 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1791 else if (type == ResourceType_Study)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1792 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1793 DicomMap tmp;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1794 transaction.GetMainDicomTags(tmp, id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1795
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1796 switch (tuple.get<4>())
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 case ResourceType_Patient:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1799 tmp.ExtractPatientInformation(tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1800 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1801 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1802
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1803 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1804 tmp.ExtractStudyInformation(tuple.get<1>());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1805 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1806 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1807
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1808 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1809 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1810 }
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1813 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1814 transaction.GetMainDicomTags(tuple.get<1>(), id);
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, publicId, expectedType, levelOfInterest);
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::GetAllMainDicomTags(DicomMap& result,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1830 const std::string& instancePublicId)
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&, DicomMap&, 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 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1839 int64_t instance;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841 if (!transaction.LookupResource(instance, type, tuple.get<2>()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1842 type != ResourceType_Instance)
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 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1845 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1846 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1847 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1848 DicomMap tmp;
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 transaction.GetMainDicomTags(tmp, instance);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1851 tuple.get<1>().Merge(tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1852
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1853 int64_t series;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1854 if (!transaction.LookupParent(series, instance))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1855 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1856 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1857 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1858
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1859 tmp.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1860 transaction.GetMainDicomTags(tmp, series);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1861 tuple.get<1>().Merge(tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1862
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1863 int64_t study;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1864 if (!transaction.LookupParent(study, series))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1865 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1866 throw OrthancException(ErrorCode_InternalError);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1869 tmp.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1870 transaction.GetMainDicomTags(tmp, study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1871 tuple.get<1>().Merge(tmp);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1872
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1873 #ifndef NDEBUG
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 // 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
1876 // patient level are copied at the study level
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 int64_t patient;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1879 if (!transaction.LookupParent(patient, study))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1880 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1881 throw OrthancException(ErrorCode_InternalError);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1884 tmp.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1885 transaction.GetMainDicomTags(tmp, study);
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 std::set<DicomTag> patientTags;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1888 tmp.GetTags(patientTags);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1889
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1890 for (std::set<DicomTag>::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1891 it = patientTags.begin(); it != patientTags.end(); ++it)
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 assert(tuple.get<1>().HasTag(*it));
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1896 #endif
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1897
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1898 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1899 }
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 };
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 result.Clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1904
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1905 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1906 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1907 operations.Apply(*this, found, result, instancePublicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1908 return found;
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
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 bool StatelessDatabaseOperations::LookupResourceType(ResourceType& type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1913 const std::string& publicId)
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 class Operations : public ReadOnlyOperationsT3<bool&, ResourceType&, const std::string&>
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 public:
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 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1923 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
1924 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1927 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1928 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1929 operations.Apply(*this, found, type, publicId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1930 return found;
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 bool StatelessDatabaseOperations::LookupParent(std::string& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1935 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1936 ResourceType parentType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1937 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1938 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
1939 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1940 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1941 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1942 const Tuple& tuple) ORTHANC_OVERRIDE
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 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1945 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1946 if (!transaction.LookupResource(id, type, tuple.get<2>()))
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 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1949 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1950
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1951 while (type != tuple.get<3>())
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 int64_t parentId;
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 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
1956 !transaction.LookupParent(parentId, id))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1957 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1958 tuple.get<0>() = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1959 return;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1962 id = parentId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1963 type = GetParentResourceType(type);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1964 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1965
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1966 tuple.get<0>() = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1967 tuple.get<1>() = transaction.GetPublicId(id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1968 }
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 bool found;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1972 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1973 operations.Apply(*this, found, target, publicId, parentType);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1978 void StatelessDatabaseOperations::ApplyLookupResources(std::vector<std::string>& resourcesId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1979 std::vector<std::string>* instancesId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1980 const DatabaseLookup& lookup,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1981 ResourceType queryLevel,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1982 size_t limit)
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 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
1985 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1986 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1987 std::list<std::string> resourcesList_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1988 std::list<std::string> instancesList_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1989
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1990 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1991 const std::list<std::string>& GetResourcesList() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1992 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1993 return resourcesList_;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1996 const std::list<std::string>& GetInstancesList() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1997 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1998 return instancesList_;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2001 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2002 const Tuple& tuple) ORTHANC_OVERRIDE
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 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2005 if (tuple.get<0>())
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 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
2008 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2009 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2010 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2011 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
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2015
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 std::vector<DatabaseConstraint> normalized;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2018 NormalizeLookup(normalized, lookup, queryLevel);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2019
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2020 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2021 operations.Apply(*this, (instancesId != NULL), normalized, queryLevel, limit);
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 CopyListToVector(resourcesId, operations.GetResourcesList());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2024
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2025 if (instancesId != NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2026 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2027 CopyListToVector(*instancesId, operations.GetInstancesList());
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
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2032 bool StatelessDatabaseOperations::DeleteResource(Json::Value& remainingAncestor,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2033 const std::string& uuid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2034 ResourceType expectedType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2035 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2036 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2037 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2038 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2039 bool found_;
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2040 Json::Value& remainingAncestor_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2041 const std::string& uuid_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2042 ResourceType expectedType_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2043
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2044 public:
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2045 Operations(Json::Value& remainingAncestor,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2046 const std::string& uuid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2047 ResourceType expectedType) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2048 found_(false),
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2049 remainingAncestor_(remainingAncestor),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2050 uuid_(uuid),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2051 expectedType_(expectedType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2052 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2053 }
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 bool IsFound() const
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 return found_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2058 }
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 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
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 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2063 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2064 if (!transaction.LookupResource(id, type, uuid_) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2065 expectedType_ != type)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2066 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2067 found_ = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2068 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2069 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2070 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2071 found_ = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2072 transaction.DeleteResource(id);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2073
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2074 std::string remainingPublicId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2075 ResourceType remainingLevel;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2076 if (transaction.GetTransactionContext().LookupRemainingLevel(remainingPublicId, remainingLevel))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2077 {
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2078 remainingAncestor_["RemainingAncestor"] = Json::Value(Json::objectValue);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2079 remainingAncestor_["RemainingAncestor"]["Path"] = GetBasePath(remainingLevel, remainingPublicId);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2080 remainingAncestor_["RemainingAncestor"]["Type"] = EnumerationToString(remainingLevel);
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2081 remainingAncestor_["RemainingAncestor"]["ID"] = remainingPublicId;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2082 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2083 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2084 {
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2085 remainingAncestor_["RemainingAncestor"] = Json::nullValue;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2086 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2087 }
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2090
4694
da1edb7d6332 "/tools/bulk-delete" to delete a group of multiple, unrelated resources at once
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4640
diff changeset
2091 Operations operations(remainingAncestor, uuid, expectedType);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2092 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2093 return operations.IsFound();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2094 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2095
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 void StatelessDatabaseOperations::LogExportedResource(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2098 const std::string& remoteModality)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2099 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2100 class Operations : public IReadWriteOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2103 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2104 const std::string& remoteModality_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2105
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2106 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2107 Operations(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2108 const std::string& remoteModality) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2109 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2110 remoteModality_(remoteModality)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2111 {
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2114 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
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 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2117 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2118 if (!transaction.LookupResource(id, type, publicId_))
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 throw OrthancException(ErrorCode_InexistentItem);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2123 std::string patientId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2124 std::string studyInstanceUid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2125 std::string seriesInstanceUid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2126 std::string sopInstanceUid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2127
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2128 int64_t currentId = id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2129 ResourceType currentType = type;
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 // 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
2132 bool done = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2133 while (!done)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2134 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2135 DicomMap map;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2136 transaction.GetMainDicomTags(map, currentId);
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 switch (currentType)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2139 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2140 case ResourceType_Patient:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2141 if (map.HasTag(DICOM_TAG_PATIENT_ID))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2142 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2143 patientId = map.GetValue(DICOM_TAG_PATIENT_ID).GetContent();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2144 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2145 done = true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2146 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2147
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2148 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2149 if (map.HasTag(DICOM_TAG_STUDY_INSTANCE_UID))
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 studyInstanceUid = map.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).GetContent();
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 currentType = ResourceType_Patient;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2154 break;
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 case ResourceType_Series:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2157 if (map.HasTag(DICOM_TAG_SERIES_INSTANCE_UID))
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 seriesInstanceUid = map.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).GetContent();
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 currentType = ResourceType_Study;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2162 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2163
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2164 case ResourceType_Instance:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2165 if (map.HasTag(DICOM_TAG_SOP_INSTANCE_UID))
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 sopInstanceUid = map.GetValue(DICOM_TAG_SOP_INSTANCE_UID).GetContent();
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 currentType = ResourceType_Series;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2170 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2171
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2172 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2173 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2174 }
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 // 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
2177 // the current resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2178 if (!done)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2179 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2180 bool ok = transaction.LookupParent(currentId, currentId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2181 (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
2182 assert(ok);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2183 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2184 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2185
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2186 ExportedResource resource(-1,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2187 type,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2188 publicId_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2189 remoteModality_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2190 SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2191 patientId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2192 studyInstanceUid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2193 seriesInstanceUid,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2194 sopInstanceUid);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2195
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2196 transaction.LogExportedResource(resource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2197 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2200 Operations operations(publicId, remoteModality);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2201 Apply(operations);
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
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 void StatelessDatabaseOperations::SetProtectedPatient(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2206 bool isProtected)
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 class Operations : public IReadWriteOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2211 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2212 bool isProtected_;
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2215 Operations(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2216 bool isProtected) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2217 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2218 isProtected_(isProtected)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2219 {
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2222 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2223 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2224 // Lookup for the requested resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2225 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2226 ResourceType type;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2227 if (!transaction.LookupResource(id, type, publicId_) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2228 type != ResourceType_Patient)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2229 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2230 throw OrthancException(ErrorCode_ParameterOutOfRange);
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2233 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2234 transaction.SetProtectedPatient(id, isProtected_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2235 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2236 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2237 };
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 Operations operations(publicId, isProtected);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2240 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2241
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2242 if (isProtected)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2243 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2244 LOG(INFO) << "Patient " << publicId << " has been protected";
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2245 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2246 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2247 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2248 LOG(INFO) << "Patient " << publicId << " has been unprotected";
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
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2253 void StatelessDatabaseOperations::SetMetadata(int64_t& newRevision,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2254 const std::string& publicId,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2255 MetadataType type,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2256 const std::string& value,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2257 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2258 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2259 const std::string& oldMD5)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2260 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2261 class Operations : public IReadWriteOperations
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2262 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2263 private:
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2264 int64_t& newRevision_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2265 const std::string& publicId_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2266 MetadataType type_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2267 const std::string& value_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2268 bool hasOldRevision_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2269 int64_t oldRevision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2270 const std::string& oldMD5_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2271
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2272 public:
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2273 Operations(int64_t& newRevision,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2274 const std::string& publicId,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2275 MetadataType type,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2276 const std::string& value,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2277 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2278 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2279 const std::string& oldMD5) :
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2280 newRevision_(newRevision),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2281 publicId_(publicId),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2282 type_(type),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2283 value_(value),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2284 hasOldRevision_(hasOldRevision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2285 oldRevision_(oldRevision),
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2286 oldMD5_(oldMD5)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2287 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2288 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2289
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2290 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2291 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2292 ResourceType resourceType;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2293 int64_t id;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2294 if (!transaction.LookupResource(id, resourceType, publicId_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2295 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2296 throw OrthancException(ErrorCode_UnknownResource);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2297 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2298 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2299 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2300 std::string oldValue;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2301 int64_t expectedRevision;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2302 if (transaction.LookupMetadata(oldValue, expectedRevision, id, type_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2303 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2304 if (hasOldRevision_)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2305 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2306 std::string expectedMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2307 Toolbox::ComputeMD5(expectedMD5, oldValue);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2308
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2309 if (expectedRevision != oldRevision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2310 expectedMD5 != oldMD5_)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2311 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2312 throw OrthancException(ErrorCode_Revision);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2313 }
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2314 }
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2315
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2316 newRevision_ = expectedRevision + 1;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2317 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2318 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2319 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2320 // The metadata is not existing yet: Ignore "oldRevision"
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2321 // and initialize a new sequence of revisions
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2322 newRevision_ = 0;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2323 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2324
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2325 transaction.SetMetadata(id, type_, value_, newRevision_);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2326
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2327 if (IsUserMetadata(type_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2328 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2329 transaction.LogChange(id, ChangeType_UpdatedMetadata, resourceType, publicId_);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2330 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2331 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2332 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2333 };
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2334
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2335 Operations operations(newRevision, publicId, type, value, hasOldRevision, oldRevision, oldMD5);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2336 Apply(operations);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2337 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2338
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2339
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2340 void StatelessDatabaseOperations::OverwriteMetadata(const std::string& publicId,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2341 MetadataType type,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2342 const std::string& value)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2343 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2344 int64_t newRevision; // Unused
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2345 SetMetadata(newRevision, publicId, type, value, false /* no old revision */, -1 /* dummy */, "" /* dummy */);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2346 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2347
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2348
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2349 bool StatelessDatabaseOperations::DeleteMetadata(const std::string& publicId,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2350 MetadataType type,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2351 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2352 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2353 const std::string& md5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2354 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2355 class Operations : public IReadWriteOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2358 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2359 MetadataType type_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2360 bool hasRevision_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2361 int64_t revision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2362 const std::string& md5_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2363 bool found_;
4586
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2366 Operations(const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2367 MetadataType type,
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2368 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2369 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2370 const std::string& md5) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2371 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2372 type_(type),
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2373 hasRevision_(hasRevision),
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2374 revision_(revision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2375 md5_(md5),
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2376 found_(false)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2377 {
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
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2380 bool HasFound() const
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2381 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2382 return found_;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2383 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2384
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2385 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2386 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2387 ResourceType resourceType;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2388 int64_t id;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2389 if (!transaction.LookupResource(id, resourceType, publicId_))
4586
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 throw OrthancException(ErrorCode_UnknownResource);
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2394 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2395 std::string value;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2396 int64_t expectedRevision;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2397 if (transaction.LookupMetadata(value, expectedRevision, id, type_))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2398 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2399 if (hasRevision_)
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2400 {
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2401 std::string expectedMD5;
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2402 Toolbox::ComputeMD5(expectedMD5, value);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2403
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2404 if (expectedRevision != revision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2405 expectedMD5 != md5_)
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2406 {
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2407 throw OrthancException(ErrorCode_Revision);
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2408 }
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2409 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2410
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2411 found_ = true;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2412 transaction.DeleteMetadata(id, type_);
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2413
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2414 if (IsUserMetadata(type_))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2415 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2416 transaction.LogChange(id, ChangeType_UpdatedMetadata, resourceType, publicId_);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2417 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2418 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2419 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2420 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2421 found_ = false;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2422 }
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2425 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2426
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2427 Operations operations(publicId, type, hasRevision, revision, md5);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2428 Apply(operations);
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2429 return operations.HasFound();
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2430 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2431
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2432
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2433 uint64_t StatelessDatabaseOperations::IncrementGlobalSequence(GlobalProperty sequence,
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2434 bool shared)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2435 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2436 class Operations : public IReadWriteOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2439 uint64_t newValue_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2440 GlobalProperty sequence_;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2441 bool shared_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2442
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2443 public:
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2444 Operations(GlobalProperty sequence,
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2445 bool shared) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2446 newValue_(0), // Dummy initialization
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2447 sequence_(sequence),
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2448 shared_(shared)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2449 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2450 }
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 uint64_t GetNewValue() const
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 return newValue_;
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2457 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
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 std::string oldString;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2460
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2461 if (transaction.LookupGlobalProperty(oldString, sequence_, shared_))
4586
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 uint64_t oldValue;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2464
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2465 try
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 oldValue = boost::lexical_cast<uint64_t>(oldString);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2468 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2469 catch (boost::bad_lexical_cast&)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2470 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2471 LOG(ERROR) << "Cannot read the global sequence "
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2472 << boost::lexical_cast<std::string>(sequence_) << ", resetting it";
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2473 oldValue = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2474 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2475
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2476 newValue_ = oldValue + 1;
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2479 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2480 // Initialize the sequence at "1"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2481 newValue_ = 1;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2482 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2483
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2484 transaction.SetGlobalProperty(sequence_, shared_, boost::lexical_cast<std::string>(newValue_));
4586
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2487
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2488 Operations operations(sequence, shared);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2489 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2490 assert(operations.GetNewValue() != 0);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2491 return operations.GetNewValue();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2492 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2493
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2494
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2495 void StatelessDatabaseOperations::DeleteChanges()
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2496 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2497 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2498 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2499 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2500 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2501 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2502 transaction.ClearChanges();
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 };
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 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2507 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2508 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2509
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2510
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2511 void StatelessDatabaseOperations::DeleteExportedResources()
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 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2514 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2515 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2516 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2517 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2518 transaction.ClearExportedResources();
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2522 Operations operations;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2523 Apply(operations);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2527 void StatelessDatabaseOperations::SetGlobalProperty(GlobalProperty property,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2528 bool shared,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2529 const std::string& value)
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 class Operations : public IReadWriteOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2534 GlobalProperty property_;
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2535 bool shared_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2536 const std::string& value_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2537
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2538 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2539 Operations(GlobalProperty property,
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2540 bool shared,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2541 const std::string& value) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2542 property_(property),
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2543 shared_(shared),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2544 value_(value)
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 }
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 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2549 {
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2550 transaction.SetGlobalProperty(property_, shared_, value_);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2551 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2552 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2553
4607
f75c63aa9de0 differentiating between shared and private global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4602
diff changeset
2554 Operations operations(property, shared, value);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2555 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2556 }
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
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2559 bool StatelessDatabaseOperations::DeleteAttachment(const std::string& publicId,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2560 FileContentType type,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2561 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2562 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2563 const std::string& md5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2564 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2565 class Operations : public IReadWriteOperations
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 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2568 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2569 FileContentType type_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2570 bool hasRevision_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2571 int64_t revision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2572 const std::string& md5_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2573 bool found_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2574
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2575 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2576 Operations(const std::string& publicId,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2577 FileContentType type,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2578 bool hasRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2579 int64_t revision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2580 const std::string& md5) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2581 publicId_(publicId),
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2582 type_(type),
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2583 hasRevision_(hasRevision),
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2584 revision_(revision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2585 md5_(md5),
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2586 found_(false)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2587 {
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
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2590 bool HasFound() const
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2591 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2592 return found_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2593 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2594
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2595 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2596 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2597 ResourceType resourceType;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2598 int64_t id;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2599 if (!transaction.LookupResource(id, resourceType, publicId_))
4586
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 throw OrthancException(ErrorCode_UnknownResource);
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 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2604 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2605 FileInfo info;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2606 int64_t expectedRevision;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2607 if (transaction.LookupAttachment(info, expectedRevision, id, type_))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2608 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2609 if (hasRevision_ &&
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2610 (expectedRevision != revision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2611 info.GetUncompressedMD5() != md5_))
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2612 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2613 throw OrthancException(ErrorCode_Revision);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2614 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2615
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2616 found_ = true;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2617 transaction.DeleteAttachment(id, type_);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2618
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2619 if (IsUserContentType(type_))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2620 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2621 transaction.LogChange(id, ChangeType_UpdatedAttachment, resourceType, publicId_);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2622 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2623 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2624 else
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2625 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2626 found_ = false;
4586
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
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
2632 Operations operations(publicId, type, hasRevision, revision, md5);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2633 Apply(operations);
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
2634 return operations.HasFound();
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2635 }
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
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2638 void StatelessDatabaseOperations::LogChange(int64_t internalId,
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2639 ChangeType changeType,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2640 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2641 ResourceType level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2642 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2643 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2644 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2645 private:
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2646 int64_t internalId_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2647 ChangeType changeType_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2648 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2649 ResourceType level_;
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 public:
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2652 Operations(int64_t internalId,
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2653 ChangeType changeType,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2654 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2655 ResourceType level) :
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2656 internalId_(internalId),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2657 changeType_(changeType),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2658 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2659 level_(level)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2660 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2661 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2662
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2663 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2664 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2665 int64_t id;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2666 ResourceType type;
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2667 if (transaction.LookupResource(id, type, publicId_) &&
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2668 id == internalId_)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2669 {
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2670 /**
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2671 * Make sure that the resource is still existing, with the
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2672 * same internal ID, which indicates the absence of bouncing
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2673 * (if deleting then recreating the same resource). Don't
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2674 * throw an exception if the resource has been deleted,
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2675 * because this function might e.g. be called from
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2676 * "StatelessDatabaseOperations::UnstableResourcesMonitorThread()"
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2677 * (for which a deleted resource is *not* an error case).
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2678 **/
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2679 if (type == level_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2680 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2681 transaction.LogChange(id, changeType_, type, publicId_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2682 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2683 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2684 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2685 // Consistency check
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2686 throw OrthancException(ErrorCode_UnknownResource);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2687 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2688 }
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 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2691
4587
888868a5dc4e ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4586
diff changeset
2692 Operations operations(internalId, changeType, publicId, level);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2693 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2694 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2695
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2696
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2697 void StatelessDatabaseOperations::ReconstructInstance(const ParsedDicomFile& dicom)
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 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2700 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2701 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2702 DicomMap summary_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2703 std::unique_ptr<DicomInstanceHasher> hasher_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2704 bool hasTransferSyntax_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2705 DicomTransferSyntax transferSyntax_;
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2706
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2707 static void ReplaceMetadata(ReadWriteTransaction& transaction,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2708 int64_t instance,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2709 MetadataType metadata,
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2710 const std::string& value)
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2711 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2712 std::string oldValue;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2713 int64_t oldRevision;
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2714
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2715 if (transaction.LookupMetadata(oldValue, oldRevision, instance, metadata))
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2716 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2717 transaction.SetMetadata(instance, metadata, value, oldRevision + 1);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2718 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2719 else
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2720 {
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2721 transaction.SetMetadata(instance, metadata, value, 0);
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2722 }
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2723 }
4586
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 public:
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2726 explicit Operations(const ParsedDicomFile& dicom)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2727 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2728 OrthancConfiguration::DefaultExtractDicomSummary(summary_, dicom);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2729 hasher_.reset(new DicomInstanceHasher(summary_));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2730 hasTransferSyntax_ = dicom.LookupTransferSyntax(transferSyntax_);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2733 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2734 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2735 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
2736
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2737 ResourceType type1, type2, type3, type4;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2738 if (!transaction.LookupResource(patient, type1, hasher_->HashPatient()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2739 !transaction.LookupResource(study, type2, hasher_->HashStudy()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2740 !transaction.LookupResource(series, type3, hasher_->HashSeries()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2741 !transaction.LookupResource(instance, type4, hasher_->HashInstance()) ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2742 type1 != ResourceType_Patient ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2743 type2 != ResourceType_Study ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2744 type3 != ResourceType_Series ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2745 type4 != ResourceType_Instance ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2746 patient == -1 ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2747 study == -1 ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2748 series == -1 ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2749 instance == -1)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2750 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2751 throw OrthancException(ErrorCode_InternalError);
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 transaction.ClearMainDicomTags(patient);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2755 transaction.ClearMainDicomTags(study);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2756 transaction.ClearMainDicomTags(series);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2757 transaction.ClearMainDicomTags(instance);
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 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2760 ResourcesContent content(false /* prevent the setting of metadata */);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2761 content.AddResource(patient, ResourceType_Patient, summary_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2762 content.AddResource(study, ResourceType_Study, summary_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2763 content.AddResource(series, ResourceType_Series, summary_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2764 content.AddResource(instance, ResourceType_Instance, summary_);
4934
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2765
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2766 transaction.SetResourcesContent(content);
4934
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2767
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2768 ReplaceMetadata(transaction, patient, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Patient)); // New in Orthanc 1.11.0
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2769 ReplaceMetadata(transaction, study, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Study)); // New in Orthanc 1.11.0
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2770 ReplaceMetadata(transaction, series, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Series)); // New in Orthanc 1.11.0
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2771 ReplaceMetadata(transaction, instance, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Instance)); // New in Orthanc 1.11.0
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2772 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2773
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2774 if (hasTransferSyntax_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2775 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2776 ReplaceMetadata(transaction, instance, MetadataType_Instance_TransferSyntax, GetTransferSyntaxUid(transferSyntax_));
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2777 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2778
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2779 const DicomValue* value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2780 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
2781 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2782 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2783 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
2784 ReplaceMetadata(transaction, instance, MetadataType_Instance_SopClassUid, value->GetContent());
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2785 }
4934
94a7b681b340 added configuration for extra main dicom tags + save signature in metadata + show warning if inconsistent main dicom tags
Alain Mazy <am@osimis.io>
parents: 4932
diff changeset
2786
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2787 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2788 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2789
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2790 Operations operations(dicom);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2791 Apply(operations);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2794
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2795 static bool IsRecyclingNeeded(IDatabaseWrapper::ITransaction& transaction,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2796 uint64_t maximumStorageSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2797 unsigned int maximumPatients,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2798 uint64_t addedInstanceSize)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2799 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2800 if (maximumStorageSize != 0)
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 if (maximumStorageSize < addedInstanceSize)
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 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
2805 boost::lexical_cast<std::string>(addedInstanceSize) +
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2806 " bytes in a storage area limited to " +
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2807 boost::lexical_cast<std::string>(maximumStorageSize));
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
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2810 if (transaction.IsDiskSizeAbove(maximumStorageSize - addedInstanceSize))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2811 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2812 return true;
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2815
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2816 if (maximumPatients != 0)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2817 {
4595
cc64385593ef added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4594
diff changeset
2818 uint64_t patientCount = transaction.GetResourcesCount(ResourceType_Patient);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2819 if (patientCount > maximumPatients)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2820 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2821 return true;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2822 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2823 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2824
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2825 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2826 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2827
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2828
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2829 void StatelessDatabaseOperations::ReadWriteTransaction::Recycle(uint64_t maximumStorageSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2830 unsigned int maximumPatients,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2831 uint64_t addedInstanceSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2832 const std::string& newPatientId)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2833 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2834 // TODO - Performance: Avoid calls to "IsRecyclingNeeded()"
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2835
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2836 if (IsRecyclingNeeded(transaction_, maximumStorageSize, maximumPatients, addedInstanceSize))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2837 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2838 // Check whether other DICOM instances from this patient are
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2839 // already stored
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2840 int64_t patientToAvoid;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2841 bool hasPatientToAvoid;
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 if (newPatientId.empty())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2844 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2845 hasPatientToAvoid = false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2846 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2847 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2848 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2849 ResourceType type;
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2850 hasPatientToAvoid = transaction_.LookupResource(patientToAvoid, type, newPatientId);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2851 if (type != ResourceType_Patient)
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 throw OrthancException(ErrorCode_InternalError);
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 }
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 // Iteratively select patient to remove until there is enough
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2858 // space in the DICOM store
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2859 int64_t patientToRecycle;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2860 while (true)
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 // 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
2863 // we must avoid to recycle them
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2864 bool ok = (hasPatientToAvoid ?
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2865 transaction_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) :
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2866 transaction_.SelectPatientToRecycle(patientToRecycle));
4586
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 if (!ok)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2869 {
4801
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
2870 throw OrthancException(ErrorCode_FullStorage, "Cannot recycle more patients");
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2871 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2872
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2873 LOG(TRACE) << "Recycling one patient";
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2874 transaction_.DeleteResource(patientToRecycle);
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2875
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4589
diff changeset
2876 if (!IsRecyclingNeeded(transaction_, maximumStorageSize, maximumPatients, addedInstanceSize))
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2877 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2878 // OK, we're done
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2879 return;
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2882 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2883 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2886 void StatelessDatabaseOperations::StandaloneRecycling(uint64_t maximumStorageSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2887 unsigned int maximumPatientCount)
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 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2890 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2891 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2892 uint64_t maximumStorageSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2893 unsigned int maximumPatientCount_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2894
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2895 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2896 Operations(uint64_t maximumStorageSize,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2897 unsigned int maximumPatientCount) :
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2898 maximumStorageSize_(maximumStorageSize),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2899 maximumPatientCount_(maximumPatientCount)
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 }
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 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
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 transaction.Recycle(maximumStorageSize_, maximumPatientCount_, 0, "");
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2906 }
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
4602
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
2909 if (maximumStorageSize != 0 ||
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
2910 maximumPatientCount != 0)
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
2911 {
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
2912 Operations operations(maximumStorageSize, maximumPatientCount);
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
2913 Apply(operations);
cfdd1f59ff6f fix OrthancCDatabasePlugin.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4595
diff changeset
2914 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2915 }
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2918 StoreStatus StatelessDatabaseOperations::Store(std::map<MetadataType, std::string>& instanceMetadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2919 const DicomMap& dicomSummary,
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2920 const DicomSequencesMap& sequencesToStore,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2921 const Attachments& attachments,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2922 const MetadataMap& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2923 const DicomInstanceOrigin& origin,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2924 bool overwrite,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2925 bool hasTransferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2926 DicomTransferSyntax transferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2927 bool hasPixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2928 uint64_t pixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2929 uint64_t maximumStorageSize,
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
2930 unsigned int maximumPatients,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
2931 bool isReconstruct)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2932 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2933 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2934 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2935 private:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2936 StoreStatus storeStatus_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2937 std::map<MetadataType, std::string>& instanceMetadata_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2938 const DicomMap& dicomSummary_;
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2939 const DicomSequencesMap& sequencesToStore_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2940 const Attachments& attachments_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2941 const MetadataMap& metadata_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2942 const DicomInstanceOrigin& origin_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2943 bool overwrite_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2944 bool hasTransferSyntax_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2945 DicomTransferSyntax transferSyntax_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2946 bool hasPixelDataOffset_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2947 uint64_t pixelDataOffset_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2948 uint64_t maximumStorageSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2949 unsigned int maximumPatientCount_;
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
2950 bool isReconstruct_;
4586
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 // Auto-computed fields
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2953 bool hasExpectedInstances_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2954 int64_t expectedInstances_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2955 std::string hashPatient_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2956 std::string hashStudy_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2957 std::string hashSeries_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2958 std::string hashInstance_;
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 static void SetInstanceMetadata(ResourcesContent& content,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2962 std::map<MetadataType, std::string>& instanceMetadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2963 int64_t instance,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2964 MetadataType metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2965 const std::string& value)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2966 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2967 content.AddMetadata(instance, metadata, value);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2968 instanceMetadata[metadata] = value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2969 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2970
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2971 static void SetMainDicomSequenceMetadata(ResourcesContent& content,
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2972 int64_t resource,
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2973 const DicomSequencesMap& sequencesToStore, // all sequences for all levels !
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2974 ResourceType level)
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2975 {
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2976 if (sequencesToStore.GetSize() > 0)
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2977 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2978 const std::set<DicomTag>& levelTags = DicomMap::GetMainDicomTags(level);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2979 std::set<DicomTag> levelSequences;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2980 DicomMap::ExtractSequences(levelSequences, levelTags);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2981
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2982 if (levelSequences.size() == 0)
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2983 {
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2984 return;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2985 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2986
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2987 Json::Value jsonMetadata;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2988 jsonMetadata["Version"] = 1;
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2989 jsonMetadata["Sequences"] = Json::objectValue;
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2990 sequencesToStore.Serialize(jsonMetadata["Sequences"], levelSequences);
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
2991
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2992 std::string serialized;
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2993 Toolbox::WriteFastJson(serialized, jsonMetadata);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2994
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2995 content.AddMetadata(resource, MetadataType_MainDicomSequences, serialized);
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2996 }
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2997
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
2998 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2999
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3000 static bool ComputeExpectedNumberOfInstances(int64_t& target,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3001 const DicomMap& dicomSummary)
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 try
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 const DicomValue* value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3006 const DicomValue* value2;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3007
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3008 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
3009 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3010 !value->IsBinary() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3011 (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
3012 !value2->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3013 !value2->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3014 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3015 // 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
3016 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
3017 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
3018 target = imagesInAcquisition * countTemporalPositions;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3019 return (target > 0);
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 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
3023 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3024 !value->IsBinary() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3025 (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
3026 !value2->IsBinary() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3027 !value2->IsNull())
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 // Support of Cardio-PET images
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3030 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
3031 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
3032 target = numberOfSlices * numberOfTimeSlices;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3033 return (target > 0);
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3036 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
3037 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3038 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3039 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3040 target = boost::lexical_cast<int64_t>(value->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3041 return (target > 0);
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3044 catch (OrthancException&)
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 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3047 catch (boost::bad_lexical_cast&)
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
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3051 return false;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3052 }
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 public:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3055 Operations(std::map<MetadataType, std::string>& instanceMetadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3056 const DicomMap& dicomSummary,
5039
28db9663fc2d DicomSequencesMap + fix unit tests
Alain Mazy <am@osimis.io>
parents: 5036
diff changeset
3057 const DicomSequencesMap& sequencesToStore,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3058 const Attachments& attachments,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3059 const MetadataMap& metadata,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3060 const DicomInstanceOrigin& origin,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3061 bool overwrite,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3062 bool hasTransferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3063 DicomTransferSyntax transferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3064 bool hasPixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3065 uint64_t pixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3066 uint64_t maximumStorageSize,
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3067 unsigned int maximumPatientCount,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3068 bool isReconstruct) :
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3069 storeStatus_(StoreStatus_Failure),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3070 instanceMetadata_(instanceMetadata),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3071 dicomSummary_(dicomSummary),
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3072 sequencesToStore_(sequencesToStore),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3073 attachments_(attachments),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3074 metadata_(metadata),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3075 origin_(origin),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3076 overwrite_(overwrite),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3077 hasTransferSyntax_(hasTransferSyntax),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3078 transferSyntax_(transferSyntax),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3079 hasPixelDataOffset_(hasPixelDataOffset),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3080 pixelDataOffset_(pixelDataOffset),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3081 maximumStorageSize_(maximumStorageSize),
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3082 maximumPatientCount_(maximumPatientCount),
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3083 isReconstruct_(isReconstruct)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3084 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3085 hasExpectedInstances_ = ComputeExpectedNumberOfInstances(expectedInstances_, dicomSummary);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3086
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3087 instanceMetadata_.clear();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3088
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3089 DicomInstanceHasher hasher(dicomSummary);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3090 hashPatient_ = hasher.HashPatient();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3091 hashStudy_ = hasher.HashStudy();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3092 hashSeries_ = hasher.HashSeries();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3093 hashInstance_ = hasher.HashInstance();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3094 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3095
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3096 StoreStatus GetStoreStatus() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3097 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3098 return storeStatus_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3099 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3100
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3101 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3102 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3103 try
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 IDatabaseWrapper::CreateInstanceResult status;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3106 int64_t instanceId;
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 // Check whether this instance is already stored
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3109 if (!transaction.CreateInstance(status, instanceId, hashPatient_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3110 hashStudy_, hashSeries_, hashInstance_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3111 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3112 // The instance already exists
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3113
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3114 if (overwrite_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3115 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3116 // Overwrite the old instance
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3117 LOG(INFO) << "Overwriting instance: " << hashInstance_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3118 transaction.DeleteResource(instanceId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3119
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3120 // 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
3121 if (!transaction.CreateInstance(status, instanceId, hashPatient_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3122 hashStudy_, hashSeries_, hashInstance_))
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 throw OrthancException(ErrorCode_InternalError);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3125 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3126 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3127 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3128 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3129 // 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
3130 transaction.GetAllMetadata(instanceMetadata_, instanceId);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3131 storeStatus_ = StoreStatus_AlreadyStored;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3132 return;
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 }
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
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3137 if (!isReconstruct_) // don't signal new resources if this is a reconstruction
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3138 {
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3139 // Warn about the creation of new resources. The order must be
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3140 // from instance to patient.
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3141
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3142 // NB: In theory, could be sped up by grouping the underlying
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3143 // calls to "transaction.LogChange()". However, this would only have an
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3144 // impact when new patient/study/series get created, which
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3145 // occurs far less often that creating new instances. The
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3146 // positive impact looks marginal in practice.
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3147 transaction.LogChange(instanceId, ChangeType_NewInstance, ResourceType_Instance, hashInstance_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3148
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3149 if (status.isNewSeries_)
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3150 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3151 transaction.LogChange(status.seriesId_, ChangeType_NewSeries, ResourceType_Series, hashSeries_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3152 }
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3153
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3154 if (status.isNewStudy_)
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3155 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3156 transaction.LogChange(status.studyId_, ChangeType_NewStudy, ResourceType_Study, hashStudy_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3157 }
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3158
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3159 if (status.isNewPatient_)
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3160 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3161 transaction.LogChange(status.patientId_, ChangeType_NewPatient, ResourceType_Patient, hashPatient_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3162 }
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3163 }
4586
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 // 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
3166 uint64_t instanceSize = 0;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3167 for (Attachments::const_iterator it = attachments_.begin();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3168 it != attachments_.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3169 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3170 instanceSize += it->GetCompressedSize();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3171 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3172
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3173 if (!isReconstruct_) // reconstruction should not affect recycling
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3174 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3175 transaction.Recycle(maximumStorageSize_, maximumPatientCount_,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3176 instanceSize, hashPatient_ /* don't consider the current patient for recycling */);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3177 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3178
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3179 // Attach the files to the newly created instance
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3180 for (Attachments::const_iterator it = attachments_.begin();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3181 it != attachments_.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3182 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3183 transaction.AddAttachment(instanceId, *it, 0 /* this is the first revision */);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3184 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3185
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3186
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3187 {
4623
95ffe3b6ef7c handling of revisions for metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4619
diff changeset
3188 ResourcesContent content(true /* new resource, metadata can be set */);
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3189
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3190
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3191 // Attach the user-specified metadata (in case of reconstruction, metadata_ contains all past metadata, including the system ones we want to keep)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3192 for (MetadataMap::const_iterator
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3193 it = metadata_.begin(); it != metadata_.end(); ++it)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3194 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3195 switch (it->first.first)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3196 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3197 case ResourceType_Patient:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3198 content.AddMetadata(status.patientId_, it->first.second, it->second);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3199 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3200
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3201 case ResourceType_Study:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3202 content.AddMetadata(status.studyId_, it->first.second, it->second);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3203 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3204
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3205 case ResourceType_Series:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3206 content.AddMetadata(status.seriesId_, it->first.second, it->second);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3207 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3208
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3209 case ResourceType_Instance:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3210 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3211 it->first.second, it->second);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3212 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3213
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3214 default:
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3215 throw OrthancException(ErrorCode_ParameterOutOfRange);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3216 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3217 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3218
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3219 // Populate the tags of the newly-created resources
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3220
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3221 content.AddResource(instanceId, ResourceType_Instance, dicomSummary_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3222 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Instance)); // New in Orthanc 1.11.0
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3223 SetMainDicomSequenceMetadata(content, instanceId, sequencesToStore_, ResourceType_Instance); // new in Orthanc 1.11.1
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3224
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3225 if (status.isNewSeries_)
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3226 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3227 content.AddResource(status.seriesId_, ResourceType_Series, dicomSummary_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3228 content.AddMetadata(status.seriesId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Series)); // New in Orthanc 1.11.0
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3229 SetMainDicomSequenceMetadata(content, status.seriesId_, sequencesToStore_, ResourceType_Series); // new in Orthanc 1.11.1
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3230 }
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3231
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3232 if (status.isNewStudy_)
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3233 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3234 content.AddResource(status.studyId_, ResourceType_Study, dicomSummary_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3235 content.AddMetadata(status.studyId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Study)); // New in Orthanc 1.11.0
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3236 SetMainDicomSequenceMetadata(content, status.studyId_, sequencesToStore_, ResourceType_Study); // new in Orthanc 1.11.1
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3237 }
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3238
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3239 if (status.isNewPatient_)
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3240 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3241 content.AddResource(status.patientId_, ResourceType_Patient, dicomSummary_);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3242 content.AddMetadata(status.patientId_, MetadataType_MainDicomTagsSignature, DicomMap::GetMainDicomTagsSignature(ResourceType_Patient)); // New in Orthanc 1.11.0
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3243 SetMainDicomSequenceMetadata(content, status.patientId_, sequencesToStore_, ResourceType_Patient); // new in Orthanc 1.11.1
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3244 }
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3245
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3246 // 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
3247 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
3248 content.AddMetadata(status.seriesId_, MetadataType_LastUpdate, now);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3249 content.AddMetadata(status.studyId_, MetadataType_LastUpdate, now);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3250 content.AddMetadata(status.patientId_, MetadataType_LastUpdate, now);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3251
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3252 if (status.isNewSeries_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3253 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3254 if (hasExpectedInstances_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3255 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3256 content.AddMetadata(status.seriesId_, MetadataType_Series_ExpectedNumberOfInstances,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3257 boost::lexical_cast<std::string>(expectedInstances_));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3258 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3259
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3260 // New in Orthanc 1.9.0
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3261 content.AddMetadata(status.seriesId_, MetadataType_RemoteAet,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3262 origin_.GetRemoteAetC());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3263 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3264
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3265 if (hasTransferSyntax_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3266 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3267 // New in Orthanc 1.2.0
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3268 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3269 MetadataType_Instance_TransferSyntax,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3270 GetTransferSyntaxUid(transferSyntax_));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3271 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3272
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3273 if (!isReconstruct_) // don't change origin metadata
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3274 {
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3275 // Attach the auto-computed metadata for the instance level,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3276 // reflecting these additions into the input metadata map
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3277 SetInstanceMetadata(content, instanceMetadata_, instanceId,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3278 MetadataType_Instance_ReceptionDate, now);
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3279 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_RemoteAet,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3280 origin_.GetRemoteAetC());
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3281 SetInstanceMetadata(content, instanceMetadata_, instanceId, MetadataType_Instance_Origin,
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3282 EnumerationToString(origin_.GetRequestOrigin()));
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3283
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3284 std::string s;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3285
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3286 if (origin_.LookupRemoteIp(s))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3287 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3288 // New in Orthanc 1.4.0
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3289 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3290 MetadataType_Instance_RemoteIp, s);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3291 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3292
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3293 if (origin_.LookupCalledAet(s))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3294 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3295 // New in Orthanc 1.4.0
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3296 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3297 MetadataType_Instance_CalledAet, s);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3298 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3299
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3300 if (origin_.LookupHttpUsername(s))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3301 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3302 // New in Orthanc 1.4.0
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3303 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3304 MetadataType_Instance_HttpUsername, s);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3305 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3306 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3307
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3308 if (hasPixelDataOffset_)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3309 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3310 // New in Orthanc 1.9.1
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3311 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3312 MetadataType_Instance_PixelDataOffset,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3313 boost::lexical_cast<std::string>(pixelDataOffset_));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3314 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3315
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3316 const DicomValue* value;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3317 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
3318 !value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3319 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3320 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3321 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3322 MetadataType_Instance_SopClassUid, value->GetContent());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3323 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3324
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3325
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3326 if ((value = dicomSummary_.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL ||
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3327 (value = dicomSummary_.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3328 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3329 if (!value->IsNull() &&
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3330 !value->IsBinary())
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3331 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3332 SetInstanceMetadata(content, instanceMetadata_, instanceId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3333 MetadataType_Instance_IndexInSeries, Toolbox::StripSpaces(value->GetContent()));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3334 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3335 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3336
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3337
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3338 transaction.SetResourcesContent(content);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3339 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3340
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3341
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3342 // 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
3343 int64_t expectedNumberOfInstances;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3344 if (ComputeExpectedNumberOfInstances(expectedNumberOfInstances, dicomSummary_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3345 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3346 SeriesStatus seriesStatus = transaction.GetSeriesStatus(status.seriesId_, expectedNumberOfInstances);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3347 if (seriesStatus == SeriesStatus_Complete)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3348 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3349 transaction.LogChange(status.seriesId_, ChangeType_CompletedSeries, ResourceType_Series, hashSeries_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3350 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3351 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3352
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3353 transaction.LogChange(status.seriesId_, ChangeType_NewChildInstance, ResourceType_Series, hashSeries_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3354 transaction.LogChange(status.studyId_, ChangeType_NewChildInstance, ResourceType_Study, hashStudy_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3355 transaction.LogChange(status.patientId_, ChangeType_NewChildInstance, ResourceType_Patient, hashPatient_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3356
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3357 // Mark the parent resources of this instance as unstable
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3358 transaction.GetTransactionContext().MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3359 transaction.GetTransactionContext().MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3360 transaction.GetTransactionContext().MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3361 transaction.GetTransactionContext().SignalAttachmentsAdded(instanceSize);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3362
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3363 storeStatus_ = StoreStatus_Success;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3364 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3365 catch (OrthancException& e)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3366 {
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3367 if (e.GetErrorCode() == ErrorCode_DatabaseCannotSerialize)
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3368 {
4801
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3369 throw; // the transaction has failed -> do not commit the current transaction (and retry)
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3370 }
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3371 else
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3372 {
4801
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3373 LOG(ERROR) << "EXCEPTION [" << e.What() << " - " << e.GetDetails() << "]";
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3374
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3375 if (e.GetErrorCode() == ErrorCode_FullStorage)
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3376 {
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3377 throw; // do not commit the current transaction
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3378 }
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3379
23aeffecb8cb Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
Alain Mazy <am@osimis.io>
parents: 4697
diff changeset
3380 // this is an expected failure, exit normaly and commit the current transaction
4612
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3381 storeStatus_ = StoreStatus_Failure;
4982733a4e39 fix database retries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4609
diff changeset
3382 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3383 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3384 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3385 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3386
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3387
5036
877bc3b96476 Handle Dicom sequences in ExtraMainDicomTags and save them in the 'MainDicomSequences' metadata
Alain Mazy <am@osimis.io>
parents: 4988
diff changeset
3388 Operations operations(instanceMetadata, dicomSummary, sequencesToStore, attachments, metadata, origin,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3389 overwrite, hasTransferSyntax, transferSyntax, hasPixelDataOffset,
4988
8fba26292a9f Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents: 4940
diff changeset
3390 pixelDataOffset, maximumStorageSize, maximumPatients, isReconstruct);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3391 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3392 return operations.GetStoreStatus();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3393 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3394
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3395
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3396 StoreStatus StatelessDatabaseOperations::AddAttachment(int64_t& newRevision,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3397 const FileInfo& attachment,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3398 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3399 uint64_t maximumStorageSize,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3400 unsigned int maximumPatients,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3401 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3402 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3403 const std::string& oldMD5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3404 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3405 class Operations : public IReadWriteOperations
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3406 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3407 private:
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3408 int64_t& newRevision_;
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3409 StoreStatus status_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3410 const FileInfo& attachment_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3411 const std::string& publicId_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3412 uint64_t maximumStorageSize_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3413 unsigned int maximumPatientCount_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3414 bool hasOldRevision_;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3415 int64_t oldRevision_;
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3416 const std::string& oldMD5_;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3417
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3418 public:
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3419 Operations(int64_t& newRevision,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3420 const FileInfo& attachment,
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3421 const std::string& publicId,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3422 uint64_t maximumStorageSize,
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3423 unsigned int maximumPatientCount,
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3424 bool hasOldRevision,
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3425 int64_t oldRevision,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3426 const std::string& oldMD5) :
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3427 newRevision_(newRevision),
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3428 status_(StoreStatus_Failure),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3429 attachment_(attachment),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3430 publicId_(publicId),
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3431 maximumStorageSize_(maximumStorageSize),
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3432 maximumPatientCount_(maximumPatientCount),
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3433 hasOldRevision_(hasOldRevision),
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3434 oldRevision_(oldRevision),
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3435 oldMD5_(oldMD5)
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3436 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3437 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3438
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3439 StoreStatus GetStatus() const
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3440 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3441 return status_;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3442 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3443
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3444 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3445 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3446 ResourceType resourceType;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3447 int64_t resourceId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3448 if (!transaction.LookupResource(resourceId, resourceType, publicId_))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3449 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3450 status_ = StoreStatus_Failure; // Inexistent resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3451 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3452 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3453 {
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3454 // Possibly remove previous attachment
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3455 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3456 FileInfo oldFile;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3457 int64_t expectedRevision;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3458 if (transaction.LookupAttachment(oldFile, expectedRevision, resourceId, attachment_.GetContentType()))
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3459 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3460 if (hasOldRevision_ &&
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3461 (expectedRevision != oldRevision_ ||
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3462 oldFile.GetUncompressedMD5() != oldMD5_))
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3463 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3464 throw OrthancException(ErrorCode_Revision);
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3465 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3466 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3467 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3468 newRevision_ = expectedRevision + 1;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3469 transaction.DeleteAttachment(resourceId, attachment_.GetContentType());
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3470 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3471 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3472 else
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3473 {
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3474 // The attachment is not existing yet: Ignore "oldRevision"
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3475 // and initialize a new sequence of revisions
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3476 newRevision_ = 0;
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3477 }
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3478 }
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3479
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3480 // Locate the patient of the target resource
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3481 int64_t patientId = resourceId;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3482 for (;;)
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3483 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3484 int64_t parent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3485 if (transaction.LookupParent(parent, patientId))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3486 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3487 // We have not reached the patient level yet
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3488 patientId = parent;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3489 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3490 else
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3491 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3492 // We have reached the patient level
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3493 break;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3494 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3495 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3496
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3497 // Possibly apply the recycling mechanism while preserving this patient
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3498 assert(transaction.GetResourceType(patientId) == ResourceType_Patient);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3499 transaction.Recycle(maximumStorageSize_, maximumPatientCount_,
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3500 attachment_.GetCompressedSize(), transaction.GetPublicId(patientId));
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3501
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4623
diff changeset
3502 transaction.AddAttachment(resourceId, attachment_, newRevision_);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3503
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3504 if (IsUserContentType(attachment_.GetContentType()))
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3505 {
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3506 transaction.LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId_);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3507 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3508
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3509 transaction.GetTransactionContext().SignalAttachmentsAdded(attachment_.GetCompressedSize());
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3510
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3511 status_ = StoreStatus_Success;
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3512 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3513 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3514 };
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3515
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3516
4640
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3517 Operations operations(newRevision, attachment, publicId, maximumStorageSize, maximumPatients,
66109d24d26e "ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4633
diff changeset
3518 hasOldRevision, oldRevision, oldMD5);
4586
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3519 Apply(operations);
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3520 return operations.GetStatus();
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3521 }
1d96fe7e054e taking StatelessDatabaseOperations out of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3522 }