annotate OrthancServer/Resources/Graveyard/DatabaseOptimizations/LookupResource.cpp @ 4831:7053502fbf97

added copyright UCLouvain
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 19:01:11 +0100
parents d9473bd5ed43
children 2e71a08eea15 43e613a7756b
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
4831
7053502fbf97 added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * License, or (at your option) any later version.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * 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
22 * 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
23 * in the program, then also delete it here.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * 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
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * General Public License for more details.
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 *
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * 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
31 * 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
32 **/
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../PrecompiledHeadersServer.h"
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "LookupResource.h"
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../../Core/OrthancException.h"
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
39 #include "../../Core/FileStorage/StorageAccessor.h"
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
40 #include "../ServerToolbox.h"
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
41 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
42
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 namespace Orthanc
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
46 static bool DoesDicomMapMatch(const DicomMap& dicom,
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
47 const DicomTag& tag,
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
48 const IFindConstraint& constraint)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
49 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
50 const DicomValue* value = dicom.TestAndGetValue(tag);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
51
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
52 return (value != NULL &&
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
53 !value->IsNull() &&
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
54 !value->IsBinary() &&
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
55 constraint.Match(value->GetContent()));
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
56 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
57
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
58
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
59 LookupResource::Level::Level(ResourceType level) : level_(level)
1749
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 const DicomTag* tags = NULL;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 size_t size;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
2121
7e8889bc95c6 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2088
diff changeset
64 ServerToolbox::LoadIdentifiers(tags, size, level);
1749
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 for (size_t i = 0; i < size; i++)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 identifiers_.insert(tags[i]);
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 DicomMap::LoadMainDicomTags(tags, size, level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 for (size_t i = 0; i < size; i++)
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 if (identifiers_.find(tags[i]) == identifiers_.end())
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 mainTags_.insert(tags[i]);
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 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 LookupResource::Level::~Level()
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 for (Constraints::iterator it = mainTagsConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 it != mainTagsConstraints_.end(); ++it)
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 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 for (Constraints::iterator it = identifiersConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 it != identifiersConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
93 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
97 bool LookupResource::Level::Add(const DicomTag& tag,
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
98 std::auto_ptr<IFindConstraint>& constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
100 if (identifiers_.find(tag) != identifiers_.end())
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
102 if (level_ == ResourceType_Patient)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
103 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
104 // 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
105 identifiersConstraints_[tag] = constraint->Clone();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
106 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
107 else
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
108 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
109 identifiersConstraints_[tag] = constraint.release();
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
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
114 else if (mainTags_.find(tag) != mainTags_.end())
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
116 if (level_ == ResourceType_Patient)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
117 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
118 // 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
119 mainTagsConstraints_[tag] = constraint->Clone();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
120 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
121 else
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
122 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
123 mainTagsConstraints_[tag] = constraint.release();
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
124 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
125
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 else
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
3005
8265a6b56100 DicomMap::FromDicomAsJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
130 // This is not a main DICOM tag
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 return false;
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 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
136 bool LookupResource::Level::IsMatch(const DicomMap& dicom) const
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
137 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
138 for (Constraints::const_iterator it = identifiersConstraints_.begin();
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
139 it != identifiersConstraints_.end(); ++it)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
140 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
141 assert(it->second != NULL);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
142
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
143 if (!DoesDicomMapMatch(dicom, it->first, *it->second))
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
144 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
145 return false;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
146 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
147 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
148
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
149 for (Constraints::const_iterator it = mainTagsConstraints_.begin();
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
150 it != mainTagsConstraints_.end(); ++it)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
151 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
152 assert(it->second != NULL);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
153
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
154 if (!DoesDicomMapMatch(dicom, it->first, *it->second))
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
155 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
156 return false;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
157 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
158 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
159
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
160 return true;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
161 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
162
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
163
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 LookupResource::LookupResource(ResourceType level) : level_(level)
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 switch (level)
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 case ResourceType_Patient:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 levels_[ResourceType_Patient] = new Level(ResourceType_Patient);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 break;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
2088
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
172 case ResourceType_Instance:
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
173 levels_[ResourceType_Instance] = new Level(ResourceType_Instance);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 // Do not add "break" here
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 case ResourceType_Series:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 levels_[ResourceType_Series] = new Level(ResourceType_Series);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 // Do not add "break" here
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
2088
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
180 case ResourceType_Study:
b9428d5f7eaf Fix serious performance issue with C-FIND
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
181 levels_[ResourceType_Study] = new Level(ResourceType_Study);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 break;
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 default:
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 throw OrthancException(ErrorCode_InternalError);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
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
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 LookupResource::~LookupResource()
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 for (Levels::iterator it = levels_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 it != levels_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 delete it->second;
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 for (Constraints::iterator it = unoptimizedConstraints_.begin();
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 it != unoptimizedConstraints_.end(); ++it)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
201 delete it->second;
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 bool LookupResource::AddInternal(ResourceType level,
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
208 const DicomTag& tag,
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 std::auto_ptr<IFindConstraint>& constraint)
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 Levels::iterator it = levels_.find(level);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 if (it != levels_.end())
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
214 if (it->second->Add(tag, constraint))
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 return true;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 return false;
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
224 void LookupResource::Add(const DicomTag& tag,
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
225 IFindConstraint* constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 std::auto_ptr<IFindConstraint> c(constraint);
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
229 if (!AddInternal(ResourceType_Patient, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
230 !AddInternal(ResourceType_Study, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
231 !AddInternal(ResourceType_Series, tag, c) &&
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
232 !AddInternal(ResourceType_Instance, tag, c))
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
234 unoptimizedConstraints_[tag] = c.release();
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
239 static bool Match(const DicomMap& tags,
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
240 const DicomTag& tag,
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
241 const IFindConstraint& constraint)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
243 const DicomValue* value = tags.TestAndGetValue(tag);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
244
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
245 if (value == NULL ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
246 value->IsNull() ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
247 value->IsBinary())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
248 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
249 return false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
250 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
251 else
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
253 return constraint.Match(value->GetContent());
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 }
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
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
258 void LookupResource::Level::Apply(SetOfResources& candidates,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
259 IDatabaseWrapper& database) const
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 // First, use the indexed identifiers
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
262 LookupIdentifierQuery query(level_);
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 for (Constraints::const_iterator it = identifiersConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
265 it != identifiersConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
266 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
267 it->second->Setup(query, it->first);
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
268 }
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 query.Apply(candidates, database);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
272 /*{
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
273 query.Print(std::cout);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
274 std::list<int64_t> source;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
275 candidates.Flatten(source);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
276 printf("=> %d\n", source.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
277 }*/
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
278
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
279 // Secondly, filter using the main DICOM tags
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
280 if (!identifiersConstraints_.empty() ||
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
281 !mainTagsConstraints_.empty())
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 std::list<int64_t> source;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
284 candidates.Flatten(source);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
285 candidates.Clear();
1749
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 std::list<int64_t> filtered;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
288 for (std::list<int64_t>::const_iterator candidate = source.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
289 candidate != source.end(); ++candidate)
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
291 DicomMap tags;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
292 database.GetMainDicomTags(tags, *candidate);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
293
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
294 bool match = true;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
295
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
296 // Re-apply the identifier constraints, as their "Setup"
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
297 // method is less restrictive than their "Match" method
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
298 for (Constraints::const_iterator it = identifiersConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
299 match && it != identifiersConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
300 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
301 if (!Match(tags, it->first, *it->second))
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 match = false;
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
304 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
305 }
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
307 for (Constraints::const_iterator it = mainTagsConstraints_.begin();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
308 match && it != mainTagsConstraints_.end(); ++it)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
309 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
310 if (!Match(tags, it->first, *it->second))
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 match = false;
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 }
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 if (match)
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 filtered.push_back(*candidate);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
319 }
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
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
322 candidates.Intersect(filtered);
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
326
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
327
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
328 bool LookupResource::IsMatch(const DicomMap& dicom) const
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
329 {
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
330 for (Levels::const_iterator it = levels_.begin(); it != levels_.end(); ++it)
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
331 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
332 if (!it->second->IsMatch(dicom))
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
333 {
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
334 return false;
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
335 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
336 }
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
337
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
338 for (Constraints::const_iterator it = unoptimizedConstraints_.begin();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
339 it != unoptimizedConstraints_.end(); ++it)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
340 {
3012
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
341 assert(it->second != NULL);
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
342
af1530b45290 Optimization: On finds, do not read JSON (disk) if main DICOM tags (DB) are sufficient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3005
diff changeset
343 if (!DoesDicomMapMatch(dicom, it->first, *it->second))
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
344 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
345 return false;
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
346 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
347 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
348
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
349 return true;
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
350 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
351
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
352
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
353 void LookupResource::ApplyLevel(SetOfResources& candidates,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
354 ResourceType level,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
355 IDatabaseWrapper& database) const
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 Levels::const_iterator it = levels_.find(level);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
358 if (it != levels_.end())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
359 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
360 it->second->Apply(candidates, database);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
361 }
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
362
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
363 if (level == ResourceType_Study &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
364 modalitiesInStudy_.get() != NULL)
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
365 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
366 // 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
367 // 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
368 // allowed modalities
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
369 std::list<int64_t> allStudies, matchingStudies;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
370 candidates.Flatten(allStudies);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
371
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
372 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
373 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
374 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
375 std::list<int64_t> childrenSeries;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
376 database.GetChildrenInternalId(childrenSeries, *study);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
377
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
378 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
379 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
380 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
381 DicomMap tags;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
382 database.GetMainDicomTags(tags, *series);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
383
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
384 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
385 if (value != NULL &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
386 !value->IsNull() &&
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
387 !value->IsBinary())
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
388 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
389 if (modalitiesInStudy_->Match(value->GetContent()))
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
390 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
391 matchingStudies.push_back(*study);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
392 break;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
393 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
394 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
395 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
396 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
397
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
398 candidates.Intersect(matchingStudies);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
399 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
400 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
401
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
402
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
403 void LookupResource::FindCandidates(std::list<int64_t>& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
404 IDatabaseWrapper& database) const
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
405 {
1754
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
406 ResourceType startingLevel;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
407 if (level_ == ResourceType_Patient)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
408 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
409 startingLevel = ResourceType_Patient;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
410 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
411 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
412 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
413 startingLevel = ResourceType_Study;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
414 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
415
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1753
diff changeset
416 SetOfResources candidates(database, startingLevel);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
417
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
418 switch (level_)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
419 {
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
420 case ResourceType_Patient:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
421 ApplyLevel(candidates, ResourceType_Patient, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
422 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
423
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
424 case ResourceType_Study:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
425 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
426 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
427
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
428 case ResourceType_Series:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
429 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
430 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
431 ApplyLevel(candidates, ResourceType_Series, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
432 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
433
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
434 case ResourceType_Instance:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
435 ApplyLevel(candidates, ResourceType_Study, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
436 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
437 ApplyLevel(candidates, ResourceType_Series, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
438 candidates.GoDown();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
439 ApplyLevel(candidates, ResourceType_Instance, database);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
440 break;
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
441
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
442 default:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
443 throw OrthancException(ErrorCode_InternalError);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
444 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
445
1753
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1751
diff changeset
446 candidates.Flatten(result);
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
447 }
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
448
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
449
1755
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
450 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
451 {
1756
03b030680e3d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1755
diff changeset
452 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
453
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
454 std::vector<std::string> items;
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
455 Toolbox::TokenizeString(items, modalities, '\\');
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
456
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
457 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
458 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
459 modalitiesInStudy_->AddAllowedValue(items[i]);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
460 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
461 }
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
462
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
463
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
464 void LookupResource::AddDicomConstraint(const DicomTag& tag,
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
465 const std::string& dicomQuery,
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1756
diff changeset
466 bool caseSensitive)
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
467 {
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
468 // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
469 // 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
470 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
471 {
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
472 SetModalitiesInStudy(dicomQuery);
39c37a994b2f handling of DICOM_TAG_MODALITIES_IN_STUDY
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
473 }
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
474 else
1751
fb569ee09a69 LookupResource complete
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
475 {
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
476 Add(tag, IFindConstraint::ParseDicomConstraint(tag, dicomQuery, caseSensitive));
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
477 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1749
diff changeset
478 }
1791
91a5d39ec665 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1758
diff changeset
479
1749
99f4a05f39fa various types of constraints
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 }