annotate OrthancFramework/Sources/DicomParsing/DicomWebJsonVisitor.h @ 5527:93dcc555b655 Orthanc-1.12.3

Orthanc-1.12.3
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 31 Jan 2024 12:33:17 +0100
parents 48b8dae6dc77
children f7adfb22e20e
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
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
11 * the License, or (at your option) any later version.
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
16 * Lesser General Public License for more details.
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
20 * <http://www.gnu.org/licenses/>.
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #if !defined(ORTHANC_ENABLE_PUGIXML)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # error Macro ORTHANC_ENABLE_PUGIXML must be defined to use this file
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "ITagVisitor.h"
4202
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
31 #include "../Compatibility.h" // For ORTHANC_OVERRIDE
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <json/value.h>
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace Orthanc
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 class ORTHANC_PUBLIC DicomWebJsonVisitor : public ITagVisitor
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 public:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 enum BinaryMode
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 BinaryMode_Ignore,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 BinaryMode_BulkDataUri,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 BinaryMode_InlineBinary
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 };
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 class IBinaryFormatter : public boost::noncopyable
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 public:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 virtual ~IBinaryFormatter()
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 virtual BinaryMode Format(std::string& bulkDataUri,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 ValueRepresentation vr) = 0;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 };
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 private:
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 Json::Value result_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 IBinaryFormatter *formatter_;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 static std::string FormatTag(const DicomTag& tag);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 Json::Value& CreateNode(const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const DicomTag& tag);
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 FormatInteger(int64_t 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 static Json::Value FormatDouble(double value);
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 public:
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
77 DicomWebJsonVisitor();
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
79 void SetFormatter(IBinaryFormatter& formatter);
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
81 void Clear();
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
83 const Json::Value& GetResult() const;
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #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
86 void FormatXml(std::string& target) const;
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 #endif
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
4734
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
89 virtual Action VisitNotSupported(const std::vector<DicomTag>& parentTags,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
90 const std::vector<size_t>& parentIndexes,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
91 const DicomTag& tag,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
92 ValueRepresentation vr)
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
93 ORTHANC_OVERRIDE;
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
4737
979ae3ea3381 DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4734
diff changeset
95 virtual Action VisitSequence(const std::vector<DicomTag>& parentTags,
979ae3ea3381 DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4734
diff changeset
96 const std::vector<size_t>& parentIndexes,
979ae3ea3381 DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4734
diff changeset
97 const DicomTag& tag,
979ae3ea3381 DANGEROUS commit: Anonymization is now also applied to nested sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4734
diff changeset
98 size_t countItems)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
4734
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
101 virtual Action VisitBinary(const std::vector<DicomTag>& parentTags,
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ValueRepresentation vr,
4734
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
105 const void* data,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
106 size_t size)
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
107 ORTHANC_OVERRIDE;
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
108
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
109 virtual Action VisitIntegers(const std::vector<DicomTag>& parentTags,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
110 const std::vector<size_t>& parentIndexes,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
111 const DicomTag& tag,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
112 ValueRepresentation vr,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
113 const std::vector<int64_t>& values)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
4734
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
116 virtual Action VisitDoubles(const std::vector<DicomTag>& parentTags,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
117 const std::vector<size_t>& parentIndexes,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
118 const DicomTag& tag,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
119 ValueRepresentation vr,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
120 const std::vector<double>& values)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
4734
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
123 virtual Action VisitAttributes(const std::vector<DicomTag>& parentTags,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
124 const std::vector<size_t>& parentIndexes,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
125 const DicomTag& tag,
b51c08bd5c38 added ITagVisitor::Action_Remove
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
126 const std::vector<DicomTag>& values)
3202
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 virtual Action VisitString(std::string& newValue,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 const std::vector<DicomTag>& parentTags,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 const std::vector<size_t>& parentIndexes,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 const DicomTag& tag,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ValueRepresentation vr,
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 const std::string& value)
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 ORTHANC_OVERRIDE;
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 };
ef4d86d05503 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }