annotate OrthancStone/Sources/Toolbox/OrthancDatasets/IOrthancConnection.cpp @ 2177:4d21befb1501 default tip

clarify DICOMweb version check
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Oct 2024 19:27:56 +0200
parents 16c01cc201e7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
2124
16c01cc201e7 updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2114
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
2114
c23eef785569 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2077
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "IOrthancConnection.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <OrthancException.h>
1737
ef2f56c0311c remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
27 #include <Toolbox.h>
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
1740
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
29 #if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE)
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
30 # error You are using a version of the Orthanc framework that is too old
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
31 #endif
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
32
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
33 #if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
34 # include <json/reader.h>
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
35 #endif
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
36
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
37
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace OrthancStone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 void IOrthancConnection::ParseJson(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 const std::string& content)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
1740
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
43 bool ok;
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
44
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
45 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
46 ok = Orthanc::Toolbox::ReadJson(result, content);
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
47 #else
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
48 // Backward compatibility (for use in orthanc-wsi 1.0)
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
49 Json::Reader reader;
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
50 ok = reader.parse(content, result);
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
51 #endif
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
52
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
53 if (!ok)
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 void IOrthancConnection::ParseJson(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 const void* content,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 size_t size)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
1740
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
64 bool ok;
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
65
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
66 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
67 ok = Orthanc::Toolbox::ReadJson(result, content, size);
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
68 #else
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
69 // Backward compatibility (for use in orthanc-wsi 1.0)
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
70 Json::Reader reader;
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
71 ok = reader.parse(reinterpret_cast<const char*>(content),
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
72 reinterpret_cast<const char*>(content) + size, result);
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
73 #endif
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
74
84d1402c98fe backward compatibility for Orthanc framework 1.8.2 in IOrthancConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
75 if (!ok)
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 void IOrthancConnection::RestApiGet(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 const std::string& uri)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 std::string content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 orthanc.RestApiGet(content, uri);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ParseJson(result, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 void IOrthancConnection::RestApiPost(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const std::string& body)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 std::string content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 orthanc.RestApiPost(content, uri, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ParseJson(result, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 void IOrthancConnection::RestApiPut(Json::Value& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 const std::string& uri,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 const std::string& body)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 std::string content;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 orthanc.RestApiPut(content, uri, body);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ParseJson(result, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }