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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
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
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
65 static void GetChanges(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
67 if (call.IsDocumentation())
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
68 {
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
69 call.GetDocumentation()
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
70 .SetTag("Tracking changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
71 .SetSummary("List changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
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.")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
73 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false)
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
74 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false)
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
75 .AddAnswerType(MimeType_Json, "The list of changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
76 .SetAnswerField("Changes", RestApiCallDocumentation::Type_JsonListOfObjects, "The individual changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
77 .SetAnswerField("Done", RestApiCallDocumentation::Type_Boolean,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
78 "Whether the last reported change is the last of the full history")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
79 .SetAnswerField("Last", RestApiCallDocumentation::Type_Number,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
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
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
82 return;
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
83 }
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
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
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
94 if (last)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
96 context.GetIndex().GetLastChange(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
98 else
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
99 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
100 context.GetIndex().GetChanges(result, since, limit);
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
101 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
102
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
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
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
162 static void DeleteChanges(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
164 if (call.IsDocumentation())
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
165 {
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
166 call.GetDocumentation()
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
167 .SetTag("Tracking changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
168 .SetSummary("Clear changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
169 .SetDescription("Clear the full history stored in the changes log");
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
170 return;
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
171 }
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
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
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
180 static void GetExports(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
182 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
183 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
184 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
185 .SetTag("Tracking changes")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
186 .SetSummary("List exports")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
187 .SetDescription("For medical traceability, Orthanc can be configured to store a log of all the resources "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
188 "that have been exported to remote modalities. In auto-routing scenarios, it is important "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
189 "to prevent this log to grow indefinitely as incoming instances are routed. You can either "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
190 "disable this logging by setting the option `LogExportedResources` to `false` in the "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
191 "configuration file, or periodically clear this log by `DELETE`-ing this URI. This route "
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
192 "might be removed in future versions of Orthanc.")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
193 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false)
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
194 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index", false)
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
195 .AddAnswerType(MimeType_Json, "The list of exports");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
196 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
197 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
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
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
207 if (last)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
209 context.GetIndex().GetLastExportedResource(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
211 else
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
212 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
213 context.GetIndex().GetExportedResources(result, since, limit);
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
214 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
215
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
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
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
220 static void DeleteExports(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
222 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
223 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
224 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
225 .SetTag("Tracking changes")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
226 .SetSummary("Clear exports")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
227 .SetDescription("Clear the full history stored in the exports log");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
228 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
229 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
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 }