comparison Core/DicomParsing/FromDcmtkBridge.h @ 2382:7284093111b0

big reorganization to cleanly separate framework vs. server
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Aug 2017 21:17:35 +0200
parents OrthancServer/FromDcmtkBridge.h@b8969010b534
children e4045b3c9772
comparison
equal deleted inserted replaced
2381:b8969010b534 2382:7284093111b0
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017 Osimis, Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #include "../DicomFormat/DicomElement.h"
37 #include "../DicomFormat/DicomMap.h"
38
39 #include <dcmtk/dcmdata/dcdatset.h>
40 #include <dcmtk/dcmdata/dcmetinf.h>
41 #include <dcmtk/dcmdata/dcpixseq.h>
42 #include <dcmtk/dcmdata/dcfilefo.h>
43 #include <json/json.h>
44
45 #if !defined(ORTHANC_ENABLE_LUA)
46 # error The macro ORTHANC_ENABLE_LUA must be defined
47 #endif
48
49 #if ORTHANC_ENABLE_DCMTK != 1
50 # error The macro ORTHANC_ENABLE_DCMTK must be set to 1
51 #endif
52
53 #if ORTHANC_BUILD_UNIT_TESTS == 1
54 # include <gtest/gtest_prod.h>
55 #endif
56
57 #if ORTHANC_ENABLE_LUA == 1
58 # include "../Lua/LuaFunctionCall.h"
59 #endif
60
61 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG)
62 # error The macro ORTHANC_ENABLE_DCMTK_JPEG must be defined
63 #endif
64
65 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS)
66 # error The macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined
67 #endif
68
69
70 namespace Orthanc
71 {
72 class FromDcmtkBridge : public boost::noncopyable
73 {
74 #if ORTHANC_BUILD_UNIT_TESTS == 1
75 FRIEND_TEST(FromDcmtkBridge, FromJson);
76 #endif
77
78 friend class ParsedDicomFile;
79
80 private:
81 FromDcmtkBridge(); // Pure static class
82
83 static void ExtractDicomSummary(DicomMap& target,
84 DcmItem& dataset,
85 unsigned int maxStringLength,
86 Encoding defaultEncoding);
87
88 static void DatasetToJson(Json::Value& parent,
89 DcmItem& item,
90 DicomToJsonFormat format,
91 DicomToJsonFlags flags,
92 unsigned int maxStringLength,
93 Encoding encoding);
94
95 static void ElementToJson(Json::Value& parent,
96 DcmElement& element,
97 DicomToJsonFormat format,
98 DicomToJsonFlags flags,
99 unsigned int maxStringLength,
100 Encoding dicomEncoding);
101
102 static void ExtractDicomAsJson(Json::Value& target,
103 DcmDataset& dataset,
104 DicomToJsonFormat format,
105 DicomToJsonFlags flags,
106 unsigned int maxStringLength,
107 Encoding defaultEncoding);
108
109 static void ChangeStringEncoding(DcmItem& dataset,
110 Encoding source,
111 Encoding target);
112
113 public:
114 static void InitializeDictionary(bool loadPrivateDictionary);
115
116 static void RegisterDictionaryTag(const DicomTag& tag,
117 ValueRepresentation vr,
118 const std::string& name,
119 unsigned int minMultiplicity,
120 unsigned int maxMultiplicity,
121 const std::string& privateCreator);
122
123 static Encoding DetectEncoding(DcmItem& dataset,
124 Encoding defaultEncoding);
125
126 static DicomTag Convert(const DcmTag& tag);
127
128 static DicomTag GetTag(const DcmElement& element);
129
130 static bool IsUnknownTag(const DicomTag& tag);
131
132 static DicomValue* ConvertLeafElement(DcmElement& element,
133 DicomToJsonFlags flags,
134 unsigned int maxStringLength,
135 Encoding encoding);
136
137 static void ExtractHeaderAsJson(Json::Value& target,
138 DcmMetaInfo& header,
139 DicomToJsonFormat format,
140 DicomToJsonFlags flags,
141 unsigned int maxStringLength);
142
143 static std::string GetTagName(const DicomTag& tag,
144 const std::string& privateCreator);
145
146 static std::string GetTagName(const DcmElement& element);
147
148 static std::string GetTagName(const DicomElement& element)
149 {
150 return GetTagName(element.GetTag(), "");
151 }
152
153 static DicomTag ParseTag(const char* name);
154
155 static DicomTag ParseTag(const std::string& name)
156 {
157 return ParseTag(name.c_str());
158 }
159
160 static bool HasTag(const DicomMap& fields,
161 const std::string& tagName)
162 {
163 return fields.HasTag(ParseTag(tagName));
164 }
165
166 static const DicomValue& GetValue(const DicomMap& fields,
167 const std::string& tagName)
168 {
169 return fields.GetValue(ParseTag(tagName));
170 }
171
172 static void SetValue(DicomMap& target,
173 const std::string& tagName,
174 DicomValue* value)
175 {
176 target.SetValue(ParseTag(tagName), value);
177 }
178
179 static void ToJson(Json::Value& result,
180 const DicomMap& values,
181 bool simplify);
182
183 static std::string GenerateUniqueIdentifier(ResourceType level);
184
185 static bool SaveToMemoryBuffer(std::string& buffer,
186 DcmDataset& dataSet);
187
188 static ValueRepresentation Convert(DcmEVR vr);
189
190 static ValueRepresentation LookupValueRepresentation(const DicomTag& tag);
191
192 static DcmElement* CreateElementForTag(const DicomTag& tag);
193
194 static void FillElementWithString(DcmElement& element,
195 const DicomTag& tag,
196 const std::string& utf8alue, // Encoded using UTF-8
197 bool decodeDataUriScheme,
198 Encoding dicomEncoding);
199
200 static DcmElement* FromJson(const DicomTag& tag,
201 const Json::Value& element, // Encoded using UTF-8
202 bool decodeDataUriScheme,
203 Encoding dicomEncoding);
204
205 static DcmPixelSequence* GetPixelSequence(DcmDataset& dataset);
206
207 static Encoding ExtractEncoding(const Json::Value& json,
208 Encoding defaultEncoding);
209
210 static DcmDataset* FromJson(const Json::Value& json, // Encoded using UTF-8
211 bool generateIdentifiers,
212 bool decodeDataUriScheme,
213 Encoding defaultEncoding);
214
215 static DcmFileFormat* LoadFromMemoryBuffer(const void* buffer,
216 size_t size);
217
218 static void FromJson(DicomMap& values,
219 const Json::Value& result);
220
221 static bool LookupTransferSyntax(std::string& result,
222 DcmFileFormat& dicom);
223
224 #if ORTHANC_ENABLE_LUA == 1
225 static void ExecuteToDicom(DicomMap& target,
226 LuaFunctionCall& call);
227 #endif
228
229 static void ExtractDicomSummary(DicomMap& target,
230 DcmItem& dataset);
231
232 static void ExtractDicomAsJson(Json::Value& target,
233 DcmDataset& dataset);
234
235 static void InitializeCodecs();
236
237 static void FinalizeCodecs();
238 };
239 }