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