annotate Core/DicomParsing/DicomWebJsonVisitor.cpp @ 3737:f29843323daf storage-commitment

accessing storage commitment reports from REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Mar 2020 20:33:01 +0100
parents 94f4a18a79cc
children
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3464
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeaders.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "DicomWebJsonVisitor.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../OrthancException.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../Toolbox.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "FromDcmtkBridge.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <boost/math/special_functions/round.hpp>
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <boost/lexical_cast.hpp>
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 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
46 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
47 static const char* const KEY_PHONETIC = "Phonetic";
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 static const char* const KEY_BULK_DATA_URI = "BulkDataURI";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 static const char* const KEY_INLINE_BINARY = "InlineBinary";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 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
51 static const char* const KEY_TAG = "tag";
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 static const char* const KEY_VALUE = "Value";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 static const char* const KEY_VR = "vr";
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 namespace Orthanc
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #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
59 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
60 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
61 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
62 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
63 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
64
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
65 if (tokens.size() >= 1)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
66 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
67 target.append_child("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
68 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
69
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
70 if (tokens.size() >= 2)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
71 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
72 target.append_child("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
73 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
74
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
75 if (tokens.size() >= 3)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
76 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
77 target.append_child("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
78 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
79
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
80 if (tokens.size() >= 4)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
81 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
82 target.append_child("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
83 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
84
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
85 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
86 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
87 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
88 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
89 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
90
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 static void ExploreXmlDataset(pugi::xml_node& target,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 const Json::Value& source)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
94 // 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
95 assert(source.type() == Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 Json::Value::Members members = source.getMemberNames();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 for (size_t i = 0; i < members.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 const DicomTag tag = FromDcmtkBridge::ParseTag(members[i]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const Json::Value& content = source[members[i]];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 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
104 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
105 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
106 const std::string vr = content[KEY_VR].asString();
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const std::string keyword = FromDcmtkBridge::GetTagName(tag, "");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 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
111 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
112 node.append_attribute(KEY_VR).set_value(vr.c_str());
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (keyword != std::string(DcmTag_ERROR_TagName))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 node.append_attribute("keyword").set_value(keyword.c_str());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 if (content.isMember(KEY_VALUE))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 assert(content[KEY_VALUE].type() == Json::arrayValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 for (Json::Value::ArrayIndex j = 0; j < content[KEY_VALUE].size(); j++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 std::string number = boost::lexical_cast<std::string>(j + 1);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (vr == "SQ")
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 (content[KEY_VALUE][j].type() == Json::objectValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 pugi::xml_node child = node.append_child("Item");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 child.append_attribute("number").set_value(number.c_str());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ExploreXmlDataset(child, content[KEY_VALUE][j]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (vr == "PN")
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
138 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
139 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
140
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
141 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
142 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
143
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
144 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
145 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
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 ||
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
148 hasIdeographic ||
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
149 hasPhonetic)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 pugi::xml_node child = node.append_child("PersonName");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 child.append_attribute("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
153
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
154 if (hasAlphabetic)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
156 pugi::xml_node name = child.append_child(KEY_ALPHABETIC);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
157 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_ALPHABETIC].asString());
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
159
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
160 if (hasIdeographic)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
162 pugi::xml_node name = child.append_child(KEY_IDEOGRAPHIC);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
163 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_IDEOGRAPHIC].asString());
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
165
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
166 if (hasPhonetic)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
168 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
169 DecomposeXmlPersonName(name, content[KEY_VALUE][j][KEY_PHONETIC].asString());
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 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 pugi::xml_node child = node.append_child("Value");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 child.append_attribute("number").set_value(number.c_str());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 switch (content[KEY_VALUE][j].type())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 case Json::stringValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 child.text() = content[KEY_VALUE][j].asCString();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 case Json::realValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 child.text() = content[KEY_VALUE][j].asFloat();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 case Json::intValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 child.text() = content[KEY_VALUE][j].asInt();
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 case Json::uintValue:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 child.text() = content[KEY_VALUE][j].asUInt();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 default:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 else if (content.isMember(KEY_BULK_DATA_URI) &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 content[KEY_BULK_DATA_URI].type() == Json::stringValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 pugi::xml_node child = node.append_child("BulkData");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 child.append_attribute("URI").set_value(content[KEY_BULK_DATA_URI].asCString());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 else if (content.isMember(KEY_INLINE_BINARY) &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 content[KEY_INLINE_BINARY].type() == Json::stringValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 pugi::xml_node child = node.append_child("InlineBinary");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 child.text() = content[KEY_INLINE_BINARY].asCString();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 #if ORTHANC_ENABLE_PUGIXML == 1
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 static void DicomWebJsonToXml(pugi::xml_document& target,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 const Json::Value& 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 root = target.append_child("NativeDicomModel");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 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
225 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
226 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
227
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 ExploreXmlDataset(root, source);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 pugi::xml_node decl = target.prepend_child(pugi::node_declaration);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 decl.append_attribute("version").set_value("1.0");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 decl.append_attribute("encoding").set_value("utf-8");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 #endif
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 std::string DicomWebJsonVisitor::FormatTag(const DicomTag& tag)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 char buf[16];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 sprintf(buf, "%04X%04X", tag.GetGroup(), tag.GetElement());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 return std::string(buf);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 Json::Value& DicomWebJsonVisitor::CreateNode(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 const DicomTag& tag)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 assert(parentTags.size() == parentIndexes.size());
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 Json::Value* node = &result_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 for (size_t i = 0; i < parentTags.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 std::string t = FormatTag(parentTags[i]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 if (!node->isMember(t))
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 Json::Value item = Json::objectValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 item[KEY_VR] = KEY_SQ;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 item[KEY_VALUE] = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 item[KEY_VALUE].append(Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 (*node) [t] = item;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 node = &(*node)[t][KEY_VALUE][0];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 else if ((*node) [t].type() != Json::objectValue ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 !(*node) [t].isMember(KEY_VR) ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 (*node) [t][KEY_VR].type() != Json::stringValue ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 (*node) [t][KEY_VR].asString() != KEY_SQ ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 !(*node) [t].isMember(KEY_VALUE) ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 (*node) [t][KEY_VALUE].type() != Json::arrayValue)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 throw OrthancException(ErrorCode_InternalError);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 size_t currentSize = (*node) [t][KEY_VALUE].size();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 if (parentIndexes[i] < currentSize)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 // The node already exists
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 else if (parentIndexes[i] == currentSize)
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) [t][KEY_VALUE].append(Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 throw OrthancException(ErrorCode_InternalError);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 node = &(*node) [t][KEY_VALUE][Json::ArrayIndex(parentIndexes[i])];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 assert(node->type() == Json::objectValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 std::string t = FormatTag(tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 if (node->isMember(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 throw OrthancException(ErrorCode_InternalError);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 (*node) [t] = Json::objectValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 return (*node) [t];
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 Json::Value DicomWebJsonVisitor::FormatInteger(int64_t value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 if (value < 0)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 return Json::Value(static_cast<int32_t>(value));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 return Json::Value(static_cast<uint32_t>(value));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 Json::Value DicomWebJsonVisitor::FormatDouble(double value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
327 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
328 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
329 long long a = boost::math::llround<double>(value);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
331 double d = fabs(value - static_cast<double>(a));
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
333 if (d <= std::numeric_limits<double>::epsilon() * 100.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
334 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
335 return FormatInteger(a);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
336 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
337 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
338 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
339 return Json::Value(value);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
340 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
341 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
342 catch (boost::math::rounding_error&)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
3312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
344 // Can occur if "long long" is too small to receive this value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
345 // (e.g. infinity)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 return Json::Value(value);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 #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
352 void DicomWebJsonVisitor::FormatXml(std::string& target) const
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 {
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
354 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
355 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
356 Toolbox::XmlToString(target, doc);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 void DicomWebJsonVisitor::VisitEmptySequence(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 const DicomTag& tag)
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 (tag.GetElement() != 0x0000)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 node[KEY_VR] = EnumerationToString(ValueRepresentation_Sequence);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 void DicomWebJsonVisitor::VisitBinary(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 const void* data,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 size_t size)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 assert(vr == ValueRepresentation_OtherByte ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 vr == ValueRepresentation_OtherDouble ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 vr == ValueRepresentation_OtherFloat ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 vr == ValueRepresentation_OtherLong ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 vr == ValueRepresentation_OtherWord ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 vr == ValueRepresentation_Unknown);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 if (tag.GetElement() != 0x0000)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 BinaryMode mode;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 std::string bulkDataUri;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 if (formatter_ == NULL)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 mode = BinaryMode_InlineBinary;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 mode = formatter_->Format(bulkDataUri, parentTags, parentIndexes, tag, vr);
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 if (mode != BinaryMode_Ignore)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 switch (mode)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 case BinaryMode_BulkDataUri:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 node[KEY_BULK_DATA_URI] = bulkDataUri;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 case BinaryMode_InlineBinary:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 std::string tmp(static_cast<const char*>(data), size);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 std::string base64;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 Toolbox::EncodeBase64(base64, tmp);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 node[KEY_INLINE_BINARY] = base64;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 default:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 throw OrthancException(ErrorCode_ParameterOutOfRange);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 }
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 void DicomWebJsonVisitor::VisitIntegers(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 const std::vector<int64_t>& values)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 if (tag.GetElement() != 0x0000 &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 vr != ValueRepresentation_NotSupported)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 if (!values.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 Json::Value content = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 for (size_t i = 0; i < values.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 content.append(FormatInteger(values[i]));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 node[KEY_VALUE] = content;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 void DicomWebJsonVisitor::VisitDoubles(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 const std::vector<double>& values)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 if (tag.GetElement() != 0x0000 &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 vr != ValueRepresentation_NotSupported)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 if (!values.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 Json::Value content = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 for (size_t i = 0; i < values.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 content.append(FormatDouble(values[i]));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 node[KEY_VALUE] = content;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 void DicomWebJsonVisitor::VisitAttributes(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 const std::vector<DicomTag>& values)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 if (tag.GetElement() != 0x0000)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 node[KEY_VR] = EnumerationToString(ValueRepresentation_AttributeTag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 if (!values.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 Json::Value content = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 for (size_t i = 0; i < values.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 content.append(FormatTag(values[i]));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 node[KEY_VALUE] = content;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 ITagVisitor::Action
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 DicomWebJsonVisitor::VisitString(std::string& newValue,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 const std::string& value)
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 (tag.GetElement() == 0x0000 ||
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 vr == ValueRepresentation_NotSupported)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 return Action_None;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 Json::Value& node = CreateNode(parentTags, parentIndexes, tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 node[KEY_VR] = EnumerationToString(vr);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
524 #if 0
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
525 /**
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
526 * 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
527 * replaces the specific character set with "ISO_IR 192"
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
528 * (UNICODE UTF-8). On Google Cloud Healthcare, however, the
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
529 * source encoding is reported, which seems more logical. We
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
530 * thus choose the Google convention. Enabling this block will
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
531 * mimic the DCMTK behavior.
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
532 **/
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 node[KEY_VALUE].append("ISO_IR 192");
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 else
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
538 #endif
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 std::string truncated;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 if (!value.empty() &&
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 value[value.size() - 1] == '\0')
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 truncated = value.substr(0, value.size() - 1);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 truncated = value;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 }
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
551
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 if (!truncated.empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 std::vector<std::string> tokens;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 Toolbox::TokenizeString(tokens, truncated, '\\');
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
557 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET &&
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
558 tokens.size() > 1 &&
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
559 tokens[0].empty())
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
560 {
3448
b3bdd6dc10f2 don't change encoding of SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
561 // 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
562 // first element from the vector of encodings
b3bdd6dc10f2 don't change encoding of SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
563 tokens.erase(tokens.begin());
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
564 }
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3391
diff changeset
565
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 node[KEY_VALUE] = Json::arrayValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 for (size_t i = 0; i < tokens.size(); i++)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 try
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 switch (vr)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 case ValueRepresentation_PersonName:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 Json::Value value = Json::objectValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 if (!tokens[i].empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 {
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
578 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
579 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
580
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
581 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
582 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
583 value[KEY_ALPHABETIC] = components[0];
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
584 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
585
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
586 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
587 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
588 value[KEY_IDEOGRAPHIC] = components[1];
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
589 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
590
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
591 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
592 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
593 value[KEY_PHONETIC] = components[2];
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
594 }
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 }
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3203
diff changeset
596
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 node[KEY_VALUE].append(value);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 case ValueRepresentation_IntegerString:
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
602 {
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
603 /**
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
604 * The calls to "StripSpaces()" below fix the
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
605 * issue reported by Rana Asim Wajid on 2019-06-05
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
606 * ("Error Exception while invoking plugin service
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
607 * 32: Bad file format"):
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
608 * https://groups.google.com/d/msg/orthanc-users/T32FovWPcCE/-hKFbfRJBgAJ
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
609 **/
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
610
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
611 std::string t = Orthanc::Toolbox::StripSpaces(tokens[i]);
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
612 if (t.empty())
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 node[KEY_VALUE].append(Json::nullValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 {
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
618 int64_t value = boost::lexical_cast<int64_t>(t);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 node[KEY_VALUE].append(FormatInteger(value));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 }
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
621
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 break;
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
623 }
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 case ValueRepresentation_DecimalString:
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
626 {
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
627 std::string t = Orthanc::Toolbox::StripSpaces(tokens[i]);
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
628 if (t.empty())
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 node[KEY_VALUE].append(Json::nullValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 {
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
634 double value = boost::lexical_cast<double>(t);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 node[KEY_VALUE].append(FormatDouble(value));
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 }
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
637
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 break;
3391
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
639 }
df0f1821b3de better fix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3389
diff changeset
640
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 default:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 if (tokens[i].empty())
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 node[KEY_VALUE].append(Json::nullValue);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 else
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 node[KEY_VALUE].append(tokens[i]);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 break;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 catch (boost::bad_lexical_cast&)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 {
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
656 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
657 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
658 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
659 {
418a89acef3b In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3448
diff changeset
660 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
661 }
418a89acef3b In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3448
diff changeset
662
418a89acef3b In DICOM-to-DICOMweb/JSON conversion, be more tolerant wrt. invalid DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3448
diff changeset
663 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
664 << ") with invalid content for VR " << EnumerationToString(vr) << tmp;
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 return Action_None;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 }