annotate OrthancServer/Search/LookupIdentifierQuery.cpp @ 2240:df47c45694ed

improvement
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Dec 2016 17:50:51 +0100
parents 7e8889bc95c6
children a3a65de1840f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1764
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
1747
ca69082ab200 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
33 #include "../PrecompiledHeadersServer.h"
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "LookupIdentifierQuery.h"
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1747
ca69082ab200 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
36 #include "../../Core/OrthancException.h"
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
37 #include "SetOfResources.h"
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
38 #include "../FromDcmtkBridge.h"
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <cassert>
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 namespace Orthanc
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
46 LookupIdentifierQuery::Disjunction::~Disjunction()
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
47 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
48 for (size_t i = 0; i < disjunction_.size(); i++)
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
49 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
50 delete disjunction_[i];
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
51 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
52 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
53
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
54
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
55 void LookupIdentifierQuery::Disjunction::Add(const DicomTag& tag,
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
56 IdentifierConstraintType type,
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
57 const std::string& value)
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
58 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
59 disjunction_.push_back(new Constraint(tag, type, value));
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
60 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
61
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
62
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
63 LookupIdentifierQuery::~LookupIdentifierQuery()
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
64 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
65 for (Constraints::iterator it = constraints_.begin();
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
66 it != constraints_.end(); ++it)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
67 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
68 delete *it;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
69 }
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
70 }
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
71
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
72
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 void LookupIdentifierQuery::AddConstraint(DicomTag tag,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 IdentifierConstraintType type,
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 const std::string& value)
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 assert(IsIdentifier(tag));
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
78 constraints_.push_back(new Disjunction);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
79 constraints_.back()->Add(tag, type, value);
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
83 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction()
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
85 constraints_.push_back(new Disjunction);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1748
diff changeset
86 return *constraints_.back();
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
90 void LookupIdentifierQuery::Apply(std::list<std::string>& result,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
91 IDatabaseWrapper& database)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
92 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
93 SetOfResources resources(database, level_);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
94 Apply(resources, database);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
95
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
96 resources.Flatten(result);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
97 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
98
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
99
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
100 void LookupIdentifierQuery::Apply(SetOfResources& result,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
101 IDatabaseWrapper& database)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
102 {
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
103 for (size_t i = 0; i < GetSize(); i++)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
104 {
1748
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
105 std::list<int64_t> a;
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
106
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
107 for (size_t j = 0; j < constraints_[i]->GetSize(); j++)
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
108 {
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
109 const Constraint& constraint = constraints_[i]->GetConstraint(j);
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
110 std::list<int64_t> b;
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
111 database.LookupIdentifier(b, level_, constraint.GetTag(), constraint.GetType(), constraint.GetValue());
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
112
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
113 a.splice(a.end(), b);
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
114 }
92203f713205 IFindConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1747
diff changeset
115
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
116 result.Intersect(a);
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
117 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
118 }
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
119
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
120
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
121 void LookupIdentifierQuery::Print(std::ostream& s) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
122 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
123 s << "Constraint: " << std::endl;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
124 for (Constraints::const_iterator
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
125 it = constraints_.begin(); it != constraints_.end(); ++it)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
126 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
127 if (it == constraints_.begin())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
128 s << " ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
129 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
130 s << "OR ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
131
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
132 for (size_t j = 0; j < (*it)->GetSize(); j++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
133 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
134 const Constraint& c = (*it)->GetConstraint(j);
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
135 s << FromDcmtkBridge::GetTagName(c.GetTag(), "");
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
136
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
137 switch (c.GetType())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
138 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
139 case IdentifierConstraintType_Equal: s << " == "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
140 case IdentifierConstraintType_SmallerOrEqual: s << " <= "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
141 case IdentifierConstraintType_GreaterOrEqual: s << " >= "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
142 case IdentifierConstraintType_Wildcard: s << " ~= "; break;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
143 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
144 s << " ? ";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
145 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
146
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
147 s << c.GetValue() << std::endl;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
148 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
149 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
150 }
1745
38dda23c7d7d LookupIdentifierQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }