annotate OrthancServer/Sources/OrthancRestApi/OrthancRestChanges.cpp @ 5850:1980354c8113 find-refactoring

add level of interest to StatelessDatabaseOperations::LookupAttachment()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Oct 2024 15:03:32 +0000
parents 8a8756b2dd0b
children
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 --------------------------------------------------------------
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
32 static const unsigned int DEFAULT_LIMIT = 100;
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
33 static const int64_t DEFAULT_TO = -1;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
35 static void GetSinceToAndLimit(int64_t& since,
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
36 int64_t& to,
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
37 unsigned int& limit,
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
38 bool& last,
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
39 const RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (call.HasArgument("last"))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 last = true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
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 last = false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 try
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 since = boost::lexical_cast<int64_t>(call.GetArgument("since", "0"));
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
52 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
53 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
54 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
55 catch (boost::bad_lexical_cast&)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
3560
28ab86c6730e "/changes": Allow the "limit" argument to be greater than 100
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
57 since = 0;
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
58 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
59 limit = DEFAULT_LIMIT;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
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
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
64 static void GetChanges(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
66 if (call.IsDocumentation())
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
67 {
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
68 call.GetDocumentation()
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
69 .SetTag("Tracking changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
70 .SetSummary("List changes")
5735
Alain Mazy <am@orthanc.team>
parents: 5640
diff changeset
71 .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. Please note that, when resources are deleted, their corresponding change entries are also removed from the Changes Log, which helps ensuring that this log does not grow indefinitely.")
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
72 .SetHttpGetArgument("last", RestApiCallDocumentation::Type_Number, "Request only the last change id (this argument must be used alone)", false)
4403
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)
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
74 .SetHttpGetArgument("since", RestApiCallDocumentation::Type_Number, "Show only the resources since the provided index excluded", false)
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
75 .SetHttpGetArgument("to", RestApiCallDocumentation::Type_Number, "Show only the resources till the provided index included (only available if your DB backend supports ExtendedChanges)", false)
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
76 .SetHttpGetArgument("type", RestApiCallDocumentation::Type_String, "Show only the changes of the provided type (only available if your DB backend supports ExtendedChanges)", false)
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
77 .AddAnswerType(MimeType_Json, "The list of changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
78 .SetAnswerField("Changes", RestApiCallDocumentation::Type_JsonListOfObjects, "The individual changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
79 .SetAnswerField("Done", RestApiCallDocumentation::Type_Boolean,
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
80 "Whether the last reported change is the last of the full history.")
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
81 .SetAnswerField("Last", RestApiCallDocumentation::Type_Number,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
82 "The index of the last reported change, can be used for the `since` argument in subsequent calls to this route")
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
83 .SetAnswerField("First", RestApiCallDocumentation::Type_Number,
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
84 "The index of the first reported change, its value-1 can be used for the `to` argument in subsequent calls to this route when browsing the changes in reverse order")
5432
59e3b6f8c5be migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
85 .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
86 return;
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
87 }
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
88
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
91 int64_t since, to;
5805
8a8756b2dd0b cleanup
Alain Mazy <am@orthanc.team>
parents: 5804
diff changeset
92 std::set<ChangeType> filterType;
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
93
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 unsigned int limit;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 bool last;
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
96 GetSinceToAndLimit(since, to, limit, last, call);
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
97
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
98 std::string filterArgument = call.GetArgument("type", "all");
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
99 if (filterArgument != "all" && filterArgument != "All")
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
100 {
5804
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
101 std::set<std::string> filterTypeStrings;
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
102 Toolbox::SplitString(filterTypeStrings, filterArgument, ';');
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
103
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
104 for (std::set<std::string>::const_iterator it = filterTypeStrings.begin(); it != filterTypeStrings.end(); ++it)
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
105 {
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
106 filterType.insert(StringToChangeType(*it));
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
107 }
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
108 }
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 Json::Value result;
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
111 if (last)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
113 context.GetIndex().GetLastChange(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
115 else if (context.GetIndex().HasExtendedChanges())
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
116 {
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
117 context.GetIndex().GetChangesExtended(result, since, to, limit, filterType);
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
118 }
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
119 else
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
120 {
5804
25df40a274fd /changes: allowing filtering on multiple changes
Alain Mazy <am@orthanc.team>
parents: 5758
diff changeset
121 if (filterType.size() > 0)
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
122 {
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
123 throw OrthancException(ErrorCode_ParameterOutOfRange, "CAPABILITIES: Trying to filter changes while the Database backend does not support it (requires a DB backend with support for ExtendedChanges)");
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
124 }
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
125
5757
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
126 if (to != DEFAULT_TO)
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
127 {
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
128 throw OrthancException(ErrorCode_ParameterOutOfRange, "CAPABILITIES: Trying to use the 'to' parameter in /changes while the Database backend does not support it (requires a DB backend with support for ExtendedChanges)");
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
129 }
5463c3ae3235 refactored extended /changes
Alain Mazy <am@orthanc.team>
parents: 5663
diff changeset
130
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
131 context.GetIndex().GetChanges(result, since, limit);
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
132 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
133
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
134 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
138 static void DeleteChanges(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
140 if (call.IsDocumentation())
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
141 {
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
142 call.GetDocumentation()
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
143 .SetTag("Tracking changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
144 .SetSummary("Clear changes")
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
145 .SetDescription("Clear the full history stored in the changes log");
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
146 return;
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
147 }
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
148
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 OrthancRestApi::GetIndex(call).DeleteChanges();
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
150 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 // Exports API --------------------------------------------------------------
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
156 static void GetExports(RestApiGetCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
158 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
159 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
160 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
161 .SetTag("Tracking changes")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
162 .SetSummary("List exports")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
163 .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
164 "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
165 "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
166 "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
167 "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
168 "might be removed in future versions of Orthanc.")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
169 .SetHttpGetArgument("limit", RestApiCallDocumentation::Type_Number, "Limit the number of results", false)
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
170 .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
171 .AddAnswerType(MimeType_Json, "The list of exports");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
172 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
173 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
174
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 ServerContext& context = OrthancRestApi::GetContext(call);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
177 int64_t since, to;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 unsigned int limit;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 bool last;
5553
28cc06e4859a Added ExtendedApiV1: /changes
Alain Mazy <am@orthanc.team>
parents: 5485
diff changeset
180 GetSinceToAndLimit(since, to, limit, last, call);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 Json::Value result;
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
183 if (last)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
185 context.GetIndex().GetLastExportedResource(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
187 else
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
188 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
189 context.GetIndex().GetExportedResources(result, since, limit);
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
190 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
191
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
192 call.GetOutput().AnswerJson(result);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
196 static void DeleteExports(RestApiDeleteCall& call)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
198 if (call.IsDocumentation())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
199 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
200 call.GetDocumentation()
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
201 .SetTag("Tracking changes")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
202 .SetSummary("Clear exports")
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
203 .SetDescription("Clear the full history stored in the exports log");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
204 return;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
205 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
206
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 OrthancRestApi::GetIndex(call).DeleteExportedResources();
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
208 call.GetOutput().AnswerBuffer("", MimeType_PlainText);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 void OrthancRestApi::RegisterChanges()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 Register("/changes", GetChanges);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 Register("/changes", DeleteChanges);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 Register("/exports", GetExports);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 Register("/exports", DeleteExports);
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 }