Mercurial > hg > orthanc
annotate OrthancServer/Search/LookupIdentifierQuery.cpp @ 2544:d5ca5a5abe12
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Apr 2018 20:42:07 +0200 |
parents | 878b59270859 |
children | 1b736d151ea1 |
rev | line source |
---|---|
1745 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1745 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1745 | 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 | |
1747 | 34 #include "../PrecompiledHeadersServer.h" |
1745 | 35 #include "LookupIdentifierQuery.h" |
36 | |
1747 | 37 #include "../../Core/OrthancException.h" |
1746 | 38 #include "SetOfResources.h" |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
39 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
1745 | 40 |
41 #include <cassert> | |
42 | |
43 | |
44 | |
45 namespace Orthanc | |
46 { | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
47 LookupIdentifierQuery::Disjunction::~Disjunction() |
1748 | 48 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
49 for (size_t i = 0; i < disjunction_.size(); i++) |
1748 | 50 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
51 delete disjunction_[i]; |
1748 | 52 } |
53 } | |
54 | |
55 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
56 void LookupIdentifierQuery::Disjunction::Add(const DicomTag& tag, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
57 IdentifierConstraintType type, |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
58 const std::string& value) |
1748 | 59 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
60 disjunction_.push_back(new Constraint(tag, type, value)); |
1748 | 61 } |
62 | |
1746 | 63 |
64 LookupIdentifierQuery::~LookupIdentifierQuery() | |
65 { | |
66 for (Constraints::iterator it = constraints_.begin(); | |
67 it != constraints_.end(); ++it) | |
68 { | |
69 delete *it; | |
70 } | |
71 } | |
72 | |
73 | |
1745 | 74 void LookupIdentifierQuery::AddConstraint(DicomTag tag, |
75 IdentifierConstraintType type, | |
76 const std::string& value) | |
77 { | |
78 assert(IsIdentifier(tag)); | |
1751
fb569ee09a69
LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1750
diff
changeset
|
79 constraints_.push_back(new Disjunction); |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
80 constraints_.back()->Add(tag, type, value); |
1745 | 81 } |
82 | |
83 | |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
84 LookupIdentifierQuery::Disjunction& LookupIdentifierQuery::AddDisjunction() |
1745 | 85 { |
1749
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
86 constraints_.push_back(new Disjunction); |
99f4a05f39fa
various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1748
diff
changeset
|
87 return *constraints_.back(); |
1745 | 88 } |
89 | |
90 | |
1746 | 91 void LookupIdentifierQuery::Apply(std::list<std::string>& result, |
92 IDatabaseWrapper& database) | |
93 { | |
94 SetOfResources resources(database, level_); | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
95 Apply(resources, database); |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
96 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
97 resources.Flatten(result); |
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 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
101 void LookupIdentifierQuery::Apply(SetOfResources& result, |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
102 IDatabaseWrapper& database) |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
103 { |
1746 | 104 for (size_t i = 0; i < GetSize(); i++) |
105 { | |
1748 | 106 std::list<int64_t> a; |
107 | |
108 for (size_t j = 0; j < constraints_[i]->GetSize(); j++) | |
109 { | |
110 const Constraint& constraint = constraints_[i]->GetConstraint(j); | |
111 std::list<int64_t> b; | |
112 database.LookupIdentifier(b, level_, constraint.GetTag(), constraint.GetType(), constraint.GetValue()); | |
113 | |
114 a.splice(a.end(), b); | |
115 } | |
116 | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
117 result.Intersect(a); |
1746 | 118 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1749
diff
changeset
|
119 } |
1746 | 120 |
1758 | 121 |
122 void LookupIdentifierQuery::Print(std::ostream& s) const | |
123 { | |
124 s << "Constraint: " << std::endl; | |
125 for (Constraints::const_iterator | |
126 it = constraints_.begin(); it != constraints_.end(); ++it) | |
127 { | |
128 if (it == constraints_.begin()) | |
129 s << " "; | |
130 else | |
131 s << "OR "; | |
132 | |
133 for (size_t j = 0; j < (*it)->GetSize(); j++) | |
134 { | |
135 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
|
136 s << FromDcmtkBridge::GetTagName(c.GetTag(), ""); |
1758 | 137 |
138 switch (c.GetType()) | |
139 { | |
140 case IdentifierConstraintType_Equal: s << " == "; break; | |
141 case IdentifierConstraintType_SmallerOrEqual: s << " <= "; break; | |
142 case IdentifierConstraintType_GreaterOrEqual: s << " >= "; break; | |
143 case IdentifierConstraintType_Wildcard: s << " ~= "; break; | |
144 default: | |
145 s << " ? "; | |
146 } | |
147 | |
148 s << c.GetValue() << std::endl; | |
149 } | |
150 } | |
151 } | |
1745 | 152 } |