annotate OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h @ 4145:c5cdb6dc6865

New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Aug 2020 14:48:11 +0200
parents bf7b9edf6b81
children 2007ab69ac16
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: 3203
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
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #if !defined(ORTHANC_ENABLE_PUGIXML)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 # error Macro ORTHANC_ENABLE_PUGIXML must be defined to use this file
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "ITagVisitor.h"
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <json/value.h>
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 namespace Orthanc
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
36 class ORTHANC_PUBLIC DicomWebJsonVisitor : public ITagVisitor
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 public:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 enum BinaryMode
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 BinaryMode_Ignore,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 BinaryMode_BulkDataUri,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 BinaryMode_InlineBinary
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 };
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 class IBinaryFormatter : public boost::noncopyable
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 public:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 virtual ~IBinaryFormatter()
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 virtual BinaryMode Format(std::string& bulkDataUri,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ValueRepresentation vr) = 0;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 };
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 private:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 Json::Value result_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 IBinaryFormatter *formatter_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 static std::string FormatTag(const DicomTag& tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Json::Value& CreateNode(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const DicomTag& tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 static Json::Value FormatInteger(int64_t value);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 static Json::Value FormatDouble(double value);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 public:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 DicomWebJsonVisitor() :
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 formatter_(NULL)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 Clear();
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 void SetFormatter(IBinaryFormatter& formatter)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 formatter_ = &formatter;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 void Clear()
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 result_ = Json::objectValue;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 const Json::Value& GetResult() const
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 return result_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 #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
97 void FormatXml(std::string& target) const;
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 virtual void VisitNotSupported(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 ValueRepresentation vr)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ORTHANC_OVERRIDE
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 virtual void VisitEmptySequence(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const DicomTag& tag)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 virtual void VisitBinary(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 const void* data,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 size_t size)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 virtual void VisitIntegers(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 const std::vector<int64_t>& values)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 virtual void VisitDoubles(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 const std::vector<double>& values)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 virtual void VisitAttributes(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 const std::vector<DicomTag>& values)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 virtual Action VisitString(std::string& newValue,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 const std::string& value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 };
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }