comparison Framework/Plugins/DatabaseConstraint.h @ 550:9ed9a91bde33 find-refactoring

un-sharing DatabaseConstraint and ISqlLookupFormatter with Orthanc core
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Sep 2024 15:04:48 +0200
parents e620f36b8e09
children 7f45f23b10d0
comparison
equal deleted inserted replaced
546:cd9766f294fa 550:9ed9a91bde33
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-2023 Osimis S.A., Belgium
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
8 *
9 * This program is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU Affero General Public License
11 * as published by the Free Software Foundation, either version 3 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 **/
22
23
24 /**
25 * NB: Until 2024-09-09, this file was synchronized with the following
26 * folder from the Orthanc main project:
27 * https://orthanc.uclouvain.be/hg/orthanc/file/default/OrthancServer/Sources/Search/
28 **/
29
30
31 #pragma once
32
33 #include "MessagesToolbox.h"
34
35 #include <DicomFormat/DicomMap.h>
36
37 #include <deque>
38
39 namespace Orthanc
40 {
41 enum ConstraintType
42 {
43 ConstraintType_Equal,
44 ConstraintType_SmallerOrEqual,
45 ConstraintType_GreaterOrEqual,
46 ConstraintType_Wildcard,
47 ConstraintType_List
48 };
49
50 namespace Plugins
51 {
52 OrthancPluginResourceType Convert(ResourceType type);
53
54 ResourceType Convert(OrthancPluginResourceType type);
55
56 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
57 OrthancPluginConstraintType Convert(ConstraintType constraint);
58 #endif
59
60 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
61 ConstraintType Convert(OrthancPluginConstraintType constraint);
62 #endif
63 }
64
65
66 class DatabaseConstraint : public boost::noncopyable
67 {
68 private:
69 ResourceType level_;
70 DicomTag tag_;
71 bool isIdentifier_;
72 ConstraintType constraintType_;
73 std::vector<std::string> values_;
74 bool caseSensitive_;
75 bool mandatory_;
76
77 public:
78 DatabaseConstraint(ResourceType level,
79 const DicomTag& tag,
80 bool isIdentifier,
81 ConstraintType type,
82 const std::vector<std::string>& values,
83 bool caseSensitive,
84 bool mandatory);
85
86 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
87 explicit DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint);
88 #endif
89
90 #if ORTHANC_PLUGINS_HAS_INTEGRATED_FIND == 1
91 explicit DatabaseConstraint(const Orthanc::DatabasePluginMessages::DatabaseConstraint& constraint);
92 #endif
93
94 ResourceType GetLevel() const
95 {
96 return level_;
97 }
98
99 const DicomTag& GetTag() const
100 {
101 return tag_;
102 }
103
104 bool IsIdentifier() const
105 {
106 return isIdentifier_;
107 }
108
109 ConstraintType GetConstraintType() const
110 {
111 return constraintType_;
112 }
113
114 size_t GetValuesCount() const
115 {
116 return values_.size();
117 }
118
119 const std::string& GetValue(size_t index) const;
120
121 const std::string& GetSingleValue() const;
122
123 bool IsCaseSensitive() const
124 {
125 return caseSensitive_;
126 }
127
128 bool IsMandatory() const
129 {
130 return mandatory_;
131 }
132
133 bool IsMatch(const DicomMap& dicom) const;
134
135 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
136 void EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint,
137 std::vector<const char*>& tmpValues) const;
138 #endif
139 };
140
141
142 class DatabaseConstraints : public boost::noncopyable
143 {
144 private:
145 std::deque<DatabaseConstraint*> constraints_;
146
147 public:
148 ~DatabaseConstraints()
149 {
150 Clear();
151 }
152
153 void Clear();
154
155 void AddConstraint(DatabaseConstraint* constraint); // Takes ownership
156
157 bool IsEmpty() const
158 {
159 return constraints_.empty();
160 }
161
162 size_t GetSize() const
163 {
164 return constraints_.size();
165 }
166
167 const DatabaseConstraint& GetConstraint(size_t index) const;
168
169 std::string Format() const;
170 };
171 }