Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.cpp @ 5853:4d932683049d get-scu tip
very first implementation of C-Get SCU
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 29 Oct 2024 17:25:49 +0100 |
parents | 3f10350b26da |
children |
rev | line source |
---|---|
3202 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
3202 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
12 * the License, or (at your option) any later version. |
3202 | 13 * |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * Lesser General Public License for more details. |
3202 | 18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
3202 | 22 **/ |
23 | |
24 | |
25 #include "../PrecompiledHeaders.h" | |
26 #include "DicomWebJsonVisitor.h" | |
27 | |
4304 | 28 #include "../Logging.h" |
3202 | 29 #include "../OrthancException.h" |
30 #include "../Toolbox.h" | |
5816
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
31 #include "../SerializationToolbox.h" |
3202 | 32 #include "FromDcmtkBridge.h" |
33 | |
34 #include <boost/math/special_functions/round.hpp> | |
35 #include <boost/lexical_cast.hpp> | |
36 | |
37 | |
38 static const char* const KEY_ALPHABETIC = "Alphabetic"; | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
39 static const char* const KEY_IDEOGRAPHIC = "Ideographic"; |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
40 static const char* const KEY_PHONETIC = "Phonetic"; |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
41 static const char* const KEY_BULK_DATA = "BulkData"; |
3202 | 42 static const char* const KEY_BULK_DATA_URI = "BulkDataURI"; |
43 static const char* const KEY_INLINE_BINARY = "InlineBinary"; | |
44 static const char* const KEY_SQ = "SQ"; | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
45 static const char* const KEY_TAG = "tag"; |
3202 | 46 static const char* const KEY_VALUE = "Value"; |
47 static const char* const KEY_VR = "vr"; | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
48 static const char* const KEY_NUMBER = "number"; |
3202 | 49 |
50 | |
51 namespace Orthanc | |
52 { | |
53 #if ORTHANC_ENABLE_PUGIXML == 1 | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
54 static void DecomposeXmlPersonName(pugi::xml_node& target, |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
55 const std::string& source) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
56 { |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
57 std::vector<std::string> tokens; |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
58 Toolbox::TokenizeString(tokens, source, '^'); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
59 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
60 if (tokens.size() >= 1) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
61 { |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
62 target.append_child("FamilyName").text() = tokens[0].c_str(); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
63 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
64 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
65 if (tokens.size() >= 2) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
66 { |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
67 target.append_child("GivenName").text() = tokens[1].c_str(); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
68 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
69 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
70 if (tokens.size() >= 3) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
71 { |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
72 target.append_child("MiddleName").text() = tokens[2].c_str(); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
73 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
74 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
75 if (tokens.size() >= 4) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
76 { |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
77 target.append_child("NamePrefix").text() = tokens[3].c_str(); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
78 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
79 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
80 if (tokens.size() >= 5) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
81 { |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
82 target.append_child("NameSuffix").text() = tokens[4].c_str(); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
83 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
84 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
85 |
3202 | 86 static void ExploreXmlDataset(pugi::xml_node& target, |
87 const Json::Value& source) | |
88 { | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
89 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.3.html#table_F.3.1-1 |
3202 | 90 assert(source.type() == Json::objectValue); |
91 | |
92 Json::Value::Members members = source.getMemberNames(); | |
93 for (size_t i = 0; i < members.size(); i++) | |
94 { | |
95 const DicomTag tag = FromDcmtkBridge::ParseTag(members[i]); | |
96 const Json::Value& content = source[members[i]]; | |
97 | |
98 assert(content.type() == Json::objectValue && | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
99 content.isMember(KEY_VR) && |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
100 content[KEY_VR].type() == Json::stringValue); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
101 const std::string vr = content[KEY_VR].asString(); |
3202 | 102 |
103 const std::string keyword = FromDcmtkBridge::GetTagName(tag, ""); | |
104 | |
105 pugi::xml_node node = target.append_child("DicomAttribute"); | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
106 node.append_attribute(KEY_TAG).set_value(members[i].c_str()); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
107 node.append_attribute(KEY_VR).set_value(vr.c_str()); |
3202 | 108 |
109 if (keyword != std::string(DcmTag_ERROR_TagName)) | |
110 { | |
111 node.append_attribute("keyword").set_value(keyword.c_str()); | |
112 } | |
113 | |
114 if (content.isMember(KEY_VALUE)) | |
115 { | |
116 assert(content[KEY_VALUE].type() == Json::arrayValue); | |
117 | |
118 for (Json::Value::ArrayIndex j = 0; j < content[KEY_VALUE].size(); j++) | |
119 { | |
120 std::string number = boost::lexical_cast<std::string>(j + 1); | |
121 | |
122 if (vr == "SQ") | |
123 { | |
124 if (content[KEY_VALUE][j].type() == Json::objectValue) | |
125 { | |
126 pugi::xml_node child = node.append_child("Item"); | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
127 child.append_attribute(KEY_NUMBER).set_value(number.c_str()); |
3202 | 128 ExploreXmlDataset(child, content[KEY_VALUE][j]); |
129 } | |
130 } | |
131 if (vr == "PN") | |
132 { | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
133 bool hasAlphabetic = (content[KEY_VALUE][j].isMember(KEY_ALPHABETIC) && |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
134 content[KEY_VALUE][j][KEY_ALPHABETIC].type() == Json::stringValue); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
135 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
136 bool hasIdeographic = (content[KEY_VALUE][j].isMember(KEY_IDEOGRAPHIC) && |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
137 content[KEY_VALUE][j][KEY_IDEOGRAPHIC].type() == Json::stringValue); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
138 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
139 bool hasPhonetic = (content[KEY_VALUE][j].isMember(KEY_PHONETIC) && |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
140 content[KEY_VALUE][j][KEY_PHONETIC].type() == Json::stringValue); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
141 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
142 if (hasAlphabetic || |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
143 hasIdeographic || |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
144 hasPhonetic) |
3202 | 145 { |
146 pugi::xml_node child = node.append_child("PersonName"); | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
147 child.append_attribute(KEY_NUMBER).set_value(number.c_str()); |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
148 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
149 if (hasAlphabetic) |
3202 | 150 { |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
151 pugi::xml_node name = child.append_child(KEY_ALPHABETIC); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
152 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_ALPHABETIC].asString()); |
3202 | 153 } |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
154 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
155 if (hasIdeographic) |
3202 | 156 { |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
157 pugi::xml_node name = child.append_child(KEY_IDEOGRAPHIC); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
158 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_IDEOGRAPHIC].asString()); |
3202 | 159 } |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
160 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
161 if (hasPhonetic) |
3202 | 162 { |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
163 pugi::xml_node name = child.append_child(KEY_PHONETIC); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
164 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_PHONETIC].asString()); |
3202 | 165 } |
166 } | |
167 } | |
168 else | |
169 { | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
170 pugi::xml_node child = node.append_child(KEY_VALUE); |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
171 child.append_attribute(KEY_NUMBER).set_value(number.c_str()); |
3202 | 172 |
173 switch (content[KEY_VALUE][j].type()) | |
174 { | |
175 case Json::stringValue: | |
176 child.text() = content[KEY_VALUE][j].asCString(); | |
177 break; | |
178 | |
179 case Json::realValue: | |
180 child.text() = content[KEY_VALUE][j].asFloat(); | |
181 break; | |
182 | |
183 case Json::intValue: | |
184 child.text() = content[KEY_VALUE][j].asInt(); | |
185 break; | |
186 | |
187 case Json::uintValue: | |
188 child.text() = content[KEY_VALUE][j].asUInt(); | |
189 break; | |
190 | |
191 default: | |
192 break; | |
193 } | |
194 } | |
195 } | |
196 } | |
197 else if (content.isMember(KEY_BULK_DATA_URI) && | |
198 content[KEY_BULK_DATA_URI].type() == Json::stringValue) | |
199 { | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
200 pugi::xml_node child = node.append_child(KEY_BULK_DATA); |
3202 | 201 child.append_attribute("URI").set_value(content[KEY_BULK_DATA_URI].asCString()); |
202 } | |
203 else if (content.isMember(KEY_INLINE_BINARY) && | |
204 content[KEY_INLINE_BINARY].type() == Json::stringValue) | |
205 { | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
206 pugi::xml_node child = node.append_child(KEY_INLINE_BINARY); |
3202 | 207 child.text() = content[KEY_INLINE_BINARY].asCString(); |
208 } | |
209 } | |
210 } | |
211 #endif | |
212 | |
213 | |
214 #if ORTHANC_ENABLE_PUGIXML == 1 | |
215 static void DicomWebJsonToXml(pugi::xml_document& target, | |
216 const Json::Value& source) | |
217 { | |
218 pugi::xml_node root = target.append_child("NativeDicomModel"); | |
219 root.append_attribute("xmlns").set_value("http://dicom.nema.org/PS3.19/models/NativeDICOM"); | |
220 root.append_attribute("xsi:schemaLocation").set_value("http://dicom.nema.org/PS3.19/models/NativeDICOM"); | |
221 root.append_attribute("xmlns:xsi").set_value("http://www.w3.org/2001/XMLSchema-instance"); | |
222 | |
223 ExploreXmlDataset(root, source); | |
224 | |
225 pugi::xml_node decl = target.prepend_child(pugi::node_declaration); | |
226 decl.append_attribute("version").set_value("1.0"); | |
227 decl.append_attribute("encoding").set_value("utf-8"); | |
228 } | |
229 #endif | |
230 | |
231 | |
232 std::string DicomWebJsonVisitor::FormatTag(const DicomTag& tag) | |
233 { | |
234 char buf[16]; | |
235 sprintf(buf, "%04X%04X", tag.GetGroup(), tag.GetElement()); | |
236 return std::string(buf); | |
237 } | |
238 | |
239 | |
240 Json::Value& DicomWebJsonVisitor::CreateNode(const std::vector<DicomTag>& parentTags, | |
241 const std::vector<size_t>& parentIndexes, | |
242 const DicomTag& tag) | |
243 { | |
244 assert(parentTags.size() == parentIndexes.size()); | |
245 | |
246 Json::Value* node = &result_; | |
247 | |
248 for (size_t i = 0; i < parentTags.size(); i++) | |
249 { | |
250 std::string t = FormatTag(parentTags[i]); | |
251 | |
252 if (!node->isMember(t)) | |
253 { | |
254 Json::Value item = Json::objectValue; | |
255 item[KEY_VR] = KEY_SQ; | |
256 item[KEY_VALUE] = Json::arrayValue; | |
257 item[KEY_VALUE].append(Json::objectValue); | |
258 (*node) [t] = item; | |
259 | |
260 node = &(*node)[t][KEY_VALUE][0]; | |
261 } | |
262 else if ((*node) [t].type() != Json::objectValue || | |
263 !(*node) [t].isMember(KEY_VR) || | |
264 (*node) [t][KEY_VR].type() != Json::stringValue || | |
265 (*node) [t][KEY_VR].asString() != KEY_SQ || | |
266 !(*node) [t].isMember(KEY_VALUE) || | |
267 (*node) [t][KEY_VALUE].type() != Json::arrayValue) | |
268 { | |
269 throw OrthancException(ErrorCode_InternalError); | |
270 } | |
271 else | |
272 { | |
273 size_t currentSize = (*node) [t][KEY_VALUE].size(); | |
274 | |
275 if (parentIndexes[i] < currentSize) | |
276 { | |
277 // The node already exists | |
278 } | |
279 else if (parentIndexes[i] == currentSize) | |
280 { | |
281 (*node) [t][KEY_VALUE].append(Json::objectValue); | |
282 } | |
283 else | |
284 { | |
285 throw OrthancException(ErrorCode_InternalError); | |
286 } | |
287 | |
288 node = &(*node) [t][KEY_VALUE][Json::ArrayIndex(parentIndexes[i])]; | |
289 } | |
290 } | |
291 | |
292 assert(node->type() == Json::objectValue); | |
293 | |
294 std::string t = FormatTag(tag); | |
295 if (node->isMember(t)) | |
296 { | |
297 throw OrthancException(ErrorCode_InternalError); | |
298 } | |
299 else | |
300 { | |
301 (*node) [t] = Json::objectValue; | |
302 return (*node) [t]; | |
303 } | |
304 } | |
305 | |
306 | |
307 Json::Value DicomWebJsonVisitor::FormatInteger(int64_t value) | |
308 { | |
309 if (value < 0) | |
310 { | |
311 return Json::Value(static_cast<int32_t>(value)); | |
312 } | |
313 else | |
314 { | |
315 return Json::Value(static_cast<uint32_t>(value)); | |
316 } | |
317 } | |
318 | |
319 | |
320 Json::Value DicomWebJsonVisitor::FormatDouble(double value) | |
321 { | |
3312 | 322 try |
323 { | |
324 long long a = boost::math::llround<double>(value); | |
3202 | 325 |
3312 | 326 double d = fabs(value - static_cast<double>(a)); |
3202 | 327 |
3312 | 328 if (d <= std::numeric_limits<double>::epsilon() * 100.0) |
329 { | |
330 return FormatInteger(a); | |
331 } | |
332 else | |
333 { | |
334 return Json::Value(value); | |
335 } | |
336 } | |
337 catch (boost::math::rounding_error&) | |
3202 | 338 { |
3312 | 339 // Can occur if "long long" is too small to receive this value |
340 // (e.g. infinity) | |
3202 | 341 return Json::Value(value); |
342 } | |
343 } | |
344 | |
5816
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
345 Json::Value DicomWebJsonVisitor::FormatDecimalString(double value, const std::string& originalString) |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
346 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
347 try |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
348 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
349 long long a = boost::math::llround<double>(value); |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
350 |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
351 double d = fabs(value - static_cast<double>(a)); |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
352 |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
353 if (d <= std::numeric_limits<double>::epsilon() * 100.0) |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
354 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
355 return FormatInteger(a); // if the decimal number is an integer, you can represent it as an integer |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
356 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
357 else |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
358 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
359 return Json::Value(originalString); // keep the original string to avoid rounding errors e.g, transforming "0.143" into 0.14299999999999 |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
360 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
361 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
362 catch (boost::math::rounding_error&) |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
363 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
364 // Can occur if "long long" is too small to receive this value |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
365 // (e.g. infinity) |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
366 return Json::Value(originalString); |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
367 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
368 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
369 |
4297 | 370 DicomWebJsonVisitor::DicomWebJsonVisitor() : |
371 formatter_(NULL) | |
372 { | |
373 Clear(); | |
374 } | |
375 | |
376 void DicomWebJsonVisitor::SetFormatter(DicomWebJsonVisitor::IBinaryFormatter &formatter) | |
377 { | |
378 formatter_ = &formatter; | |
379 } | |
380 | |
381 void DicomWebJsonVisitor::Clear() | |
382 { | |
383 result_ = Json::objectValue; | |
384 } | |
385 | |
386 const Json::Value &DicomWebJsonVisitor::GetResult() const | |
387 { | |
388 return result_; | |
389 } | |
390 | |
3202 | 391 |
392 #if ORTHANC_ENABLE_PUGIXML == 1 | |
3203
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3202
diff
changeset
|
393 void DicomWebJsonVisitor::FormatXml(std::string& target) const |
3202 | 394 { |
3203
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3202
diff
changeset
|
395 pugi::xml_document doc; |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3202
diff
changeset
|
396 DicomWebJsonToXml(doc, result_); |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3202
diff
changeset
|
397 Toolbox::XmlToString(target, doc); |
3202 | 398 } |
399 #endif | |
400 | |
401 | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
402 ITagVisitor::Action |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
403 DicomWebJsonVisitor::VisitNotSupported(const std::vector<DicomTag> &parentTags, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
404 const std::vector<size_t> &parentIndexes, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
405 const DicomTag &tag, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
406 ValueRepresentation vr) |
4297 | 407 { |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
408 return Action_None; |
4297 | 409 } |
410 | |
411 | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
412 ITagVisitor::Action |
4737
979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4734
diff
changeset
|
413 DicomWebJsonVisitor::VisitSequence(const std::vector<DicomTag>& parentTags, |
979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4734
diff
changeset
|
414 const std::vector<size_t>& parentIndexes, |
979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4734
diff
changeset
|
415 const DicomTag& tag, |
979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4734
diff
changeset
|
416 size_t countItems) |
3202 | 417 { |
4737
979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4734
diff
changeset
|
418 if (countItems == 0 && |
979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4734
diff
changeset
|
419 tag.GetElement() != 0x0000) |
3202 | 420 { |
421 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
422 node[KEY_VR] = EnumerationToString(ValueRepresentation_Sequence); | |
423 } | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
424 |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
425 return Action_None; |
3202 | 426 } |
427 | |
428 | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
429 ITagVisitor::Action |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
430 DicomWebJsonVisitor::VisitBinary(const std::vector<DicomTag>& parentTags, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
431 const std::vector<size_t>& parentIndexes, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
432 const DicomTag& tag, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
433 ValueRepresentation vr, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
434 const void* data, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
435 size_t size) |
3202 | 436 { |
437 assert(vr == ValueRepresentation_OtherByte || | |
438 vr == ValueRepresentation_OtherDouble || | |
439 vr == ValueRepresentation_OtherFloat || | |
440 vr == ValueRepresentation_OtherLong || | |
441 vr == ValueRepresentation_OtherWord || | |
442 vr == ValueRepresentation_Unknown); | |
443 | |
444 if (tag.GetElement() != 0x0000) | |
445 { | |
446 BinaryMode mode; | |
447 std::string bulkDataUri; | |
448 | |
449 if (formatter_ == NULL) | |
450 { | |
451 mode = BinaryMode_InlineBinary; | |
452 } | |
453 else | |
454 { | |
455 mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr); | |
456 } | |
457 | |
458 if (mode != BinaryMode_Ignore) | |
459 { | |
460 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
461 node[KEY_VR] = EnumerationToString(vr); | |
462 | |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
463 /** |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
464 * The test on "size > 0" is new in Orthanc 1.9.3, and fixes |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
465 * issue #195 (No need for BulkDataURI when Data Element is |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
466 * empty): https://orthanc.uclouvain.be/bugs/show_bug.cgi?id=195 |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
467 **/ |
4660
4e81412ead0a
in DICOMweb JSON, BulkDataURI is forced for sequences and pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4655
diff
changeset
|
468 if (size > 0 || |
4e81412ead0a
in DICOMweb JSON, BulkDataURI is forced for sequences and pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4655
diff
changeset
|
469 tag == DICOM_TAG_PIXEL_DATA || |
4e81412ead0a
in DICOMweb JSON, BulkDataURI is forced for sequences and pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4655
diff
changeset
|
470 vr == ValueRepresentation_Sequence /* new in Orthanc 1.9.4 */) |
3202 | 471 { |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
472 switch (mode) |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
473 { |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
474 case BinaryMode_BulkDataUri: |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
475 node[KEY_BULK_DATA_URI] = bulkDataUri; |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
476 break; |
3202 | 477 |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
478 case BinaryMode_InlineBinary: |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
479 { |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
480 std::string tmp(static_cast<const char*>(data), size); |
3202 | 481 |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
482 std::string base64; |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
483 Toolbox::EncodeBase64(base64, tmp); |
3202 | 484 |
4655
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
485 node[KEY_INLINE_BINARY] = base64; |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
486 break; |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
487 } |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
488 |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
489 default: |
9f7eef20bc7d
Fix issue #195 (No need for BulkDataURI when Data Element is empty)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
490 throw OrthancException(ErrorCode_ParameterOutOfRange); |
3202 | 491 } |
492 } | |
493 } | |
494 } | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
495 |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
496 return Action_None; |
3202 | 497 } |
498 | |
499 | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
500 ITagVisitor::Action |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
501 DicomWebJsonVisitor::VisitIntegers(const std::vector<DicomTag>& parentTags, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
502 const std::vector<size_t>& parentIndexes, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
503 const DicomTag& tag, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
504 ValueRepresentation vr, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
505 const std::vector<int64_t>& values) |
3202 | 506 { |
507 if (tag.GetElement() != 0x0000 && | |
508 vr != ValueRepresentation_NotSupported) | |
509 { | |
510 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
511 node[KEY_VR] = EnumerationToString(vr); | |
512 | |
513 if (!values.empty()) | |
514 { | |
515 Json::Value content = Json::arrayValue; | |
516 for (size_t i = 0; i < values.size(); i++) | |
517 { | |
518 content.append(FormatInteger(values[i])); | |
519 } | |
520 | |
521 node[KEY_VALUE] = content; | |
522 } | |
523 } | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
524 |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
525 return Action_None; |
3202 | 526 } |
527 | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
528 ITagVisitor::Action |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
529 DicomWebJsonVisitor::VisitDoubles(const std::vector<DicomTag>& parentTags, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
530 const std::vector<size_t>& parentIndexes, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
531 const DicomTag& tag, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
532 ValueRepresentation vr, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
533 const std::vector<double>& values) |
3202 | 534 { |
535 if (tag.GetElement() != 0x0000 && | |
536 vr != ValueRepresentation_NotSupported) | |
537 { | |
538 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
539 node[KEY_VR] = EnumerationToString(vr); | |
540 | |
541 if (!values.empty()) | |
542 { | |
543 Json::Value content = Json::arrayValue; | |
544 for (size_t i = 0; i < values.size(); i++) | |
545 { | |
546 content.append(FormatDouble(values[i])); | |
547 } | |
548 | |
549 node[KEY_VALUE] = content; | |
550 } | |
551 } | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
552 |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
553 return Action_None; |
3202 | 554 } |
555 | |
556 | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
557 ITagVisitor::Action |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
558 DicomWebJsonVisitor::VisitAttributes(const std::vector<DicomTag>& parentTags, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
559 const std::vector<size_t>& parentIndexes, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
560 const DicomTag& tag, |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
561 const std::vector<DicomTag>& values) |
3202 | 562 { |
563 if (tag.GetElement() != 0x0000) | |
564 { | |
565 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
566 node[KEY_VR] = EnumerationToString(ValueRepresentation_AttributeTag); | |
567 | |
568 if (!values.empty()) | |
569 { | |
570 Json::Value content = Json::arrayValue; | |
571 for (size_t i = 0; i < values.size(); i++) | |
572 { | |
573 content.append(FormatTag(values[i])); | |
574 } | |
575 | |
576 node[KEY_VALUE] = content; | |
577 } | |
578 } | |
4734
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
579 |
b51c08bd5c38
added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4660
diff
changeset
|
580 return Action_None; |
3202 | 581 } |
582 | |
583 | |
584 ITagVisitor::Action | |
585 DicomWebJsonVisitor::VisitString(std::string& newValue, | |
586 const std::vector<DicomTag>& parentTags, | |
587 const std::vector<size_t>& parentIndexes, | |
588 const DicomTag& tag, | |
589 ValueRepresentation vr, | |
590 const std::string& value) | |
591 { | |
592 if (tag.GetElement() == 0x0000 || | |
593 vr == ValueRepresentation_NotSupported) | |
594 { | |
595 return Action_None; | |
596 } | |
597 else | |
598 { | |
599 Json::Value& node = CreateNode(parentTags, parentIndexes, tag); | |
600 node[KEY_VR] = EnumerationToString(vr); | |
601 | |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
602 #if 0 |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
603 /** |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
604 * TODO - The JSON file has an UTF-8 encoding, thus DCMTK |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
605 * replaces the specific character set with "ISO_IR 192" |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
606 * (UNICODE UTF-8). On Google Cloud Healthcare, however, the |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
607 * source encoding is reported, which seems more logical. We |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
608 * thus choose the Google convention. Enabling this block will |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
609 * mimic the DCMTK behavior. |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
610 **/ |
3202 | 611 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET) |
612 { | |
613 node[KEY_VALUE].append("ISO_IR 192"); | |
614 } | |
615 else | |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
616 #endif |
3202 | 617 { |
618 std::string truncated; | |
619 | |
620 if (!value.empty() && | |
621 value[value.size() - 1] == '\0') | |
622 { | |
623 truncated = value.substr(0, value.size() - 1); | |
624 } | |
625 else | |
626 { | |
627 truncated = value; | |
628 } | |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
629 |
3202 | 630 if (!truncated.empty()) |
631 { | |
632 std::vector<std::string> tokens; | |
633 Toolbox::TokenizeString(tokens, truncated, '\\'); | |
634 | |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
635 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET && |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
636 tokens.size() > 1 && |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
637 tokens[0].empty()) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
638 { |
3448
b3bdd6dc10f2
don't change encoding of SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
639 // Specific character set with code extension: Remove the |
b3bdd6dc10f2
don't change encoding of SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
640 // first element from the vector of encodings |
b3bdd6dc10f2
don't change encoding of SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
641 tokens.erase(tokens.begin()); |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
642 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3391
diff
changeset
|
643 |
3202 | 644 node[KEY_VALUE] = Json::arrayValue; |
645 for (size_t i = 0; i < tokens.size(); i++) | |
646 { | |
647 try | |
648 { | |
649 switch (vr) | |
650 { | |
651 case ValueRepresentation_PersonName: | |
652 { | |
4200 | 653 Json::Value tmp = Json::objectValue; |
3202 | 654 if (!tokens[i].empty()) |
655 { | |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
656 std::vector<std::string> components; |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
657 Toolbox::TokenizeString(components, tokens[i], '='); |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
658 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
659 if (components.size() >= 1) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
660 { |
4200 | 661 tmp[KEY_ALPHABETIC] = components[0]; |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
662 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
663 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
664 if (components.size() >= 2) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
665 { |
4200 | 666 tmp[KEY_IDEOGRAPHIC] = components[1]; |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
667 } |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
668 |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
669 if (components.size() >= 3) |
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
670 { |
4200 | 671 tmp[KEY_PHONETIC] = components[2]; |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
672 } |
3202 | 673 } |
3221
4be505c2ac56
Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
674 |
4200 | 675 node[KEY_VALUE].append(tmp); |
3202 | 676 break; |
677 } | |
678 | |
679 case ValueRepresentation_IntegerString: | |
3391 | 680 { |
681 /** | |
682 * The calls to "StripSpaces()" below fix the | |
683 * issue reported by Rana Asim Wajid on 2019-06-05 | |
684 * ("Error Exception while invoking plugin service | |
685 * 32: Bad file format"): | |
686 * https://groups.google.com/d/msg/orthanc-users/T32FovWPcCE/-hKFbfRJBgAJ | |
687 **/ | |
688 | |
4297 | 689 std::string t = Toolbox::StripSpaces(tokens[i]); |
3391 | 690 if (t.empty()) |
3202 | 691 { |
692 node[KEY_VALUE].append(Json::nullValue); | |
693 } | |
694 else | |
695 { | |
4200 | 696 int64_t tmp = boost::lexical_cast<int64_t>(t); |
697 node[KEY_VALUE].append(FormatInteger(tmp)); | |
3202 | 698 } |
3391 | 699 |
3202 | 700 break; |
3391 | 701 } |
3202 | 702 |
703 case ValueRepresentation_DecimalString: | |
3391 | 704 { |
4297 | 705 std::string t = Toolbox::StripSpaces(tokens[i]); |
5816
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
706 boost::replace_all(t, ",", "."); // some invalid files uses "," instead of "." |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
707 |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
708 // remove invalid/useless trailing decimal separator |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
709 if (t.size() > 0 && t[t.size()-1] == '.') |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
710 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
711 t.resize(t.size() -1); |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
712 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
713 |
3391 | 714 if (t.empty()) |
3202 | 715 { |
716 node[KEY_VALUE].append(Json::nullValue); | |
717 } | |
718 else | |
719 { | |
5816
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
720 // https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.2.3.html |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
721 // DS values can be represented as String or Number in Json. |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
722 // For IS, DS, SV and UV, a JSON String representation can be used to preserve the original format during transformation of the representation, or if needed to avoid losing precision of a decimal string. |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
723 // Since 1.12.5, always use the string repesentation. Before, decimal numbers were represented as double which led to loss of precision (e.g: 0.143 represented as 0.1429999999) |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
724 double tmp; |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
725 if (SerializationToolbox::ParseDouble(tmp, t)) // make sure that the string contains a valid decimal number |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
726 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
727 node[KEY_VALUE].append(t); |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
728 } |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
729 else |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
730 { |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
731 throw boost::bad_lexical_cast(); |
3f10350b26da
DICOMWeb Json formatter: improve support for ill-formed DS values + DS values are now represented as strings instead of doubles
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
732 } |
3202 | 733 } |
3391 | 734 |
3202 | 735 break; |
3391 | 736 } |
737 | |
3202 | 738 default: |
739 if (tokens[i].empty()) | |
740 { | |
741 node[KEY_VALUE].append(Json::nullValue); | |
742 } | |
743 else | |
744 { | |
745 node[KEY_VALUE].append(tokens[i]); | |
746 } | |
747 | |
748 break; | |
749 } | |
750 } | |
751 catch (boost::bad_lexical_cast&) | |
752 { | |
3464
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
753 std::string tmp; |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
754 if (value.size() < 64 && |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
755 Toolbox::IsAsciiString(value)) |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
756 { |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
757 tmp = ": " + value; |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
758 } |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
759 |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
760 LOG(WARNING) << "Ignoring DICOM tag (" << tag.Format() |
418a89acef3b
In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3448
diff
changeset
|
761 << ") with invalid content for VR " << EnumerationToString(vr) << tmp; |
3202 | 762 } |
763 } | |
764 } | |
765 } | |
766 } | |
767 | |
768 return Action_None; | |
769 } | |
770 } |