Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestChanges.cpp @ 5663:3765085693e5 large-queries
merge default -> large-queries
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 04 Jul 2024 07:40:58 +0200 |
parents | 28cc06e4859a f7adfb22e20e |
children | 5463c3ae3235 |
rev | line source |
---|---|
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1247
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * modify it under the terms of the GNU General Public License as |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * published by the Free Software Foundation, either version 3 of the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * License, or (at your option) any later version. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
24 #include "../PrecompiledHeadersServer.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
27 #include "../ServerContext.h" |
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
28 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 // Changes API -------------------------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
33 static void GetSinceToAndLimit(int64_t& since, |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
34 int64_t& to, |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
35 unsigned int& limit, |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
36 bool& last, |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
37 const RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 { |
3560
28ab86c6730e
"/changes": Allow the "limit" argument to be greater than 100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
39 static const unsigned int DEFAULT_LIMIT = 100; |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
40 static const int64_t DEFAULT_TO = -1; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 if (call.HasArgument("last")) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 last = true; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 return; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 last = false; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 try |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 since = boost::lexical_cast<int64_t>(call.GetArgument("since", "0")); |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
53 to = boost::lexical_cast<int64_t>(call.GetArgument("to", boost::lexical_cast<std::string>(DEFAULT_TO))); |
3560
28ab86c6730e
"/changes": Allow the "limit" argument to be greater than 100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
54 limit = boost::lexical_cast<unsigned int>(call.GetArgument("limit", boost::lexical_cast<std::string>(DEFAULT_LIMIT))); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 } |
2836
7133ad478eea
fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
56 catch (boost::bad_lexical_cast&) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 { |
3560
28ab86c6730e
"/changes": Allow the "limit" argument to be greater than 100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
58 since = 0; |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
59 to = DEFAULT_TO; |
3560
28ab86c6730e
"/changes": Allow the "limit" argument to be greater than 100
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
60 limit = DEFAULT_LIMIT; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 return; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
974 | 65 static void GetChanges(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
4403 | 67 if (call.IsDocumentation()) |
68 { | |
69 call.GetDocumentation() | |
70 .SetTag("Tracking changes") | |
71 .SetSummary("List changes") | |
72 .SetDescription("Whenever Orthanc receives a new DICOM instance, this event is recorded in the so-called _Changes Log_. This enables remote scripts to react to the arrival of new DICOM resources. A typical application is auto-routing, where an external script waits for a new DICOM instance to arrive into Orthanc, then forward this instance to another modality.") | |
73 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) | |
74 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false) | |
75 .AddAnswerType(MimeType_Json, "The list of changes") | |
76 .SetAnswerField("Changes", RestApiCallDocumentation::Type_JsonListOfObjects, "The individual changes") | |
77 .SetAnswerField("Done", RestApiCallDocumentation::Type_Boolean, | |
78 "Whether the last reported change is the last of the full history") | |
79 .SetAnswerField("Last", RestApiCallDocumentation::Type_Number, | |
80 "The index of the last reported change, can be used for the `since` argument in subsequent calls to this route") | |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
81 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/changes?since=0&limit=2", true); |
4403 | 82 return; |
83 } | |
84 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 int64_t since; |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
88 int64_t toNotUsed; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 unsigned int limit; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 bool last; |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
91 GetSinceToAndLimit(since, toNotUsed, limit, last, call); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 Json::Value result; |
1247 | 94 if (last) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 { |
1247 | 96 context.GetIndex().GetLastChange(result); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 } |
1247 | 98 else |
99 { | |
100 context.GetIndex().GetChanges(result, since, limit); | |
101 } | |
102 | |
103 call.GetOutput().AnswerJson(result); | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
106 static void GetChanges2(RestApiGetCall& call) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
107 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
108 if (call.IsDocumentation()) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
109 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
110 call.GetDocumentation() |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
111 .SetTag("Tracking changes") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
112 .SetSummary("List changes") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
113 .SetDescription("Whenever Orthanc receives a new DICOM instance, this event is recorded in the so-called _Changes Log_. This enables remote scripts to react to the arrival of new DICOM resources. A typical application is auto-routing, where an external script waits for a new DICOM instance to arrive into Orthanc, then forward this instance to another modality.") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
114 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
115 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
116 .SetHttpGetArgument("to", RestApiCallDocumentation::Type_Number, "Show only the resources till the provided index", false) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
117 .SetHttpGetArgument("type", RestApiCallDocumentation::Type_String, "Show only the changes of the provided type", false) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
118 .AddAnswerType(MimeType_Json, "The list of changes") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
119 .SetAnswerField("Changes", RestApiCallDocumentation::Type_JsonListOfObjects, "The individual changes") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
120 .SetAnswerField("Done", RestApiCallDocumentation::Type_Boolean, |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
121 "Whether the last reported change is the last of the full history") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
122 .SetAnswerField("Last", RestApiCallDocumentation::Type_Number, |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
123 "The index of the last reported change, can be used for the `since` argument in subsequent calls to this route") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
124 .SetHttpGetSample("https://orthanc.uclouvain.be/demo/changes?since=0&limit=2", true); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
125 return; |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
126 } |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
127 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
128 ServerContext& context = OrthancRestApi::GetContext(call); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
129 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
130 int64_t since, to; |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
131 ChangeType filterType = ChangeType_INTERNAL_All; |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
132 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
133 unsigned int limit; |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
134 bool last; |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
135 GetSinceToAndLimit(since, to, limit, last, call); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
136 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
137 std::string filterArgument = call.GetArgument("type", "all"); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
138 if (filterArgument != "all" && filterArgument != "All") |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
139 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
140 filterType = StringToChangeType(filterArgument); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
141 } |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
142 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
143 Json::Value result; |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
144 if (last) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
145 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
146 context.GetIndex().GetLastChange(result); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
147 } |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
148 else |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
149 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
150 if (filterType != ChangeType_INTERNAL_All && !context.GetIndex().HasExtendedApiV1()) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
151 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
152 throw OrthancException(ErrorCode_ParameterOutOfRange, "Trying to filter changes while the Database backend does not support it (requires ExtendedApiV1)"); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
153 } |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
154 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
155 context.GetIndex().GetChanges2(result, since, to, limit, filterType); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
156 } |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
157 |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
158 call.GetOutput().AnswerJson(result); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
159 } |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
160 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
974 | 162 static void DeleteChanges(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 { |
4403 | 164 if (call.IsDocumentation()) |
165 { | |
166 call.GetDocumentation() | |
167 .SetTag("Tracking changes") | |
168 .SetSummary("Clear changes") | |
169 .SetDescription("Clear the full history stored in the changes log"); | |
170 return; | |
171 } | |
172 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 OrthancRestApi::GetIndex(call).DeleteChanges(); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
174 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 // Exports API -------------------------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 |
974 | 180 static void GetExports(RestApiGetCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 { |
4414 | 182 if (call.IsDocumentation()) |
183 { | |
184 call.GetDocumentation() | |
185 .SetTag("Tracking changes") | |
186 .SetSummary("List exports") | |
187 .SetDescription("For medical traceability, Orthanc can be configured to store a log of all the resources " | |
188 "that have been exported to remote modalities. In auto-routing scenarios, it is important " | |
189 "to prevent this log to grow indefinitely as incoming instances are routed. You can either " | |
190 "disable this logging by setting the option `LogExportedResources` to `false` in the " | |
191 "configuration file, or periodically clear this log by `DELETE`-ing this URI. This route " | |
192 "might be removed in future versions of Orthanc.") | |
193 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false) | |
194 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false) | |
195 .AddAnswerType(MimeType_Json, "The list of exports"); | |
196 return; | |
197 } | |
198 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 ServerContext& context = OrthancRestApi::GetContext(call); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
201 int64_t since, to; |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 unsigned int limit; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 bool last; |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
204 GetSinceToAndLimit(since, to, limit, last, call); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 Json::Value result; |
1247 | 207 if (last) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 { |
1247 | 209 context.GetIndex().GetLastExportedResource(result); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 } |
1247 | 211 else |
212 { | |
213 context.GetIndex().GetExportedResources(result, since, limit); | |
214 } | |
215 | |
216 call.GetOutput().AnswerJson(result); | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 |
974 | 220 static void DeleteExports(RestApiDeleteCall& call) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 { |
4414 | 222 if (call.IsDocumentation()) |
223 { | |
224 call.GetDocumentation() | |
225 .SetTag("Tracking changes") | |
226 .SetSummary("Clear exports") | |
227 .SetDescription("Clear the full history stored in the exports log"); | |
228 return; | |
229 } | |
230 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 OrthancRestApi::GetIndex(call).DeleteExportedResources(); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
232 call.GetOutput().AnswerBuffer("", MimeType_PlainText); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 void OrthancRestApi::RegisterChanges() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 Register("/changes", GetChanges); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 Register("/changes", DeleteChanges); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 Register("/exports", GetExports); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 Register("/exports", DeleteExports); |
5553
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
242 if (context_.GetIndex().HasExtendedApiV1()) |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
243 { |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
244 Register("/extended-api-v1/changes", GetChanges2); |
28cc06e4859a
Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents:
5485
diff
changeset
|
245 } |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 } |