annotate OrthancServer/ServerContext.cpp @ 1004:a226e0959d8b lua-scripting

DicomInstanceToStore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jul 2014 14:06:05 +0200
parents b067017a8a5b
children 84b6d7bca6db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "PrecompiledHeadersServer.h"
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ServerContext.h"
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
36 #include "../Core/HttpServer/FilesystemHttpSender.h"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
37 #include "../Core/Lua/LuaFunctionCall.h"
795
d466b3606aca refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
38 #include "FromDcmtkBridge.h"
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
39 #include "ServerToolbox.h"
771
537837f50fbb refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 730
diff changeset
40 #include "OrthancInitialization.h"
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
41
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <glog/logging.h>
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 376
diff changeset
43 #include <EmbeddedResources.h>
794
437c4a83d2cc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
44 #include <dcmtk/dcmdata/dcfilefo.h>
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
46
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
47 #include "Scheduler/DeleteInstanceCommand.h"
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
48 #include "Scheduler/StoreScuCommand.h"
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
49
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
50
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
51
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
52 #define ENABLE_DICOM_CACHE 1
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
53
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
54 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter";
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
55 static const char* ON_STORED_INSTANCE = "OnStoredInstance";
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
56
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
57 static const size_t DICOM_CACHE_SIZE = 2;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
58
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
59 /**
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
60 * IMPORTANT: We make the assumption that the same instance of
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
61 * FileStorage can be accessed from multiple threads. This seems OK
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
62 * since the filesystem implements the required locking mechanisms,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
63 * but maybe a read-writer lock on the "FileStorage" could be
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
64 * useful. Conversely, "ServerIndex" already implements mutex-based
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
65 * locking.
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
66 **/
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
67
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 namespace Orthanc
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
376
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
70 ServerContext::ServerContext(const boost::filesystem::path& storagePath,
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
71 const boost::filesystem::path& indexPath) :
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
72 storage_(storagePath.string()),
2cef9c2d4148 separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 320
diff changeset
73 index_(*this, indexPath.string()),
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
74 accessor_(storage_),
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
75 compressionEnabled_(false),
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
76 provider_(*this),
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
77 dicomCache_(provider_, DICOM_CACHE_SIZE),
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 942
diff changeset
78 scheduler_(Configuration::GetGlobalIntegerParameter("LimitJobs", 10))
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
810
401a9633e492 configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 795
diff changeset
80 scu_.SetLocalApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC"));
774
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 771
diff changeset
81 //scu_.SetMillisecondsBeforeClose(1); // The connection is always released
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 771
diff changeset
82
394
9784f19f7e1b path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 376
diff changeset
83 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
86 void ServerContext::SetCompressionEnabled(bool enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
87 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
88 if (enabled)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
89 LOG(WARNING) << "Disk compression is enabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
90 else
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
91 LOG(WARNING) << "Disk compression is disabled";
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
92
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
93 compressionEnabled_ = enabled;
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
94 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
95
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
96 void ServerContext::RemoveFile(const std::string& fileUuid)
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
97 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
98 storage_.Remove(fileUuid);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
99 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
100
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
101
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
102 bool ServerContext::ApplyReceivedInstanceFilter(const Json::Value& simplified,
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
103 const std::string& remoteAet)
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
104 {
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
105 LuaContextLocker locker(*this);
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
106
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
107 if (locker.GetLua().IsExistingFunction(RECEIVED_INSTANCE_FILTER))
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
108 {
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
109 LuaFunctionCall call(locker.GetLua(), RECEIVED_INSTANCE_FILTER);
997
1b1d51e9f1a2 return Json from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 996
diff changeset
110 call.PushJson(simplified);
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
111 call.PushString(remoteAet);
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
112
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
113 if (!call.ExecutePredicate())
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
114 {
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
115 return false;
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
116 }
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
117 }
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
118
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
119 return true;
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
120 }
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
121
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
122
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
123 void ServerContext::ApplyOnStoredInstance(const std::string& instanceId,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
124 const Json::Value& simplifiedDicom,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
125 const Json::Value& metadata)
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
126 {
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
127 LuaContextLocker locker(*this);
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
128
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
129 if (locker.GetLua().IsExistingFunction(ON_STORED_INSTANCE))
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
130 {
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
131 LuaFunctionCall call(locker.GetLua(), ON_STORED_INSTANCE);
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
132 call.PushString(instanceId);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
133 call.PushJson(simplifiedDicom);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
134 call.PushJson(metadata);
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
135
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
136 Json::Value result;
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
137 call.ExecuteToJson(result);
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
138
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
139 printf("TODO\n");
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
140 std::cout << result;
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
141 }
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
142
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
143 #if 1
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
144 {
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
145 // Autorouting test
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
146 RemoteModalityParameters p = Configuration::GetModalityUsingSymbolicName("sample");
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
147
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
148 ServerJob job;
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
149 ServerCommandInstance& a = job.AddCommand(new StoreScuCommand(*this, p));
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
150 a.AddInput(instanceId);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
151
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
152 /*ServerCommandInstance& b = job.AddCommand(new DeleteInstanceCommand(*this));
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
153 a.ConnectNext(b);*/
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
154
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
155 job.SetDescription("Autorouting test");
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
156 scheduler_.Submit(job);
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
157 }
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
158 #endif
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
159 }
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
160
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
161
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
162 StoreStatus ServerContext::Store(std::string& resultPublicId,
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
163 DicomInstanceToStore& dicom)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
164 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
165 try
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
166 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
167 DicomInstanceHasher hasher(dicom.GetSummary());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
168 resultPublicId = hasher.HashInstance();
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
169
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
170 Json::Value simplified;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
171 SimplifyTags(simplified, dicom.GetJson());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
172
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
173 // Test if the instance must be filtered out
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
174 if (!ApplyReceivedInstanceFilter(simplified, dicom.GetRemoteAet()))
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
175 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
176 LOG(INFO) << "An incoming instance has been discarded by the filter";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
177 return StoreStatus_FilteredOut;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
178 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
179
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
180 if (compressionEnabled_)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
181 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
182 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
183 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
184 else
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
185 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
186 accessor_.SetCompressionForNextOperations(CompressionType_None);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
187 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
188
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
189 FileInfo dicomInfo = accessor_.Write(dicom.GetBufferData(), dicom.GetBufferSize(), FileContentType_Dicom);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
190 FileInfo jsonInfo = accessor_.Write(dicom.GetJson().toStyledString(), FileContentType_DicomAsJson);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
191
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
192 ServerIndex::Attachments attachments;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
193 attachments.push_back(dicomInfo);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
194 attachments.push_back(jsonInfo);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
195
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
196 StoreStatus status = index_.Store(dicom.GetSummary(), attachments, dicom.GetRemoteAet(), dicom.GetMetadata());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
197
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
198 if (status != StoreStatus_Success)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
199 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
200 storage_.Remove(dicomInfo.GetUuid());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
201 storage_.Remove(jsonInfo.GetUuid());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
202 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
203
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
204 switch (status)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
205 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
206 case StoreStatus_Success:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
207 LOG(INFO) << "New instance stored";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
208 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
209
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
210 case StoreStatus_AlreadyStored:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
211 LOG(INFO) << "Already stored";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
212 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
213
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
214 case StoreStatus_Failure:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
215 LOG(ERROR) << "Store failure";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
216 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
217
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
218 default:
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
219 // This should never happen
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
220 break;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
221 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
222
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
223 if (status == StoreStatus_Success ||
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
224 status == StoreStatus_AlreadyStored)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
225 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
226 try
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
227 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
228 Json::Value metadata = Json::objectValue;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
229 for (ServerIndex::MetadataMap::const_iterator
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
230 it = dicom.GetMetadata().begin();
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
231 it != dicom.GetMetadata().end(); ++it)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
232 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
233 if (it->first.first == ResourceType_Instance)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
234 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
235 metadata[EnumerationToString(it->first.second)] = it->second;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
236 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
237 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
238
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
239 ApplyOnStoredInstance(resultPublicId, simplified, metadata);
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
240 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
241 catch (OrthancException&)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
242 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
243 LOG(ERROR) << "Error when dealing with OnStoredInstance";
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
244 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
245 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
246
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
247 return status;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
248 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
249 catch (OrthancException& e)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
250 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
251 if (e.GetErrorCode() == ErrorCode_InexistentTag)
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
252 {
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
253 LogMissingRequiredTag(dicom.GetSummary());
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
254 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
255
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
256 throw;
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
257 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
258 }
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
259
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
260
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
261
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
262 StoreStatus ServerContext::Store(const char* dicomInstance,
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 size_t dicomSize,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 const DicomMap& dicomSummary,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 const Json::Value& dicomJson,
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
266 const std::string& remoteAet,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
267 const ServerIndex::MetadataMap& metadata)
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
269 Json::Value simplified;
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
270 SimplifyTags(simplified, dicomJson);
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
271
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
272 // Test if the instance must be filtered out
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
273 if (!ApplyReceivedInstanceFilter(simplified, remoteAet))
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
274 {
996
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
275 LOG(INFO) << "An incoming instance has been discarded by the filter";
cf52f3bcb2b3 clarification of Lua classes wrt multithreading
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
276 return StoreStatus_FilteredOut;
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
277 }
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
278
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
279 if (compressionEnabled_)
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
280 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
281 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
282 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
283 else
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
284 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
285 accessor_.SetCompressionForNextOperations(CompressionType_None);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
286 }
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
287
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
288 FileInfo dicomInfo = accessor_.Write(dicomInstance, dicomSize, FileContentType_Dicom);
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
289 FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_DicomAsJson);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
290
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
291 ServerIndex::Attachments attachments;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
292 attachments.push_back(dicomInfo);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
293 attachments.push_back(jsonInfo);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
294
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
295 // TODO REMOVE CONST_CAST !!!!
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
296 StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet, const_cast<ServerIndex::MetadataMap&>(metadata));
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 if (status != StoreStatus_Success)
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
300 storage_.Remove(dicomInfo.GetUuid());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
301 storage_.Remove(jsonInfo.GetUuid());
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 switch (status)
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
306 case StoreStatus_Success:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
307 LOG(INFO) << "New instance stored";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
308 break;
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
309
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
310 case StoreStatus_AlreadyStored:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
311 LOG(INFO) << "Already stored";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
312 break;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
314 case StoreStatus_Failure:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
315 LOG(ERROR) << "Store failure";
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
316 break;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
397
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
318 default:
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
319 // This should never happen
941ea46e9e26 lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 394
diff changeset
320 break;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
323 if (status == StoreStatus_Success ||
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
324 status == StoreStatus_AlreadyStored)
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
325 {
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
326 try
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
327 {
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
328 DicomInstanceHasher hasher(dicomSummary);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
329 std::string instanceId = hasher.HashInstance();
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
330
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
331 Json::Value metadata;
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
332 index_.GetMetadata(metadata, instanceId);
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
333
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
334 ApplyOnStoredInstance(instanceId, simplified, metadata);
1001
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
335 }
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
336 catch (OrthancException&)
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
337 {
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
338 LOG(ERROR) << "Error when dealing with OnStoredInstance";
f3929718ea7e autorouting primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 998
diff changeset
339 }
998
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
340 }
4136fab6a639 callback on stored instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 997
diff changeset
341
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 return status;
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 }
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
344
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
345
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
346 void ServerContext::AnswerDicomFile(RestApiOutput& output,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
347 const std::string& instancePublicId,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
348 FileContentType content)
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
349 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
350 FileInfo attachment;
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
351 if (!index_.LookupAttachment(attachment, instancePublicId, content))
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
352 {
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
353 throw OrthancException(ErrorCode_InternalError);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
354 }
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
355
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
356 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
320
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
357
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
358 std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid()));
320
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
359 sender->SetContentType("application/dicom");
1b0ffed55ab0 fix download dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
360 sender->SetDownloadFilename(instancePublicId + ".dcm");
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
361 output.AnswerFile(*sender);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
362 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
363
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
364
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
365 void ServerContext::ReadJson(Json::Value& result,
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
366 const std::string& instancePublicId)
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
367 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
368 std::string s;
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
369 ReadFile(s, instancePublicId, FileContentType_DicomAsJson);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
370
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
371 Json::Reader reader;
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
372 if (!reader.parse(s, result))
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
373 {
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
374 throw OrthancException("Corrupted JSON file");
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
375 }
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
376 }
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
377
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
378
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
379 void ServerContext::ReadFile(std::string& result,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
380 const std::string& instancePublicId,
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
381 FileContentType content,
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
382 bool uncompressIfNeeded)
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
383 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
384 FileInfo attachment;
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
385 if (!index_.LookupAttachment(attachment, instancePublicId, content))
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
386 {
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
387 throw OrthancException(ErrorCode_InternalError);
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
388 }
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
389
697
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
390 if (uncompressIfNeeded)
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
391 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
392 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType());
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
393 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
394 else
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
395 {
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
396 accessor_.SetCompressionForNextOperations(CompressionType_None);
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
397 }
dd1ce9a2844c access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 696
diff changeset
398
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
399 accessor_.Read(result, attachment.GetUuid());
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
400 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
401
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
402
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
403 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
404 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
405 std::string content;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
406 context_.ReadFile(content, instancePublicId, FileContentType_Dicom);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
407 return new ParsedDicomFile(content);
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
408 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
409
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
410
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
411 ServerContext::DicomCacheLocker::DicomCacheLocker(ServerContext& that,
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
412 const std::string& instancePublicId) :
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
413 that_(that)
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
414 {
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
415 #if ENABLE_DICOM_CACHE == 0
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
416 static std::auto_ptr<IDynamicObject> p;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
417 p.reset(provider_.Provide(instancePublicId));
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
418 dicom_ = dynamic_cast<ParsedDicomFile*>(p.get());
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
419 #else
778
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
420 that_.dicomCacheMutex_.lock();
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
421 dicom_ = &dynamic_cast<ParsedDicomFile&>(that_.dicomCache_.Access(instancePublicId));
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
422 #endif
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
423 }
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
424
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
425
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
426 ServerContext::DicomCacheLocker::~DicomCacheLocker()
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
427 {
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
428 #if ENABLE_DICOM_CACHE == 0
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
429 #else
aebf0071020e refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 774
diff changeset
430 that_.dicomCacheMutex_.unlock();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 288
diff changeset
431 #endif
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 269
diff changeset
432 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
433
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
434
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
435 static DcmFileFormat& GetDicom(ParsedDicomFile& file)
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
436 {
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
437 return *reinterpret_cast<DcmFileFormat*>(file.GetDcmtkObject());
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
438 }
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
439
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
440
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
441 StoreStatus ServerContext::Store(std::string& resultPublicId,
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
442 ParsedDicomFile& dicomInstance,
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
443 const char* dicomBuffer,
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
444 size_t dicomSize,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
445 const ServerIndex::MetadataMap& metadata)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
446 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
447 DicomMap dicomSummary;
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
448 FromDcmtkBridge::Convert(dicomSummary, *GetDicom(dicomInstance).getDataset());
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
449
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
450 try
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
451 {
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
452 DicomInstanceHasher hasher(dicomSummary);
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
453 resultPublicId = hasher.HashInstance();
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
454
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
455 Json::Value dicomJson;
792
111a1738e11e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 791
diff changeset
456 FromDcmtkBridge::ToJson(dicomJson, *GetDicom(dicomInstance).getDataset());
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
457
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
458 StoreStatus status = StoreStatus_Failure;
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
459 if (dicomSize > 0)
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
460 {
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
461 status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, "", metadata);
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
462 }
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
463
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
464 return status;
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
465 }
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
466 catch (OrthancException& e)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
467 {
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
468 if (e.GetErrorCode() == ErrorCode_InexistentTag)
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
469 {
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
470 LogMissingRequiredTag(dicomSummary);
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
471 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
472
942
b3f6fb1130cd fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
473 throw;
730
309e686b41e7 better logging about nonexistent tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
474 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
475 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
476
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
477
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
478 StoreStatus ServerContext::Store(std::string& resultPublicId,
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
479 ParsedDicomFile& dicomInstance,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
480 const ServerIndex::MetadataMap& metadata)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
481 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
482 std::string buffer;
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1002
diff changeset
483 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, *GetDicom(dicomInstance).getDataset()))
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
484 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
485 throw OrthancException(ErrorCode_InternalError);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
486 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
487
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
488 if (buffer.size() == 0)
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
489 return Store(resultPublicId, dicomInstance, NULL, 0, metadata);
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
490 else
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
491 return Store(resultPublicId, dicomInstance, &buffer[0], buffer.size(), metadata);
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
492 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
493
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
494
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
495 StoreStatus ServerContext::Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
496 const char* dicomBuffer,
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
497 size_t dicomSize,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
498 const ServerIndex::MetadataMap& metadata)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
499 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
500 ParsedDicomFile dicom(dicomBuffer, dicomSize);
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
501 return Store(resultPublicId, dicom, dicomBuffer, dicomSize, metadata);
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
502 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
503
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
504
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
505 StoreStatus ServerContext::Store(std::string& resultPublicId,
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
506 const std::string& dicomContent,
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
507 const ServerIndex::MetadataMap& metadata)
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
508 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
509 if (dicomContent.size() == 0)
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
510 {
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
511 return Store(resultPublicId, NULL, 0);
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
512 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
513 else
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
514 {
1002
b067017a8a5b anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1001
diff changeset
515 return Store(resultPublicId, &dicomContent[0], dicomContent.size(), metadata);
791
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
516 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
517 }
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
518
381f90e2b69d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 778
diff changeset
519
695
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
520 void ServerContext::SetStoreMD5ForAttachments(bool storeMD5)
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
521 {
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
522 LOG(INFO) << "Storing MD5 for attachments: " << (storeMD5 ? "yes" : "no");
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
523 accessor_.SetStoreMD5(storeMD5);
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
524 }
c59bc408fb10 parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
525
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
526
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
527 bool ServerContext::AddAttachment(const std::string& resourceId,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
528 FileContentType attachmentType,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
529 const void* data,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
530 size_t size)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
531 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
532 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
533
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
534 if (compressionEnabled_)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
535 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
536 accessor_.SetCompressionForNextOperations(CompressionType_Zlib);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
537 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
538 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
539 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
540 accessor_.SetCompressionForNextOperations(CompressionType_None);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
541 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
542
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
543 FileInfo info = accessor_.Write(data, size, attachmentType);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
544 StoreStatus status = index_.AddAttachment(info, resourceId);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
545
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
546 if (status != StoreStatus_Success)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
547 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
548 storage_.Remove(info.GetUuid());
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
549 return false;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
550 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
551 else
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
552 {
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
553 return true;
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
554 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 697
diff changeset
555 }
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 }