comparison OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Core/DicomParsing/DicomWebJsonVisitor.h@94f4a18a79cc
children e00f3d089991
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #if !defined(ORTHANC_ENABLE_PUGIXML)
37 # error Macro ORTHANC_ENABLE_PUGIXML must be defined to use this file
38 #endif
39
40 #include "ITagVisitor.h"
41
42 #include <json/value.h>
43
44
45 namespace Orthanc
46 {
47 class DicomWebJsonVisitor : public ITagVisitor
48 {
49 public:
50 enum BinaryMode
51 {
52 BinaryMode_Ignore,
53 BinaryMode_BulkDataUri,
54 BinaryMode_InlineBinary
55 };
56
57 class IBinaryFormatter : public boost::noncopyable
58 {
59 public:
60 virtual ~IBinaryFormatter()
61 {
62 }
63
64 virtual BinaryMode Format(std::string& bulkDataUri,
65 const std::vector<DicomTag>& parentTags,
66 const std::vector<size_t>& parentIndexes,
67 const DicomTag& tag,
68 ValueRepresentation vr) = 0;
69 };
70
71 private:
72 Json::Value result_;
73 IBinaryFormatter *formatter_;
74
75 static std::string FormatTag(const DicomTag& tag);
76
77 Json::Value& CreateNode(const std::vector<DicomTag>& parentTags,
78 const std::vector<size_t>& parentIndexes,
79 const DicomTag& tag);
80
81 static Json::Value FormatInteger(int64_t value);
82
83 static Json::Value FormatDouble(double value);
84
85 public:
86 DicomWebJsonVisitor() :
87 formatter_(NULL)
88 {
89 Clear();
90 }
91
92 void SetFormatter(IBinaryFormatter& formatter)
93 {
94 formatter_ = &formatter;
95 }
96
97 void Clear()
98 {
99 result_ = Json::objectValue;
100 }
101
102 const Json::Value& GetResult() const
103 {
104 return result_;
105 }
106
107 #if ORTHANC_ENABLE_PUGIXML == 1
108 void FormatXml(std::string& target) const;
109 #endif
110
111 virtual void VisitNotSupported(const std::vector<DicomTag>& parentTags,
112 const std::vector<size_t>& parentIndexes,
113 const DicomTag& tag,
114 ValueRepresentation vr)
115 ORTHANC_OVERRIDE
116 {
117 }
118
119 virtual void VisitEmptySequence(const std::vector<DicomTag>& parentTags,
120 const std::vector<size_t>& parentIndexes,
121 const DicomTag& tag)
122 ORTHANC_OVERRIDE;
123
124 virtual void VisitBinary(const std::vector<DicomTag>& parentTags,
125 const std::vector<size_t>& parentIndexes,
126 const DicomTag& tag,
127 ValueRepresentation vr,
128 const void* data,
129 size_t size)
130 ORTHANC_OVERRIDE;
131
132 virtual void VisitIntegers(const std::vector<DicomTag>& parentTags,
133 const std::vector<size_t>& parentIndexes,
134 const DicomTag& tag,
135 ValueRepresentation vr,
136 const std::vector<int64_t>& values)
137 ORTHANC_OVERRIDE;
138
139 virtual void VisitDoubles(const std::vector<DicomTag>& parentTags,
140 const std::vector<size_t>& parentIndexes,
141 const DicomTag& tag,
142 ValueRepresentation vr,
143 const std::vector<double>& values)
144 ORTHANC_OVERRIDE;
145
146 virtual void VisitAttributes(const std::vector<DicomTag>& parentTags,
147 const std::vector<size_t>& parentIndexes,
148 const DicomTag& tag,
149 const std::vector<DicomTag>& values)
150 ORTHANC_OVERRIDE;
151
152 virtual Action VisitString(std::string& newValue,
153 const std::vector<DicomTag>& parentTags,
154 const std::vector<size_t>& parentIndexes,
155 const DicomTag& tag,
156 ValueRepresentation vr,
157 const std::string& value)
158 ORTHANC_OVERRIDE;
159 };
160 }