annotate OrthancServer/Sources/Search/DatabaseMetadataConstraint.cpp @ 5856:d1dea8ad74a6 find-refactoring

implement StorageAccessOnFind for answers
author Alain Mazy <am@orthanc.team>
date Mon, 04 Nov 2024 21:51:24 +0100
parents 7030fa489669
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5828
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
1 /**
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
8 *
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
12 * License, or (at your option) any later version.
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
13 *
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
17 * General Public License for more details.
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
18 *
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
21 **/
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
22
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
23
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
24 #include "../PrecompiledHeadersServer.h"
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
25 #include "DatabaseMetadataConstraint.h"
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
26
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
27 #include "../../../OrthancFramework/Sources/OrthancException.h"
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
28
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
29 #include <boost/lexical_cast.hpp>
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
30 #include <cassert>
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
31
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
32
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
33 namespace Orthanc
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
34 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
35 DatabaseMetadataConstraint::DatabaseMetadataConstraint(MetadataType metadata,
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
36 ConstraintType type,
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
37 const std::vector<std::string>& values,
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
38 bool caseSensitive) :
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
39 metadata_(metadata),
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
40 constraintType_(type),
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
41 values_(values),
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
42 caseSensitive_(caseSensitive)
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
43 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
44 if (type != ConstraintType_List &&
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
45 values_.size() != 1)
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
46 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
47 throw OrthancException(ErrorCode_ParameterOutOfRange);
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
48 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
49 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
50
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
51
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
52 DatabaseMetadataConstraint::DatabaseMetadataConstraint(MetadataType metadata,
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
53 ConstraintType type,
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
54 const std::string& value,
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
55 bool caseSensitive) :
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
56 metadata_(metadata),
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
57 constraintType_(type),
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
58 caseSensitive_(caseSensitive)
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
59 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
60 if (type == ConstraintType_List)
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
61 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
62 throw OrthancException(ErrorCode_ParameterOutOfRange);
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
63 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
64
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
65 values_.push_back(value);
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
66 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
67
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
68 const std::string& DatabaseMetadataConstraint::GetValue(size_t index) const
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
69 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
70 if (index >= values_.size())
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
71 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
72 throw OrthancException(ErrorCode_ParameterOutOfRange);
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
73 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
74 else
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
75 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
76 return values_[index];
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
77 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
78 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
79
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
80
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
81 const std::string& DatabaseMetadataConstraint::GetSingleValue() const
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
82 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
83 if (values_.size() != 1)
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
84 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
85 throw OrthancException(ErrorCode_BadSequenceOfCalls);
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
86 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
87 else
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
88 {
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
89 return values_[0];
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
90 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
91 }
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
92
7030fa489669 tools/find: QueryMetadata
Alain Mazy <am@orthanc.team>
parents:
diff changeset
93 }