Mercurial > hg > orthanc
annotate OrthancServer/ServerContext.cpp @ 689:2d0a347e8cfc
switch to 2014
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Feb 2014 16:06:58 +0100 |
parents | 08eca5d86aad |
children | c59bc408fb10 |
rev | line source |
---|---|
224 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
224 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "ServerContext.h" | |
34 | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
35 #include "../Core/HttpServer/FilesystemHttpSender.h" |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
36 #include "../Core/Lua/LuaFunctionCall.h" |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
37 #include "ServerToolbox.h" |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
38 |
224 | 39 #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
|
40 #include <EmbeddedResources.h> |
224 | 41 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
42 #define ENABLE_DICOM_CACHE 1 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
43 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
44 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter"; |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
45 |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
46 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
|
47 |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
48 /** |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
49 * 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
|
50 * 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
|
51 * since the filesystem implements the required locking mechanisms, |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
52 * 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
|
53 * useful. Conversely, "ServerIndex" already implements mutex-based |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
54 * locking. |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
55 **/ |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
56 |
224 | 57 namespace Orthanc |
58 { | |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
320
diff
changeset
|
59 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
|
60 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
|
61 storage_(storagePath.string()), |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
320
diff
changeset
|
62 index_(*this, indexPath.string()), |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
63 accessor_(storage_), |
656 | 64 compressionEnabled_(false), |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
65 provider_(*this), |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
66 dicomCache_(provider_, DICOM_CACHE_SIZE) |
224 | 67 { |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
68 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); |
224 | 69 } |
70 | |
236 | 71 void ServerContext::SetCompressionEnabled(bool enabled) |
72 { | |
73 if (enabled) | |
74 LOG(WARNING) << "Disk compression is enabled"; | |
75 else | |
76 LOG(WARNING) << "Disk compression is disabled"; | |
77 | |
78 compressionEnabled_ = enabled; | |
79 } | |
80 | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
81 void ServerContext::RemoveFile(const std::string& fileUuid) |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
82 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
83 storage_.Remove(fileUuid); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
84 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
85 |
304 | 86 StoreStatus ServerContext::Store(const char* dicomInstance, |
224 | 87 size_t dicomSize, |
88 const DicomMap& dicomSummary, | |
89 const Json::Value& dicomJson, | |
90 const std::string& remoteAet) | |
91 { | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
92 // Test if the instance must be filtered out |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
93 if (lua_.IsExistingFunction(RECEIVED_INSTANCE_FILTER)) |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
94 { |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
95 Json::Value simplified; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
96 SimplifyTags(simplified, dicomJson); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
97 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
98 LuaFunctionCall call(lua_, RECEIVED_INSTANCE_FILTER); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
99 call.PushJSON(simplified); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
100 call.PushString(remoteAet); |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
101 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
102 if (!call.ExecutePredicate()) |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
103 { |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
407
diff
changeset
|
104 LOG(INFO) << "An incoming instance has been discarded by the filter"; |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
105 return StoreStatus_FilteredOut; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
106 } |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
107 } |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
108 |
236 | 109 if (compressionEnabled_) |
110 { | |
111 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); | |
112 } | |
113 else | |
114 { | |
115 accessor_.SetCompressionForNextOperations(CompressionType_None); | |
116 } | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
117 |
304 | 118 FileInfo dicomInfo = accessor_.Write(dicomInstance, dicomSize, FileContentType_Dicom); |
233 | 119 FileInfo jsonInfo = accessor_.Write(dicomJson.toStyledString(), FileContentType_Json); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
120 |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
121 ServerIndex::Attachments attachments; |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
122 attachments.push_back(dicomInfo); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
123 attachments.push_back(jsonInfo); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
124 |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
125 StoreStatus status = index_.Store(dicomSummary, attachments, remoteAet); |
224 | 126 |
127 if (status != StoreStatus_Success) | |
128 { | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
129 storage_.Remove(dicomInfo.GetUuid()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
130 storage_.Remove(jsonInfo.GetUuid()); |
224 | 131 } |
132 | |
133 switch (status) | |
134 { | |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
135 case StoreStatus_Success: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
136 LOG(INFO) << "New instance stored"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
137 break; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
138 |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
139 case StoreStatus_AlreadyStored: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
140 LOG(INFO) << "Already stored"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
141 break; |
224 | 142 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
143 case StoreStatus_Failure: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
144 LOG(ERROR) << "Store failure"; |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
145 break; |
224 | 146 |
397
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
147 default: |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
148 // This should never happen |
941ea46e9e26
lua filter of new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
394
diff
changeset
|
149 break; |
224 | 150 } |
151 | |
152 return status; | |
153 } | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
154 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
155 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
156 void ServerContext::AnswerFile(RestApiOutput& output, |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
157 const std::string& instancePublicId, |
233 | 158 FileContentType content) |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
159 { |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
160 FileInfo attachment; |
236 | 161 if (!index_.LookupAttachment(attachment, instancePublicId, content)) |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
162 { |
236 | 163 throw OrthancException(ErrorCode_InternalError); |
164 } | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
165 |
236 | 166 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType()); |
320 | 167 |
236 | 168 std::auto_ptr<HttpFileSender> sender(accessor_.ConstructHttpFileSender(attachment.GetUuid())); |
320 | 169 sender->SetContentType("application/dicom"); |
170 sender->SetDownloadFilename(instancePublicId + ".dcm"); | |
236 | 171 output.AnswerFile(*sender); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
172 } |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
173 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
174 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
175 void ServerContext::ReadJson(Json::Value& result, |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
176 const std::string& instancePublicId) |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
177 { |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
178 std::string s; |
233 | 179 ReadFile(s, instancePublicId, FileContentType_Json); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
180 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
181 Json::Reader reader; |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
182 if (!reader.parse(s, result)) |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
183 { |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
184 throw OrthancException("Corrupted JSON file"); |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
185 } |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
186 } |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
187 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
188 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
189 void ServerContext::ReadFile(std::string& result, |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
190 const std::string& instancePublicId, |
233 | 191 FileContentType content) |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
192 { |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
193 FileInfo attachment; |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
194 if (!index_.LookupAttachment(attachment, instancePublicId, content)) |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
195 { |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
196 throw OrthancException(ErrorCode_InternalError); |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
197 } |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
198 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
199 accessor_.SetCompressionForNextOperations(attachment.GetCompressionType()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
200 accessor_.Read(result, attachment.GetUuid()); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
201 } |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
202 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
203 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
204 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
|
205 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
206 std::string content; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
207 context_.ReadFile(content, instancePublicId, FileContentType_Dicom); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
208 return new ParsedDicomFile(content); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
209 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
210 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
211 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
212 ParsedDicomFile& ServerContext::GetDicomFile(const std::string& instancePublicId) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
213 { |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
214 #if ENABLE_DICOM_CACHE == 0 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
215 static std::auto_ptr<IDynamicObject> p; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
216 p.reset(provider_.Provide(instancePublicId)); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
217 return dynamic_cast<ParsedDicomFile&>(*p); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
218 #else |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
219 return dynamic_cast<ParsedDicomFile&>(dicomCache_.Access(instancePublicId)); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
288
diff
changeset
|
220 #endif |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
221 } |
304 | 222 |
223 | |
224 StoreStatus ServerContext::Store(std::string& resultPublicId, | |
225 DcmFileFormat& dicomInstance, | |
226 const char* dicomBuffer, | |
227 size_t dicomSize) | |
228 { | |
229 DicomMap dicomSummary; | |
230 FromDcmtkBridge::Convert(dicomSummary, *dicomInstance.getDataset()); | |
231 | |
232 DicomInstanceHasher hasher(dicomSummary); | |
233 resultPublicId = hasher.HashInstance(); | |
234 | |
235 Json::Value dicomJson; | |
236 FromDcmtkBridge::ToJson(dicomJson, *dicomInstance.getDataset()); | |
237 | |
238 StoreStatus status = StoreStatus_Failure; | |
239 if (dicomSize > 0) | |
240 { | |
241 status = Store(dicomBuffer, dicomSize, dicomSummary, dicomJson, ""); | |
242 } | |
243 | |
244 return status; | |
245 } | |
246 | |
247 | |
248 StoreStatus ServerContext::Store(std::string& resultPublicId, | |
249 DcmFileFormat& dicomInstance) | |
250 { | |
251 std::string buffer; | |
252 if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer, dicomInstance.getDataset())) | |
253 { | |
254 throw OrthancException(ErrorCode_InternalError); | |
255 } | |
256 | |
257 if (buffer.size() == 0) | |
258 return Store(resultPublicId, dicomInstance, NULL, 0); | |
259 else | |
260 return Store(resultPublicId, dicomInstance, &buffer[0], buffer.size()); | |
261 } | |
262 | |
263 | |
264 StoreStatus ServerContext::Store(std::string& resultPublicId, | |
265 const char* dicomBuffer, | |
266 size_t dicomSize) | |
267 { | |
268 ParsedDicomFile dicom(dicomBuffer, dicomSize); | |
269 return Store(resultPublicId, dicom.GetDicom(), dicomBuffer, dicomSize); | |
270 } | |
271 | |
224 | 272 } |