annotate OrthancServer/FromDcmtkBridge.cpp @ 2116:2fabd1073728

prevent registering two tags with the same symbolic name
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 31 Oct 2016 15:42:18 +0100
parents a657f7772e69
children b9bd52c72ba2
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"
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
40 #include "ToDcmtkBridge.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1429
diff changeset
41 #include "../Core/Logging.h"
107
3b45473c0a73 replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 106
diff changeset
42 #include "../Core/Toolbox.h"
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
43 #include "../Core/Uuid.h"
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
44 #include "../Core/OrthancException.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
46 #include <list>
71
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
47 #include <limits>
aa65ced5f0f0 fix for visual studio
jodogne
parents: 62
diff changeset
48
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #include <boost/lexical_cast.hpp>
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
50 #include <boost/filesystem.hpp>
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
51 #include <boost/algorithm/string/predicate.hpp>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
53 #include <dcmtk/dcmdata/dcdeftag.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 #include <dcmtk/dcmdata/dcdicent.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #include <dcmtk/dcmdata/dcdict.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 #include <dcmtk/dcmdata/dcfilefo.h>
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
57 #include <dcmtk/dcmdata/dcostrmb.h>
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
58 #include <dcmtk/dcmdata/dcpixel.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
59 #include <dcmtk/dcmdata/dcuid.h>
1935
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
60 #include <dcmtk/dcmdata/dcistrmb.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
61
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
62 #include <dcmtk/dcmdata/dcvrae.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
63 #include <dcmtk/dcmdata/dcvras.h>
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
64 #include <dcmtk/dcmdata/dcvrat.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
65 #include <dcmtk/dcmdata/dcvrcs.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
66 #include <dcmtk/dcmdata/dcvrda.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
67 #include <dcmtk/dcmdata/dcvrds.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
68 #include <dcmtk/dcmdata/dcvrdt.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 #include <dcmtk/dcmdata/dcvrfd.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 #include <dcmtk/dcmdata/dcvrfl.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
71 #include <dcmtk/dcmdata/dcvris.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
72 #include <dcmtk/dcmdata/dcvrlo.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
73 #include <dcmtk/dcmdata/dcvrlt.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
74 #include <dcmtk/dcmdata/dcvrpn.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
75 #include <dcmtk/dcmdata/dcvrsh.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 #include <dcmtk/dcmdata/dcvrsl.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 #include <dcmtk/dcmdata/dcvrss.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
78 #include <dcmtk/dcmdata/dcvrst.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
79 #include <dcmtk/dcmdata/dcvrtm.h>
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
80 #include <dcmtk/dcmdata/dcvrui.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 #include <dcmtk/dcmdata/dcvrul.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 #include <dcmtk/dcmdata/dcvrus.h>
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
83 #include <dcmtk/dcmdata/dcvrut.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
682
efc4928be6fb Recover pixel data for more transfer syntaxes (notably JPEG)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 677
diff changeset
85
1930
1c147c3c3121 fix static builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
86 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1
1c147c3c3121 fix static builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
87 #include <EmbeddedResources.h>
1c147c3c3121 fix static builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
88 #endif
1c147c3c3121 fix static builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
89
1c147c3c3121 fix static builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
90
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
91 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
93 static inline uint16_t GetCharValue(char c)
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
94 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
95 if (c >= '0' && c <= '9')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
96 return c - '0';
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
97 else if (c >= 'a' && c <= 'f')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
98 return c - 'a' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
99 else if (c >= 'A' && c <= 'F')
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
100 return c - 'A' + 10;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
101 else
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
102 return 0;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
103 }
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 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
106 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
107 return ((GetCharValue(c[0]) << 12) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
108 (GetCharValue(c[1]) << 8) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
109 (GetCharValue(c[2]) << 4) +
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
110 GetCharValue(c[3]));
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
111 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 176
diff changeset
112
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
113
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
114 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
115 static void LoadEmbeddedDictionary(DcmDataDictionary& dictionary,
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
116 EmbeddedResources::FileResourceId resource)
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
117 {
2017
08ce34cfacad refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
118 std::string content;
08ce34cfacad refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
119 EmbeddedResources::GetFileResource(content, resource);
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
120
2017
08ce34cfacad refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
121 Toolbox::TemporaryFile tmp;
08ce34cfacad refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
122 tmp.Write(content);
1656
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 if (!dictionary.loadDictionary(tmp.GetPath().c_str()))
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
125 {
2017
08ce34cfacad refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
126 LOG(ERROR) << "Cannot read embedded dictionary. Under Windows, make sure that "
08ce34cfacad refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
127 << "your TEMP directory does not contain special characters.";
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
128 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
129 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
130 }
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 #else
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
133 static void LoadExternalDictionary(DcmDataDictionary& dictionary,
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
134 const std::string& directory,
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
135 const std::string& filename)
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
136 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
137 boost::filesystem::path p = directory;
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
138 p = p / filename;
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 LOG(WARNING) << "Loading the external DICOM dictionary " << p;
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 if (!dictionary.loadDictionary(p.string().c_str()))
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
143 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
144 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
145 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
146 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
147
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
148 #endif
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
149
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
150
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
151 namespace
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 class DictionaryLocker
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 private:
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
156 DcmDataDictionary& dictionary_;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
157
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
158 public:
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
159 DictionaryLocker() : dictionary_(dcmDataDict.wrlock())
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
160 {
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
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
163 ~DictionaryLocker()
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
164 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
165 dcmDataDict.unlock();
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
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
168 DcmDataDictionary& operator*()
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 return dictionary_;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
171 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
172
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
173 DcmDataDictionary* operator->()
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
174 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
175 return &dictionary_;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
176 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
177 };
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
178 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
179
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
180
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
181 void FromDcmtkBridge::InitializeDictionary()
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
182 {
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
183 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
184 DictionaryLocker locker;
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
185
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
186 locker->clear();
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
187
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
188 #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
189 LOG(WARNING) << "Loading the embedded dictionaries";
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
190 /**
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
191 * 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
192 * 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
193 * dictionary is not loaded by storescu.
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
194 **/
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
195 //LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICONDE);
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
196
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
197 LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICOM);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
198 LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_PRIVATE);
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
199
1976
325772dadcd6 Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1936
diff changeset
200 #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
201 std::string path = DCMTK_DICTIONARY_DIR;
1656
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
202
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
203 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
204 if (env != NULL)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
205 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
206 path = std::string(env);
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
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
209 LoadExternalDictionary(*locker, path, "dicom.dic");
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
210 LoadExternalDictionary(*locker, path, "private.dic");
1656
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 #else
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
213 #error Support your platform here
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
214 #endif
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
215 }
1656
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 /* make sure data dictionary is loaded */
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
218 if (!dcmDataDict.isDictionaryLoaded())
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
219 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
220 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
221 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
222 }
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 // Test the dictionary with a simple DICOM tag
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
226 DcmTag key(0x0010, 0x1030); // This is PatientWeight
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
227 if (key.getEVR() != EVR_DS)
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
228 {
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
229 LOG(ERROR) << "The DICOM dictionary has not been correctly read";
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
230 throw OrthancException(ErrorCode_InternalError);
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
231 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
232 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
233 }
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
234
d3ba98d6b6e9 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1655
diff changeset
235
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
236 void FromDcmtkBridge::RegisterDictionaryTag(const DicomTag& tag,
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
237 ValueRepresentation vr,
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
238 const std::string& name,
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
239 unsigned int minMultiplicity,
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
240 unsigned int maxMultiplicity,
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
241 const std::string& privateCreator)
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
242 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
243 if (minMultiplicity < 1)
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 throw OrthancException(ErrorCode_ParameterOutOfRange);
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
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
248 bool arbitrary = false;
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
249 if (maxMultiplicity == 0)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
250 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
251 maxMultiplicity = DcmVariableVM;
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
252 arbitrary = true;
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
253 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
254 else if (maxMultiplicity < minMultiplicity)
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
255 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
256 throw OrthancException(ErrorCode_ParameterOutOfRange);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
257 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
258
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
259 DcmEVR evr = ToDcmtkBridge::Convert(vr);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
260
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
261 LOG(INFO) << "Registering tag in dictionary: " << tag << " " << (DcmVR(evr).getValidVRName()) << " "
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
262 << name << " (multiplicity: " << minMultiplicity << "-"
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
263 << (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
264
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
265 std::auto_ptr<DcmDictEntry> entry;
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
266 if (privateCreator.empty())
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
267 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
268 if (tag.GetGroup() % 2 == 1)
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
269 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
270 char buf[128];
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
271 sprintf(buf, "Warning: You are registering a private tag (%04x,%04x), "
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
272 "but no private creator was associated with it",
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
273 tag.GetGroup(), tag.GetElement());
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
274 LOG(WARNING) << buf;
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
275 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
276
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
277 entry.reset(new DcmDictEntry(tag.GetGroup(),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
278 tag.GetElement(),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
279 evr, name.c_str(),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
280 static_cast<int>(minMultiplicity),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
281 static_cast<int>(maxMultiplicity),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
282 NULL /* version */,
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
283 OFTrue /* doCopyString */,
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
284 NULL /* private creator */));
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
285 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
286 else
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
287 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
288 // "Private Data Elements have an odd Group Number that is not
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
289 // (0001,eeee), (0003,eeee), (0005,eeee), (0007,eeee), or
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
290 // (FFFF,eeee)."
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
291 if (tag.GetGroup() % 2 == 0 /* even */ ||
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
292 tag.GetGroup() == 0x0001 ||
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
293 tag.GetGroup() == 0x0003 ||
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
294 tag.GetGroup() == 0x0005 ||
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
295 tag.GetGroup() == 0x0007 ||
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
296 tag.GetGroup() == 0xffff)
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
297 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
298 char buf[128];
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
299 sprintf(buf, "Trying to register private tag (%04x,%04x), but it must have an odd group >= 0x0009",
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
300 tag.GetGroup(), tag.GetElement());
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
301 LOG(ERROR) << buf;
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
302 throw OrthancException(ErrorCode_ParameterOutOfRange);
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
303 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
304
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
305 entry.reset(new DcmDictEntry(tag.GetGroup(),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
306 tag.GetElement(),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
307 evr, name.c_str(),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
308 static_cast<int>(minMultiplicity),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
309 static_cast<int>(maxMultiplicity),
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
310 "private" /* version */,
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
311 OFTrue /* doCopyString */,
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
312 privateCreator.c_str()));
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
313 }
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
314
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
315 entry->setGroupRangeRestriction(DcmDictRange_Unspecified);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
316 entry->setElementRangeRestriction(DcmDictRange_Unspecified);
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
317
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
318 {
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
319 DictionaryLocker locker;
2116
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
320
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
321 if (locker->findEntry(name.c_str()))
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
322 {
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
323 LOG(ERROR) << "Cannot register two tags with the same symbolic name \"" << name << "\"";
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
324 throw OrthancException(ErrorCode_AlreadyExistingTag);
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
325 }
2fabd1073728 prevent registering two tags with the same symbolic name
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
326
1657
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
327 locker->addEntry(entry.release());
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
328 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
329 }
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
330
5360cdba70d8 New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1656
diff changeset
331
1936
dba0db0a94b4 generalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
332 Encoding FromDcmtkBridge::DetectEncoding(DcmItem& dataset,
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
333 Encoding defaultEncoding)
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
334 {
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
335 Encoding encoding = defaultEncoding;
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
336
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
337 OFString tmp;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
338 if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good())
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
339 {
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
340 std::string characterSet = Toolbox::StripSpaces(std::string(tmp.c_str()));
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
341
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
342 if (characterSet.empty())
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
343 {
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
344 // Empty specific character set tag: Use the default encoding
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
345 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
346 else if (GetDicomEncoding(encoding, characterSet.c_str()))
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
347 {
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
348 // The specific character set is supported by the Orthanc core
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
349 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
350 else
1087
e07b90fb00eb more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1086
diff changeset
351 {
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
352 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
353 << ", fallback to ASCII (remove all special characters)";
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
354 encoding = Encoding_Ascii;
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
355 }
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
356 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
357 else
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
358 {
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
359 // No specific character set tag: Use the default encoding
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1087
diff changeset
360 }
957
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
361
63973b76a51f detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 956
diff changeset
362 return encoding;
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
363 }
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
364
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
365
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
366 void FromDcmtkBridge::Convert(DicomMap& target,
1936
dba0db0a94b4 generalization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1935
diff changeset
367 DcmItem& dataset,
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
368 unsigned int maxStringLength,
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
369 Encoding defaultEncoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
371 Encoding encoding = DetectEncoding(dataset, defaultEncoding);
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
372
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 target.Clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 for (unsigned long i = 0; i < dataset.card(); i++)
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 DcmElement* element = dataset.getElement(i);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 if (element && element->isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 target.SetValue(element->getTag().getGTag(),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 element->getTag().getETag(),
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
381 ConvertLeafElement(*element, DicomToJsonFlags_Default, maxStringLength, encoding));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
387 DicomTag FromDcmtkBridge::Convert(const DcmTag& tag)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
388 {
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
389 return DicomTag(tag.getGTag(), tag.getETag());
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
390 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
391
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
392
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 DicomTag FromDcmtkBridge::GetTag(const DcmElement& element)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 return DicomTag(element.getGTag(), element.getETag());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
399 DicomValue* FromDcmtkBridge::ConvertLeafElement(DcmElement& element,
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
400 DicomToJsonFlags flags,
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
401 unsigned int maxStringLength,
956
2fd5a163776d primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 949
diff changeset
402 Encoding encoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 if (!element.isLeaf())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
406 // This function is only applicable to leaf elements
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
407 throw OrthancException(ErrorCode_BadParameterType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
410 char *c = NULL;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
411 if (element.isaString() &&
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
412 element.getString(c).good())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
414 if (c == NULL) // This case corresponds to the empty string
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
416 return new DicomValue("", false);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
420 std::string s(c);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
421 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
422
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
423 if (maxStringLength != 0 &&
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
424 utf8.size() > maxStringLength)
1854
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
425 {
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
426 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
427 }
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
428 else
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
429 {
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
430 return new DicomValue(utf8, false);
e2c3d752ee1a prevent too long tags to be inserted
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1831
diff changeset
431 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 // http://support.dcmtk.org/docs/dcvr_8h-source.html
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 switch (element.getVR())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 /**
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
442 * Deal with binary data (including PixelData).
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 **/
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
444
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
445 case EVR_OB: // other byte
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
446 case EVR_OF: // other float
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
447 case EVR_OW: // other word
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
448 case EVR_UN: // unknown value representation
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
449 case EVR_ox: // OB or OW depending on context
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
450 case EVR_DS: // decimal string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
451 case EVR_IS: // integer string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
452 case EVR_AS: // age string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
453 case EVR_DA: // date string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
454 case EVR_DT: // date time string
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
455 case EVR_TM: // time string
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
456 case EVR_AE: // application entity title
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
457 case EVR_CS: // code string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
458 case EVR_SH: // short string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
459 case EVR_LO: // long string
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
460 case EVR_ST: // short text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
461 case EVR_LT: // long text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
462 case EVR_UT: // unlimited text
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
463 case EVR_PN: // person name
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
464 case EVR_UI: // unique identifier
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
465 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
466 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
467 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
468 if (!(flags & DicomToJsonFlags_ConvertBinaryToNull))
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
469 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
470 Uint8* data = NULL;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
471 if (element.getUint8Array(data) == EC_Normal)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
472 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
473 return new DicomValue(reinterpret_cast<const char*>(data), element.getLength(), true);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
474 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
475 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
477 return new DicomValue;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
478 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
479
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
480 /**
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
481 * Numeric types
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
482 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
484 case EVR_SL: // signed long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
485 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
486 Sint32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
487 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
488 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
489 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
490 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
491 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
492
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
493 case EVR_SS: // signed short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
494 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
495 Sint16 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
496 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
497 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
498 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
499 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
500 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
501
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
502 case EVR_UL: // unsigned long
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
503 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
504 Uint32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
505 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
506 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
507 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
508 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
509 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
510
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
511 case EVR_US: // unsigned short
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
512 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
513 Uint16 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
514 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
515 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
516 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
517 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
518 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
519
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
520 case EVR_FL: // float single-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
521 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
522 Float32 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
523 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
524 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
525 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
526 return new DicomValue;
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
527 }
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
528
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
529 case EVR_FD: // float double-precision
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
530 {
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
531 Float64 f;
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
532 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
533 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
534 else
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
535 return new DicomValue;
1131
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
536 }
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
537
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
538
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
539 /**
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
540 * Attribute tag.
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
541 **/
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
542
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
543 case EVR_AT:
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
544 {
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
545 DcmTagKey tag;
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
546 if (dynamic_cast<DcmAttributeTag&>(element).getTagVal(tag, 0).good())
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
547 {
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
548 DicomTag t(tag.getGroup(), tag.getElement());
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
549 return new DicomValue(t.Format(), false);
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
550 }
1131
ac6bd50a8c83 fix issue 16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1093
diff changeset
551 else
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
552 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
553 return new DicomValue;
1147
ae9a83a6fa47 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1131
diff changeset
554 }
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
555 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 /**
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
559 * 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
560 * "element.isLeaf()".
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
561 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
563 case EVR_SQ: // sequence of items
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
564 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
567 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
568 * Internal to DCMTK.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
569 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
571 case EVR_xs: // SS or US depending on context
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
572 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
573 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
574 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
575 case EVR_item: // used internally for items
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
576 case EVR_metainfo: // used internally for meta info datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
577 case EVR_dataset: // used internally for datasets
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
578 case EVR_fileFormat: // used internally for DICOM files
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
579 case EVR_dicomDir: // used internally for DICOMDIR objects
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
580 case EVR_dirRecord: // used internally for DICOMDIR records
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
581 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
582 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
583 case EVR_PixelData: // used internally for uncompressed pixeld data
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
584 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
585 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
588 /**
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
589 * Default case.
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
590 **/
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
592 default:
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
593 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 catch (boost::bad_lexical_cast)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
598 return new DicomValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
600 catch (std::bad_cast)
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
601 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
602 return new DicomValue;
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
603 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
607 static Json::Value& PrepareNode(Json::Value& parent,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
608 DcmElement& element,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
609 DicomToJsonFormat format)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 {
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
611 assert(parent.type() == Json::objectValue);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
613 DicomTag tag(FromDcmtkBridge::GetTag(element));
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
614 const std::string formattedTag = tag.Format();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
615
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
616 if (format == DicomToJsonFormat_Short)
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 parent[formattedTag] = Json::nullValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
619 return parent[formattedTag];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
620 }
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 // This code gives access to the name of the private tags
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
623 std::string tagName = FromDcmtkBridge::GetTagName(element);
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
624
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
625 switch (format)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 {
1860
c7d70f659190 DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1854
diff changeset
627 case DicomToJsonFormat_Human:
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
628 parent[tagName] = Json::nullValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
629 return parent[tagName];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
630
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
631 case DicomToJsonFormat_Full:
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 parent[formattedTag] = Json::objectValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
634 Json::Value& node = parent[formattedTag];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
635
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
636 if (element.isLeaf())
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
637 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
638 node["Name"] = tagName;
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
639
2076
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2074
diff changeset
640 if (element.getTag().getPrivateCreator() != NULL)
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
641 {
2076
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2074
diff changeset
642 node["PrivateCreator"] = element.getTag().getPrivateCreator();
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
643 }
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
644
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
645 return node;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
646 }
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
647 else
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
648 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
649 node["Name"] = tagName;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
650 node["Type"] = "Sequence";
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
651 node["Value"] = Json::nullValue;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
652 return node["Value"];
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
653 }
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
654 }
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
655
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
656 default:
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
657 throw OrthancException(ErrorCode_ParameterOutOfRange);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
658 }
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
659 }
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
660
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
661
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
662 static void LeafValueToJson(Json::Value& target,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
663 const DicomValue& value,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
664 DicomToJsonFormat format,
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
665 DicomToJsonFlags flags,
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
666 unsigned int maxStringLength)
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
667 {
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
668 Json::Value* targetValue = NULL;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
669 Json::Value* targetType = NULL;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
670
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
671 switch (format)
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
672 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
673 case DicomToJsonFormat_Short:
1860
c7d70f659190 DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1854
diff changeset
674 case DicomToJsonFormat_Human:
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
675 {
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
676 assert(target.type() == Json::nullValue);
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
677 targetValue = &target;
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
678 break;
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
679 }
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
680
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
681 case DicomToJsonFormat_Full:
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
683 assert(target.type() == Json::objectValue);
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
684 target["Value"] = Json::nullValue;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
685 target["Type"] = Json::nullValue;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
686 targetType = &target["Type"];
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
687 targetValue = &target["Value"];
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
688 break;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 }
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
690
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
691 default:
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
692 throw OrthancException(ErrorCode_ParameterOutOfRange);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
693 }
1738
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
694
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
695 assert(targetValue != NULL);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
696 assert(targetValue->type() == Json::nullValue);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
697 assert(targetType == NULL || targetType->type() == Json::nullValue);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
698
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
699 if (value.IsNull())
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
700 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
701 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
702 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
703 *targetType = "Null";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
704 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
705 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
706 else if (value.IsBinary())
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
707 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
708 if (flags & DicomToJsonFlags_ConvertBinaryToAscii)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
709 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
710 *targetValue = Toolbox::ConvertToAscii(value.GetContent());
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
711 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
712 else
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
713 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
714 std::string s;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
715 value.FormatDataUriScheme(s);
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
716 *targetValue = s;
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
717 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
718
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
719 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
720 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
721 *targetType = "Binary";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
722 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
723 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
724 else if (maxStringLength == 0 ||
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
725 value.GetContent().size() <= maxStringLength)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
726 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
727 *targetValue = value.GetContent();
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
728
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
729 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
730 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
731 *targetType = "String";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
732 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
733 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
734 else
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
735 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
736 if (targetType != NULL)
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
737 {
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
738 *targetType = "TooLong";
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
739 }
15a788a63846 DicomToJsonFlags_IncludeBinary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1737
diff changeset
740 }
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
741 }
35
f6d12037f886 full json vs. simplified json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
742
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
743
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
744 static void DatasetToJson(Json::Value& parent,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
745 DcmItem& item,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
746 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
747 DicomToJsonFlags flags,
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
748 unsigned int maxStringLength,
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
749 Encoding encoding);
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
750
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
751
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
752 void FromDcmtkBridge::ToJson(Json::Value& parent,
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
753 DcmElement& element,
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
754 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
755 DicomToJsonFlags flags,
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
756 unsigned int maxStringLength,
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
757 Encoding encoding)
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
758 {
1691
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
759 if (parent.type() == Json::nullValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
760 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
761 parent = Json::objectValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
762 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
763
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1690
diff changeset
764 assert(parent.type() == Json::objectValue);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
765 Json::Value& target = PrepareNode(parent, element, format);
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
766
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
767 if (element.isLeaf())
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
768 {
1929
cda5b0ab4ce5 ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1928
diff changeset
769 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
770 LeafValueToJson(target, *v, format, flags, maxStringLength);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
774 assert(target.type() == Json::nullValue);
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
775 target = Json::arrayValue;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 // "All subclasses of DcmElement except for DcmSequenceOfItems
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
779 // etc. are not." The following dynamic_cast is thus OK.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(element);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 for (unsigned long i = 0; i < sequence.card(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 DcmItem* child = sequence.getItem(i);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
785 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
786 DatasetToJson(v, *child, format, flags, maxStringLength, encoding);
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
787 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
792 static void DatasetToJson(Json::Value& parent,
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
793 DcmItem& item,
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
794 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
795 DicomToJsonFlags flags,
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
796 unsigned int maxStringLength,
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
797 Encoding encoding)
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
798 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
799 assert(parent.type() == Json::objectValue);
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
800
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
801 for (unsigned long i = 0; i < item.card(); i++)
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
802 {
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
803 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
804 if (element == NULL)
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
805 {
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
806 throw OrthancException(ErrorCode_InternalError);
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
807 }
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
808
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
809 DicomTag tag(FromDcmtkBridge::Convert(element->getTag()));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
810
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
811 /*element->getTag().isPrivate()*/
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
812 if (tag.IsPrivate() &&
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
813 !(flags & DicomToJsonFlags_IncludePrivateTags))
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
814 {
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
815 continue;
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
816 }
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
817
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
818 if (!(flags & DicomToJsonFlags_IncludeUnknownTags))
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
819 {
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
820 DictionaryLocker locker;
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
821 if (locker->findEntry(element->getTag(), NULL) == NULL)
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
822 {
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
823 continue;
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
824 }
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
825 }
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
826
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
827 DcmEVR evr = element->getTag().getEVR();
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
828 if (evr == EVR_OB ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
829 evr == EVR_OF ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
830 evr == EVR_OW ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
831 evr == EVR_UN ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
832 evr == EVR_ox)
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
833 {
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
834 // This is a binary tag
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
835 if ((tag == DICOM_TAG_PIXEL_DATA && !(flags & DicomToJsonFlags_IncludePixelData)) ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
836 (tag != DICOM_TAG_PIXEL_DATA && !(flags & DicomToJsonFlags_IncludeBinary)))
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
837 {
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
838 continue;
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
839 }
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
840 }
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
841
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
842 FromDcmtkBridge::ToJson(parent, *element, format, flags, maxStringLength, encoding);
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
843 }
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
844 }
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
845
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
846
1687
4d80fc990dae refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1686
diff changeset
847 void FromDcmtkBridge::ToJson(Json::Value& target,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 DcmDataset& dataset,
1686
14a32b2fa63e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1657
diff changeset
849 DicomToJsonFormat format,
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
850 DicomToJsonFlags flags,
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
851 unsigned int maxStringLength,
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
852 Encoding defaultEncoding)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 {
1688
27d70e9ee2e4 DicomToJsonFormat enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1687
diff changeset
854 target = Json::objectValue;
1928
84c7eaeb5244 Configuration::GetDefaultEncoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1927
diff changeset
855 DatasetToJson(target, dataset, format, flags, maxStringLength, DetectEncoding(dataset, defaultEncoding));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
1831
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
859 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
860 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
861 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
862 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
863 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
864 {
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
865 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
866 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
867 }
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
868
3ae2ff249675 "/instances/.../header" to get the meta information (header) of the DICOM instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1818
diff changeset
869
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
870
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
871 static std::string GetTagNameInternal(DcmTag& tag)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 {
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
873 {
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
874 // Some patches for important tags because of different DICOM
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
875 // dictionaries between DCMTK versions
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
876 DicomTag tmp(tag.getGroup(), tag.getElement());
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
877 std::string n = tmp.GetMainTagsName();
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
878 if (n.size() != 0)
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
879 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
880 return n;
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
881 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
882 // End of patches
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
883 }
106
332fec038d52 patch for dcmtk dictionaries
jodogne
parents: 80
diff changeset
884
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
885 #if 0
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
886 // This version explicitly calls the dictionary
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 const DcmDictEntry* entry = dict.findEntry(tag, NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
890 std::string s(DcmTag_ERROR_TagName);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 if (entry != NULL)
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 s = std::string(entry->getTagName());
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 return s;
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
898 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
899 const char* name = tag.getTagName();
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
900 if (name == NULL)
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
901 {
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
902 return DcmTag_ERROR_TagName;
305
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 else
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 return std::string(name);
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
907 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
908 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
912 std::string FromDcmtkBridge::GetTagName(const DicomTag& t,
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
913 const std::string& privateCreator)
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
914 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
915 DcmTag tag(t.GetGroup(), t.GetElement());
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
916
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
917 if (!privateCreator.empty())
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
918 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
919 tag.setPrivateCreator(privateCreator.c_str());
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
920 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
921
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
922 return GetTagNameInternal(tag);
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
923 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
924
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
925
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
926 std::string FromDcmtkBridge::GetTagName(const DcmElement& element)
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
927 {
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
928 // Copy the tag to ensure const-correctness of DcmElement. Note
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
929 // that the private creator information is also copied.
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
930 DcmTag tag(element.getTag());
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
931
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
932 return GetTagNameInternal(tag);
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
933 }
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
934
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
935
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
936
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
937 DicomTag FromDcmtkBridge::ParseTag(const char* name)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
939 if (strlen(name) == 9 &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
940 isxdigit(name[0]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
941 isxdigit(name[1]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
942 isxdigit(name[2]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
943 isxdigit(name[3]) &&
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 957
diff changeset
944 (name[4] == '-' || name[4] == ',') &&
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
945 isxdigit(name[5]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
946 isxdigit(name[6]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
947 isxdigit(name[7]) &&
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
948 isxdigit(name[8]))
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
949 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
950 uint16_t group = GetTagValue(name);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
951 uint16_t element = GetTagValue(name + 5);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
952 return DicomTag(group, element);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
953 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 303
diff changeset
954
1861
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
955 if (strlen(name) == 8 &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
956 isxdigit(name[0]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
957 isxdigit(name[1]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
958 isxdigit(name[2]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
959 isxdigit(name[3]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
960 isxdigit(name[4]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
961 isxdigit(name[5]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
962 isxdigit(name[6]) &&
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
963 isxdigit(name[7]))
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
964 {
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
965 uint16_t group = GetTagValue(name);
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
966 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
967 return DicomTag(group, element);
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
968 }
a7bea843a7bc "OrthancPluginLookupDictionary()" to get information about some DICOM tag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
969
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
970 #if 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 const DcmDataDictionary& dict = dcmDataDict.rdlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 const DcmDictEntry* entry = dict.findEntry(name);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 if (entry == NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 dcmDataDict.unlock();
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
977 throw OrthancException(ErrorCode_UnknownDicomTag);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 DcmTagKey key = entry->getKey();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 DicomTag tag(key.getGroup(), key.getElement());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 dcmDataDict.unlock();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 return tag;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 }
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
986 #else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
987 DcmTag tag;
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
988 if (DcmTag::findTagFromName(name, tag).good())
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
989 {
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
990 return DicomTag(tag.getGTag(), tag.getETag());
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
991 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
992 else
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
993 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1557
diff changeset
994 throw OrthancException(ErrorCode_UnknownDicomTag);
305
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
995 }
86bb79522f19 name of the private tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
996 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999
1655
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
1000 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
1001 {
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
1002 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
1003 return tmp.isUnknownVR();
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
1004 }
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
1005
e40fd0d925c5 /tools/create-dicom can create tags with unknown VR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
1006
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 void FromDcmtkBridge::ToJson(Json::Value& result,
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1008 const DicomMap& values,
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1009 bool simplify)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 if (result.type() != Json::objectValue)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012 {
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
1013 throw OrthancException(ErrorCode_BadParameterType);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 result.clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 for (DicomMap::Map::const_iterator
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
1019 it = values.map_.begin(); it != values.map_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 {
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
1021 // TODO Inject PrivateCreator if some is available in the DicomMap?
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
1022 const std::string tagName = GetTagName(it->first, "");
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
1023
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1024 if (simplify)
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1025 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1026 if (it->second->IsNull())
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1027 {
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
1028 result[tagName] = Json::nullValue;
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1029 }
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1030 else
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1031 {
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1032 // TODO IsBinary
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
1033 result[tagName] = it->second->GetContent();
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1034 }
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1035 }
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1036 else
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1037 {
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1038 Json::Value value = Json::objectValue;
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1039
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2076
diff changeset
1040 value["Name"] = tagName;
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1041
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1042 if (it->second->IsNull())
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1043 {
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1044 value["Type"] = "Null";
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1045 value["Value"] = Json::nullValue;
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1046 }
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1047 else
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1048 {
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1049 // TODO IsBinary
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1050 value["Type"] = "String";
1737
ec66a16aa398 removal of DicomStringValue and DicomNullValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
1051 value["Value"] = it->second->GetContent();
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1052 }
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1053
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1054 result[it->first.Format()] = value;
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
1055 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 }
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1058
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1059
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1060 std::string FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType level)
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1061 {
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1062 char uid[100];
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1063
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1064 switch (level)
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1065 {
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1066 case ResourceType_Patient:
311
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1067 // The "PatientID" field is of type LO (Long String), 64
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1068 // 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
1069 // as a random PatientID.
26efccdff583 anonymisation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 308
diff changeset
1070 return Toolbox::GenerateUuid();
306
326d5a4a5af3 modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 305
diff changeset
1071
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1072 case ResourceType_Instance:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1073 return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1074
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1075 case ResourceType_Series:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1076 return dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1077
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 784
diff changeset
1078 case ResourceType_Study:
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1079 return dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1080
302
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1081 default:
238134081136 modification of dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 291
diff changeset
1082 throw OrthancException(ErrorCode_ParameterOutOfRange);
176
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1083 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1084 }
81f11fb357f2 uid generation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
1085
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1086 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
1087 DcmDataset& dataSet)
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1088 {
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1089 // 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
1090 // 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
1091 // syntax, with explicit length.
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1092
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1093 // 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
1094
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
1095
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
1096 /**
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
1097 * 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
1098 * "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
1099 * 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
1100 * (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
1101 **/
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
1102 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
1103 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
1104 {
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
1105 // 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
1106 // 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
1107 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
1108 }
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
1109
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1110 E_EncodingType encodingType = /*opt_sequenceType*/ EET_ExplicitLength;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1111
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
1112 // Create the meta-header information
1004
a226e0959d8b DicomInstanceToStore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
1113 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
1114 ff.validateMetaInfo(xfer);
1316
1c8dfedefefe Fix anonymization generating non-portable DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1307
diff changeset
1115 ff.removeInvalidGroups();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1116
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
1117 // 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
1118 {
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1119 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
1120 buffer.resize(estimatedSize);
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1121 }
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1122
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1123 DcmOutputBufferStream ob(&buffer[0], buffer.size());
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1124
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
1125 // 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
1126 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
1127 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
1128 /*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
1129 /*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
1130 ff.transferEnd();
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1131
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1132 if (c.good())
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1133 {
1876
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1134 // 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
1135 // 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
1136 ob.flush();
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1137
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1138 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
1139 if (effectiveSize < buffer.size())
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1140 {
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1141 buffer.resize(effectiveSize);
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1142 }
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1143
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1144 return true;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1145 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1146 else
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1147 {
1876
9b458e4484a1 truncation of serialized DICOM buffers if calcElementLength was overestimated
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1861
diff changeset
1148 // Error
291
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1149 buffer.clear();
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1150 return false;
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1151 }
4d7469f72a0b embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
1152 }
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1153
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1154
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1155 ValueRepresentation FromDcmtkBridge::LookupValueRepresentation(const DicomTag& tag)
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1156 {
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1157 DcmTag t(tag.GetGroup(), tag.GetElement());
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1158 return Convert(t.getEVR());
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1159 }
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1160
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1161 ValueRepresentation FromDcmtkBridge::Convert(const DcmEVR vr)
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1162 {
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1163 switch (vr)
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1164 {
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1165 case EVR_AE:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1166 return ValueRepresentation_ApplicationEntity;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1167
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1168 case EVR_AS:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1169 return ValueRepresentation_AgeString;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1170
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1171 case EVR_AT:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1172 return ValueRepresentation_AttributeTag;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1173
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1174 case EVR_CS:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1175 return ValueRepresentation_CodeString;
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1176
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1177 case EVR_DA:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1178 return ValueRepresentation_Date;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1179
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1180 case EVR_DS:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1181 return ValueRepresentation_DecimalString;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1182
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1183 case EVR_DT:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1184 return ValueRepresentation_DateTime;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1185
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1186 case EVR_FL:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1187 return ValueRepresentation_FloatingPointSingle;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1188
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1189 case EVR_FD:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1190 return ValueRepresentation_FloatingPointDouble;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1191
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1192 case EVR_IS:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1193 return ValueRepresentation_IntegerString;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1194
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1195 case EVR_LO:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1196 return ValueRepresentation_LongString;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1197
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1198 case EVR_LT:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1199 return ValueRepresentation_LongText;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1200
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1201 case EVR_OB:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1202 return ValueRepresentation_OtherByte;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1203
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1204 // Not supported as of DCMTK 3.6.0
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1205 /*case EVR_OD:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1206 return ValueRepresentation_OtherDouble;*/
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1207
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1208 case EVR_OF:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1209 return ValueRepresentation_OtherFloat;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1210
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1211 // Not supported as of DCMTK 3.6.0
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1212 /*case EVR_OL:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1213 return ValueRepresentation_OtherLong;*/
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1214
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1215 case EVR_OW:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1216 return ValueRepresentation_OtherWord;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1217
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1218 case EVR_PN:
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
1219 return ValueRepresentation_PersonName;
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1220
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1221 case EVR_SH:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1222 return ValueRepresentation_ShortString;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1223
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1224 case EVR_SL:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1225 return ValueRepresentation_SignedLong;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1226
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1227 case EVR_SQ:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1228 return ValueRepresentation_Sequence;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1229
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1230 case EVR_SS:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1231 return ValueRepresentation_SignedShort;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1232
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1233 case EVR_ST:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1234 return ValueRepresentation_ShortText;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1235
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1236 case EVR_TM:
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1237 return ValueRepresentation_Time;
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1238
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1239 // Not supported as of DCMTK 3.6.0
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1240 /*case EVR_UC:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1241 return ValueRepresentation_UnlimitedCharacters;*/
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1242
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1243 case EVR_UI:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1244 return ValueRepresentation_UniqueIdentifier;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1245
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1246 case EVR_UL:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1247 return ValueRepresentation_UnsignedLong;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1248
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1249 case EVR_UN:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1250 return ValueRepresentation_Unknown;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1251
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1252 // Not supported as of DCMTK 3.6.0
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1253 /*case EVR_UR:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1254 return ValueRepresentation_UniversalResource;*/
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1255
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1256 case EVR_US:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1257 return ValueRepresentation_UnsignedShort;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1258
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1259 case EVR_UT:
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1260 return ValueRepresentation_UnlimitedText;
1792
b769623c806c safety check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1765
diff changeset
1261
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1262 default:
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1998
diff changeset
1263 return ValueRepresentation_NotSupported;
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
1264 }
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1265 }
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1316
diff changeset
1266
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1267
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1268 static bool IsBinaryTag(const DcmTag& key)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1269 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1270 return (key.isUnknownVR() ||
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1271 key.getEVR() == EVR_OB ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1272 key.getEVR() == EVR_OF ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1273 key.getEVR() == EVR_OW ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1274 key.getEVR() == EVR_UN ||
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1275 key.getEVR() == EVR_ox);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1276 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1277
1689
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 DcmElement* FromDcmtkBridge::CreateElementForTag(const DicomTag& tag)
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 DcmTag key(tag.GetGroup(), tag.GetElement());
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1282
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1283 if (tag.IsPrivate() ||
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1284 IsBinaryTag(key))
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1285 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1286 return new DcmOtherByteOtherWord(key);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1287 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1288
1689
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 /**
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1294 * Binary types, handled above
1689
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_UN: // unknown value representation
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1301 case EVR_ox: // OB or OW depending on context
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1302 throw OrthancException(ErrorCode_InternalError);
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1303
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1304
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 * String types.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1307 * http://support.dcmtk.org/docs/classDcmByteString.html
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1308 **/
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 case EVR_AS: // age string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1311 return new DcmAgeString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1312
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1313 case EVR_AE: // application entity title
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1314 return new DcmApplicationEntity(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1315
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1316 case EVR_CS: // code string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1317 return new DcmCodeString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1318
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1319 case EVR_DA: // date string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1320 return new DcmDate(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1321
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1322 case EVR_DT: // date time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1323 return new DcmDateTime(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1324
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1325 case EVR_DS: // decimal string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1326 return new DcmDecimalString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1327
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1328 case EVR_IS: // integer string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1329 return new DcmIntegerString(key);
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 case EVR_TM: // time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1332 return new DcmTime(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1333
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1334 case EVR_UI: // unique identifier
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1335 return new DcmUniqueIdentifier(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1336
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1337 case EVR_ST: // short text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1338 return new DcmShortText(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1339
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1340 case EVR_LO: // long string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1341 return new DcmLongString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1342
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1343 case EVR_LT: // long text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1344 return new DcmLongText(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1345
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1346 case EVR_UT: // unlimited text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1347 return new DcmUnlimitedText(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1348
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1349 case EVR_SH: // short string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1350 return new DcmShortString(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1351
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1352 case EVR_PN: // person name
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1353 return new DcmPersonName(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1354
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 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1357 * Numerical types
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_SL: // signed long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1361 return new DcmSignedLong(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1362
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1363 case EVR_SS: // signed short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1364 return new DcmSignedShort(key);
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_UL: // unsigned long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1367 return new DcmUnsignedLong(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1368
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1369 case EVR_US: // unsigned short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1370 return new DcmUnsignedShort(key);
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 case EVR_FL: // float single-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1373 return new DcmFloatingPointSingle(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1374
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1375 case EVR_FD: // float double-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1376 return new DcmFloatingPointDouble(key);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1377
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 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1380 * Sequence types, should never occur at this point.
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 case EVR_SQ: // sequence of items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1384 throw OrthancException(ErrorCode_ParameterOutOfRange);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1385
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 /**
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1388 * TODO
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1389 **/
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1390
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1391 case EVR_AT: // attribute tag
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1392 throw OrthancException(ErrorCode_NotImplemented);
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1393
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1394
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1738
diff changeset
1395 /**
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1396 * Internal to DCMTK.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1397 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1398
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1399 case EVR_xs: // SS or US depending on context
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1400 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
1401 case EVR_na: // na="not applicable", for data which has no VR
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1402 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1403 case EVR_item: // used internally for items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1404 case EVR_metainfo: // used internally for meta info datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1405 case EVR_dataset: // used internally for datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1406 case EVR_fileFormat: // used internally for DICOM files
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1407 case EVR_dicomDir: // used internally for DICOMDIR objects
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1408 case EVR_dirRecord: // used internally for DICOMDIR records
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1409 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1410 case EVR_pixelItem: // used internally for pixel items in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1411 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
1412 case EVR_PixelData: // used internally for uncompressed pixeld data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1413 case EVR_OverlayData: // used internally for overlay data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1414 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
1415 default:
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1416 break;
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 throw OrthancException(ErrorCode_InternalError);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1420 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1421
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1422
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1423
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1424 void FromDcmtkBridge::FillElementWithString(DcmElement& element,
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1425 const DicomTag& tag,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1426 const std::string& utf8Value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1427 bool decodeDataUriScheme,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1428 Encoding dicomEncoding)
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1429 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1430 std::string binary;
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1431 const std::string* decoded = &utf8Value;
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1432
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1433 if (decodeDataUriScheme &&
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1434 boost::starts_with(utf8Value, "data:application/octet-stream;base64,"))
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1435 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1436 std::string mime;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
1437 if (!Toolbox::DecodeDataUriScheme(mime, binary, utf8Value))
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
1438 {
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
1439 throw OrthancException(ErrorCode_BadFileFormat);
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
1440 }
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
1441
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1442 decoded = &binary;
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1443 }
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1444 else if (dicomEncoding != Encoding_Utf8)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1445 {
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1446 binary = Toolbox::ConvertFromUtf8(utf8Value, dicomEncoding);
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1447 decoded = &binary;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1448 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1449
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1450 DcmTag key(tag.GetGroup(), tag.GetElement());
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1451
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1452 if (tag.IsPrivate() ||
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1453 IsBinaryTag(key))
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1454 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1455 if (element.putUint8Array((const Uint8*) decoded->c_str(), decoded->size()).good())
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1456 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1457 return;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1458 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1459 else
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1460 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1461 throw OrthancException(ErrorCode_InternalError);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1462 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1463 }
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 bool ok = false;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1466
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1467 try
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1468 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1469 switch (key.getEVR())
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1470 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1471 // http://support.dcmtk.org/docs/dcvr_8h-source.html
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1472
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1473 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1474 * TODO.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1475 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1476
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1477 case EVR_OB: // other byte
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1478 case EVR_OF: // other float
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1479 case EVR_OW: // other word
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1480 case EVR_AT: // attribute tag
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1481 throw OrthancException(ErrorCode_NotImplemented);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1482
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1483 case EVR_UN: // unknown value representation
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1484 throw OrthancException(ErrorCode_ParameterOutOfRange);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1485
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1486
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1487 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1488 * String types.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1489 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1490
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1491 case EVR_DS: // decimal string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1492 case EVR_IS: // integer string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1493 case EVR_AS: // age string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1494 case EVR_DA: // date string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1495 case EVR_DT: // date time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1496 case EVR_TM: // time string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1497 case EVR_AE: // application entity title
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1498 case EVR_CS: // code string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1499 case EVR_SH: // short string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1500 case EVR_LO: // long string
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1501 case EVR_ST: // short text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1502 case EVR_LT: // long text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1503 case EVR_UT: // unlimited text
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1504 case EVR_PN: // person name
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1505 case EVR_UI: // unique identifier
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1506 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1507 ok = element.putString(decoded->c_str()).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1508 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1509 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1510
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1511
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1512 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1513 * Numerical types
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1514 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1515
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1516 case EVR_SL: // signed long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1517 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1518 ok = element.putSint32(boost::lexical_cast<Sint32>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1519 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1520 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1521
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1522 case EVR_SS: // signed short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1523 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1524 ok = element.putSint16(boost::lexical_cast<Sint16>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1525 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1526 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1527
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1528 case EVR_UL: // unsigned long
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1529 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1530 ok = element.putUint32(boost::lexical_cast<Uint32>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1531 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1532 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1533
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1534 case EVR_US: // unsigned short
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1535 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1536 ok = element.putUint16(boost::lexical_cast<Uint16>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1537 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1538 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1539
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1540 case EVR_FL: // float single-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1541 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1542 ok = element.putFloat32(boost::lexical_cast<float>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1543 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1544 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1545
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1546 case EVR_FD: // float double-precision
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1547 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1548 ok = element.putFloat64(boost::lexical_cast<double>(*decoded)).good();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1549 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1550 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1551
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1552
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1553 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1554 * Sequence types, should never occur at this point.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1555 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1556
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1557 case EVR_SQ: // sequence of items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1558 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1559 ok = false;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1560 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1561 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1562
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1563
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1564 /**
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1565 * Internal to DCMTK.
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1566 **/
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1567
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1568 case EVR_ox: // OB or OW depending on context
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1569 case EVR_xs: // SS or US depending on context
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1570 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
1571 case EVR_na: // na="not applicable", for data which has no VR
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1572 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1573 case EVR_item: // used internally for items
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1574 case EVR_metainfo: // used internally for meta info datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1575 case EVR_dataset: // used internally for datasets
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1576 case EVR_fileFormat: // used internally for DICOM files
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1577 case EVR_dicomDir: // used internally for DICOMDIR objects
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1578 case EVR_dirRecord: // used internally for DICOMDIR records
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1579 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1580 case EVR_pixelItem: // used internally for pixel items in a compressed image
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1581 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
1582 case EVR_PixelData: // used internally for uncompressed pixeld data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1583 case EVR_OverlayData: // used internally for overlay data
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1584 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
1585 default:
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1586 break;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1587 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1588 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1589 catch (boost::bad_lexical_cast&)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1590 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1591 ok = false;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1592 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1593
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1594 if (!ok)
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1595 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1596 throw OrthancException(ErrorCode_InternalError);
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1597 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1598 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1599
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1600
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1601 DcmElement* FromDcmtkBridge::FromJson(const DicomTag& tag,
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
1602 const Json::Value& value,
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1603 bool decodeDataUriScheme,
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1694
diff changeset
1604 Encoding dicomEncoding)
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1605 {
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1606 std::auto_ptr<DcmElement> element;
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1607
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1608 switch (value.type())
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1609 {
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1610 case Json::stringValue:
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1611 element.reset(CreateElementForTag(tag));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1612 FillElementWithString(*element, tag, value.asString(), decodeDataUriScheme, dicomEncoding);
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1613 break;
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1614
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1615 case Json::arrayValue:
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1616 {
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1617 DcmTag key(tag.GetGroup(), tag.GetElement());
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1618 if (key.getEVR() != EVR_SQ)
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1619 {
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1620 throw OrthancException(ErrorCode_BadParameterType);
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1621 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1622
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1623 DcmSequenceOfItems* sequence = new DcmSequenceOfItems(key, value.size());
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1624 element.reset(sequence);
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1625
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1626 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1627 {
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1628 std::auto_ptr<DcmItem> item(new DcmItem);
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1629
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1630 Json::Value::Members members = value[i].getMemberNames();
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1631 for (Json::Value::ArrayIndex j = 0; j < members.size(); j++)
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1632 {
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1792
diff changeset
1633 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
1634 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1635
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1636 sequence->append(item.release());
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1637 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1638
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1639 break;
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1640 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1641
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1642 default:
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1689
diff changeset
1643 throw OrthancException(ErrorCode_BadParameterType);
1689
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1644 }
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1645
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1646 return element.release();
26083d84d237 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1688
diff changeset
1647 }
1765
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1648
57b9e6890482 New configuration option: "Dictionary" to declare custom DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
1649
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
1650 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
1651 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1652 DcmElement *element = NULL;
1927
b60f27664b8f simplification in FromDcmtkBridge
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
1653 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
1654 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1655 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
1656 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1657
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1658 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
1659 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
1660 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
1661 (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
1662 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1663 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
1664 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1665 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
1666 {
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1667 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
1668 }
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
1669 }
1934
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1670
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1671
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1672 Encoding FromDcmtkBridge::ExtractEncoding(const Json::Value& json,
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1673 Encoding defaultEncoding)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1674 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1675 if (json.type() != Json::objectValue)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1676 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1677 throw OrthancException(ErrorCode_BadParameterType);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1678 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1679
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1680 Encoding encoding = defaultEncoding;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1681
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1682 const Json::Value::Members tags = json.getMemberNames();
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1683
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1684 // Look for SpecificCharacterSet (0008,0005) in the JSON file
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1685 for (size_t i = 0; i < tags.size(); i++)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1686 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1687 DicomTag tag = FromDcmtkBridge::ParseTag(tags[i]);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1688 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1689 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1690 const Json::Value& value = json[tags[i]];
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1691 if (value.type() != Json::stringValue ||
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1692 !GetDicomEncoding(encoding, value.asCString()))
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1693 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1694 LOG(ERROR) << "Unknown encoding while creating DICOM from JSON: " << value;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1695 throw OrthancException(ErrorCode_BadRequest);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1696 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1697 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1698 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1699
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1700 return encoding;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1701 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1702
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1703
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1704 static void SetString(DcmDataset& target,
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1705 const DcmTag& tag,
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1706 const std::string& value)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1707 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1708 if (!target.putAndInsertString(tag, value.c_str()).good())
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1709 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1710 throw OrthancException(ErrorCode_InternalError);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1711 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1712 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1713
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1714
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1715 DcmDataset* FromDcmtkBridge::FromJson(const Json::Value& json, // Encoded using UTF-8
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1716 bool generateIdentifiers,
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1717 bool decodeDataUriScheme,
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1718 Encoding defaultEncoding)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1719 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1720 std::auto_ptr<DcmDataset> result(new DcmDataset);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1721 Encoding encoding = ExtractEncoding(json, defaultEncoding);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1722
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1723 SetString(*result, DCM_SpecificCharacterSet, GetDicomSpecificCharacterSet(encoding));
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1724
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1725 const Json::Value::Members tags = json.getMemberNames();
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1726
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1727 bool hasPatientId = false;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1728 bool hasStudyInstanceUid = false;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1729 bool hasSeriesInstanceUid = false;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1730 bool hasSopInstanceUid = false;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1731
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1732 for (size_t i = 0; i < tags.size(); i++)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1733 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1734 DicomTag tag = FromDcmtkBridge::ParseTag(tags[i]);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1735 const Json::Value& value = json[tags[i]];
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1736
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1737 if (tag == DICOM_TAG_PATIENT_ID)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1738 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1739 hasPatientId = true;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1740 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1741 else if (tag == DICOM_TAG_STUDY_INSTANCE_UID)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1742 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1743 hasStudyInstanceUid = true;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1744 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1745 else if (tag == DICOM_TAG_SERIES_INSTANCE_UID)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1746 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1747 hasSeriesInstanceUid = true;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1748 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1749 else if (tag == DICOM_TAG_SOP_INSTANCE_UID)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1750 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1751 hasSopInstanceUid = true;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1752 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1753
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1754 if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1755 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1756 std::auto_ptr<DcmElement> element(FromDcmtkBridge::FromJson(tag, value, decodeDataUriScheme, encoding));
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1757 const DcmTagKey& tag = element->getTag();
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1758
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1759 result->findAndDeleteElement(tag);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1760
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1761 DcmElement* tmp = element.release();
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1762 if (!result->insert(tmp, false, false).good())
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1763 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1764 delete tmp;
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1765 throw OrthancException(ErrorCode_InternalError);
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1766 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1767 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1768 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1769
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1770 if (!hasPatientId &&
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1771 generateIdentifiers)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1772 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1773 SetString(*result, DCM_PatientID, GenerateUniqueIdentifier(ResourceType_Patient));
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1774 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1775
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1776 if (!hasStudyInstanceUid &&
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1777 generateIdentifiers)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1778 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1779 SetString(*result, DCM_StudyInstanceUID, GenerateUniqueIdentifier(ResourceType_Study));
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1780 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1781
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1782 if (!hasSeriesInstanceUid &&
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1783 generateIdentifiers)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1784 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1785 SetString(*result, DCM_SeriesInstanceUID, GenerateUniqueIdentifier(ResourceType_Series));
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1786 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1787
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1788 if (!hasSopInstanceUid &&
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1789 generateIdentifiers)
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1790 {
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1791 SetString(*result, DCM_SOPInstanceUID, GenerateUniqueIdentifier(ResourceType_Instance));
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1792 }
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1793
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1794 return result.release();
72a2fd7fed8b FromDcmtkBridge::FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1930
diff changeset
1795 }
1935
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1796
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1797
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1798 DcmFileFormat* FromDcmtkBridge::LoadFromMemoryBuffer(const void* buffer,
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1799 size_t size)
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1800 {
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1801 DcmInputBufferStream is;
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1802 if (size > 0)
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1803 {
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1804 is.setBuffer(buffer, size);
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1805 }
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1806 is.setEos();
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1807
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1808 std::auto_ptr<DcmFileFormat> result(new DcmFileFormat);
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1809
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1810 result->transferInit();
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1811 if (!result->read(is).good())
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1812 {
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1813 throw OrthancException(ErrorCode_BadFileFormat);
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1814 }
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1815
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1816 result->loadAllDataIntoMemory();
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1817 result->transferEnd();
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1818
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1819 return result.release();
e251606c1433 FromDcmtkBridge::LoadFromMemoryBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1934
diff changeset
1820 }
1998
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1821
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1822
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1823 void FromDcmtkBridge::FromJson(DicomMap& target,
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1824 const Json::Value& source)
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1825 {
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1826 if (source.type() != Json::objectValue)
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1827 {
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1828 throw OrthancException(ErrorCode_BadFileFormat);
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1829 }
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1830
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1831 target.Clear();
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1832
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1833 Json::Value::Members members = source.getMemberNames();
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1834
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1835 for (size_t i = 0; i < members.size(); i++)
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1836 {
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1837 const Json::Value& value = source[members[i]];
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1838
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1839 if (value.type() != Json::stringValue)
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1840 {
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1841 throw OrthancException(ErrorCode_BadFileFormat);
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1842 }
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1843
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
1844 target.SetValue(ParseTag(members[i]), value.asString(), false);
1998
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1845 }
9b61701c35f2 New URI "/modalities/.../move" to issue C-Move SCU requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1846 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1847 }