Mercurial > hg > orthanc
annotate OrthancServer/FromDcmtkBridge.cpp @ 1693:558b25228a23
creation of tag hierarchy from json
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 Oct 2015 13:45:33 +0200 |
parents | e447f3cb8b30 |
children | 06d579e82bb8 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1147
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1147
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 | |
448
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
32 |
9d830dcc7730
missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
419
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "PrecompiledHeadersServer.h" |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
35 |
71 | 36 #ifndef NOMINMAX |
37 #define NOMINMAX | |
38 #endif | |
0 | 39 |
846 | 40 #include "Internals/DicomImageDecoder.h" |
41 | |
0 | 42 #include "FromDcmtkBridge.h" |
43 #include "ToDcmtkBridge.h" | |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1004
diff
changeset
|
44 #include "OrthancInitialization.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
45 #include "../Core/Logging.h" |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
46 #include "../Core/Toolbox.h" |
62 | 47 #include "../Core/OrthancException.h" |
1612
96582230ddcb
Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
48 #include "../Core/Images/PngWriter.h" |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
49 #include "../Core/Uuid.h" |
0 | 50 #include "../Core/DicomFormat/DicomString.h" |
51 #include "../Core/DicomFormat/DicomNullValue.h" | |
79 | 52 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
0 | 53 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
54 #include <list> |
71 | 55 #include <limits> |
56 | |
0 | 57 #include <boost/lexical_cast.hpp> |
1656 | 58 #include <boost/filesystem.hpp> |
0 | 59 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
60 #include <dcmtk/dcmdata/dcchrstr.h> |
0 | 61 #include <dcmtk/dcmdata/dcdicent.h> |
62 #include <dcmtk/dcmdata/dcdict.h> | |
63 #include <dcmtk/dcmdata/dcfilefo.h> | |
64 #include <dcmtk/dcmdata/dcistrmb.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
65 #include <dcmtk/dcmdata/dcuid.h> |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
66 #include <dcmtk/dcmdata/dcmetinf.h> |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
67 #include <dcmtk/dcmdata/dcdeftag.h> |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
68 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
69 #include <dcmtk/dcmdata/dcvrae.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
70 #include <dcmtk/dcmdata/dcvras.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
71 #include <dcmtk/dcmdata/dcvrcs.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
72 #include <dcmtk/dcmdata/dcvrda.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
73 #include <dcmtk/dcmdata/dcvrds.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
74 #include <dcmtk/dcmdata/dcvrdt.h> |
0 | 75 #include <dcmtk/dcmdata/dcvrfd.h> |
76 #include <dcmtk/dcmdata/dcvrfl.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
77 #include <dcmtk/dcmdata/dcvris.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
78 #include <dcmtk/dcmdata/dcvrlo.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
79 #include <dcmtk/dcmdata/dcvrlt.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
80 #include <dcmtk/dcmdata/dcvrpn.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
81 #include <dcmtk/dcmdata/dcvrsh.h> |
0 | 82 #include <dcmtk/dcmdata/dcvrsl.h> |
83 #include <dcmtk/dcmdata/dcvrss.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
84 #include <dcmtk/dcmdata/dcvrst.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
85 #include <dcmtk/dcmdata/dcvrtm.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
86 #include <dcmtk/dcmdata/dcvrui.h> |
0 | 87 #include <dcmtk/dcmdata/dcvrul.h> |
88 #include <dcmtk/dcmdata/dcvrus.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
89 #include <dcmtk/dcmdata/dcvrut.h> |
676
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
90 #include <dcmtk/dcmdata/dcpixel.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
91 #include <dcmtk/dcmdata/dcpixseq.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
92 #include <dcmtk/dcmdata/dcpxitem.h> |
1131 | 93 #include <dcmtk/dcmdata/dcvrat.h> |
676
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
94 |
1656 | 95 #include <dcmtk/dcmnet/dul.h> |
0 | 96 |
2 | 97 #include <boost/math/special_functions/round.hpp> |
1689 | 98 #include <boost/algorithm/string/predicate.hpp> |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
99 #include <dcmtk/dcmdata/dcostrmb.h> |
0 | 100 |
682
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
677
diff
changeset
|
101 |
62 | 102 namespace Orthanc |
0 | 103 { |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
104 static inline uint16_t GetCharValue(char c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
105 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
106 if (c >= '0' && c <= '9') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
107 return c - '0'; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
108 else if (c >= 'a' && c <= 'f') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
109 return c - 'a' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
110 else if (c >= 'A' && c <= 'F') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
111 return c - 'A' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
112 else |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
113 return 0; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
114 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
115 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
116 static inline uint16_t GetTagValue(const char* c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
117 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
118 return ((GetCharValue(c[0]) << 12) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
119 (GetCharValue(c[1]) << 8) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
120 (GetCharValue(c[2]) << 4) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
121 GetCharValue(c[3])); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
122 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
123 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
124 |
1656 | 125 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 |
126 static void LoadEmbeddedDictionary(DcmDataDictionary& dictionary, | |
127 EmbeddedResources::FileResourceId resource) | |
128 { | |
129 Toolbox::TemporaryFile tmp; | |
130 | |
131 FILE* fp = fopen(tmp.GetPath().c_str(), "wb"); | |
132 fwrite(EmbeddedResources::GetFileResourceBuffer(resource), | |
133 EmbeddedResources::GetFileResourceSize(resource), 1, fp); | |
134 fclose(fp); | |
135 | |
136 if (!dictionary.loadDictionary(tmp.GetPath().c_str())) | |
137 { | |
138 throw OrthancException(ErrorCode_InternalError); | |
139 } | |
140 } | |
141 | |
142 #else | |
143 static void LoadExternalDictionary(DcmDataDictionary& dictionary, | |
144 const std::string& directory, | |
145 const std::string& filename) | |
146 { | |
147 boost::filesystem::path p = directory; | |
148 p = p / filename; | |
149 | |
150 LOG(WARNING) << "Loading the external DICOM dictionary " << p; | |
151 | |
152 if (!dictionary.loadDictionary(p.string().c_str())) | |
153 { | |
154 throw OrthancException(ErrorCode_InternalError); | |
155 } | |
156 } | |
157 | |
158 #endif | |
159 | |
160 | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
161 namespace |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
162 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
163 class DictionaryLocker |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
164 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
165 private: |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
166 DcmDataDictionary& dictionary_; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
167 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
168 public: |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
169 DictionaryLocker() : dictionary_(dcmDataDict.wrlock()) |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
170 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
171 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
172 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
173 ~DictionaryLocker() |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
174 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
175 dcmDataDict.unlock(); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
176 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
177 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
178 DcmDataDictionary& operator*() |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
179 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
180 return dictionary_; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
181 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
182 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
183 DcmDataDictionary* operator->() |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
184 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
185 return &dictionary_; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
186 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
187 }; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
188 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
189 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
190 |
1656 | 191 void FromDcmtkBridge::InitializeDictionary() |
192 { | |
193 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */ | |
194 dcmDisableGethostbyaddr.set(OFTrue); | |
195 | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
196 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
197 DictionaryLocker locker; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
198 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
199 locker->clear(); |
1656 | 200 |
201 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
202 LOG(WARNING) << "Loading the embedded dictionaries"; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
203 /** |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
204 * Do not load DICONDE dictionary, it breaks the other tags. The |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
205 * command "strace storescu 2>&1 |grep dic" shows that DICONDE |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
206 * dictionary is not loaded by storescu. |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
207 **/ |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
208 //LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICONDE); |
1656 | 209 |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
210 LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICOM); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
211 LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_PRIVATE); |
1656 | 212 |
213 #elif defined(__linux) || defined(__FreeBSD_kernel__) | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
214 std::string path = DCMTK_DICTIONARY_DIR; |
1656 | 215 |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
216 const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
217 if (env != NULL) |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
218 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
219 path = std::string(env); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
220 } |
1656 | 221 |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
222 LoadExternalDictionary(*locker, path, "dicom.dic"); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
223 LoadExternalDictionary(*locker, path, "private.dic"); |
1656 | 224 |
225 #else | |
226 #error Support your platform here | |
227 #endif | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
228 } |
1656 | 229 |
230 /* make sure data dictionary is loaded */ | |
231 if (!dcmDataDict.isDictionaryLoaded()) | |
232 { | |
233 LOG(ERROR) << "No DICOM dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE; | |
234 throw OrthancException(ErrorCode_InternalError); | |
235 } | |
236 | |
237 { | |
238 // Test the dictionary with a simple DICOM tag | |
239 DcmTag key(0x0010, 0x1030); // This is PatientWeight | |
240 if (key.getEVR() != EVR_DS) | |
241 { | |
242 LOG(ERROR) << "The DICOM dictionary has not been correctly read"; | |
243 throw OrthancException(ErrorCode_InternalError); | |
244 } | |
245 } | |
246 } | |
247 | |
248 | |
1657
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
249 void FromDcmtkBridge::RegisterDictionaryTag(const DicomTag& tag, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
250 const DcmEVR& vr, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
251 const std::string& name, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
252 unsigned int minMultiplicity, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
253 unsigned int maxMultiplicity) |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
254 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
255 if (minMultiplicity < 1) |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
256 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
257 throw OrthancException(ErrorCode_ParameterOutOfRange); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
258 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
259 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
260 if (maxMultiplicity == 0) |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
261 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
262 maxMultiplicity = DcmVariableVM; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
263 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
264 else if (maxMultiplicity < minMultiplicity) |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
265 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
266 throw OrthancException(ErrorCode_ParameterOutOfRange); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
267 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
268 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
269 std::auto_ptr<DcmDictEntry> entry(new DcmDictEntry(tag.GetGroup(), |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
270 tag.GetElement(), |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
271 vr, name.c_str(), |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
272 static_cast<int>(minMultiplicity), |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
273 static_cast<int>(maxMultiplicity), |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
274 NULL /* version */, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
275 OFTrue /* doCopyString */, |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
276 NULL /* private creator */)); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
277 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
278 entry->setGroupRangeRestriction(DcmDictRange_Unspecified); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
279 entry->setElementRangeRestriction(DcmDictRange_Unspecified); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
280 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
281 { |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
282 DictionaryLocker locker; |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
283 locker->addEntry(entry.release()); |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
284 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
285 } |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
286 |
5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
287 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
288 Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset) |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
289 { |
1093
552a038f7c96
Default encoding is Latin-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
290 // By default, Latin1 encoding is assumed |
1557 | 291 std::string s = Configuration::GetGlobalStringParameter("DefaultEncoding", "Latin1"); |
1093
552a038f7c96
Default encoding is Latin-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
292 Encoding encoding = s.empty() ? Encoding_Latin1 : StringToEncoding(s.c_str()); |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
293 |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
294 OFString tmp; |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
295 if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good()) |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
296 { |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
297 std::string characterSet = Toolbox::StripSpaces(std::string(tmp.c_str())); |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
298 |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
299 if (characterSet.empty()) |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
300 { |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
301 // Empty specific character set tag: Use the default encoding |
1087 | 302 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
303 else if (GetDicomEncoding(encoding, characterSet.c_str())) |
1087 | 304 { |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
305 // The specific character set is supported by the Orthanc core |
1087 | 306 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
307 else |
1087 | 308 { |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
309 LOG(WARNING) << "Value of Specific Character Set (0008,0005) is not supported: " << characterSet |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
310 << ", fallback to ASCII (remove all special characters)"; |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
311 encoding = Encoding_Ascii; |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
312 } |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
313 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
314 else |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
315 { |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
316 // No specific character set tag: Use the default encoding |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
317 } |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
318 |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
319 return encoding; |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
320 } |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
321 |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
322 |
0 | 323 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset) |
324 { | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
325 Encoding encoding = DetectEncoding(dataset); |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
326 |
0 | 327 target.Clear(); |
328 for (unsigned long i = 0; i < dataset.card(); i++) | |
329 { | |
330 DcmElement* element = dataset.getElement(i); | |
331 if (element && element->isLeaf()) | |
332 { | |
333 target.SetValue(element->getTag().getGTag(), | |
334 element->getTag().getETag(), | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
335 ConvertLeafElement(*element, encoding)); |
0 | 336 } |
337 } | |
338 } | |
339 | |
340 | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
341 DicomTag FromDcmtkBridge::Convert(const DcmTag& tag) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
342 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
343 return DicomTag(tag.getGTag(), tag.getETag()); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
344 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
345 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
346 |
0 | 347 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element) |
348 { | |
349 return DicomTag(element.getGTag(), element.getETag()); | |
350 } | |
351 | |
352 | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
353 bool FromDcmtkBridge::IsPrivateTag(DcmTag& tag) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
354 { |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
355 #if 1 |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
356 DcmTagKey tmp(tag.getGTag(), tag.getETag()); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
357 return tmp.isPrivate(); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
358 #else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
359 // Implementation for Orthanc versions <= 0.8.5 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
360 return (tag.getPrivateCreator() != NULL || |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
361 !strcmp("PrivateCreator", tag.getTagName())); // TODO - This may change with future versions of DCMTK |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
362 #endif |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
363 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
364 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
365 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
366 bool FromDcmtkBridge::IsPrivateTag(const DicomTag& tag) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
367 { |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
368 #if 1 |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
369 DcmTagKey tmp(tag.GetGroup(), tag.GetElement()); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
370 return tmp.isPrivate(); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
371 #else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
372 // Implementation for Orthanc versions <= 0.8.5 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
373 DcmTag tmp(tag.GetGroup(), tag.GetElement()); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
374 return IsPrivateTag(tmp); |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
375 #endif |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
376 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
377 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
378 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
379 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element, |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
380 Encoding encoding) |
0 | 381 { |
382 if (!element.isLeaf()) | |
383 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
384 // This function is only applicable to leaf elements |
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
385 throw OrthancException(ErrorCode_BadParameterType); |
0 | 386 } |
387 | |
388 if (element.isaString()) | |
389 { | |
390 char *c; | |
1429
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
391 if (element.getString(c).good()) |
0 | 392 { |
1429
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
393 if (c == NULL) // This case corresponds to the empty string |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
394 { |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
395 return new DicomString(""); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
396 } |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
397 else |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
398 { |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
399 std::string s(c); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
400 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
401 return new DicomString(utf8); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1417
diff
changeset
|
402 } |
0 | 403 } |
404 else | |
405 { | |
406 return new DicomNullValue; | |
407 } | |
408 } | |
409 | |
410 try | |
411 { | |
412 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
413 switch (element.getVR()) | |
414 { | |
415 | |
416 /** | |
417 * TODO. | |
418 **/ | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
419 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
420 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
421 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
422 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
423 case EVR_UN: // unknown value representation |
1131 | 424 return new DicomNullValue; |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
425 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
426 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
427 * String types, should never happen at this point because of |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
428 * "element.isaString()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
429 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
430 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
431 case EVR_DS: // decimal string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
432 case EVR_IS: // integer string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
433 case EVR_AS: // age string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
434 case EVR_DA: // date string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
435 case EVR_DT: // date time string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
436 case EVR_TM: // time string |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
437 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
438 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
439 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
440 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
441 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
442 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
443 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
444 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
445 case EVR_UI: // unique identifier |
1131 | 446 return new DicomNullValue; |
0 | 447 |
448 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
449 /** |
1131 | 450 * Numberic types |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
451 **/ |
0 | 452 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
453 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
454 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
455 Sint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
456 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
457 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
458 else |
1131 | 459 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
460 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
461 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
462 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
463 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
464 Sint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
465 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
466 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
467 else |
1131 | 468 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
469 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
470 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
471 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
472 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
473 Uint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
474 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
475 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
476 else |
1131 | 477 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
478 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
479 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
480 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
481 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
482 Uint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
483 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
484 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
485 else |
1131 | 486 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
487 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
488 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
489 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
490 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
491 Float32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
492 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
493 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
494 else |
1131 | 495 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
496 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
497 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
498 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
499 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
500 Float64 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
501 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
502 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
503 else |
1131 | 504 return new DicomNullValue; |
505 } | |
506 | |
507 | |
508 /** | |
509 * Attribute tag. | |
510 **/ | |
511 | |
512 case EVR_AT: | |
513 { | |
1147 | 514 DcmTagKey tag; |
515 if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good()) | |
516 { | |
517 DicomTag t(tag.getGroup(), tag.getElement()); | |
518 return new DicomString(t.Format()); | |
519 } | |
1131 | 520 else |
1147 | 521 { |
1131 | 522 return new DicomNullValue; |
1147 | 523 } |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
524 } |
0 | 525 |
526 | |
527 /** | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
528 * Sequence types, should never occur at this point because of |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
529 * "element.isLeaf()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
530 **/ |
0 | 531 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
532 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
533 return new DicomNullValue; |
0 | 534 |
535 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
536 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
537 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
538 **/ |
0 | 539 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
540 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
541 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
542 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
543 case EVR_na: // na="not applicable", for data which has no VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
544 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
545 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
546 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
547 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
548 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
549 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
550 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
551 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
552 case EVR_pixelItem: // used internally for pixel items in a compressed image |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
553 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
554 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
555 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
556 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
557 return new DicomNullValue; |
0 | 558 |
559 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
560 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
561 * Default case. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
562 **/ |
0 | 563 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
564 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
565 return new DicomNullValue; |
0 | 566 } |
567 } | |
568 catch (boost::bad_lexical_cast) | |
569 { | |
570 return new DicomNullValue; | |
571 } | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
572 catch (std::bad_cast) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
573 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
574 return new DicomNullValue; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
575 } |
0 | 576 } |
577 | |
578 | |
1687 | 579 static Json::Value& PrepareNode(Json::Value& parent, |
580 DcmElement& element, | |
581 DicomToJsonFormat format) | |
0 | 582 { |
1687 | 583 assert(parent.type() == Json::objectValue); |
0 | 584 |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
585 DicomTag tag(FromDcmtkBridge::GetTag(element)); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
586 const std::string formattedTag = tag.Format(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
587 |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
588 if (format == DicomToJsonFormat_Short) |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
589 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
590 parent[formattedTag] = Json::nullValue; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
591 return parent[formattedTag]; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
592 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
593 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
594 // This code gives access to the name of the private tags |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
595 DcmTag tagbis(element.getTag()); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
596 const std::string tagName(tagbis.getTagName()); |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
597 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
598 switch (format) |
0 | 599 { |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
600 case DicomToJsonFormat_Simple: |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
601 parent[tagName] = Json::nullValue; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
602 return parent[tagName]; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
603 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
604 case DicomToJsonFormat_Full: |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
605 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
606 parent[formattedTag] = Json::objectValue; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
607 Json::Value& node = parent[formattedTag]; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
608 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
609 if (element.isLeaf()) |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
610 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
611 node["Name"] = tagName; |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
612 |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
613 if (tagbis.getPrivateCreator() != NULL) |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
614 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
615 node["PrivateCreator"] = tagbis.getPrivateCreator(); |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
616 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
617 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
618 return node; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
619 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
620 else |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
621 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
622 node["Name"] = tagName; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
623 node["Type"] = "Sequence"; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
624 node["Value"] = Json::nullValue; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
625 return node["Value"]; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
626 } |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
627 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
628 |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
629 default: |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
630 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1687 | 631 } |
632 } | |
633 | |
634 | |
635 static void LeafValueToJson(Json::Value& target, | |
636 const DicomValue& value, | |
637 DicomToJsonFormat format, | |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
638 unsigned int maxStringLength) |
1687 | 639 { |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
640 std::string content = value.AsString(); |
1687 | 641 |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
642 switch (format) |
1687 | 643 { |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
644 case DicomToJsonFormat_Short: |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
645 case DicomToJsonFormat_Simple: |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
646 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
647 assert(target.type() == Json::nullValue); |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
648 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
649 if (!value.IsNull() && |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
650 (maxStringLength == 0 || |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
651 content.size() <= maxStringLength)) |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
652 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
653 target = content; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
654 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
655 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
656 break; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
657 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
658 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
659 case DicomToJsonFormat_Full: |
0 | 660 { |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
661 assert(target.type() == Json::objectValue); |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
662 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
663 if (value.IsNull()) |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
664 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
665 target["Type"] = "Null"; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
666 target["Value"] = Json::nullValue; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
667 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
668 else |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
669 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
670 if (maxStringLength == 0 || |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
671 content.size() <= maxStringLength) |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
672 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
673 target["Type"] = "String"; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
674 target["Value"] = content; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
675 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
676 else |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
677 { |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
678 target["Type"] = "TooLong"; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
679 target["Value"] = Json::nullValue; |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
680 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
681 } |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
682 break; |
0 | 683 } |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
684 |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
685 default: |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
686 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1687 | 687 } |
688 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
689 |
1687 | 690 |
691 static void DatasetToJson(Json::Value& parent, | |
692 DcmItem& item, | |
693 DicomToJsonFormat format, | |
694 unsigned int maxStringLength, | |
695 Encoding encoding); | |
696 | |
697 | |
1690 | 698 void FromDcmtkBridge::ToJson(Json::Value& parent, |
699 DcmElement& element, | |
700 DicomToJsonFormat format, | |
701 unsigned int maxStringLength, | |
702 Encoding encoding) | |
1687 | 703 { |
1691 | 704 if (parent.type() == Json::nullValue) |
705 { | |
706 parent = Json::objectValue; | |
707 } | |
708 | |
709 assert(parent.type() == Json::objectValue); | |
1687 | 710 Json::Value& target = PrepareNode(parent, element, format); |
711 | |
712 if (element.isLeaf()) | |
713 { | |
714 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, encoding)); | |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
715 LeafValueToJson(target, *v, format, maxStringLength); |
0 | 716 } |
717 else | |
718 { | |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
719 assert(target.type() == Json::nullValue); |
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
720 target = Json::arrayValue; |
0 | 721 |
722 // "All subclasses of DcmElement except for DcmSequenceOfItems | |
723 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset | |
1687 | 724 // etc. are not." The following dynamic_cast is thus OK. |
0 | 725 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); |
726 | |
727 for (unsigned long i = 0; i < sequence.card(); i++) | |
728 { | |
729 DcmItem* child = sequence.getItem(i); | |
1687 | 730 Json::Value& v = target.append(Json::objectValue); |
1686 | 731 DatasetToJson(v, *child, format, maxStringLength, encoding); |
1687 | 732 } |
0 | 733 } |
734 } | |
735 | |
736 | |
1687 | 737 static void DatasetToJson(Json::Value& parent, |
1686 | 738 DcmItem& item, |
739 DicomToJsonFormat format, | |
740 unsigned int maxStringLength, | |
741 Encoding encoding) | |
742 { | |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
743 assert(parent.type() == Json::objectValue); |
1686 | 744 |
745 for (unsigned long i = 0; i < item.card(); i++) | |
746 { | |
747 DcmElement* element = item.getElement(i); | |
1690 | 748 FromDcmtkBridge::ToJson(parent, *element, format, maxStringLength, encoding); |
1686 | 749 } |
750 } | |
751 | |
752 | |
1687 | 753 void FromDcmtkBridge::ToJson(Json::Value& target, |
0 | 754 DcmDataset& dataset, |
1686 | 755 DicomToJsonFormat format, |
0 | 756 unsigned int maxStringLength) |
757 { | |
1688
27d70e9ee2e4
DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
758 target = Json::objectValue; |
1687 | 759 DatasetToJson(target, dataset, format, maxStringLength, DetectEncoding(dataset)); |
0 | 760 } |
761 | |
762 | |
763 std::string FromDcmtkBridge::GetName(const DicomTag& t) | |
764 { | |
106 | 765 // Some patches for important tags because of different DICOM |
766 // dictionaries between DCMTK versions | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
767 std::string n = t.GetMainTagsName(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
768 if (n.size() != 0) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
769 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
770 return n; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
771 } |
106 | 772 // End of patches |
773 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
774 #if 0 |
0 | 775 DcmTagKey tag(t.GetGroup(), t.GetElement()); |
776 const DcmDataDictionary& dict = dcmDataDict.rdlock(); | |
777 const DcmDictEntry* entry = dict.findEntry(tag, NULL); | |
778 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
779 std::string s(DcmTag_ERROR_TagName); |
0 | 780 if (entry != NULL) |
781 { | |
782 s = std::string(entry->getTagName()); | |
783 } | |
784 | |
785 dcmDataDict.unlock(); | |
786 return s; | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
787 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
788 DcmTag tag(t.GetGroup(), t.GetElement()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
789 const char* name = tag.getTagName(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
790 if (name == NULL) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
791 { |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
792 return DcmTag_ERROR_TagName; |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
793 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
794 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
795 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
796 return std::string(name); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
797 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
798 #endif |
0 | 799 } |
800 | |
801 | |
304 | 802 DicomTag FromDcmtkBridge::ParseTag(const char* name) |
0 | 803 { |
304 | 804 if (strlen(name) == 9 && |
805 isxdigit(name[0]) && | |
806 isxdigit(name[1]) && | |
807 isxdigit(name[2]) && | |
808 isxdigit(name[3]) && | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
809 (name[4] == '-' || name[4] == ',') && |
304 | 810 isxdigit(name[5]) && |
811 isxdigit(name[6]) && | |
812 isxdigit(name[7]) && | |
813 isxdigit(name[8])) | |
814 { | |
815 uint16_t group = GetTagValue(name); | |
816 uint16_t element = GetTagValue(name + 5); | |
817 return DicomTag(group, element); | |
818 } | |
819 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
820 #if 0 |
0 | 821 const DcmDataDictionary& dict = dcmDataDict.rdlock(); |
822 const DcmDictEntry* entry = dict.findEntry(name); | |
823 | |
824 if (entry == NULL) | |
825 { | |
826 dcmDataDict.unlock(); | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
827 throw OrthancException(ErrorCode_UnknownDicomTag); |
0 | 828 } |
829 else | |
830 { | |
831 DcmTagKey key = entry->getKey(); | |
832 DicomTag tag(key.getGroup(), key.getElement()); | |
833 dcmDataDict.unlock(); | |
834 return tag; | |
835 } | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
836 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
837 DcmTag tag; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
838 if (DcmTag::findTagFromName(name, tag).good()) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
839 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
840 return DicomTag(tag.getGTag(), tag.getETag()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
841 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
842 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
843 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1557
diff
changeset
|
844 throw OrthancException(ErrorCode_UnknownDicomTag); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
845 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
846 #endif |
0 | 847 } |
848 | |
849 | |
1655
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
850 bool FromDcmtkBridge::IsUnknownTag(const DicomTag& tag) |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
851 { |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
852 DcmTag tmp(tag.GetGroup(), tag.GetElement()); |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
853 return tmp.isUnknownVR(); |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
854 } |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
855 |
e40fd0d925c5
/tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
856 |
0 | 857 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) |
858 { | |
859 for (DicomMap::Map::const_iterator | |
656 | 860 it = m.map_.begin(); it != m.map_.end(); ++it) |
0 | 861 { |
862 DicomTag t = it->first; | |
863 std::string s = it->second->AsString(); | |
319 | 864 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str()); |
0 | 865 } |
866 } | |
867 | |
868 | |
869 void FromDcmtkBridge::ToJson(Json::Value& result, | |
1368 | 870 const DicomMap& values, |
871 bool simplify) | |
0 | 872 { |
873 if (result.type() != Json::objectValue) | |
874 { | |
62 | 875 throw OrthancException(ErrorCode_BadParameterType); |
0 | 876 } |
877 | |
878 result.clear(); | |
879 | |
880 for (DicomMap::Map::const_iterator | |
656 | 881 it = values.map_.begin(); it != values.map_.end(); ++it) |
0 | 882 { |
1368 | 883 if (simplify) |
884 { | |
885 result[GetName(it->first)] = it->second->AsString(); | |
886 } | |
887 else | |
888 { | |
889 Json::Value value = Json::objectValue; | |
890 | |
891 value["Name"] = GetName(it->first); | |
892 | |
893 if (it->second->IsNull()) | |
894 { | |
895 value["Type"] = "Null"; | |
896 value["Value"] = Json::nullValue; | |
897 } | |
898 else | |
899 { | |
900 value["Type"] = "String"; | |
901 value["Value"] = it->second->AsString(); | |
902 } | |
903 | |
904 result[it->first.Format()] = value; | |
905 } | |
0 | 906 } |
907 } | |
176 | 908 |
909 | |
788 | 910 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level) |
176 | 911 { |
912 char uid[100]; | |
913 | |
914 switch (level) | |
915 { | |
788 | 916 case ResourceType_Patient: |
311 | 917 // The "PatientID" field is of type LO (Long String), 64 |
918 // Bytes Maximum. An UUID is of length 36, thus it can be used | |
919 // as a random PatientID. | |
920 return Toolbox::GenerateUuid(); | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
921 |
788 | 922 case ResourceType_Instance: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
923 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); |
176 | 924 |
788 | 925 case ResourceType_Series: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
926 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT); |
176 | 927 |
788 | 928 case ResourceType_Study: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
929 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT); |
176 | 930 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
931 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
932 throw OrthancException(ErrorCode_ParameterOutOfRange); |
176 | 933 } |
934 } | |
935 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
936 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer, |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
937 DcmDataset& dataSet) |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
938 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
939 // Determine the transfer syntax which shall be used to write the |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
940 // information to the file. We always switch to the Little Endian |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
941 // syntax, with explicit length. |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
942 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
943 // http://support.dcmtk.org/docs/dcxfer_8h-source.html |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
944 |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
945 |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
946 /** |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
947 * Note that up to Orthanc 0.7.1 (inclusive), the |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
948 * "EXS_LittleEndianExplicit" was always used to save the DICOM |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
949 * dataset into memory. We now keep the original transfer syntax |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
950 * (if available). |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
951 **/ |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
952 E_TransferSyntax xfer = dataSet.getOriginalXfer(); |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
953 if (xfer == EXS_Unknown) |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
954 { |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
955 // No information about the original transfer syntax: This is |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
956 // most probably a DICOM dataset that was read from memory. |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
957 xfer = EXS_LittleEndianExplicit; |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
958 } |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
959 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
960 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
961 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
962 // Create the meta-header information |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
963 DcmFileFormat ff(&dataSet); |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
964 ff.validateMetaInfo(xfer); |
1316
1c8dfedefefe
Fix anonymization generating non-portable DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1307
diff
changeset
|
965 ff.removeInvalidGroups(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
966 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
967 // Create a memory buffer with the proper size |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
968 uint32_t s = ff.calcElementLength(xfer, encodingType); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
969 buffer.resize(s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
970 DcmOutputBufferStream ob(&buffer[0], s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
971 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
972 // Fill the memory buffer with the meta-header and the dataset |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
973 ff.transferInit(); |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
974 OFCondition c = ff.write(ob, xfer, encodingType, NULL, |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
975 /*opt_groupLength*/ EGL_recalcGL, |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
976 /*opt_paddingType*/ EPD_withoutPadding); |
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
977 ff.transferEnd(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
978 |
661
d233b5090105
accept more transfer syntaxes for C-Store SCP, write meta-header when receiving files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
979 // Handle errors |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
980 if (c.good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
981 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
982 return true; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
983 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
984 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
985 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
986 buffer.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
987 return false; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
988 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
989 } |
1360 | 990 |
991 | |
1417
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
992 ValueRepresentation FromDcmtkBridge::GetValueRepresentation(const DicomTag& tag) |
1360 | 993 { |
994 DcmTag t(tag.GetGroup(), tag.GetElement()); | |
1417
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
995 switch (t.getEVR()) |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
996 { |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
997 case EVR_PN: |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
998 return ValueRepresentation_PatientName; |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
999 |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1000 case EVR_DA: |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1001 return ValueRepresentation_Date; |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1002 |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1003 case EVR_DT: |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1004 return ValueRepresentation_DateTime; |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1005 |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1006 case EVR_TM: |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1007 return ValueRepresentation_Time; |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1008 |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1009 default: |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1010 return ValueRepresentation_Other; |
8e23f16a198d
fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
1011 } |
1360 | 1012 } |
1013 | |
1689 | 1014 |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1015 static bool IsBinaryTag(const DcmTag& key) |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1016 { |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1017 return key.isPrivate() || key.isUnknownVR(); |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1018 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1019 |
1689 | 1020 |
1021 DcmElement* FromDcmtkBridge::CreateElementForTag(const DicomTag& tag) | |
1022 { | |
1023 DcmTag key(tag.GetGroup(), tag.GetElement()); | |
1024 | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1025 if (IsBinaryTag(key)) |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1026 { |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1027 return new DcmOtherByteOtherWord(key); |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1028 } |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1029 |
1689 | 1030 switch (key.getEVR()) |
1031 { | |
1032 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
1033 | |
1034 /** | |
1035 * TODO. | |
1036 **/ | |
1037 | |
1038 case EVR_OB: // other byte | |
1039 case EVR_OF: // other float | |
1040 case EVR_OW: // other word | |
1041 case EVR_AT: // attribute tag | |
1042 throw OrthancException(ErrorCode_NotImplemented); | |
1043 | |
1044 case EVR_UN: // unknown value representation | |
1045 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1046 | |
1047 | |
1048 /** | |
1049 * String types. | |
1050 * http://support.dcmtk.org/docs/classDcmByteString.html | |
1051 **/ | |
1052 | |
1053 case EVR_AS: // age string | |
1054 return new DcmAgeString(key); | |
1055 | |
1056 case EVR_AE: // application entity title | |
1057 return new DcmApplicationEntity(key); | |
1058 | |
1059 case EVR_CS: // code string | |
1060 return new DcmCodeString(key); | |
1061 | |
1062 case EVR_DA: // date string | |
1063 return new DcmDate(key); | |
1064 | |
1065 case EVR_DT: // date time string | |
1066 return new DcmDateTime(key); | |
1067 | |
1068 case EVR_DS: // decimal string | |
1069 return new DcmDecimalString(key); | |
1070 | |
1071 case EVR_IS: // integer string | |
1072 return new DcmIntegerString(key); | |
1073 | |
1074 case EVR_TM: // time string | |
1075 return new DcmTime(key); | |
1076 | |
1077 case EVR_UI: // unique identifier | |
1078 return new DcmUniqueIdentifier(key); | |
1079 | |
1080 case EVR_ST: // short text | |
1081 return new DcmShortText(key); | |
1082 | |
1083 case EVR_LO: // long string | |
1084 return new DcmLongString(key); | |
1085 | |
1086 case EVR_LT: // long text | |
1087 return new DcmLongText(key); | |
1088 | |
1089 case EVR_UT: // unlimited text | |
1090 return new DcmUnlimitedText(key); | |
1091 | |
1092 case EVR_SH: // short string | |
1093 return new DcmShortString(key); | |
1094 | |
1095 case EVR_PN: // person name | |
1096 return new DcmPersonName(key); | |
1097 | |
1098 | |
1099 /** | |
1100 * Numerical types | |
1101 **/ | |
1102 | |
1103 case EVR_SL: // signed long | |
1104 return new DcmSignedLong(key); | |
1105 | |
1106 case EVR_SS: // signed short | |
1107 return new DcmSignedShort(key); | |
1108 | |
1109 case EVR_UL: // unsigned long | |
1110 return new DcmUnsignedLong(key); | |
1111 | |
1112 case EVR_US: // unsigned short | |
1113 return new DcmUnsignedShort(key); | |
1114 | |
1115 case EVR_FL: // float single-precision | |
1116 return new DcmFloatingPointSingle(key); | |
1117 | |
1118 case EVR_FD: // float double-precision | |
1119 return new DcmFloatingPointDouble(key); | |
1120 | |
1121 | |
1122 /** | |
1123 * Sequence types, should never occur at this point. | |
1124 **/ | |
1125 | |
1126 case EVR_SQ: // sequence of items | |
1127 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1128 | |
1129 | |
1130 /** | |
1131 * Internal to DCMTK. | |
1132 **/ | |
1133 | |
1134 case EVR_ox: // OB or OW depending on context | |
1135 case EVR_xs: // SS or US depending on context | |
1136 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) | |
1137 case EVR_na: // na="not applicable", for data which has no VR | |
1138 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor | |
1139 case EVR_item: // used internally for items | |
1140 case EVR_metainfo: // used internally for meta info datasets | |
1141 case EVR_dataset: // used internally for datasets | |
1142 case EVR_fileFormat: // used internally for DICOM files | |
1143 case EVR_dicomDir: // used internally for DICOMDIR objects | |
1144 case EVR_dirRecord: // used internally for DICOMDIR records | |
1145 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image | |
1146 case EVR_pixelItem: // used internally for pixel items in a compressed image | |
1147 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | |
1148 case EVR_PixelData: // used internally for uncompressed pixeld data | |
1149 case EVR_OverlayData: // used internally for overlay data | |
1150 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR | |
1151 default: | |
1152 break; | |
1153 } | |
1154 | |
1155 throw OrthancException(ErrorCode_InternalError); | |
1156 } | |
1157 | |
1158 | |
1159 | |
1160 void FromDcmtkBridge::FillElementWithString(DcmElement& element, | |
1161 const DicomTag& tag, | |
1162 const std::string& value, | |
1163 bool decodeBinaryTags) | |
1164 { | |
1165 std::string binary; | |
1166 const std::string* decoded = &value; | |
1167 | |
1168 if (decodeBinaryTags && | |
1169 boost::starts_with(value, "data:application/octet-stream;base64,")) | |
1170 { | |
1171 std::string mime; | |
1172 Toolbox::DecodeDataUriScheme(mime, binary, value); | |
1173 decoded = &binary; | |
1174 } | |
1175 | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1176 DcmTag key(tag.GetGroup(), tag.GetElement()); |
1689 | 1177 |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1178 if (IsBinaryTag(key)) |
1689 | 1179 { |
1180 if (element.putUint8Array((const Uint8*) decoded->c_str(), decoded->size()).good()) | |
1181 { | |
1182 return; | |
1183 } | |
1184 else | |
1185 { | |
1186 throw OrthancException(ErrorCode_InternalError); | |
1187 } | |
1188 } | |
1189 | |
1190 bool ok = false; | |
1191 | |
1192 try | |
1193 { | |
1194 switch (key.getEVR()) | |
1195 { | |
1196 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
1197 | |
1198 /** | |
1199 * TODO. | |
1200 **/ | |
1201 | |
1202 case EVR_OB: // other byte | |
1203 case EVR_OF: // other float | |
1204 case EVR_OW: // other word | |
1205 case EVR_AT: // attribute tag | |
1206 throw OrthancException(ErrorCode_NotImplemented); | |
1207 | |
1208 case EVR_UN: // unknown value representation | |
1209 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1210 | |
1211 | |
1212 /** | |
1213 * String types. | |
1214 **/ | |
1215 | |
1216 case EVR_DS: // decimal string | |
1217 case EVR_IS: // integer string | |
1218 case EVR_AS: // age string | |
1219 case EVR_DA: // date string | |
1220 case EVR_DT: // date time string | |
1221 case EVR_TM: // time string | |
1222 case EVR_AE: // application entity title | |
1223 case EVR_CS: // code string | |
1224 case EVR_SH: // short string | |
1225 case EVR_LO: // long string | |
1226 case EVR_ST: // short text | |
1227 case EVR_LT: // long text | |
1228 case EVR_UT: // unlimited text | |
1229 case EVR_PN: // person name | |
1230 case EVR_UI: // unique identifier | |
1231 { | |
1232 ok = element.putString(decoded->c_str()).good(); | |
1233 break; | |
1234 } | |
1235 | |
1236 | |
1237 /** | |
1238 * Numerical types | |
1239 **/ | |
1240 | |
1241 case EVR_SL: // signed long | |
1242 { | |
1243 ok = element.putSint32(boost::lexical_cast<Sint32>(*decoded)).good(); | |
1244 break; | |
1245 } | |
1246 | |
1247 case EVR_SS: // signed short | |
1248 { | |
1249 ok = element.putSint16(boost::lexical_cast<Sint16>(*decoded)).good(); | |
1250 break; | |
1251 } | |
1252 | |
1253 case EVR_UL: // unsigned long | |
1254 { | |
1255 ok = element.putUint32(boost::lexical_cast<Uint32>(*decoded)).good(); | |
1256 break; | |
1257 } | |
1258 | |
1259 case EVR_US: // unsigned short | |
1260 { | |
1261 ok = element.putUint16(boost::lexical_cast<Uint16>(*decoded)).good(); | |
1262 break; | |
1263 } | |
1264 | |
1265 case EVR_FL: // float single-precision | |
1266 { | |
1267 ok = element.putFloat32(boost::lexical_cast<float>(*decoded)).good(); | |
1268 break; | |
1269 } | |
1270 | |
1271 case EVR_FD: // float double-precision | |
1272 { | |
1273 ok = element.putFloat64(boost::lexical_cast<double>(*decoded)).good(); | |
1274 break; | |
1275 } | |
1276 | |
1277 | |
1278 /** | |
1279 * Sequence types, should never occur at this point. | |
1280 **/ | |
1281 | |
1282 case EVR_SQ: // sequence of items | |
1283 { | |
1284 ok = false; | |
1285 break; | |
1286 } | |
1287 | |
1288 | |
1289 /** | |
1290 * Internal to DCMTK. | |
1291 **/ | |
1292 | |
1293 case EVR_ox: // OB or OW depending on context | |
1294 case EVR_xs: // SS or US depending on context | |
1295 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) | |
1296 case EVR_na: // na="not applicable", for data which has no VR | |
1297 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor | |
1298 case EVR_item: // used internally for items | |
1299 case EVR_metainfo: // used internally for meta info datasets | |
1300 case EVR_dataset: // used internally for datasets | |
1301 case EVR_fileFormat: // used internally for DICOM files | |
1302 case EVR_dicomDir: // used internally for DICOMDIR objects | |
1303 case EVR_dirRecord: // used internally for DICOMDIR records | |
1304 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image | |
1305 case EVR_pixelItem: // used internally for pixel items in a compressed image | |
1306 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | |
1307 case EVR_PixelData: // used internally for uncompressed pixeld data | |
1308 case EVR_OverlayData: // used internally for overlay data | |
1309 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR | |
1310 default: | |
1311 break; | |
1312 } | |
1313 } | |
1314 catch (boost::bad_lexical_cast&) | |
1315 { | |
1316 ok = false; | |
1317 } | |
1318 | |
1319 if (!ok) | |
1320 { | |
1321 throw OrthancException(ErrorCode_InternalError); | |
1322 } | |
1323 } | |
1324 | |
1325 | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1326 DcmElement* FromDcmtkBridge::FromJson(const DicomTag& tag, |
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1327 const Json::Value& value, |
1689 | 1328 bool decodeBinaryTags) |
1329 { | |
1330 std::auto_ptr<DcmElement> element; | |
1331 | |
1690 | 1332 switch (value.type()) |
1689 | 1333 { |
1690 | 1334 case Json::stringValue: |
1335 element.reset(CreateElementForTag(tag)); | |
1336 FillElementWithString(*element, tag, value.asString(), decodeBinaryTags); | |
1337 break; | |
1338 | |
1339 case Json::arrayValue: | |
1340 { | |
1341 DcmTag key(tag.GetGroup(), tag.GetElement()); | |
1342 if (key.getEVR() != EVR_SQ) | |
1343 { | |
1344 throw OrthancException(ErrorCode_BadParameterType); | |
1345 } | |
1346 | |
1347 DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key, value.size()); | |
1348 element.reset(sequence); | |
1349 | |
1350 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) | |
1351 { | |
1352 std::auto_ptr<DcmItem> item(new DcmItem); | |
1353 | |
1354 Json::Value::Members members = value[i].getMemberNames(); | |
1355 for (Json::Value::ArrayIndex j = 0; j < members.size(); j++) | |
1356 { | |
1693
558b25228a23
creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1691
diff
changeset
|
1357 item->insert(FromJson(ParseTag(members[j]), value[i][members[j]], decodeBinaryTags)); |
1690 | 1358 } |
1359 | |
1360 sequence->append(item.release()); | |
1361 } | |
1362 | |
1363 break; | |
1364 } | |
1365 | |
1366 default: | |
1367 throw OrthancException(ErrorCode_BadParameterType); | |
1689 | 1368 } |
1369 | |
1370 return element.release(); | |
1371 } | |
0 | 1372 } |