Mercurial > hg > orthanc
annotate OrthancServer/FromDcmtkBridge.h @ 2128:9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 15:13:16 +0100 |
parents | 03b065778fc3 |
children | bb199bccdc45 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1004
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 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. | |
136 | 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. | |
0 | 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 #pragma once | |
34 | |
789 | 35 #include "ServerEnumerations.h" |
2125 | 36 #include "OrthancInitialization.h" |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
37 |
2115
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
38 #include "../Core/DicomFormat/DicomElement.h" |
791 | 39 #include "../Core/DicomFormat/DicomMap.h" |
40 | |
0 | 41 #include <dcmtk/dcmdata/dcdatset.h> |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
42 #include <dcmtk/dcmdata/dcmetinf.h> |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
43 #include <dcmtk/dcmdata/dcpixseq.h> |
1935
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
44 #include <dcmtk/dcmdata/dcfilefo.h> |
0 | 45 #include <json/json.h> |
46 | |
2126 | 47 #if ORTHANC_BUILD_UNIT_TESTS == 1 |
48 # include <gtest/gtest_prod.h> | |
49 #endif | |
50 | |
51 | |
62 | 52 namespace Orthanc |
0 | 53 { |
2125 | 54 class FromDcmtkBridge : public boost::noncopyable |
0 | 55 { |
2126 | 56 #if ORTHANC_BUILD_UNIT_TESTS == 1 |
57 FRIEND_TEST(FromDcmtkBridge, FromJson); | |
58 #endif | |
59 | |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
60 friend class ParsedDicomFile; |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
61 |
2125 | 62 private: |
63 FromDcmtkBridge(); // Pure static class | |
64 | |
65 static void ExtractDicomSummary(DicomMap& target, | |
66 DcmItem& dataset, | |
67 unsigned int maxStringLength, | |
68 Encoding defaultEncoding); | |
69 | |
2126 | 70 static void DatasetToJson(Json::Value& parent, |
71 DcmItem& item, | |
72 DicomToJsonFormat format, | |
73 DicomToJsonFlags flags, | |
74 unsigned int maxStringLength, | |
75 Encoding encoding); | |
76 | |
77 static void ElementToJson(Json::Value& parent, | |
78 DcmElement& element, | |
79 DicomToJsonFormat format, | |
80 DicomToJsonFlags flags, | |
81 unsigned int maxStringLength, | |
82 Encoding dicomEncoding); | |
83 | |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
84 static void ExtractDicomAsJson(Json::Value& target, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
85 DcmDataset& dataset, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
86 DicomToJsonFormat format, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
87 DicomToJsonFlags flags, |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
88 unsigned int maxStringLength); |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
89 |
0 | 90 public: |
1656 | 91 static void InitializeDictionary(); |
92 | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
93 static void RegisterDictionaryTag(const DicomTag& tag, |
2006
6301bbcbcaed
more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
94 ValueRepresentation vr, |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
95 const std::string& name, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
96 unsigned int minMultiplicity, |
2115
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
97 unsigned int maxMultiplicity, |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
98 const std::string& privateCreator); |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
99 |
1936 | 100 static Encoding DetectEncoding(DcmItem& dataset, |
1928
84c7eaeb5244
Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1924
diff
changeset
|
101 Encoding defaultEncoding); |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
102 |
2125 | 103 static void ExtractDicomSummary(DicomMap& target, |
104 DcmItem& dataset) | |
105 { | |
106 ExtractDicomSummary(target, dataset, ORTHANC_MAXIMUM_TAG_LENGTH, Configuration::GetDefaultEncoding()); | |
107 } | |
0 | 108 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
109 static DicomTag Convert(const DcmTag& tag); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
110 |
0 | 111 static DicomTag GetTag(const DcmElement& element); |
112 | |
1655
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
113 static bool IsUnknownTag(const DicomTag& tag); |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
114 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
115 static DicomValue* ConvertLeafElement(DcmElement& element, |
1736
b953c6eef28d
ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1735
diff
changeset
|
116 DicomToJsonFlags flags, |
1929
cda5b0ab4ce5
ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1928
diff
changeset
|
117 unsigned int maxStringLength, |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
118 Encoding encoding); |
0 | 119 |
2126 | 120 static void ExtractDicomAsJson(Json::Value& target, |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
121 DcmDataset& dataset) |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
122 { |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
123 ExtractDicomAsJson(target, dataset, DicomToJsonFormat_Full, DicomToJsonFlags_Default, ORTHANC_MAXIMUM_TAG_LENGTH); |
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2126
diff
changeset
|
124 } |
1690 | 125 |
2126 | 126 static void ExtractHeaderAsJson(Json::Value& target, |
127 DcmMetaInfo& header, | |
128 DicomToJsonFormat format, | |
129 DicomToJsonFlags flags, | |
130 unsigned int maxStringLength); | |
1831
3ae2ff249675
"/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
131 |
2115
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
132 static std::string GetTagName(const DicomTag& tag, |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
133 const std::string& privateCreator); |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
134 |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
135 static std::string GetTagName(const DcmElement& element); |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
136 |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
137 static std::string GetTagName(const DicomElement& element) |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
138 { |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
139 return GetTagName(element.GetTag(), ""); |
a657f7772e69
Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
140 } |
0 | 141 |
304 | 142 static DicomTag ParseTag(const char* name); |
0 | 143 |
304 | 144 static DicomTag ParseTag(const std::string& name) |
0 | 145 { |
304 | 146 return ParseTag(name.c_str()); |
0 | 147 } |
148 | |
149 static bool HasTag(const DicomMap& fields, | |
150 const std::string& tagName) | |
151 { | |
304 | 152 return fields.HasTag(ParseTag(tagName)); |
0 | 153 } |
154 | |
155 static const DicomValue& GetValue(const DicomMap& fields, | |
156 const std::string& tagName) | |
157 { | |
304 | 158 return fields.GetValue(ParseTag(tagName)); |
0 | 159 } |
160 | |
161 static void SetValue(DicomMap& target, | |
162 const std::string& tagName, | |
163 DicomValue* value) | |
164 { | |
304 | 165 target.SetValue(ParseTag(tagName), value); |
0 | 166 } |
167 | |
168 static void ToJson(Json::Value& result, | |
1368 | 169 const DicomMap& values, |
170 bool simplify); | |
176 | 171 |
788 | 172 static std::string GenerateUniqueIdentifier(ResourceType level); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
173 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
174 static bool SaveToMemoryBuffer(std::string& buffer, |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
175 DcmDataset& dataSet); |
1360 | 176 |
2006
6301bbcbcaed
more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
177 static ValueRepresentation Convert(DcmEVR vr); |
6301bbcbcaed
more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
178 |
6301bbcbcaed
more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1998
diff
changeset
|
179 static ValueRepresentation LookupValueRepresentation(const DicomTag& tag); |
1689 | 180 |
181 static DcmElement* CreateElementForTag(const DicomTag& tag); | |
182 | |
183 static void FillElementWithString(DcmElement& element, | |
184 const DicomTag& tag, | |
1695 | 185 const std::string& utf8alue, // Encoded using UTF-8 |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1765
diff
changeset
|
186 bool decodeDataUriScheme, |
1695 | 187 Encoding dicomEncoding); |
1689 | 188 |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1690
diff
changeset
|
189 static DcmElement* FromJson(const DicomTag& tag, |
1934
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
190 const Json::Value& element, // Encoded using UTF-8 |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1765
diff
changeset
|
191 bool decodeDataUriScheme, |
1695 | 192 Encoding dicomEncoding); |
1765
57b9e6890482
New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1737
diff
changeset
|
193 |
1924
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
194 static DcmPixelSequence* GetPixelSequence(DcmDataset& dataset); |
1934
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
195 |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
196 static Encoding ExtractEncoding(const Json::Value& json, |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
197 Encoding defaultEncoding); |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
198 |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
199 static DcmDataset* FromJson(const Json::Value& json, // Encoded using UTF-8 |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
200 bool generateIdentifiers, |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
201 bool decodeDataUriScheme, |
72a2fd7fed8b
FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
202 Encoding defaultEncoding); |
1935
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
203 |
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
204 static DcmFileFormat* LoadFromMemoryBuffer(const void* buffer, |
e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1934
diff
changeset
|
205 size_t size); |
1998
9b61701c35f2
New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1936
diff
changeset
|
206 |
9b61701c35f2
New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1936
diff
changeset
|
207 static void FromJson(DicomMap& values, |
9b61701c35f2
New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1936
diff
changeset
|
208 const Json::Value& result); |
0 | 209 }; |
210 } |