comparison OrthancServer/Search/LookupIdentifierQuery.h @ 1747:ca69082ab200 db-changes

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 26 Oct 2015 16:58:11 +0100
parents OrthancServer/LookupIdentifierQuery.h@d143db00a794
children 92203f713205
comparison
equal deleted inserted replaced
1746:d143db00a794 1747:ca69082ab200
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * In addition, as a special exception, the copyright holders of this
12 * program give permission to link the code of its release with the
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
14 * that use the same license as the "OpenSSL" library), and distribute
15 * the linked executables. You must obey the GNU General Public License
16 * in all respects for all of the code used other than "OpenSSL". If you
17 * modify file(s) with this exception, you may extend this exception to
18 * your version of the file(s), but you are not obligated to do so. If
19 * you do not wish to do so, delete this exception statement from your
20 * version. If you delete this exception statement from all source files
21 * in the program, then also delete it here.
22 *
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 **/
31
32
33 #pragma once
34
35 #include "../ServerEnumerations.h"
36 #include "../IDatabaseWrapper.h"
37
38 #include <vector>
39 #include <boost/noncopyable.hpp>
40
41 namespace Orthanc
42 {
43 /**
44 * Primitive for wildcard matching, as defined in DICOM:
45 * http://dicom.nema.org/dicom/2013/output/chtml/part04/sect_C.2.html#sect_C.2.2.2.4
46 *
47 * "Any occurrence of an "*" or a "?", then "*" shall match any
48 * sequence of characters (including a zero length value) and "?"
49 * shall match any single character. This matching is case
50 * sensitive, except for Attributes with an PN Value
51 * Representation (e.g., Patient Name (0010,0010))."
52 *
53 * Pay attention to the fact that "*" (resp. "?") generally
54 * corresponds to "%" (resp. "_") in primitive LIKE of SQL. The
55 * values "%", "_", "\" should in the user request should
56 * respectively be escaped as "\%", "\_" and "\\".
57 *
58 * This matching must be case sensitive: The special case of PN VR
59 * is taken into consideration by normalizing the query string in
60 * method "NormalizeIdentifier()".
61 **/
62
63 class LookupIdentifierQuery : public boost::noncopyable
64 {
65 private:
66 struct Constraint
67 {
68 DicomTag tag_;
69 IdentifierConstraintType type_;
70 std::string value_;
71
72 Constraint(const DicomTag& tag,
73 IdentifierConstraintType type,
74 const std::string& value) :
75 tag_(tag),
76 type_(type),
77 value_(value)
78 {
79 }
80 };
81
82 typedef std::vector<Constraint*> Constraints;
83
84 ResourceType level_;
85 Constraints constraints_;
86
87 void CheckIndex(size_t index) const;
88
89 static std::string NormalizeIdentifier(const std::string& value);
90
91 public:
92 LookupIdentifierQuery(ResourceType level) : level_(level)
93 {
94 }
95
96 ~LookupIdentifierQuery();
97
98 bool IsIdentifier(const DicomTag& tag) const;
99
100 void AddConstraint(DicomTag tag,
101 IdentifierConstraintType type,
102 const std::string& value);
103
104 ResourceType GetLevel() const
105 {
106 return level_;
107 }
108
109 size_t GetSize() const
110 {
111 return constraints_.size();
112 }
113
114 const DicomTag& GetTag(size_t index) const;
115
116 IdentifierConstraintType GetType(size_t index) const;
117
118 const std::string& GetValue(size_t index) const;
119
120 static void StoreIdentifiers(IDatabaseWrapper& database,
121 int64_t resource,
122 ResourceType level,
123 const DicomMap& map);
124
125 // The database must be locked
126 void Apply(std::list<std::string>& result,
127 IDatabaseWrapper& database);
128 };
129 }