comparison Resources/Orthanc/Databases/DatabaseConstraint.h @ 152:063aa53b5917

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2020 08:54:32 +0200
parents
children e712ff3eede3
comparison
equal deleted inserted replaced
150:d9101318442d 152:063aa53b5917
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-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #if !defined(ORTHANC_BUILDING_SERVER_LIBRARY)
37 # error Macro ORTHANC_BUILDING_SERVER_LIBRARY must be defined
38 #endif
39
40 #if ORTHANC_BUILDING_SERVER_LIBRARY == 1
41 # include "../../../OrthancFramework/Sources/DicomFormat/DicomMap.h"
42 #else
43 // This is for the "orthanc-databases" project to reuse this file
44 # include <DicomFormat/DicomMap.h>
45 #endif
46
47 #define ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT 0
48
49 #if ORTHANC_ENABLE_PLUGINS == 1
50 # include <orthanc/OrthancCDatabasePlugin.h>
51 # if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1
52 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 2)
53 # undef ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT
54 # define ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT 1
55 # endif
56 # endif
57 #endif
58
59 namespace Orthanc
60 {
61 enum ConstraintType
62 {
63 ConstraintType_Equal,
64 ConstraintType_SmallerOrEqual,
65 ConstraintType_GreaterOrEqual,
66 ConstraintType_Wildcard,
67 ConstraintType_List
68 };
69
70 namespace Plugins
71 {
72 #if ORTHANC_ENABLE_PLUGINS == 1
73 OrthancPluginResourceType Convert(ResourceType type);
74 #endif
75
76 #if ORTHANC_ENABLE_PLUGINS == 1
77 ResourceType Convert(OrthancPluginResourceType type);
78 #endif
79
80 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
81 OrthancPluginConstraintType Convert(ConstraintType constraint);
82 #endif
83
84 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
85 ConstraintType Convert(OrthancPluginConstraintType constraint);
86 #endif
87 }
88
89
90 // This class is also used by the "orthanc-databases" project
91 class DatabaseConstraint
92 {
93 private:
94 ResourceType level_;
95 DicomTag tag_;
96 bool isIdentifier_;
97 ConstraintType constraintType_;
98 std::vector<std::string> values_;
99 bool caseSensitive_;
100 bool mandatory_;
101
102 public:
103 DatabaseConstraint(ResourceType level,
104 const DicomTag& tag,
105 bool isIdentifier,
106 ConstraintType type,
107 const std::vector<std::string>& values,
108 bool caseSensitive,
109 bool mandatory);
110
111 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
112 DatabaseConstraint(const OrthancPluginDatabaseConstraint& constraint);
113 #endif
114
115 ResourceType GetLevel() const
116 {
117 return level_;
118 }
119
120 const DicomTag& GetTag() const
121 {
122 return tag_;
123 }
124
125 bool IsIdentifier() const
126 {
127 return isIdentifier_;
128 }
129
130 ConstraintType GetConstraintType() const
131 {
132 return constraintType_;
133 }
134
135 size_t GetValuesCount() const
136 {
137 return values_.size();
138 }
139
140 const std::string& GetValue(size_t index) const;
141
142 const std::string& GetSingleValue() const;
143
144 bool IsCaseSensitive() const
145 {
146 return caseSensitive_;
147 }
148
149 bool IsMandatory() const
150 {
151 return mandatory_;
152 }
153
154 bool IsMatch(const DicomMap& dicom) const;
155
156 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
157 void EncodeForPlugins(OrthancPluginDatabaseConstraint& constraint,
158 std::vector<const char*>& tmpValues) const;
159 #endif
160 };
161 }