Mercurial > hg > orthanc
annotate OrthancServer/FromDcmtkBridge.cpp @ 2770:6cf5479009f6 Orthanc-0.9.0
close old branch
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 09:44:54 +0200 |
parents | b22ba8c5edbe |
children | 8e23f16a198d |
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" |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
106
diff
changeset
|
45 #include "../Core/Toolbox.h" |
62 | 46 #include "../Core/OrthancException.h" |
799 | 47 #include "../Core/ImageFormats/PngWriter.h" |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
48 #include "../Core/Uuid.h" |
0 | 49 #include "../Core/DicomFormat/DicomString.h" |
50 #include "../Core/DicomFormat/DicomNullValue.h" | |
79 | 51 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
0 | 52 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
53 #include <list> |
71 | 54 #include <limits> |
55 | |
0 | 56 #include <boost/lexical_cast.hpp> |
57 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
58 #include <dcmtk/dcmdata/dcchrstr.h> |
0 | 59 #include <dcmtk/dcmdata/dcdicent.h> |
60 #include <dcmtk/dcmdata/dcdict.h> | |
61 #include <dcmtk/dcmdata/dcfilefo.h> | |
62 #include <dcmtk/dcmdata/dcistrmb.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
63 #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
|
64 #include <dcmtk/dcmdata/dcmetinf.h> |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
65 #include <dcmtk/dcmdata/dcdeftag.h> |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
66 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
67 #include <dcmtk/dcmdata/dcvrae.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
68 #include <dcmtk/dcmdata/dcvras.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
69 #include <dcmtk/dcmdata/dcvrcs.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
70 #include <dcmtk/dcmdata/dcvrda.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
71 #include <dcmtk/dcmdata/dcvrds.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
72 #include <dcmtk/dcmdata/dcvrdt.h> |
0 | 73 #include <dcmtk/dcmdata/dcvrfd.h> |
74 #include <dcmtk/dcmdata/dcvrfl.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
75 #include <dcmtk/dcmdata/dcvris.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
76 #include <dcmtk/dcmdata/dcvrlo.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
77 #include <dcmtk/dcmdata/dcvrlt.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
78 #include <dcmtk/dcmdata/dcvrpn.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
79 #include <dcmtk/dcmdata/dcvrsh.h> |
0 | 80 #include <dcmtk/dcmdata/dcvrsl.h> |
81 #include <dcmtk/dcmdata/dcvrss.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
82 #include <dcmtk/dcmdata/dcvrst.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
83 #include <dcmtk/dcmdata/dcvrtm.h> |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
84 #include <dcmtk/dcmdata/dcvrui.h> |
0 | 85 #include <dcmtk/dcmdata/dcvrul.h> |
86 #include <dcmtk/dcmdata/dcvrus.h> | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
87 #include <dcmtk/dcmdata/dcvrut.h> |
676
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
88 #include <dcmtk/dcmdata/dcpixel.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
89 #include <dcmtk/dcmdata/dcpixseq.h> |
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
90 #include <dcmtk/dcmdata/dcpxitem.h> |
1131 | 91 #include <dcmtk/dcmdata/dcvrat.h> |
676
aa5ca7a2166f
experiments with pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
661
diff
changeset
|
92 |
0 | 93 |
2 | 94 #include <boost/math/special_functions/round.hpp> |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
95 #include <glog/logging.h> |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
96 #include <dcmtk/dcmdata/dcostrmb.h> |
0 | 97 |
682
efc4928be6fb
Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
677
diff
changeset
|
98 |
62 | 99 namespace Orthanc |
0 | 100 { |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
101 static inline uint16_t GetCharValue(char c) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
102 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
103 if (c >= '0' && c <= '9') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
104 return c - '0'; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
105 else if (c >= 'a' && c <= 'f') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
106 return c - 'a' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
107 else if (c >= 'A' && c <= 'F') |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
108 return c - 'A' + 10; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
109 else |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
110 return 0; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
111 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
112 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
113 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
|
114 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
115 return ((GetCharValue(c[0]) << 12) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
116 (GetCharValue(c[1]) << 8) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
117 (GetCharValue(c[2]) << 4) + |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
118 GetCharValue(c[3])); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
119 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
176
diff
changeset
|
120 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
121 |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
122 Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset) |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
123 { |
1093
552a038f7c96
Default encoding is Latin-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
124 // By default, Latin1 encoding is assumed |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1004
diff
changeset
|
125 std::string s = Configuration::GetGlobalStringParameter("DefaultEncoding", ""); |
1093
552a038f7c96
Default encoding is Latin-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
126 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
|
127 |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
128 OFString tmp; |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
129 if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good()) |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
130 { |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
131 std::string characterSet = Toolbox::StripSpaces(std::string(tmp.c_str())); |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
132 |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
133 if (characterSet.empty()) |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
134 { |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
135 // Empty specific character set tag: Use the default encoding |
1087 | 136 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
137 else if (GetDicomEncoding(encoding, characterSet.c_str())) |
1087 | 138 { |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
139 // The specific character set is supported by the Orthanc core |
1087 | 140 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
141 else |
1087 | 142 { |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
143 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
|
144 << ", fallback to ASCII (remove all special characters)"; |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
145 encoding = Encoding_Ascii; |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
146 } |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
147 } |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
148 else |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
149 { |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
150 // No specific character set tag: Use the default encoding |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
151 } |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
152 |
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
153 return encoding; |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
154 } |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
155 |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
156 |
0 | 157 void FromDcmtkBridge::Convert(DicomMap& target, DcmDataset& dataset) |
158 { | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
159 Encoding encoding = DetectEncoding(dataset); |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
160 |
0 | 161 target.Clear(); |
162 for (unsigned long i = 0; i < dataset.card(); i++) | |
163 { | |
164 DcmElement* element = dataset.getElement(i); | |
165 if (element && element->isLeaf()) | |
166 { | |
167 target.SetValue(element->getTag().getGTag(), | |
168 element->getTag().getETag(), | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
169 ConvertLeafElement(*element, encoding)); |
0 | 170 } |
171 } | |
172 } | |
173 | |
174 | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
175 DicomTag FromDcmtkBridge::Convert(const DcmTag& tag) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
176 { |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
177 return DicomTag(tag.getGTag(), tag.getETag()); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
178 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
179 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
180 |
0 | 181 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element) |
182 { | |
183 return DicomTag(element.getGTag(), element.getETag()); | |
184 } | |
185 | |
186 | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
187 bool FromDcmtkBridge::IsPrivateTag(DcmTag& tag) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
188 { |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
189 #if 1 |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
190 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
|
191 return tmp.isPrivate(); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
192 #else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
193 // Implementation for Orthanc versions <= 0.8.5 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
194 return (tag.getPrivateCreator() != NULL || |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
195 !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
|
196 #endif |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
197 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
198 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
199 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
200 bool FromDcmtkBridge::IsPrivateTag(const DicomTag& tag) |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
201 { |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
202 #if 1 |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
203 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
|
204 return tmp.isPrivate(); |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
205 #else |
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
206 // Implementation for Orthanc versions <= 0.8.5 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
207 DcmTag tmp(tag.GetGroup(), tag.GetElement()); |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
208 return IsPrivateTag(tmp); |
1307
f796207e3df1
Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
209 #endif |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
210 } |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
211 |
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
212 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
213 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element, |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
214 Encoding encoding) |
0 | 215 { |
216 if (!element.isLeaf()) | |
217 { | |
62 | 218 throw OrthancException("Only applicable to leaf elements"); |
0 | 219 } |
220 | |
221 if (element.isaString()) | |
222 { | |
223 char *c; | |
224 if (element.getString(c).good() && | |
225 c != NULL) | |
226 { | |
227 std::string s(c); | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
228 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding); |
0 | 229 return new DicomString(utf8); |
230 } | |
231 else | |
232 { | |
233 return new DicomNullValue; | |
234 } | |
235 } | |
236 | |
237 try | |
238 { | |
239 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
240 switch (element.getVR()) | |
241 { | |
242 | |
243 /** | |
244 * TODO. | |
245 **/ | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
246 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
247 case EVR_OB: // other byte |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
248 case EVR_OF: // other float |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
249 case EVR_OW: // other word |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
250 case EVR_UN: // unknown value representation |
1131 | 251 return new DicomNullValue; |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
252 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
253 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
254 * 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
|
255 * "element.isaString()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
256 **/ |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
257 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
258 case EVR_DS: // decimal string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
259 case EVR_IS: // integer string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
260 case EVR_AS: // age string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
261 case EVR_DA: // date string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
262 case EVR_DT: // date time string |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
263 case EVR_TM: // time string |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
264 case EVR_AE: // application entity title |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
265 case EVR_CS: // code string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
266 case EVR_SH: // short string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
267 case EVR_LO: // long string |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
268 case EVR_ST: // short text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
269 case EVR_LT: // long text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
270 case EVR_UT: // unlimited text |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
271 case EVR_PN: // person name |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
272 case EVR_UI: // unique identifier |
1131 | 273 return new DicomNullValue; |
0 | 274 |
275 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
276 /** |
1131 | 277 * Numberic types |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
278 **/ |
0 | 279 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
280 case EVR_SL: // signed long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
281 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
282 Sint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
283 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
284 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
285 else |
1131 | 286 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
287 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
288 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
289 case EVR_SS: // signed short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
290 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
291 Sint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
292 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
293 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
294 else |
1131 | 295 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
296 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
297 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
298 case EVR_UL: // unsigned long |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
299 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
300 Uint32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
301 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
302 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
303 else |
1131 | 304 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
305 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
306 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
307 case EVR_US: // unsigned short |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
308 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
309 Uint16 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
310 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
311 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
312 else |
1131 | 313 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
314 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
315 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
316 case EVR_FL: // float single-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
317 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
318 Float32 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
319 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
320 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
321 else |
1131 | 322 return new DicomNullValue; |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
323 } |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
324 |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
325 case EVR_FD: // float double-precision |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
326 { |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
327 Float64 f; |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
328 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good()) |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
329 return new DicomString(boost::lexical_cast<std::string>(f)); |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
330 else |
1131 | 331 return new DicomNullValue; |
332 } | |
333 | |
334 | |
335 /** | |
336 * Attribute tag. | |
337 **/ | |
338 | |
339 case EVR_AT: | |
340 { | |
1147 | 341 DcmTagKey tag; |
342 if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good()) | |
343 { | |
344 DicomTag t(tag.getGroup(), tag.getElement()); | |
345 return new DicomString(t.Format()); | |
346 } | |
1131 | 347 else |
1147 | 348 { |
1131 | 349 return new DicomNullValue; |
1147 | 350 } |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
351 } |
0 | 352 |
353 | |
354 /** | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
355 * 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
|
356 * "element.isLeaf()". |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
357 **/ |
0 | 358 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
359 case EVR_SQ: // sequence of items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
360 return new DicomNullValue; |
0 | 361 |
362 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
363 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
364 * Internal to DCMTK. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
365 **/ |
0 | 366 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
367 case EVR_ox: // OB or OW depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
368 case EVR_xs: // SS or US depending on context |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 case EVR_item: // used internally for items |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
373 case EVR_metainfo: // used internally for meta info datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
374 case EVR_dataset: // used internally for datasets |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
375 case EVR_fileFormat: // used internally for DICOM files |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
376 case EVR_dicomDir: // used internally for DICOMDIR objects |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
377 case EVR_dirRecord: // used internally for DICOMDIR records |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 case EVR_PixelData: // used internally for uncompressed pixeld data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
382 case EVR_OverlayData: // used internally for overlay data |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
383 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
|
384 return new DicomNullValue; |
0 | 385 |
386 | |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
387 /** |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
388 * Default case. |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
389 **/ |
0 | 390 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
391 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
392 return new DicomNullValue; |
0 | 393 } |
394 } | |
395 catch (boost::bad_lexical_cast) | |
396 { | |
397 return new DicomNullValue; | |
398 } | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
399 catch (std::bad_cast) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
400 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
401 return new DicomNullValue; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
402 } |
0 | 403 } |
404 | |
405 | |
406 static void StoreElement(Json::Value& target, | |
407 DcmElement& element, | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
408 unsigned int maxStringLength, |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
409 Encoding encoding); |
0 | 410 |
411 static void StoreItem(Json::Value& target, | |
412 DcmItem& item, | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
413 unsigned int maxStringLength, |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
414 Encoding encoding) |
0 | 415 { |
416 target = Json::Value(Json::objectValue); | |
417 | |
418 for (unsigned long i = 0; i < item.card(); i++) | |
419 { | |
420 DcmElement* element = item.getElement(i); | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
421 StoreElement(target, *element, maxStringLength, encoding); |
0 | 422 } |
423 } | |
424 | |
425 | |
426 static void StoreElement(Json::Value& target, | |
427 DcmElement& element, | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
428 unsigned int maxStringLength, |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
429 Encoding encoding) |
0 | 430 { |
431 assert(target.type() == Json::objectValue); | |
432 | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
433 DicomTag tag(FromDcmtkBridge::GetTag(element)); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
434 const std::string formattedTag = tag.Format(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
435 |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
436 #if 0 |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
437 const std::string tagName = FromDcmtkBridge::GetName(tag); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
438 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
439 // This version of the code gives access to the name of the private tags |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
440 DcmTag tagbis(element.getTag()); |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
441 const std::string tagName(tagbis.getTagName()); |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
442 #endif |
0 | 443 |
444 if (element.isLeaf()) | |
445 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
446 Json::Value value(Json::objectValue); |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
447 value["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
448 |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
449 if (tagbis.getPrivateCreator() != NULL) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
450 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
451 value["PrivateCreator"] = tagbis.getPrivateCreator(); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
452 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
453 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
454 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, encoding)); |
0 | 455 if (v->IsNull()) |
456 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
457 value["Type"] = "Null"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
458 value["Value"] = Json::nullValue; |
0 | 459 } |
460 else | |
461 { | |
462 std::string s = v->AsString(); | |
463 if (maxStringLength == 0 || | |
464 s.size() <= maxStringLength) | |
465 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
466 value["Type"] = "String"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
467 value["Value"] = s; |
0 | 468 } |
469 else | |
470 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
471 value["Type"] = "TooLong"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
472 value["Value"] = Json::nullValue; |
0 | 473 } |
474 } | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
475 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
476 target[formattedTag] = value; |
0 | 477 } |
478 else | |
479 { | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
480 Json::Value children(Json::arrayValue); |
0 | 481 |
482 // "All subclasses of DcmElement except for DcmSequenceOfItems | |
483 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset | |
484 // etc. are not." The following cast is thus OK. | |
485 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element); | |
486 | |
487 for (unsigned long i = 0; i < sequence.card(); i++) | |
488 { | |
489 DcmItem* child = sequence.getItem(i); | |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
490 Json::Value& v = children.append(Json::objectValue); |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
491 StoreItem(v, *child, maxStringLength, encoding); |
0 | 492 } |
35
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
493 |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
494 target[formattedTag]["Name"] = tagName; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
495 target[formattedTag]["Type"] = "Sequence"; |
f6d12037f886
full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
496 target[formattedTag]["Value"] = children; |
0 | 497 } |
498 } | |
499 | |
500 | |
501 void FromDcmtkBridge::ToJson(Json::Value& root, | |
502 DcmDataset& dataset, | |
503 unsigned int maxStringLength) | |
504 { | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
505 StoreItem(root, dataset, maxStringLength, DetectEncoding(dataset)); |
0 | 506 } |
507 | |
508 | |
509 | |
510 void FromDcmtkBridge::ToJson(Json::Value& target, | |
511 const std::string& path, | |
512 unsigned int maxStringLength) | |
513 { | |
514 DcmFileFormat dicom; | |
515 if (!dicom.loadFile(path.c_str()).good()) | |
516 { | |
62 | 517 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 518 } |
519 else | |
520 { | |
521 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); | |
522 } | |
523 } | |
524 | |
525 | |
526 | |
527 std::string FromDcmtkBridge::GetName(const DicomTag& t) | |
528 { | |
106 | 529 // Some patches for important tags because of different DICOM |
530 // dictionaries between DCMTK versions | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
531 std::string n = t.GetMainTagsName(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
532 if (n.size() != 0) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
533 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
534 return n; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
535 } |
106 | 536 // End of patches |
537 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
538 #if 0 |
0 | 539 DcmTagKey tag(t.GetGroup(), t.GetElement()); |
540 const DcmDataDictionary& dict = dcmDataDict.rdlock(); | |
541 const DcmDictEntry* entry = dict.findEntry(tag, NULL); | |
542 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
543 std::string s(DcmTag_ERROR_TagName); |
0 | 544 if (entry != NULL) |
545 { | |
546 s = std::string(entry->getTagName()); | |
547 } | |
548 | |
549 dcmDataDict.unlock(); | |
550 return s; | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
551 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
552 DcmTag tag(t.GetGroup(), t.GetElement()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
553 const char* name = tag.getTagName(); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
554 if (name == NULL) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
555 { |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
556 return DcmTag_ERROR_TagName; |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
557 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
558 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
559 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
560 return std::string(name); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
561 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
562 #endif |
0 | 563 } |
564 | |
565 | |
304 | 566 DicomTag FromDcmtkBridge::ParseTag(const char* name) |
0 | 567 { |
304 | 568 if (strlen(name) == 9 && |
569 isxdigit(name[0]) && | |
570 isxdigit(name[1]) && | |
571 isxdigit(name[2]) && | |
572 isxdigit(name[3]) && | |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
573 (name[4] == '-' || name[4] == ',') && |
304 | 574 isxdigit(name[5]) && |
575 isxdigit(name[6]) && | |
576 isxdigit(name[7]) && | |
577 isxdigit(name[8])) | |
578 { | |
579 uint16_t group = GetTagValue(name); | |
580 uint16_t element = GetTagValue(name + 5); | |
581 return DicomTag(group, element); | |
582 } | |
583 | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
584 #if 0 |
0 | 585 const DcmDataDictionary& dict = dcmDataDict.rdlock(); |
586 const DcmDictEntry* entry = dict.findEntry(name); | |
587 | |
588 if (entry == NULL) | |
589 { | |
590 dcmDataDict.unlock(); | |
62 | 591 throw OrthancException("Unknown DICOM tag"); |
0 | 592 } |
593 else | |
594 { | |
595 DcmTagKey key = entry->getKey(); | |
596 DicomTag tag(key.getGroup(), key.getElement()); | |
597 dcmDataDict.unlock(); | |
598 return tag; | |
599 } | |
305
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
600 #else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
601 DcmTag tag; |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
602 if (DcmTag::findTagFromName(name, tag).good()) |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
603 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
604 return DicomTag(tag.getGTag(), tag.getETag()); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
605 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
606 else |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
607 { |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
608 throw OrthancException("Unknown DICOM tag"); |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
609 } |
86bb79522f19
name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
610 #endif |
0 | 611 } |
612 | |
613 | |
614 void FromDcmtkBridge::Print(FILE* fp, const DicomMap& m) | |
615 { | |
616 for (DicomMap::Map::const_iterator | |
656 | 617 it = m.map_.begin(); it != m.map_.end(); ++it) |
0 | 618 { |
619 DicomTag t = it->first; | |
620 std::string s = it->second->AsString(); | |
319 | 621 fprintf(fp, "0x%04x 0x%04x (%s) [%s]\n", t.GetGroup(), t.GetElement(), GetName(t).c_str(), s.c_str()); |
0 | 622 } |
623 } | |
624 | |
625 | |
626 void FromDcmtkBridge::ToJson(Json::Value& result, | |
1368 | 627 const DicomMap& values, |
628 bool simplify) | |
0 | 629 { |
630 if (result.type() != Json::objectValue) | |
631 { | |
62 | 632 throw OrthancException(ErrorCode_BadParameterType); |
0 | 633 } |
634 | |
635 result.clear(); | |
636 | |
637 for (DicomMap::Map::const_iterator | |
656 | 638 it = values.map_.begin(); it != values.map_.end(); ++it) |
0 | 639 { |
1368 | 640 if (simplify) |
641 { | |
642 result[GetName(it->first)] = it->second->AsString(); | |
643 } | |
644 else | |
645 { | |
646 Json::Value value = Json::objectValue; | |
647 | |
648 value["Name"] = GetName(it->first); | |
649 | |
650 if (it->second->IsNull()) | |
651 { | |
652 value["Type"] = "Null"; | |
653 value["Value"] = Json::nullValue; | |
654 } | |
655 else | |
656 { | |
657 value["Type"] = "String"; | |
658 value["Value"] = it->second->AsString(); | |
659 } | |
660 | |
661 result[it->first.Format()] = value; | |
662 } | |
0 | 663 } |
664 } | |
176 | 665 |
666 | |
788 | 667 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level) |
176 | 668 { |
669 char uid[100]; | |
670 | |
671 switch (level) | |
672 { | |
788 | 673 case ResourceType_Patient: |
311 | 674 // The "PatientID" field is of type LO (Long String), 64 |
675 // Bytes Maximum. An UUID is of length 36, thus it can be used | |
676 // as a random PatientID. | |
677 return Toolbox::GenerateUuid(); | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
678 |
788 | 679 case ResourceType_Instance: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
680 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT); |
176 | 681 |
788 | 682 case ResourceType_Series: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
683 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT); |
176 | 684 |
788 | 685 case ResourceType_Study: |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
686 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT); |
176 | 687 |
302
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
688 default: |
238134081136
modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
291
diff
changeset
|
689 throw OrthancException(ErrorCode_ParameterOutOfRange); |
176 | 690 } |
691 } | |
692 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
693 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer, |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
694 DcmDataset& dataSet) |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
695 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
696 // 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
|
697 // 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
|
698 // syntax, with explicit length. |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
699 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
700 // 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
|
701 |
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
|
702 |
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
|
703 /** |
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
|
704 * 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
|
705 * "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
|
706 * 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
|
707 * (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
|
708 **/ |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
709 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
|
710 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
|
711 { |
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
|
712 // 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
|
713 // 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
|
714 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
|
715 } |
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
|
716 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
717 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
718 |
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
|
719 // Create the meta-header information |
1004
a226e0959d8b
DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
720 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
|
721 ff.validateMetaInfo(xfer); |
1316
1c8dfedefefe
Fix anonymization generating non-portable DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1307
diff
changeset
|
722 ff.removeInvalidGroups(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
723 |
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
|
724 // 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
|
725 uint32_t s = ff.calcElementLength(xfer, encodingType); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
726 buffer.resize(s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
727 DcmOutputBufferStream ob(&buffer[0], s); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
728 |
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
|
729 // 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
|
730 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
|
731 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
|
732 /*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
|
733 /*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
|
734 ff.transferEnd(); |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
735 |
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
|
736 // Handle errors |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
737 if (c.good()) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
738 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
739 return true; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
740 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
741 else |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
742 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
743 buffer.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
744 return false; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
745 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
746 } |
1360 | 747 |
748 | |
749 bool FromDcmtkBridge::IsPNValueRepresentation(const DicomTag& tag) | |
750 { | |
751 DcmTag t(tag.GetGroup(), tag.GetElement()); | |
752 return t.getEVR() == EVR_PN; | |
753 } | |
754 | |
0 | 755 } |