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