annotate OrthancServer/Search/LookupResource.cpp @ 1758:318c2e83c2bd db-changes

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Oct 2015 12:53:45 +0100
parents 03b030680e3d
children 91a5d39ec665
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
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
36 #include "ListConstraint.h"
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
37 #include "RangeConstraint.h"
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
38 #include "ValueConstraint.h"
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
39 #include "WildcardConstraint.h"
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
40
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include "../../Core/OrthancException.h"
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
42 #include "../../Core/FileStorage/StorageAccessor.h"
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
43 #include "../ServerToolbox.h"
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
44 #include "../FromDcmtkBridge.h"
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
45
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 namespace Orthanc
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
49 LookupResource::Level::Level(ResourceType level) : level_(level)
1749
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 const DicomTag* tags = NULL;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 size_t size;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 LookupIdentifierQuery::LoadIdentifiers(tags, size, level);
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 for (size_t i = 0; i < size; i++)
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 identifiers_.insert(tags[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
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 DicomMap::LoadMainDicomTags(tags, size, level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 for (size_t i = 0; i < size; i++)
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 if (identifiers_.find(tags[i]) == identifiers_.end())
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 mainTags_.insert(tags[i]);
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 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 LookupResource::Level::~Level()
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 for (Constraints::iterator it = mainTagsConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 it != mainTagsConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
77 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
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 for (Constraints::iterator it = identifiersConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 it != identifiersConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
83 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
87 bool LookupResource::Level::Add(const DicomTag& tag,
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
88 std::auto_ptr<IFindConstraint>& constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
90 if (identifiers_.find(tag) != identifiers_.end())
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
92 if (level_ == ResourceType_Patient)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
93 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
94 // 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
95 identifiersConstraints_[tag] = constraint->Clone();
1750
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 else
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
98 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
99 identifiersConstraints_[tag] = constraint.release();
1750
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
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
104 else if (mainTags_.find(tag) != mainTags_.end())
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
106 if (level_ == ResourceType_Patient)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
107 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
108 // 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
109 mainTagsConstraints_[tag] = constraint->Clone();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
110 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
111 else
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
112 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
113 mainTagsConstraints_[tag] = constraint.release();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
114 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
115
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return true;
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 else
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 return false;
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 }
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
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 LookupResource::LookupResource(ResourceType level) : level_(level)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 switch (level)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 case ResourceType_Patient:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 levels_[ResourceType_Patient] = new Level(ResourceType_Patient);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 break;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 case ResourceType_Study:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 levels_[ResourceType_Study] = new Level(ResourceType_Study);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 // Do not add "break" here
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 case ResourceType_Series:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 levels_[ResourceType_Series] = new Level(ResourceType_Series);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 // Do not add "break" here
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 case ResourceType_Instance:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 levels_[ResourceType_Instance] = new Level(ResourceType_Instance);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 break;
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 default:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 throw OrthancException(ErrorCode_InternalError);
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 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
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 LookupResource::~LookupResource()
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 for (Levels::iterator it = levels_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 it != levels_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 delete it->second;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
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 for (Constraints::iterator it = unoptimizedConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 it != unoptimizedConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
162 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
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
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 bool LookupResource::AddInternal(ResourceType level,
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
169 const DicomTag& tag,
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 std::auto_ptr<IFindConstraint>& constraint)
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 Levels::iterator it = levels_.find(level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 if (it != levels_.end())
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
175 if (it->second->Add(tag, constraint))
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 return true;
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 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 return false;
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
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 void LookupResource::Add(const DicomTag& tag,
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
186 IFindConstraint* constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 std::auto_ptr<IFindConstraint> c(constraint);
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 if (!AddInternal(ResourceType_Patient, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
191 !AddInternal(ResourceType_Study, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
192 !AddInternal(ResourceType_Series, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
193 !AddInternal(ResourceType_Instance, tag, c))
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
195 unoptimizedConstraints_[tag] = c.release();
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
200 static bool Match(const DicomMap& tags,
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
201 const DicomTag& tag,
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
202 const IFindConstraint& constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
204 const DicomValue* value = tags.TestAndGetValue(tag);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
205
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
206 if (value == NULL ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
207 value->IsNull() ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
208 value->IsBinary())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
209 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
210 return false;
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 else
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
214 return constraint.Match(value->GetContent());
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
215 }
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
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
218
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
219 void LookupResource::Level::Apply(SetOfResources& candidates,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
220 IDatabaseWrapper& database) const
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
221 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
222 // First, use the indexed identifiers
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
223 LookupIdentifierQuery query(level_);
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 for (Constraints::const_iterator it = identifiersConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
226 it != identifiersConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
227 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
228 it->second->Setup(query, it->first);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
229 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
230
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
231 query.Apply(candidates, database);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
233 /*{
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
234 query.Print(std::cout);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
235 std::list<int64_t> source;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
236 candidates.Flatten(source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
237 printf("=> %d\n", source.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
238 }*/
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
239
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
240 // Secondly, filter using the main DICOM tags
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
241 if (!identifiersConstraints_.empty() ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
242 !mainTagsConstraints_.empty())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
243 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
244 std::list<int64_t> source;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
245 candidates.Flatten(source);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
246 candidates.Clear();
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
248 std::list<int64_t> filtered;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
249 for (std::list<int64_t>::const_iterator candidate = source.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
250 candidate != source.end(); ++candidate)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
252 DicomMap tags;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
253 database.GetMainDicomTags(tags, *candidate);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
254
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
255 bool match = true;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
256
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
257 // Re-apply the identifier constraints, as their "Setup"
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
258 // method is less restrictive than their "Match" method
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
259 for (Constraints::const_iterator it = identifiersConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
260 match && it != identifiersConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
261 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
262 if (!Match(tags, it->first, *it->second))
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
263 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
264 match = false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
265 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
266 }
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
268 for (Constraints::const_iterator it = mainTagsConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
269 match && it != mainTagsConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
270 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
271 if (!Match(tags, it->first, *it->second))
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
272 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
273 match = false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
274 }
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 if (match)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
278 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
279 filtered.push_back(*candidate);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
280 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
281 }
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 candidates.Intersect(filtered);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
287
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
288
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
289 bool LookupResource::IsMatch(const Json::Value& dicomAsJson) const
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
290 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
291 for (Constraints::const_iterator it = unoptimizedConstraints_.begin();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
292 it != unoptimizedConstraints_.end(); ++it)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
293 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
294 std::string tag = it->first.Format();
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
295 if (dicomAsJson.isMember(tag) &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
296 dicomAsJson[tag]["Type"] == "String")
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
297 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
298 std::string value = dicomAsJson[tag]["Value"].asString();
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
299 if (!it->second->Match(value))
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
300 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
301 return false;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
302 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
303 }
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
304 else
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
305 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
306 return false;
1750
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
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
310 return true;
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
311 }
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
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
314 void LookupResource::ApplyLevel(SetOfResources& candidates,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
315 ResourceType level,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
316 IDatabaseWrapper& database) const
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
317 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
318 Levels::const_iterator it = levels_.find(level);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
319 if (it != levels_.end())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
320 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
321 it->second->Apply(candidates, database);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
322 }
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
323
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
324 if (level == ResourceType_Study &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
325 modalitiesInStudy_.get() != NULL)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
326 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
327 // 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
328 // 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
329 // allowed modalities
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
330 std::list<int64_t> allStudies, matchingStudies;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
331 candidates.Flatten(allStudies);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
332
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
333 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
334 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
335 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
336 std::list<int64_t> childrenSeries;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
337 database.GetChildrenInternalId(childrenSeries, *study);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
338
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
339 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
340 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
341 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
342 DicomMap tags;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
343 database.GetMainDicomTags(tags, *series);
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 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
346 if (value != NULL &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
347 !value->IsNull() &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
348 !value->IsBinary())
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 if (modalitiesInStudy_->Match(value->GetContent()))
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 matchingStudies.push_back(*study);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
353 break;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
354 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
355 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
356 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
357 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
358
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
359 candidates.Intersect(matchingStudies);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
360 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
361 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
362
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
363
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
364 void LookupResource::FindCandidates(std::list<int64_t>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
365 IDatabaseWrapper& database) const
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
366 {
1754
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
367 ResourceType startingLevel;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
368 if (level_ == ResourceType_Patient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
369 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
370 startingLevel = ResourceType_Patient;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
371 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
372 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
373 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
374 startingLevel = ResourceType_Study;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
375 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
376
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
377 SetOfResources candidates(database, startingLevel);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
378
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
379 switch (level_)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
380 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
381 case ResourceType_Patient:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
382 ApplyLevel(candidates, ResourceType_Patient, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
383 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
384
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
385 case ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
386 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
387 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
388
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
389 case ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
390 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
391 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
392 ApplyLevel(candidates, ResourceType_Series, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
393 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
394
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
395 case ResourceType_Instance:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
396 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
397 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
398 ApplyLevel(candidates, ResourceType_Series, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
399 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
400 ApplyLevel(candidates, ResourceType_Instance, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
401 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
402
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
403 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
404 throw OrthancException(ErrorCode_InternalError);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
405 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
406
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
407 candidates.Flatten(result);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
408 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
409
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
410
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
411 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
412 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
413 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
414
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
415 std::vector<std::string> items;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
416 Toolbox::TokenizeString(items, modalities, '\\');
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 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
419 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
420 modalitiesInStudy_->AddAllowedValue(items[i]);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
421 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
422 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
423
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
424
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
425 void LookupResource::AddDicomConstraint(const DicomTag& tag,
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
426 const std::string& dicomQuery,
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
427 bool caseSensitive)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
428 {
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
429 ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag);
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
430
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
431 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
432 // 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
433 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
434 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
435 SetModalitiesInStudy(dicomQuery);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
436 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
437 else if ((vr == ValueRepresentation_Date ||
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
438 vr == ValueRepresentation_DateTime ||
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
439 vr == ValueRepresentation_Time) &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
440 dicomQuery.find('-') != std::string::npos)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
441 {
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
442 /**
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
443 * Range matching is only defined for TM, DA and DT value
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
444 * representations. This code fixes issues 35 and 37.
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
445 *
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
446 * Reference: "Range matching is not defined for types of
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
447 * Attributes other than dates and times", DICOM PS 3.4,
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
448 * C.2.2.2.5 ("Range Matching").
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
449 **/
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
450 size_t separator = dicomQuery.find('-');
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
451 std::string lower = dicomQuery.substr(0, separator);
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
452 std::string upper = dicomQuery.substr(separator + 1);
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
453 Add(tag, new RangeConstraint(lower, upper, caseSensitive));
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
454 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
455 else if (dicomQuery.find('\\') != std::string::npos)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
456 {
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
457 std::auto_ptr<ListConstraint> constraint(new ListConstraint(caseSensitive));
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
458
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
459 std::vector<std::string> items;
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
460 Toolbox::TokenizeString(items, dicomQuery, '\\');
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
461
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
462 for (size_t i = 0; i < items.size(); i++)
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
463 {
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
464 constraint->AddAllowedValue(items[i]);
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
465 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
466
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
467 Add(tag, constraint.release());
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
468 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
469 else if (dicomQuery.find('*') != std::string::npos ||
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
470 dicomQuery.find('?') != std::string::npos)
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
471 {
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
472 Add(tag, new WildcardConstraint(dicomQuery, caseSensitive));
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
473 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
474 else
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
475 {
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
476 /**
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
477 * Case-insensitive match for PN value representation (Patient
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
478 * Name). Case-senstive match for all the other value
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
479 * representations.
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
480 *
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
481 * Reference: DICOM PS 3.4
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
482 * - C.2.2.2.1 ("Single Value Matching")
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
483 * - C.2.2.2.4 ("Wild Card Matching")
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
484 * http://medical.nema.org/Dicom/2011/11_04pu.pdf
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
485 *
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
486 * "Except for Attributes with a PN Value Representation, only
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
487 * entities with values which match exactly the value specified in the
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
488 * request shall match. This matching is case-sensitive, i.e.,
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
489 * sensitive to the exact encoding of the key attribute value in
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
490 * character sets where a letter may have multiple encodings (e.g.,
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
491 * based on its case, its position in a word, or whether it is
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
492 * accented)
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
493 *
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
494 * For Attributes with a PN Value Representation (e.g., Patient Name
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
495 * (0010,0010)), an application may perform literal matching that is
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
496 * either case-sensitive, or that is insensitive to some or all
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
497 * aspects of case, position, accent, or other character encoding
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
498 * variants."
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
499 *
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
500 * (0008,0018) UI SOPInstanceUID => Case-sensitive
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
501 * (0008,0050) SH AccessionNumber => Case-sensitive
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
502 * (0010,0020) LO PatientID => Case-sensitive
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
503 * (0020,000D) UI StudyInstanceUID => Case-sensitive
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
504 * (0020,000E) UI SeriesInstanceUID => Case-sensitive
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
505 **/
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
506
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
507 Add(tag, new ValueConstraint(dicomQuery, caseSensitive));
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
508 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
509 }
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }