annotate OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.cpp @ 5087:df4a90a65af9

DicomModification::SetAllowManualIdentifiers() has been removed since it was always true -> code cleanup
author Alain Mazy <am@osimis.io>
date Mon, 26 Sep 2022 18:56:40 +0200
parents 43e613a7756b
children 0ea402b4d901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../PrecompiledHeaders.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "DicomWebJsonVisitor.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
27 #include "../Logging.h"
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../OrthancException.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../Toolbox.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "FromDcmtkBridge.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <boost/math/special_functions/round.hpp>
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <boost/lexical_cast.hpp>
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 static const char* const KEY_BULK_DATA_URI = "BulkDataURI";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 static const char* const KEY_INLINE_BINARY = "InlineBinary";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 static const char* const KEY_VALUE = "Value";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 namespace Orthanc
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 static void ExploreXmlDataset(pugi::xml_node& target,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 const Json::Value& source)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 assert(source.type() == Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 Json::Value::Members members = source.getMemberNames();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 for (size_t i = 0; i < members.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const DicomTag tag = FromDcmtkBridge::ParseTag(members[i]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const Json::Value& content = source[members[i]];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const std::string keyword = FromDcmtkBridge::GetTagName(tag, "");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if (keyword != std::string(DcmTag_ERROR_TagName))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 node.append_attribute("keyword").set_value(keyword.c_str());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 if (content.isMember(KEY_VALUE))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 assert(content[KEY_VALUE].type() == Json::arrayValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 for (Json::Value::ArrayIndex j = 0; j < content[KEY_VALUE].size(); j++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 std::string number = boost::lexical_cast<std::string>(j + 1);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (vr == "SQ")
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (content[KEY_VALUE][j].type() == Json::objectValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ExploreXmlDataset(child, content[KEY_VALUE][j]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (vr == "PN")
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 switch (content[KEY_VALUE][j].type())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 case Json::stringValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 child.text() = content[KEY_VALUE][j].asCString();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 case Json::realValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 child.text() = content[KEY_VALUE][j].asFloat();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 case Json::intValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 child.text() = content[KEY_VALUE][j].asInt();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 case Json::uintValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 child.text() = content[KEY_VALUE][j].asUInt();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 default:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 else if (content.isMember(KEY_BULK_DATA_URI) &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 content[KEY_BULK_DATA_URI].type() == Json::stringValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 child.append_attribute("URI").set_value(content[KEY_BULK_DATA_URI].asCString());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 else if (content.isMember(KEY_INLINE_BINARY) &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 content[KEY_INLINE_BINARY].type() == Json::stringValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 child.text() = content[KEY_INLINE_BINARY].asCString();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 #if ORTHANC_ENABLE_PUGIXML == 1
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 static void DicomWebJsonToXml(pugi::xml_document& target,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 const Json::Value& source)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 pugi::xml_node root = target.append_child("NativeDicomModel");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 root.append_attribute("xmlns").set_value("http://dicom.nema.org/PS3.19/models/NativeDICOM");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 root.append_attribute("xsi:schemaLocation").set_value("http://dicom.nema.org/PS3.19/models/NativeDICOM");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 root.append_attribute("xmlns:xsi").set_value("http://www.w3.org/2001/XMLSchema-instance");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 ExploreXmlDataset(root, source);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 pugi::xml_node decl = target.prepend_child(pugi::node_declaration);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 decl.append_attribute("version").set_value("1.0");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 decl.append_attribute("encoding").set_value("utf-8");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 std::string DicomWebJsonVisitor::FormatTag(const DicomTag& tag)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 char buf[16];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 sprintf(buf, "%04X%04X", tag.GetGroup(), tag.GetElement());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 return std::string(buf);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 Json::Value& DicomWebJsonVisitor::CreateNode(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 const DicomTag& tag)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 assert(parentTags.size() == parentIndexes.size());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 Json::Value* node = &result_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 for (size_t i = 0; i < parentTags.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 std::string t = FormatTag(parentTags[i]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (!node->isMember(t))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 Json::Value item = Json::objectValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 item[KEY_VR] = KEY_SQ;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 item[KEY_VALUE] = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 item[KEY_VALUE].append(Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 (*node) [t] = item;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 node = &(*node)[t][KEY_VALUE][0];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 else if ((*node) [t].type() != Json::objectValue ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 !(*node) [t].isMember(KEY_VR) ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 (*node) [t][KEY_VR].type() != Json::stringValue ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 (*node) [t][KEY_VR].asString() != KEY_SQ ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 !(*node) [t].isMember(KEY_VALUE) ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 (*node) [t][KEY_VALUE].type() != Json::arrayValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 throw OrthancException(ErrorCode_InternalError);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 size_t currentSize = (*node) [t][KEY_VALUE].size();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 if (parentIndexes[i] < currentSize)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 // The node already exists
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 else if (parentIndexes[i] == currentSize)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 (*node) [t][KEY_VALUE].append(Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 throw OrthancException(ErrorCode_InternalError);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 node = &(*node) [t][KEY_VALUE][Json::ArrayIndex(parentIndexes[i])];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 assert(node->type() == Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 std::string t = FormatTag(tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (node->isMember(t))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 throw OrthancException(ErrorCode_InternalError);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 (*node) [t] = Json::objectValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 return (*node) [t];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 Json::Value DicomWebJsonVisitor::FormatInteger(int64_t value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 if (value < 0)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 return Json::Value(static_cast<int32_t>(value));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 return Json::Value(static_cast<uint32_t>(value));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 Json::Value DicomWebJsonVisitor::FormatDouble(double value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
320 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
321 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
322 long long a = boost::math::llround<double>(value);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
324 double d = fabs(value - static_cast<double>(a));
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
326 if (d <= std::numeric_limits<double>::epsilon() * 100.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
327 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
328 return FormatInteger(a);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
329 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
330 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
331 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
332 return Json::Value(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
333 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
334 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
335 catch (boost::math::rounding_error&)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 {
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
337 // Can occur if "long long" is too small to receive this value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
338 // (e.g. infinity)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 return Json::Value(value);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
343 DicomWebJsonVisitor::DicomWebJsonVisitor() :
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
344 formatter_(NULL)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
345 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
346 Clear();
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
347 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
348
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
349 void DicomWebJsonVisitor::SetFormatter(DicomWebJsonVisitor::IBinaryFormatter &formatter)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
350 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
351 formatter_ = &formatter;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
352 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
353
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
354 void DicomWebJsonVisitor::Clear()
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
355 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
356 result_ = Json::objectValue;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
357 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
358
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
359 const Json::Value &DicomWebJsonVisitor::GetResult() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
360 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
361 return result_;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
362 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
363
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
380 {
4734
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4660
diff changeset
381 return Action_None;
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
382 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
383
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 node[KEY_VR] = EnumerationToString(ValueRepresentation_Sequence);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 assert(vr == ValueRepresentation_OtherByte ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 vr == ValueRepresentation_OtherDouble ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 vr == ValueRepresentation_OtherFloat ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 vr == ValueRepresentation_OtherLong ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 vr == ValueRepresentation_OtherWord ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 vr == ValueRepresentation_Unknown);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 if (tag.GetElement() != 0x0000)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 BinaryMode mode;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 std::string bulkDataUri;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 if (formatter_ == NULL)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 mode = BinaryMode_InlineBinary;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 if (mode != BinaryMode_Ignore)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 if (tag.GetElement() != 0x0000 &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 vr != ValueRepresentation_NotSupported)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 if (!values.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 Json::Value content = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 for (size_t i = 0; i < values.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 content.append(FormatInteger(values[i]));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 node[KEY_VALUE] = content;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 if (tag.GetElement() != 0x0000 &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 vr != ValueRepresentation_NotSupported)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 if (!values.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 Json::Value content = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 for (size_t i = 0; i < values.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 content.append(FormatDouble(values[i]));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 node[KEY_VALUE] = content;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 if (tag.GetElement() != 0x0000)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 node[KEY_VR] = EnumerationToString(ValueRepresentation_AttributeTag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 if (!values.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 Json::Value content = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 for (size_t i = 0; i < values.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 content.append(FormatTag(values[i]));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 node[KEY_VALUE] = content;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 ITagVisitor::Action
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 DicomWebJsonVisitor::VisitString(std::string& newValue,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 const std::string& value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 if (tag.GetElement() == 0x0000 ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 vr == ValueRepresentation_NotSupported)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 return Action_None;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 node[KEY_VALUE].append("ISO_IR 192");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 else
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
589 #endif
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 std::string truncated;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 if (!value.empty() &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 value[value.size() - 1] == '\0')
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 truncated = value.substr(0, value.size() - 1);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 truncated = value;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 }
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
602
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 if (!truncated.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 std::vector<std::string> tokens;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 Toolbox::TokenizeString(tokens, truncated, '\\');
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 node[KEY_VALUE] = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 for (size_t i = 0; i < tokens.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 try
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 switch (vr)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 case ValueRepresentation_PersonName:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 {
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
626 Json::Value tmp = Json::objectValue;
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 if (!tokens[i].empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
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
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
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
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
648 node[KEY_VALUE].append(tmp);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 case ValueRepresentation_IntegerString:
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
653 {
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
654 /**
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
655 * The calls to "StripSpaces()" below fix the
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
656 * issue reported by Rana Asim Wajid on 2019-06-05
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
657 * ("Error Exception while invoking plugin service
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
658 * 32: Bad file format"):
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
659 * https://groups.google.com/d/msg/orthanc-users/T32FovWPcCE/-hKFbfRJBgAJ
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
660 **/
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
661
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
662 std::string t = Toolbox::StripSpaces(tokens[i]);
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
663 if (t.empty())
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 node[KEY_VALUE].append(Json::nullValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 {
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
669 int64_t tmp = boost::lexical_cast<int64_t>(t);
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
670 node[KEY_VALUE].append(FormatInteger(tmp));
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 }
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
672
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 break;
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
674 }
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 case ValueRepresentation_DecimalString:
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
677 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
678 std::string t = Toolbox::StripSpaces(tokens[i]);
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
679 if (t.empty())
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 node[KEY_VALUE].append(Json::nullValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 {
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
685 double tmp = boost::lexical_cast<double>(t);
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
686 node[KEY_VALUE].append(FormatDouble(tmp));
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 }
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
688
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 break;
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
690 }
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
691
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 default:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 if (tokens[i].empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 node[KEY_VALUE].append(Json::nullValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 node[KEY_VALUE].append(tokens[i]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 catch (boost::bad_lexical_cast&)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 return Action_None;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 }