comparison OrthancServer/Sources/Database/OrthancIdentifiers.cpp @ 5554:12d8a1a266e9 find-refactoring

introduction of FindRequest and FindResponse
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Apr 2024 16:13:24 +0200
parents
children 3f13db27b399
comparison
equal deleted inserted replaced
5549:dcbf0c776945 5554:12d8a1a266e9
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22
23 #include "FindRequest.h"
24
25 #include "../../../OrthancFramework/Sources/OrthancException.h"
26
27
28 namespace Orthanc
29 {
30 OrthancIdentifiers::OrthancIdentifiers(const OrthancIdentifiers& other)
31 {
32 if (other.HasPatientId())
33 {
34 SetPatientId(other.GetPatientId());
35 }
36
37 if (other.HasStudyId())
38 {
39 SetStudyId(other.GetStudyId());
40 }
41
42 if (other.HasSeriesId())
43 {
44 SetSeriesId(other.GetSeriesId());
45 }
46
47 if (other.HasInstanceId())
48 {
49 SetInstanceId(other.GetInstanceId());
50 }
51 }
52
53
54 void OrthancIdentifiers::SetPatientId(const std::string& id)
55 {
56 if (HasPatientId())
57 {
58 throw OrthancException(ErrorCode_BadSequenceOfCalls);
59 }
60 else
61 {
62 patientId_.reset(new std::string(id));
63 }
64 }
65
66
67 const std::string& OrthancIdentifiers::GetPatientId() const
68 {
69 if (HasPatientId())
70 {
71 return *patientId_;
72 }
73 else
74 {
75 throw OrthancException(ErrorCode_BadSequenceOfCalls);
76 }
77 }
78
79
80 void OrthancIdentifiers::SetStudyId(const std::string& id)
81 {
82 if (HasStudyId())
83 {
84 throw OrthancException(ErrorCode_BadSequenceOfCalls);
85 }
86 else
87 {
88 studyId_.reset(new std::string(id));
89 }
90 }
91
92
93 const std::string& OrthancIdentifiers::GetStudyId() const
94 {
95 if (HasStudyId())
96 {
97 return *studyId_;
98 }
99 else
100 {
101 throw OrthancException(ErrorCode_BadSequenceOfCalls);
102 }
103 }
104
105
106 void OrthancIdentifiers::SetSeriesId(const std::string& id)
107 {
108 if (HasSeriesId())
109 {
110 throw OrthancException(ErrorCode_BadSequenceOfCalls);
111 }
112 else
113 {
114 seriesId_.reset(new std::string(id));
115 }
116 }
117
118
119 const std::string& OrthancIdentifiers::GetSeriesId() const
120 {
121 if (HasSeriesId())
122 {
123 return *seriesId_;
124 }
125 else
126 {
127 throw OrthancException(ErrorCode_BadSequenceOfCalls);
128 }
129 }
130
131
132 void OrthancIdentifiers::SetInstanceId(const std::string& id)
133 {
134 if (HasInstanceId())
135 {
136 throw OrthancException(ErrorCode_BadSequenceOfCalls);
137 }
138 else
139 {
140 instanceId_.reset(new std::string(id));
141 }
142 }
143
144
145 const std::string& OrthancIdentifiers::GetInstanceId() const
146 {
147 if (HasInstanceId())
148 {
149 return *instanceId_;
150 }
151 else
152 {
153 throw OrthancException(ErrorCode_BadSequenceOfCalls);
154 }
155 }
156
157
158 ResourceType OrthancIdentifiers::DetectLevel() const
159 {
160 if (HasPatientId() &&
161 !HasStudyId() &&
162 !HasSeriesId() &&
163 !HasInstanceId())
164 {
165 return ResourceType_Patient;
166 }
167 else if (HasPatientId() &&
168 HasStudyId() &&
169 !HasSeriesId() &&
170 !HasInstanceId())
171 {
172 return ResourceType_Study;
173 }
174 else if (HasPatientId() &&
175 HasStudyId() &&
176 HasSeriesId() &&
177 !HasInstanceId())
178 {
179 return ResourceType_Series;
180 }
181 else if (HasPatientId() &&
182 HasStudyId() &&
183 HasSeriesId() &&
184 HasInstanceId())
185 {
186 return ResourceType_Instance;
187 }
188 else
189 {
190 throw OrthancException(ErrorCode_InexistentItem);
191 }
192 }
193
194
195 void OrthancIdentifiers::SetLevel(ResourceType level,
196 const std::string id)
197 {
198 switch (level)
199 {
200 case ResourceType_Patient:
201 SetPatientId(id);
202 break;
203
204 case ResourceType_Study:
205 SetStudyId(id);
206 break;
207
208 case ResourceType_Series:
209 SetSeriesId(id);
210 break;
211
212 case ResourceType_Instance:
213 SetInstanceId(id);
214 break;
215
216 default:
217 throw OrthancException(ErrorCode_ParameterOutOfRange);
218 }
219 }
220
221
222 std::string OrthancIdentifiers::GetLevel(ResourceType level) const
223 {
224 switch (level)
225 {
226 case ResourceType_Patient:
227 return GetPatientId();
228
229 case ResourceType_Study:
230 return GetStudyId();
231
232 case ResourceType_Series:
233 return GetSeriesId();
234
235 case ResourceType_Instance:
236 return GetInstanceId();
237
238 default:
239 throw OrthancException(ErrorCode_ParameterOutOfRange);
240 }
241 }
242 }