annotate OrthancServer/Search/LookupResource.cpp @ 2112:82461d1e8e17

removal warning with MSVC
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Oct 2016 11:32:38 +0200
parents b9428d5f7eaf
children 7e8889bc95c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1791
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
99f4a05f39fa various types of constraints
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
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "../PrecompiledHeadersServer.h"
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "LookupResource.h"
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../../Core/OrthancException.h"
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
37 #include "../../Core/FileStorage/StorageAccessor.h"
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
38 #include "../ServerToolbox.h"
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
39 #include "../FromDcmtkBridge.h"
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
40
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace Orthanc
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
44 LookupResource::Level::Level(ResourceType level) : level_(level)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 const DicomTag* tags = NULL;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 size_t size;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 LookupIdentifierQuery::LoadIdentifiers(tags, size, level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 for (size_t i = 0; i < size; i++)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 identifiers_.insert(tags[i]);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 DicomMap::LoadMainDicomTags(tags, size, level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 for (size_t i = 0; i < size; i++)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (identifiers_.find(tags[i]) == identifiers_.end())
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 mainTags_.insert(tags[i]);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 LookupResource::Level::~Level()
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 for (Constraints::iterator it = mainTagsConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 it != mainTagsConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
72 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 for (Constraints::iterator it = identifiersConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 it != identifiersConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
78 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
82 bool LookupResource::Level::Add(const DicomTag& tag,
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
83 std::auto_ptr<IFindConstraint>& constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
85 if (identifiers_.find(tag) != identifiers_.end())
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
87 if (level_ == ResourceType_Patient)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
88 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
89 // The filters on the patient level must be cloned to the study level
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
90 identifiersConstraints_[tag] = constraint->Clone();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
91 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
92 else
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
93 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
94 identifiersConstraints_[tag] = constraint.release();
1750
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
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
99 else if (mainTags_.find(tag) != mainTags_.end())
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
101 if (level_ == ResourceType_Patient)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
102 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
103 // The filters on the patient level must be cloned to the study level
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
104 mainTagsConstraints_[tag] = constraint->Clone();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
105 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
106 else
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
107 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
108 mainTagsConstraints_[tag] = constraint.release();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
109 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
110
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 else
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return false;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 LookupResource::LookupResource(ResourceType level) : level_(level)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 switch (level)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 case ResourceType_Patient:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 levels_[ResourceType_Patient] = new Level(ResourceType_Patient);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 break;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
2088
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
128 case ResourceType_Instance:
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
129 levels_[ResourceType_Instance] = new Level(ResourceType_Instance);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 // Do not add "break" here
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 case ResourceType_Series:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 levels_[ResourceType_Series] = new Level(ResourceType_Series);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 // Do not add "break" here
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
2088
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
136 case ResourceType_Study:
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
137 levels_[ResourceType_Study] = new Level(ResourceType_Study);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 break;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 default:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 throw OrthancException(ErrorCode_InternalError);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 LookupResource::~LookupResource()
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 for (Levels::iterator it = levels_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 it != levels_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 delete it->second;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 for (Constraints::iterator it = unoptimizedConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 it != unoptimizedConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
157 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 bool LookupResource::AddInternal(ResourceType level,
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
164 const DicomTag& tag,
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 std::auto_ptr<IFindConstraint>& constraint)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 Levels::iterator it = levels_.find(level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 if (it != levels_.end())
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
170 if (it->second->Add(tag, constraint))
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 return false;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
180 void LookupResource::Add(const DicomTag& tag,
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
181 IFindConstraint* constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 std::auto_ptr<IFindConstraint> c(constraint);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
185 if (!AddInternal(ResourceType_Patient, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
186 !AddInternal(ResourceType_Study, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
187 !AddInternal(ResourceType_Series, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
188 !AddInternal(ResourceType_Instance, tag, c))
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
190 unoptimizedConstraints_[tag] = c.release();
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
195 static bool Match(const DicomMap& tags,
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
196 const DicomTag& tag,
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
197 const IFindConstraint& constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
199 const DicomValue* value = tags.TestAndGetValue(tag);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
200
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
201 if (value == NULL ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
202 value->IsNull() ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
203 value->IsBinary())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
204 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
205 return false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
206 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
207 else
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
209 return constraint.Match(value->GetContent());
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
210 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
211 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
212
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
213
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
214 void LookupResource::Level::Apply(SetOfResources& candidates,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
215 IDatabaseWrapper& database) const
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
216 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
217 // First, use the indexed identifiers
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
218 LookupIdentifierQuery query(level_);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
219
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
220 for (Constraints::const_iterator it = identifiersConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
221 it != identifiersConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
222 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
223 it->second->Setup(query, it->first);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
224 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
225
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
226 query.Apply(candidates, database);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
228 /*{
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
229 query.Print(std::cout);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
230 std::list<int64_t> source;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
231 candidates.Flatten(source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
232 printf("=> %d\n", source.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
233 }*/
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
234
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
235 // Secondly, filter using the main DICOM tags
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
236 if (!identifiersConstraints_.empty() ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
237 !mainTagsConstraints_.empty())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
238 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
239 std::list<int64_t> source;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
240 candidates.Flatten(source);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
241 candidates.Clear();
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
243 std::list<int64_t> filtered;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
244 for (std::list<int64_t>::const_iterator candidate = source.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
245 candidate != source.end(); ++candidate)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
247 DicomMap tags;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
248 database.GetMainDicomTags(tags, *candidate);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
249
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
250 bool match = true;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
251
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
252 // Re-apply the identifier constraints, as their "Setup"
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
253 // method is less restrictive than their "Match" method
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
254 for (Constraints::const_iterator it = identifiersConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
255 match && it != identifiersConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
256 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
257 if (!Match(tags, it->first, *it->second))
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
258 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
259 match = false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
260 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
261 }
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
263 for (Constraints::const_iterator it = mainTagsConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
264 match && it != mainTagsConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
265 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
266 if (!Match(tags, it->first, *it->second))
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
267 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
268 match = false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
269 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
270 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
271
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
272 if (match)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
273 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
274 filtered.push_back(*candidate);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
275 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
276 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
277
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
278 candidates.Intersect(filtered);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
282
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
283
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
284 bool LookupResource::IsMatch(const Json::Value& dicomAsJson) const
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
285 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
286 for (Constraints::const_iterator it = unoptimizedConstraints_.begin();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
287 it != unoptimizedConstraints_.end(); ++it)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
288 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
289 std::string tag = it->first.Format();
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
290 if (dicomAsJson.isMember(tag) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
291 dicomAsJson[tag]["Type"] == "String")
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
292 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
293 std::string value = dicomAsJson[tag]["Value"].asString();
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
294 if (!it->second->Match(value))
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
295 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
296 return false;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
297 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
298 }
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
299 else
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
300 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
301 return false;
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
302 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
303 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
304
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
305 return true;
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
306 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
307
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
308
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
309 void LookupResource::ApplyLevel(SetOfResources& candidates,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
310 ResourceType level,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
311 IDatabaseWrapper& database) const
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
312 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
313 Levels::const_iterator it = levels_.find(level);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
314 if (it != levels_.end())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
315 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
316 it->second->Apply(candidates, database);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
317 }
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
318
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
319 if (level == ResourceType_Study &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
320 modalitiesInStudy_.get() != NULL)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
321 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
322 // There is a constraint on the "ModalitiesInStudy" DICOM
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
323 // extension. Check out whether one child series has one of the
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
324 // allowed modalities
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
325 std::list<int64_t> allStudies, matchingStudies;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
326 candidates.Flatten(allStudies);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
327
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
328 for (std::list<int64_t>::const_iterator
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
329 study = allStudies.begin(); study != allStudies.end(); ++study)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
330 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
331 std::list<int64_t> childrenSeries;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
332 database.GetChildrenInternalId(childrenSeries, *study);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
333
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
334 for (std::list<int64_t>::const_iterator
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
335 series = childrenSeries.begin(); series != childrenSeries.end(); ++series)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
336 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
337 DicomMap tags;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
338 database.GetMainDicomTags(tags, *series);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
339
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
340 const DicomValue* value = tags.TestAndGetValue(DICOM_TAG_MODALITY);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
341 if (value != NULL &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
342 !value->IsNull() &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
343 !value->IsBinary())
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
344 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
345 if (modalitiesInStudy_->Match(value->GetContent()))
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
346 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
347 matchingStudies.push_back(*study);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
348 break;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
349 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
350 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
351 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
352 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
353
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
354 candidates.Intersect(matchingStudies);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
355 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
356 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
357
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
358
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
359 void LookupResource::FindCandidates(std::list<int64_t>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
360 IDatabaseWrapper& database) const
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
361 {
1754
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
362 ResourceType startingLevel;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
363 if (level_ == ResourceType_Patient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
364 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
365 startingLevel = ResourceType_Patient;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
366 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
367 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
368 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
369 startingLevel = ResourceType_Study;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
370 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
371
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
372 SetOfResources candidates(database, startingLevel);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
373
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
374 switch (level_)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
375 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
376 case ResourceType_Patient:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
377 ApplyLevel(candidates, ResourceType_Patient, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
378 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
379
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
380 case ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
381 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
382 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
383
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
384 case ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
385 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
386 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
387 ApplyLevel(candidates, ResourceType_Series, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
388 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
389
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
390 case ResourceType_Instance:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
391 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
392 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
393 ApplyLevel(candidates, ResourceType_Series, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
394 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
395 ApplyLevel(candidates, ResourceType_Instance, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
396 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
397
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
398 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
399 throw OrthancException(ErrorCode_InternalError);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
400 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
401
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
402 candidates.Flatten(result);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
403 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
404
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
405
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
406 void LookupResource::SetModalitiesInStudy(const std::string& modalities)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
407 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
408 modalitiesInStudy_.reset(new ListConstraint(true /* case sensitive */));
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
409
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
410 std::vector<std::string> items;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
411 Toolbox::TokenizeString(items, modalities, '\\');
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
412
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
413 for (size_t i = 0; i < items.size(); i++)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
414 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
415 modalitiesInStudy_->AddAllowedValue(items[i]);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
416 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
417 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
418
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
419
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
420 void LookupResource::AddDicomConstraint(const DicomTag& tag,
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
421 const std::string& dicomQuery,
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
422 bool caseSensitive)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
423 {
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
424 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
425 // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
426 if (tag == DICOM_TAG_MODALITIES_IN_STUDY)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
427 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
428 SetModalitiesInStudy(dicomQuery);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
429 }
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
430 else
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
431 {
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
432 Add(tag, IFindConstraint::ParseDicomConstraint(tag, dicomQuery, caseSensitive));
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
433 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
434 }
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
435
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }