annotate OrthancServer/FromDcmtkBridge.cpp @ 1929:cda5b0ab4ce5

ORTHANC_MAXIMUM_TAG_LENGTH made explicit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Mar 2016 14:28:59 +0100
parents 84c7eaeb5244
children 1c147c3c3121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1876
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1147
diff changeset
4 * Department, University Hospital of Liege, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
448
9d830dcc7730 missing copyright information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 419
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "PrecompiledHeadersServer.h"
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
34
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
35 #ifndef NOMINMAX
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
36 #define NOMINMAX
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
37 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "FromDcmtkBridge.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1429
diff changeset
40 #include "../Core/Logging.h"
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 106
diff changeset
41 #include "../Core/Toolbox.h"
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
42 #include "../Core/Uuid.h"
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
43 #include "../Core/OrthancException.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
45 #include <list>
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
46 #include <limits>
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
47
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #include <boost/lexical_cast.hpp>
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
49 #include <boost/filesystem.hpp>
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
50 #include <boost/algorithm/string/predicate.hpp>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
52 #include <dcmtk/dcmdata/dcdeftag.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 #include <dcmtk/dcmdata/dcdicent.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 #include <dcmtk/dcmdata/dcdict.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #include <dcmtk/dcmdata/dcfilefo.h>
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
56 #include <dcmtk/dcmdata/dcostrmb.h>
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
57 #include <dcmtk/dcmdata/dcpixel.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
58 #include <dcmtk/dcmdata/dcuid.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
59
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
60 #include <dcmtk/dcmdata/dcvrae.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
61 #include <dcmtk/dcmdata/dcvras.h>
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
62 #include <dcmtk/dcmdata/dcvrat.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
63 #include <dcmtk/dcmdata/dcvrcs.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
64 #include <dcmtk/dcmdata/dcvrda.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
65 #include <dcmtk/dcmdata/dcvrds.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
66 #include <dcmtk/dcmdata/dcvrdt.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 #include <dcmtk/dcmdata/dcvrfd.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 #include <dcmtk/dcmdata/dcvrfl.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
69 #include <dcmtk/dcmdata/dcvris.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
70 #include <dcmtk/dcmdata/dcvrlo.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
71 #include <dcmtk/dcmdata/dcvrlt.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
72 #include <dcmtk/dcmdata/dcvrpn.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
73 #include <dcmtk/dcmdata/dcvrsh.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 #include <dcmtk/dcmdata/dcvrsl.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 #include <dcmtk/dcmdata/dcvrss.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
76 #include <dcmtk/dcmdata/dcvrst.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
77 #include <dcmtk/dcmdata/dcvrtm.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
78 #include <dcmtk/dcmdata/dcvrui.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #include <dcmtk/dcmdata/dcvrul.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #include <dcmtk/dcmdata/dcvrus.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
81 #include <dcmtk/dcmdata/dcvrut.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
83
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
84 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
86 static inline uint16_t GetCharValue(char c)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
87 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
88 if (c >= '0' && c <= '9')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
89 return c - '0';
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
90 else if (c >= 'a' && c <= 'f')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
91 return c - 'a' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
92 else if (c >= 'A' && c <= 'F')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
93 return c - 'A' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
94 else
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
95 return 0;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
96 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
97
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
98 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
99 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
100 return ((GetCharValue(c[0]) << 12) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
101 (GetCharValue(c[1]) << 8) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
102 (GetCharValue(c[2]) << 4) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
103 GetCharValue(c[3]));
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
104 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
105
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
106
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
107 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
108 static void LoadEmbeddedDictionary(DcmDataDictionary& dictionary,
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
109 EmbeddedResources::FileResourceId resource)
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
110 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
111 Toolbox::TemporaryFile tmp;
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
112
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
113 FILE* fp = fopen(tmp.GetPath().c_str(), "wb");
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
114 fwrite(EmbeddedResources::GetFileResourceBuffer(resource),
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
115 EmbeddedResources::GetFileResourceSize(resource), 1, fp);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
116 fclose(fp);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
117
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
118 if (!dictionary.loadDictionary(tmp.GetPath().c_str()))
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
119 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
120 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
121 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
122 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
123
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
124 #else
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
125 static void LoadExternalDictionary(DcmDataDictionary& dictionary,
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
126 const std::string& directory,
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
127 const std::string& filename)
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
128 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
129 boost::filesystem::path p = directory;
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
130 p = p / filename;
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
131
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
132 LOG(WARNING) << "Loading the external DICOM dictionary " << p;
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
133
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
134 if (!dictionary.loadDictionary(p.string().c_str()))
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
135 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
136 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
137 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
138 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
139
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
140 #endif
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
141
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
142
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
143 namespace
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
144 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
145 class DictionaryLocker
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
146 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
147 private:
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
148 DcmDataDictionary& dictionary_;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
149
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
150 public:
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
151 DictionaryLocker() : dictionary_(dcmDataDict.wrlock())
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
152 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
153 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
154
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
155 ~DictionaryLocker()
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
156 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
157 dcmDataDict.unlock();
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
158 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
159
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
160 DcmDataDictionary& operator*()
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
161 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
162 return dictionary_;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
163 }
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 DcmDataDictionary* operator->()
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
166 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
167 return &dictionary_;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
168 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
169 };
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
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
173 void FromDcmtkBridge::InitializeDictionary()
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
174 {
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
175 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
176 DictionaryLocker locker;
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 locker->clear();
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
179
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
180 #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
181 LOG(WARNING) << "Loading the embedded dictionaries";
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 * 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
184 * 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
185 * dictionary is not loaded by storescu.
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 //LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICONDE);
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
188
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
189 LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICOM);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
190 LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_PRIVATE);
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
191
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
192 #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
193 std::string path = DCMTK_DICTIONARY_DIR;
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
194
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
195 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
196 if (env != NULL)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
197 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
198 path = std::string(env);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
199 }
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
200
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
201 LoadExternalDictionary(*locker, path, "dicom.dic");
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
202 LoadExternalDictionary(*locker, path, "private.dic");
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
203
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
204 #else
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
205 #error Support your platform here
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
206 #endif
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
207 }
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
208
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
209 /* make sure data dictionary is loaded */
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
210 if (!dcmDataDict.isDictionaryLoaded())
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
211 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
212 LOG(ERROR) << "No DICOM dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE;
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
213 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
214 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
215
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
216 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
217 // Test the dictionary with a simple DICOM tag
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
218 DcmTag key(0x0010, 0x1030); // This is PatientWeight
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
219 if (key.getEVR() != EVR_DS)
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
220 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
221 LOG(ERROR) << "The DICOM dictionary has not been correctly read";
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
222 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
223 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
224 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
225 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
226
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
227
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
228 void FromDcmtkBridge::RegisterDictionaryTag(const DicomTag& tag,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
229 const DcmEVR& vr,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
230 const std::string& name,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
231 unsigned int minMultiplicity,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
232 unsigned int maxMultiplicity)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
233 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
234 if (minMultiplicity < 1)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
235 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
236 throw OrthancException(ErrorCode_ParameterOutOfRange);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
237 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
238
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
239 bool arbitrary = false;
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
240 if (maxMultiplicity == 0)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
241 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
242 maxMultiplicity = DcmVariableVM;
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
243 arbitrary = true;
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
244 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
245 else if (maxMultiplicity < minMultiplicity)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
246 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
247 throw OrthancException(ErrorCode_ParameterOutOfRange);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
248 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
249
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
250 LOG(INFO) << "Registering tag in dictionary: " << tag << " " << (DcmVR(vr).getValidVRName()) << " "
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
251 << name << " (multiplicity: " << minMultiplicity << "-"
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
252 << (arbitrary ? "n" : boost::lexical_cast<std::string>(maxMultiplicity)) << ")";
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
253
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
254 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
255 tag.GetElement(),
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
256 vr, name.c_str(),
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
257 static_cast<int>(minMultiplicity),
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
258 static_cast<int>(maxMultiplicity),
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
259 NULL /* version */,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
260 OFTrue /* doCopyString */,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
261 NULL /* private creator */));
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
262
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
263 entry->setGroupRangeRestriction(DcmDictRange_Unspecified);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
264 entry->setElementRangeRestriction(DcmDictRange_Unspecified);
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 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
267 DictionaryLocker locker;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
268 locker->addEntry(entry.release());
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
269 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
270 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
271
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
272
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
273 Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset,
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
274 Encoding defaultEncoding)
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
275 {
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
276 Encoding encoding = defaultEncoding;
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
277
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
278 OFString tmp;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
279 if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good())
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
280 {
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
281 std::string characterSet = Toolbox::StripSpaces(std::string(tmp.c_str()));
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
282
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
283 if (characterSet.empty())
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
284 {
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
285 // Empty specific character set tag: Use the default encoding
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
286 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
287 else if (GetDicomEncoding(encoding, characterSet.c_str()))
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
288 {
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
289 // The specific character set is supported by the Orthanc core
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
290 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
291 else
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
292 {
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
293 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
294 << ", fallback to ASCII (remove all special characters)";
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
295 encoding = Encoding_Ascii;
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 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
298 else
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
299 {
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
300 // No specific character set tag: Use the default encoding
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
301 }
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
302
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
303 return encoding;
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
304 }
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
305
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
306
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
307 void FromDcmtkBridge::Convert(DicomMap& target,
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
308 DcmDataset& dataset,
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
309 unsigned int maxStringLength,
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
310 Encoding defaultEncoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
312 Encoding encoding = DetectEncoding(dataset, defaultEncoding);
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
313
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 target.Clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 for (unsigned long i = 0; i < dataset.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 DcmElement* element = dataset.getElement(i);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 if (element && element->isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 target.SetValue(element->getTag().getGTag(),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 element->getTag().getETag(),
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
322 ConvertLeafElement(*element, DicomToJsonFlags_Default, maxStringLength, encoding));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
328 DicomTag FromDcmtkBridge::Convert(const DcmTag& tag)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
329 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
330 return DicomTag(tag.getGTag(), tag.getETag());
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
331 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
332
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
333
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 return DicomTag(element.getGTag(), element.getETag());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
340 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element,
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
341 DicomToJsonFlags flags,
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
342 unsigned int maxStringLength,
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
343 Encoding encoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 if (!element.isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
347 // This function is only applicable to leaf elements
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
348 throw OrthancException(ErrorCode_BadParameterType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
351 char *c = NULL;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
352 if (element.isaString() &&
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
353 element.getString(c).good())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
355 if (c == NULL) // This case corresponds to the empty string
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
357 return new DicomValue("", false);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
361 std::string s(c);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
362 std::string utf8 = Toolbox::ConvertToUtf8(s, encoding);
1854
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
363
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
364 if (maxStringLength != 0 &&
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
365 utf8.size() > maxStringLength)
1854
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
366 {
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
367 return new DicomValue; // Create a NULL value
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
368 }
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
369 else
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
370 {
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
371 return new DicomValue(utf8, false);
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
372 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 // http://support.dcmtk.org/docs/dcvr_8h-source.html
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 switch (element.getVR())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 /**
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
383 * Deal with binary data (including PixelData).
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 **/
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
385
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
386 case EVR_OB: // other byte
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
387 case EVR_OF: // other float
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
388 case EVR_OW: // other word
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
389 case EVR_UN: // unknown value representation
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
390 case EVR_ox: // OB or OW depending on context
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
391 case EVR_DS: // decimal string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
392 case EVR_IS: // integer string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
393 case EVR_AS: // age string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
394 case EVR_DA: // date string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
395 case EVR_DT: // date time string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
396 case EVR_TM: // time string
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
397 case EVR_AE: // application entity title
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
398 case EVR_CS: // code string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
399 case EVR_SH: // short string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
400 case EVR_LO: // long string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
401 case EVR_ST: // short text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
402 case EVR_LT: // long text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
403 case EVR_UT: // unlimited text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
404 case EVR_PN: // person name
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
405 case EVR_UI: // unique identifier
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
406 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
407 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
408 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
409 if (!(flags & DicomToJsonFlags_ConvertBinaryToNull))
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
410 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
411 Uint8* data = NULL;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
412 if (element.getUint8Array(data) == EC_Normal)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
413 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
414 return new DicomValue(reinterpret_cast<const char*>(data), element.getLength(), true);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
415 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
416 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
418 return new DicomValue;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
419 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
420
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
421 /**
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
422 * Numberic types
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
423 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
425 case EVR_SL: // signed long
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 Sint32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
428 if (dynamic_cast<DcmSignedLong&>(element).getSint32(f).good())
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
429 return new DicomValue(boost::lexical_cast<std::string>(f), false);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
430 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
431 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
432 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
433
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
434 case EVR_SS: // signed short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
435 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
436 Sint16 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
437 if (dynamic_cast<DcmSignedShort&>(element).getSint16(f).good())
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
438 return new DicomValue(boost::lexical_cast<std::string>(f), false);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
439 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
440 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
441 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
442
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
443 case EVR_UL: // unsigned long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
444 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
445 Uint32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
446 if (dynamic_cast<DcmUnsignedLong&>(element).getUint32(f).good())
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
447 return new DicomValue(boost::lexical_cast<std::string>(f), false);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
448 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
449 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
450 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
451
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
452 case EVR_US: // unsigned short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
453 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
454 Uint16 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
455 if (dynamic_cast<DcmUnsignedShort&>(element).getUint16(f).good())
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
456 return new DicomValue(boost::lexical_cast<std::string>(f), false);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
457 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
458 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
459 }
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 case EVR_FL: // float single-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
462 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
463 Float32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
464 if (dynamic_cast<DcmFloatingPointSingle&>(element).getFloat32(f).good())
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
465 return new DicomValue(boost::lexical_cast<std::string>(f), false);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
466 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
467 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
468 }
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 case EVR_FD: // float double-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
471 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
472 Float64 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
473 if (dynamic_cast<DcmFloatingPointDouble&>(element).getFloat64(f).good())
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
474 return new DicomValue(boost::lexical_cast<std::string>(f), false);
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
475 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
476 return new DicomValue;
1131
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
477 }
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
478
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
479
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
480 /**
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
481 * Attribute tag.
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
482 **/
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
483
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
484 case EVR_AT:
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
485 {
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
486 DcmTagKey tag;
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
487 if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good())
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
488 {
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
489 DicomTag t(tag.getGroup(), tag.getElement());
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
490 return new DicomValue(t.Format(), false);
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
491 }
1131
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
492 else
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
493 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
494 return new DicomValue;
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
495 }
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
496 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 /**
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
500 * 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
501 * "element.isLeaf()".
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
502 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
504 case EVR_SQ: // sequence of items
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
505 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
508 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
509 * Internal to DCMTK.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
510 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
512 case EVR_xs: // SS or US depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
513 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
514 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
515 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
516 case EVR_item: // used internally for items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
517 case EVR_metainfo: // used internally for meta info datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
518 case EVR_dataset: // used internally for datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
519 case EVR_fileFormat: // used internally for DICOM files
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
520 case EVR_dicomDir: // used internally for DICOMDIR objects
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
521 case EVR_dirRecord: // used internally for DICOMDIR records
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
522 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
523 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
524 case EVR_PixelData: // used internally for uncompressed pixeld data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
525 case EVR_OverlayData: // used internally for overlay data
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
526 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
529 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
530 * Default case.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
531 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
533 default:
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
534 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
539 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 }
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
541 catch (std::bad_cast)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
542 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
543 return new DicomValue;
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
544 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
548 static Json::Value& PrepareNode(Json::Value& parent,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
549 DcmElement& element,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
550 DicomToJsonFormat format)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
552 assert(parent.type() == Json::objectValue);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
554 DicomTag tag(FromDcmtkBridge::GetTag(element));
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
555 const std::string formattedTag = tag.Format();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
556
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
557 if (format == DicomToJsonFormat_Short)
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
558 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
559 parent[formattedTag] = Json::nullValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
560 return parent[formattedTag];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
561 }
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
562
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
563 // 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
564 DcmTag tagbis(element.getTag());
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
565 const std::string tagName(tagbis.getTagName());
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
566
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
567 switch (format)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 {
1860
c7d70f659190 DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1854
diff changeset
569 case DicomToJsonFormat_Human:
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
570 parent[tagName] = Json::nullValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
571 return parent[tagName];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
572
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
573 case DicomToJsonFormat_Full:
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
574 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
575 parent[formattedTag] = Json::objectValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
576 Json::Value& node = parent[formattedTag];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
577
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
578 if (element.isLeaf())
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
579 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
580 node["Name"] = tagName;
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
581
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
582 if (tagbis.getPrivateCreator() != NULL)
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
583 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
584 node["PrivateCreator"] = tagbis.getPrivateCreator();
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
585 }
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
586
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
587 return node;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
588 }
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
589 else
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
590 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
591 node["Name"] = tagName;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
592 node["Type"] = "Sequence";
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
593 node["Value"] = Json::nullValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
594 return node["Value"];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
595 }
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
596 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
597
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
598 default:
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
599 throw OrthancException(ErrorCode_ParameterOutOfRange);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
600 }
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
601 }
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
602
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
603
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
604 static void LeafValueToJson(Json::Value& target,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
605 const DicomValue& value,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
606 DicomToJsonFormat format,
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
607 DicomToJsonFlags flags,
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
608 unsigned int maxStringLength)
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
609 {
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
610 Json::Value* targetValue = NULL;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
611 Json::Value* targetType = NULL;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
612
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
613 switch (format)
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
614 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
615 case DicomToJsonFormat_Short:
1860
c7d70f659190 DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1854
diff changeset
616 case DicomToJsonFormat_Human:
1688
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 assert(target.type() == Json::nullValue);
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
619 targetValue = &target;
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
620 break;
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
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
623 case DicomToJsonFormat_Full:
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
625 assert(target.type() == Json::objectValue);
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
626 target["Value"] = Json::nullValue;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
627 target["Type"] = Json::nullValue;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
628 targetType = &target["Type"];
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
629 targetValue = &target["Value"];
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
630 break;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
632
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
633 default:
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
634 throw OrthancException(ErrorCode_ParameterOutOfRange);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
635 }
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
636
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
637 assert(targetValue != NULL);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
638 assert(targetValue->type() == Json::nullValue);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
639 assert(targetType == NULL || targetType->type() == Json::nullValue);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
640
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
641 if (value.IsNull())
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
642 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
643 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
644 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
645 *targetType = "Null";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
646 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
647 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
648 else if (value.IsBinary())
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
649 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
650 if (flags & DicomToJsonFlags_ConvertBinaryToAscii)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
651 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
652 *targetValue = Toolbox::ConvertToAscii(value.GetContent());
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
653 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
654 else
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
655 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
656 std::string s;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
657 value.FormatDataUriScheme(s);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
658 *targetValue = s;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
659 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
660
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
661 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
662 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
663 *targetType = "Binary";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
664 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
665 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
666 else if (maxStringLength == 0 ||
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
667 value.GetContent().size() <= maxStringLength)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
668 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
669 *targetValue = value.GetContent();
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
670
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
671 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
672 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
673 *targetType = "String";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
674 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
675 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
676 else
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
677 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
678 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
679 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
680 *targetType = "TooLong";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
681 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
682 }
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
683 }
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
684
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
685
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
686 static void DatasetToJson(Json::Value& parent,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
687 DcmItem& item,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
688 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
689 DicomToJsonFlags flags,
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
690 unsigned int maxStringLength,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
691 Encoding encoding);
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
692
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
693
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
694 void FromDcmtkBridge::ToJson(Json::Value& parent,
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
695 DcmElement& element,
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
696 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
697 DicomToJsonFlags flags,
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
698 unsigned int maxStringLength,
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
699 Encoding encoding)
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
700 {
1691
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
701 if (parent.type() == Json::nullValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
702 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
703 parent = Json::objectValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
704 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
705
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
706 assert(parent.type() == Json::objectValue);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
707 Json::Value& target = PrepareNode(parent, element, format);
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
708
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
709 if (element.isLeaf())
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
710 {
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
711 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(element, flags, maxStringLength, encoding));
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
712 LeafValueToJson(target, *v, format, flags, maxStringLength);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
716 assert(target.type() == Json::nullValue);
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
717 target = Json::arrayValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 // "All subclasses of DcmElement except for DcmSequenceOfItems
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
721 // etc. are not." The following dynamic_cast is thus OK.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 for (unsigned long i = 0; i < sequence.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 DcmItem* child = sequence.getItem(i);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
727 Json::Value& v = target.append(Json::objectValue);
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
728 DatasetToJson(v, *child, format, flags, maxStringLength, encoding);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
729 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
734 static void DatasetToJson(Json::Value& parent,
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
735 DcmItem& item,
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
736 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
737 DicomToJsonFlags flags,
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
738 unsigned int maxStringLength,
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
739 Encoding encoding)
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
740 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
741 assert(parent.type() == Json::objectValue);
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
742
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
743 for (unsigned long i = 0; i < item.card(); i++)
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
744 {
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
745 DcmElement* element = item.getElement(i);
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
746 if (element == NULL)
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
747 {
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
748 throw OrthancException(ErrorCode_InternalError);
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
749 }
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
750
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
751 DicomTag tag(FromDcmtkBridge::Convert(element->getTag()));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
752
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
753 /*element->getTag().isPrivate()*/
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
754 if (tag.IsPrivate() &&
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
755 !(flags & DicomToJsonFlags_IncludePrivateTags))
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
756 {
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
757 continue;
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
758 }
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
759
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
760 if (!(flags & DicomToJsonFlags_IncludeUnknownTags))
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
761 {
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
762 DictionaryLocker locker;
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
763 if (locker->findEntry(element->getTag(), NULL) == NULL)
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
764 {
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
765 continue;
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
766 }
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
767 }
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
768
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
769 DcmEVR evr = element->getTag().getEVR();
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
770 if (evr == EVR_OB ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
771 evr == EVR_OF ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
772 evr == EVR_OW ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
773 evr == EVR_UN ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
774 evr == EVR_ox)
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
775 {
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
776 // This is a binary tag
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
777 if ((tag == DICOM_TAG_PIXEL_DATA && !(flags & DicomToJsonFlags_IncludePixelData)) ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
778 (tag != DICOM_TAG_PIXEL_DATA && !(flags & DicomToJsonFlags_IncludeBinary)))
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
779 {
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
780 continue;
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
781 }
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
782 }
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
783
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
784 FromDcmtkBridge::ToJson(parent, *element, format, flags, maxStringLength, encoding);
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
785 }
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
786 }
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
787
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
788
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
789 void FromDcmtkBridge::ToJson(Json::Value& target,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 DcmDataset& dataset,
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
791 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
792 DicomToJsonFlags flags,
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
793 unsigned int maxStringLength,
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
794 Encoding defaultEncoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
796 target = Json::objectValue;
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
797 DatasetToJson(target, dataset, format, flags, maxStringLength, DetectEncoding(dataset, defaultEncoding));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
801 void FromDcmtkBridge::ToJson(Json::Value& target,
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
802 DcmMetaInfo& dataset,
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
803 DicomToJsonFormat format,
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
804 DicomToJsonFlags flags,
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
805 unsigned int maxStringLength)
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
806 {
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
807 target = Json::objectValue;
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
808 DatasetToJson(target, dataset, format, flags, maxStringLength, Encoding_Ascii);
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
809 }
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
810
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
811
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 std::string FromDcmtkBridge::GetName(const DicomTag& t)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 {
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
814 // Some patches for important tags because of different DICOM
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
815 // dictionaries between DCMTK versions
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
816 std::string n = t.GetMainTagsName();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
817 if (n.size() != 0)
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
818 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
819 return n;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
820 }
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
821 // End of patches
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
822
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
823 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 DcmTagKey tag(t.GetGroup(), t.GetElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 const DcmDictEntry* entry = dict.findEntry(tag, NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
828 std::string s(DcmTag_ERROR_TagName);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 if (entry != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 s = std::string(entry->getTagName());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 return s;
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(t.GetGroup(), t.GetElement());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
838 const char* name = tag.getTagName();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
839 if (name == NULL)
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
840 {
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
841 return DcmTag_ERROR_TagName;
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
842 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
843 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
844 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
845 return std::string(name);
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
846 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
847 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
851 DicomTag FromDcmtkBridge::ParseTag(const char* name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
853 if (strlen(name) == 9 &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
854 isxdigit(name[0]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
855 isxdigit(name[1]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
856 isxdigit(name[2]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
857 isxdigit(name[3]) &&
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
858 (name[4] == '-' || name[4] == ',') &&
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
859 isxdigit(name[5]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
860 isxdigit(name[6]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
861 isxdigit(name[7]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
862 isxdigit(name[8]))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
863 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
864 uint16_t group = GetTagValue(name);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
865 uint16_t element = GetTagValue(name + 5);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
866 return DicomTag(group, element);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
867 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
868
1861
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
869 if (strlen(name) == 8 &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
870 isxdigit(name[0]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
871 isxdigit(name[1]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
872 isxdigit(name[2]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
873 isxdigit(name[3]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
874 isxdigit(name[4]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
875 isxdigit(name[5]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
876 isxdigit(name[6]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
877 isxdigit(name[7]))
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
878 {
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
879 uint16_t group = GetTagValue(name);
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
880 uint16_t element = GetTagValue(name + 4);
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
881 return DicomTag(group, element);
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
882 }
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
883
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
884 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 const DcmDictEntry* entry = dict.findEntry(name);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 if (entry == NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 dcmDataDict.unlock();
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
891 throw OrthancException(ErrorCode_UnknownDicomTag);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 DcmTagKey key = entry->getKey();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 DicomTag tag(key.getGroup(), key.getElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 return tag;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 }
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
900 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
901 DcmTag tag;
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
902 if (DcmTag::findTagFromName(name, tag).good())
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
903 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
904 return DicomTag(tag.getGTag(), tag.getETag());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
905 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
906 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
907 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
908 throw OrthancException(ErrorCode_UnknownDicomTag);
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
909 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
910 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913
1655
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
914 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
915 {
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
916 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
917 return tmp.isUnknownVR();
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
918 }
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
919
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
920
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 void FromDcmtkBridge::ToJson(Json::Value& result,
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
922 const DicomMap& values,
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
923 bool simplify)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 if (result.type() != Json::objectValue)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
927 throw OrthancException(ErrorCode_BadParameterType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 result.clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 for (DicomMap::Map::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
933 it = values.map_.begin(); it != values.map_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 {
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
935 if (simplify)
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
936 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
937 if (it->second->IsNull())
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
938 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
939 result[GetName(it->first)] = Json::nullValue;
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
940 }
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
941 else
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
942 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
943 // TODO IsBinary
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
944 result[GetName(it->first)] = it->second->GetContent();
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
945 }
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
946 }
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
947 else
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
948 {
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
949 Json::Value value = Json::objectValue;
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
950
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
951 value["Name"] = GetName(it->first);
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
952
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
953 if (it->second->IsNull())
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
954 {
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
955 value["Type"] = "Null";
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
956 value["Value"] = Json::nullValue;
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
957 }
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
958 else
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
959 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
960 // TODO IsBinary
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
961 value["Type"] = "String";
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
962 value["Value"] = it->second->GetContent();
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
963 }
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
964
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
965 result[it->first.Format()] = value;
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
966 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 }
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
969
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
970
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
971 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level)
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
972 {
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
973 char uid[100];
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
974
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
975 switch (level)
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
976 {
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
977 case ResourceType_Patient:
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
978 // The "PatientID" field is of type LO (Long String), 64
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
979 // Bytes Maximum. An UUID is of length 36, thus it can be used
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
980 // as a random PatientID.
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
981 return Toolbox::GenerateUuid();
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
982
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
983 case ResourceType_Instance:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
984 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
985
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
986 case ResourceType_Series:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
987 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
988
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
989 case ResourceType_Study:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
990 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
991
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
992 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
993 throw OrthancException(ErrorCode_ParameterOutOfRange);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
994 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
995 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
996
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
997 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
998 DcmDataset& dataSet)
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
999 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1000 // 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
1001 // 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
1002 // syntax, with explicit length.
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1003
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1004 // 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
1005
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
1006
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
1007 /**
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
1008 * 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
1009 * "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
1010 * 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
1011 * (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
1012 **/
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
1013 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
1014 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
1015 {
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
1016 // 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
1017 // 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
1018 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
1019 }
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
1020
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1021 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1022
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
1023 // Create the meta-header information
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
1024 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
1025 ff.validateMetaInfo(xfer);
1316
1c8dfedefefe Fix anonymization generating non-portable DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1307
diff changeset
1026 ff.removeInvalidGroups();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1027
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
1028 // Create a memory buffer with the proper size
1876
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1029 {
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1030 const uint32_t estimatedSize = ff.calcElementLength(xfer, encodingType); // (*)
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1031 buffer.resize(estimatedSize);
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1032 }
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1033
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1034 DcmOutputBufferStream ob(&buffer[0], buffer.size());
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1035
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
1036 // 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
1037 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
1038 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
1039 /*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
1040 /*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
1041 ff.transferEnd();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1042
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1043 if (c.good())
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1044 {
1876
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1045 // The DICOM file is successfully written, truncate the target
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1046 // buffer if its size was overestimated by (*)
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1047 ob.flush();
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1048
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1049 size_t effectiveSize = static_cast<size_t>(ob.tell());
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1050 if (effectiveSize < buffer.size())
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1051 {
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1052 buffer.resize(effectiveSize);
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1053 }
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1054
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1055 return true;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1056 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1057 else
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1058 {
1876
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1059 // Error
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1060 buffer.clear();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1061 return false;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1062 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1063 }
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1064
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1065
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1066 ValueRepresentation FromDcmtkBridge::GetValueRepresentation(const DicomTag& tag)
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1067 {
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1068 DcmTag t(tag.GetGroup(), tag.GetElement());
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1069 switch (t.getEVR())
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1070 {
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1071 case EVR_PN:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1072 return ValueRepresentation_PatientName;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1073
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1074 case EVR_DA:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1075 return ValueRepresentation_Date;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1076
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1077 case EVR_DT:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1078 return ValueRepresentation_DateTime;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1079
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1080 case EVR_TM:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1081 return ValueRepresentation_Time;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1082
1792
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1765
diff changeset
1083 case EVR_SQ:
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1765
diff changeset
1084 return ValueRepresentation_Sequence;
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1765
diff changeset
1085
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1086 default:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1087 return ValueRepresentation_Other;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1088 }
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1089 }
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1090
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1091
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1092 static bool IsBinaryTag(const DcmTag& key)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1093 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1094 return (key.isUnknownVR() ||
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1095 key.getEVR() == EVR_OB ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1096 key.getEVR() == EVR_OF ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1097 key.getEVR() == EVR_OW ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1098 key.getEVR() == EVR_UN ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1099 key.getEVR() == EVR_ox);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1100 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1101
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1102
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1103 DcmElement* FromDcmtkBridge::CreateElementForTag(const DicomTag& tag)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1104 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1105 DcmTag key(tag.GetGroup(), tag.GetElement());
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1106
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1107 if (tag.IsPrivate() ||
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1108 IsBinaryTag(key))
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1109 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1110 return new DcmOtherByteOtherWord(key);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1111 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1112
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1113 switch (key.getEVR())
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1114 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1115 // http://support.dcmtk.org/docs/dcvr_8h-source.html
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1116
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1117 /**
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1118 * Binary types, handled above
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1119 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1120
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1121 case EVR_OB: // other byte
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1122 case EVR_OF: // other float
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1123 case EVR_OW: // other word
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1124 case EVR_UN: // unknown value representation
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1125 case EVR_ox: // OB or OW depending on context
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1126 throw OrthancException(ErrorCode_InternalError);
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1127
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1128
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1129 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1130 * String types.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1131 * http://support.dcmtk.org/docs/classDcmByteString.html
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1132 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1133
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1134 case EVR_AS: // age string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1135 return new DcmAgeString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1136
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1137 case EVR_AE: // application entity title
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1138 return new DcmApplicationEntity(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1139
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1140 case EVR_CS: // code string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1141 return new DcmCodeString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1142
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1143 case EVR_DA: // date string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1144 return new DcmDate(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1145
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1146 case EVR_DT: // date time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1147 return new DcmDateTime(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1148
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1149 case EVR_DS: // decimal string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1150 return new DcmDecimalString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1151
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1152 case EVR_IS: // integer string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1153 return new DcmIntegerString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1154
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1155 case EVR_TM: // time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1156 return new DcmTime(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1157
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1158 case EVR_UI: // unique identifier
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1159 return new DcmUniqueIdentifier(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1160
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1161 case EVR_ST: // short text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1162 return new DcmShortText(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1163
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1164 case EVR_LO: // long string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1165 return new DcmLongString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1166
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1167 case EVR_LT: // long text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1168 return new DcmLongText(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1169
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1170 case EVR_UT: // unlimited text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1171 return new DcmUnlimitedText(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1172
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1173 case EVR_SH: // short string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1174 return new DcmShortString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1175
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1176 case EVR_PN: // person name
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1177 return new DcmPersonName(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1178
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1179
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1180 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1181 * Numerical types
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1182 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1183
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1184 case EVR_SL: // signed long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1185 return new DcmSignedLong(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1186
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1187 case EVR_SS: // signed short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1188 return new DcmSignedShort(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1189
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1190 case EVR_UL: // unsigned long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1191 return new DcmUnsignedLong(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1192
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1193 case EVR_US: // unsigned short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1194 return new DcmUnsignedShort(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1195
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1196 case EVR_FL: // float single-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1197 return new DcmFloatingPointSingle(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1198
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1199 case EVR_FD: // float double-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1200 return new DcmFloatingPointDouble(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1201
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1202
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1203 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1204 * Sequence types, should never occur at this point.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1205 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1206
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1207 case EVR_SQ: // sequence of items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1208 throw OrthancException(ErrorCode_ParameterOutOfRange);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1209
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1210
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1211 /**
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1212 * TODO
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1213 **/
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1214
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1215 case EVR_AT: // attribute tag
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1216 throw OrthancException(ErrorCode_NotImplemented);
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1217
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1218
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1219 /**
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1220 * Internal to DCMTK.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1221 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1222
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1223 case EVR_xs: // SS or US depending on context
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1224 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1225 case EVR_na: // na="not applicable", for data which has no VR
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1226 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1227 case EVR_item: // used internally for items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1228 case EVR_metainfo: // used internally for meta info datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1229 case EVR_dataset: // used internally for datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1230 case EVR_fileFormat: // used internally for DICOM files
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1231 case EVR_dicomDir: // used internally for DICOMDIR objects
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1232 case EVR_dirRecord: // used internally for DICOMDIR records
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1233 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1234 case EVR_pixelItem: // used internally for pixel items in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1235 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1236 case EVR_PixelData: // used internally for uncompressed pixeld data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1237 case EVR_OverlayData: // used internally for overlay data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1238 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1239 default:
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1240 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1241 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1242
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1243 throw OrthancException(ErrorCode_InternalError);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1244 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1245
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1246
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1247
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1248 void FromDcmtkBridge::FillElementWithString(DcmElement& element,
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1249 const DicomTag& tag,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1250 const std::string& utf8Value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1251 bool decodeDataUriScheme,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1252 Encoding dicomEncoding)
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1253 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1254 std::string binary;
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1255 const std::string* decoded = &utf8Value;
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1256
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1257 if (decodeDataUriScheme &&
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1258 boost::starts_with(utf8Value, "data:application/octet-stream;base64,"))
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1259 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1260 std::string mime;
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1261 Toolbox::DecodeDataUriScheme(mime, binary, utf8Value);
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1262 decoded = &binary;
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1263 }
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1264 else if (dicomEncoding != Encoding_Utf8)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1265 {
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1266 binary = Toolbox::ConvertFromUtf8(utf8Value, dicomEncoding);
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1267 decoded = &binary;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1268 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1269
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1270 DcmTag key(tag.GetGroup(), tag.GetElement());
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1271
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1272 if (tag.IsPrivate() ||
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1273 IsBinaryTag(key))
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1274 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1275 if (element.putUint8Array((const Uint8*) decoded->c_str(), decoded->size()).good())
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1276 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1277 return;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1278 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1279 else
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1280 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1281 throw OrthancException(ErrorCode_InternalError);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1282 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1283 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1284
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1285 bool ok = false;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1286
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1287 try
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1288 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1289 switch (key.getEVR())
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1290 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1291 // http://support.dcmtk.org/docs/dcvr_8h-source.html
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1292
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1293 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1294 * TODO.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1295 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1296
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1297 case EVR_OB: // other byte
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1298 case EVR_OF: // other float
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1299 case EVR_OW: // other word
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1300 case EVR_AT: // attribute tag
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1301 throw OrthancException(ErrorCode_NotImplemented);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1302
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1303 case EVR_UN: // unknown value representation
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1304 throw OrthancException(ErrorCode_ParameterOutOfRange);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1305
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1306
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1307 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1308 * String types.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1309 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1310
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1311 case EVR_DS: // decimal string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1312 case EVR_IS: // integer string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1313 case EVR_AS: // age string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1314 case EVR_DA: // date string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1315 case EVR_DT: // date time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1316 case EVR_TM: // time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1317 case EVR_AE: // application entity title
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1318 case EVR_CS: // code string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1319 case EVR_SH: // short string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1320 case EVR_LO: // long string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1321 case EVR_ST: // short text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1322 case EVR_LT: // long text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1323 case EVR_UT: // unlimited text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1324 case EVR_PN: // person name
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1325 case EVR_UI: // unique identifier
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1326 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1327 ok = element.putString(decoded->c_str()).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1328 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1329 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1330
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1331
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1332 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1333 * Numerical types
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1334 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1335
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1336 case EVR_SL: // signed long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1337 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1338 ok = element.putSint32(boost::lexical_cast<Sint32>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1339 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1340 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1341
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1342 case EVR_SS: // signed short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1343 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1344 ok = element.putSint16(boost::lexical_cast<Sint16>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1345 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1346 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1347
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1348 case EVR_UL: // unsigned long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1349 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1350 ok = element.putUint32(boost::lexical_cast<Uint32>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1351 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1352 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1353
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1354 case EVR_US: // unsigned short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1355 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1356 ok = element.putUint16(boost::lexical_cast<Uint16>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1357 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1358 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1359
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1360 case EVR_FL: // float single-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1361 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1362 ok = element.putFloat32(boost::lexical_cast<float>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1363 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1364 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1365
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1366 case EVR_FD: // float double-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1367 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1368 ok = element.putFloat64(boost::lexical_cast<double>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1369 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1370 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1371
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1372
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1373 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1374 * Sequence types, should never occur at this point.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1375 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1376
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1377 case EVR_SQ: // sequence of items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1378 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1379 ok = false;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1380 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1381 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1382
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1383
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1384 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1385 * Internal to DCMTK.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1386 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1387
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1388 case EVR_ox: // OB or OW depending on context
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1389 case EVR_xs: // SS or US depending on context
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1390 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1391 case EVR_na: // na="not applicable", for data which has no VR
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1392 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1393 case EVR_item: // used internally for items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1394 case EVR_metainfo: // used internally for meta info datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1395 case EVR_dataset: // used internally for datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1396 case EVR_fileFormat: // used internally for DICOM files
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1397 case EVR_dicomDir: // used internally for DICOMDIR objects
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1398 case EVR_dirRecord: // used internally for DICOMDIR records
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1399 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1400 case EVR_pixelItem: // used internally for pixel items in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1401 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1402 case EVR_PixelData: // used internally for uncompressed pixeld data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1403 case EVR_OverlayData: // used internally for overlay data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1404 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1405 default:
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1406 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1407 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1408 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1409 catch (boost::bad_lexical_cast&)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1410 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1411 ok = false;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1412 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1413
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1414 if (!ok)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1415 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1416 throw OrthancException(ErrorCode_InternalError);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1417 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1418 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1419
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1420
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1421 DcmElement* FromDcmtkBridge::FromJson(const DicomTag& tag,
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1422 const Json::Value& value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1423 bool decodeDataUriScheme,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1424 Encoding dicomEncoding)
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1425 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1426 std::auto_ptr<DcmElement> element;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1427
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1428 switch (value.type())
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1429 {
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1430 case Json::stringValue:
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1431 element.reset(CreateElementForTag(tag));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1432 FillElementWithString(*element, tag, value.asString(), decodeDataUriScheme, dicomEncoding);
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1433 break;
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1434
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1435 case Json::arrayValue:
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1436 {
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1437 DcmTag key(tag.GetGroup(), tag.GetElement());
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1438 if (key.getEVR() != EVR_SQ)
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1439 {
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1440 throw OrthancException(ErrorCode_BadParameterType);
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1441 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1442
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1443 DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key, value.size());
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1444 element.reset(sequence);
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1445
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1446 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1447 {
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1448 std::auto_ptr<DcmItem> item(new DcmItem);
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1449
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1450 Json::Value::Members members = value[i].getMemberNames();
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1451 for (Json::Value::ArrayIndex j = 0; j < members.size(); j++)
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1452 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1453 item->insert(FromJson(ParseTag(members[j]), value[i][members[j]], decodeDataUriScheme, dicomEncoding));
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1454 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1455
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1456 sequence->append(item.release());
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1457 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1458
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1459 break;
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1460 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1461
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1462 default:
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1463 throw OrthancException(ErrorCode_BadParameterType);
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1464 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1465
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1466 return element.release();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1467 }
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1468
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1469
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1470 DcmEVR FromDcmtkBridge::ParseValueRepresentation(const std::string& s)
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1471 {
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1472 if (s == "AE")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1473 return EVR_AE;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1474
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1475 if (s == "AS")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1476 return EVR_AS;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1477
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1478 if (s == "AT")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1479 return EVR_AT;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1480
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1481 if (s == "CS")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1482 return EVR_CS;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1483
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1484 if (s == "DA")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1485 return EVR_DA;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1486
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1487 if (s == "DS")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1488 return EVR_DS;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1489
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1490 if (s == "DT")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1491 return EVR_DT;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1492
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1493 if (s == "FD")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1494 return EVR_FD;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1495
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1496 if (s == "FL")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1497 return EVR_FL;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1498
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1499 if (s == "IS")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1500 return EVR_IS;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1501
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1502 if (s == "LO")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1503 return EVR_LO;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1504
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1505 if (s == "LT")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1506 return EVR_LT;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1507
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1508 if (s == "OB")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1509 return EVR_OB;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1510
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1511 if (s == "OF")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1512 return EVR_OF;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1513
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1514 if (s == "OW")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1515 return EVR_OW;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1516
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1517 if (s == "PN")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1518 return EVR_PN;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1519
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1520 if (s == "SH")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1521 return EVR_SH;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1522
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1523 if (s == "SL")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1524 return EVR_SL;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1525
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1526 if (s == "SQ")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1527 return EVR_SQ;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1528
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1529 if (s == "SS")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1530 return EVR_SS;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1531
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1532 if (s == "ST")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1533 return EVR_ST;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1534
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1535 if (s == "TM")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1536 return EVR_TM;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1537
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1538 if (s == "UI")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1539 return EVR_UI;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1540
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1541 if (s == "UL")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1542 return EVR_UL;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1543
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1544 if (s == "UN")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1545 return EVR_UN;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1546
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1547 if (s == "US")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1548 return EVR_US;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1549
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1550 if (s == "UT")
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1551 return EVR_UT;
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1552
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1553 throw OrthancException(ErrorCode_ParameterOutOfRange);
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1554 }
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1555
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1556
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1557 DcmPixelSequence* FromDcmtkBridge::GetPixelSequence(DcmDataset& dataset)
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1558 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1559 DcmElement *element = NULL;
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
1560 if (!dataset.findAndGetElement(DCM_PixelData, element).good())
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1561 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1562 throw OrthancException(ErrorCode_BadFileFormat);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1563 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1564
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1565 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1566 DcmPixelSequence* pixelSequence = NULL;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1567 if (!pixelData.getEncapsulatedRepresentation
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1568 (dataset.getOriginalXfer(), NULL, pixelSequence).good())
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1569 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1570 return NULL;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1571 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1572 else
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1573 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1574 return pixelSequence;
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1575 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1576 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 }