Mercurial > hg > orthanc
annotate OrthancServer/Sources/Search/DatabaseLookup.cpp @ 5227:988dab8deb1c db-protobuf
"/tools/find" accepts the "WithLabels" and "WithoutLabels" arguments
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Apr 2023 09:16:12 +0200 |
parents | df39c7583a49 |
children | 72dfa0ac84eb |
rev | line source |
---|---|
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5176
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5176
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU General Public License as |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * published by the Free Software Foundation, either version 3 of the |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * License, or (at your option) any later version. |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * General Public License for more details. |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "../PrecompiledHeadersServer.h" |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "DatabaseLookup.h" |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "../ServerToolbox.h" |
4045 | 27 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" |
28 #include "../../../OrthancFramework/Sources/DicomParsing/ToDcmtkBridge.h" | |
29 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
30 #include "../../../OrthancFramework/Sources/Toolbox.h" | |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
4304 | 32 #include <boost/lexical_cast.hpp> |
33 | |
34 | |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 namespace Orthanc |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 DatabaseLookup::~DatabaseLookup() |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 for (size_t i = 0; i < constraints_.size(); i++) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 assert(constraints_[i] != NULL); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 delete constraints_[i]; |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 const DicomTagConstraint& DatabaseLookup::GetConstraint(size_t index) const |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 if (index >= constraints_.size()) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 throw OrthancException(ErrorCode_ParameterOutOfRange); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 else |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 assert(constraints_[index] != NULL); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 return *constraints_[index]; |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
61 void DatabaseLookup::AddConstraintInternal(DicomTagConstraint* constraint) |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 if (constraint == NULL) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 throw OrthancException(ErrorCode_NullPointer); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 else |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 constraints_.push_back(constraint); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
74 bool DatabaseLookup::IsMatch(const DicomMap& value) const |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 for (size_t i = 0; i < constraints_.size(); i++) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 assert(constraints_[i] != NULL); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 if (!constraints_[i]->IsMatch(value)) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 return false; |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 return true; |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
89 bool DatabaseLookup::IsMatch(DcmItem& item, |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3182
diff
changeset
|
90 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3182
diff
changeset
|
91 bool hasCodeExtensions) const |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
92 { |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
93 for (size_t i = 0; i < constraints_.size(); i++) |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
94 { |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
95 assert(constraints_[i] != NULL); |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
96 |
3072 | 97 const bool isOptionalConstraint = !constraints_[i]->IsMandatory(); |
98 const DcmTagKey tag = ToDcmtkBridge::Convert(constraints_[i]->GetTag()); | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
99 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
100 DcmElement* element = NULL; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
101 if (!item.findAndGetElement(tag, element).good()) |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
102 { |
3072 | 103 return isOptionalConstraint; |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
104 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
105 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
106 if (element == NULL) |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
107 { |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
108 return false; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
109 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
110 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
111 std::set<DicomTag> ignoreTagLength; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3679
diff
changeset
|
112 std::unique_ptr<DicomValue> value(FromDcmtkBridge::ConvertLeafElement |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3679
diff
changeset
|
113 (*element, DicomToJsonFlags_None, |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3679
diff
changeset
|
114 0, encoding, hasCodeExtensions, ignoreTagLength)); |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
115 |
3072 | 116 // WARNING: Also modify "HierarchicalMatcher::Setup()" if modifying this code |
117 if (value.get() == NULL || | |
118 value->IsNull()) | |
119 { | |
120 return isOptionalConstraint; | |
121 } | |
122 else if (value->IsBinary() || | |
123 !constraints_[i]->IsMatch(value->GetContent())) | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
124 { |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
125 return false; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
126 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
127 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
128 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
129 return true; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
130 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
131 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
132 |
3027 | 133 void DatabaseLookup::AddDicomConstraintInternal(const DicomTag& tag, |
134 ValueRepresentation vr, | |
135 const std::string& dicomQuery, | |
136 bool caseSensitive, | |
137 bool mandatoryTag) | |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 if ((vr == ValueRepresentation_Date || |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 vr == ValueRepresentation_DateTime || |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 vr == ValueRepresentation_Time) && |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 dicomQuery.find('-') != std::string::npos) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 /** |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 * Range matching is only defined for TM, DA and DT value |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 * representations. This code fixes issues 35 and 37. |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 * Reference: "Range matching is not defined for types of |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 * Attributes other than dates and times", DICOM PS 3.4, |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 * C.2.2.2.5 ("Range Matching"). |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 **/ |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 size_t separator = dicomQuery.find('-'); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 std::string lower = dicomQuery.substr(0, separator); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 std::string upper = dicomQuery.substr(separator + 1); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 if (!lower.empty()) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 { |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
158 AddConstraintInternal(new DicomTagConstraint |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
159 (tag, ConstraintType_GreaterOrEqual, lower, caseSensitive, mandatoryTag)); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 if (!upper.empty()) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 { |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
164 AddConstraintInternal(new DicomTagConstraint |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
165 (tag, ConstraintType_SmallerOrEqual, upper, caseSensitive, mandatoryTag)); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 } |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
168 else if (dicomQuery.find('\\') != std::string::npos) |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 DicomTag fixedTag(tag); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3679
diff
changeset
|
172 std::unique_ptr<DicomTagConstraint> constraint |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2893
diff
changeset
|
173 (new DicomTagConstraint(fixedTag, ConstraintType_List, caseSensitive, mandatoryTag)); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 std::vector<std::string> items; |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 Toolbox::TokenizeString(items, dicomQuery, '\\'); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 for (size_t i = 0; i < items.size(); i++) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 constraint->AddValue(items[i]); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
183 AddConstraintInternal(constraint.release()); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 } |
3679
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
185 else if ( |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
186 /** |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
187 * New test in Orthanc 1.6.0: Wild card matching is only allowed |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
188 * for a subset of value representations: AE, CS, LO, LT, PN, |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
189 * SH, ST, UC, UR, UT. |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
190 * http://dicom.nema.org/medical/dicom/2019e/output/chtml/part04/sect_C.2.2.2.4.html |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
191 **/ |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
192 (vr == ValueRepresentation_ApplicationEntity || // AE |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
193 vr == ValueRepresentation_CodeString || // CS |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
194 vr == ValueRepresentation_LongString || // LO |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
195 vr == ValueRepresentation_LongText || // LT |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
196 vr == ValueRepresentation_PersonName || // PN |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
197 vr == ValueRepresentation_ShortString || // SH |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
198 vr == ValueRepresentation_ShortText || // ST |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
199 vr == ValueRepresentation_UnlimitedCharacters || // UC |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
200 vr == ValueRepresentation_UniversalResource || // UR |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
201 vr == ValueRepresentation_UnlimitedText // UT |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
202 ) && |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
203 (dicomQuery.find('*') != std::string::npos || |
6358923d3ced
C-FIND: forbid wildcard matching on some VRs, ignore main tags below the queried level
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
204 dicomQuery.find('?') != std::string::npos)) |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 { |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
206 AddConstraintInternal(new DicomTagConstraint |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
207 (tag, ConstraintType_Wildcard, dicomQuery, caseSensitive, mandatoryTag)); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 else |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 { |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
211 AddConstraintInternal(new DicomTagConstraint |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
212 (tag, ConstraintType_Equal, dicomQuery, caseSensitive, mandatoryTag)); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 } |
3027 | 215 |
216 | |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 void DatabaseLookup::AddDicomConstraint(const DicomTag& tag, |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 const std::string& dicomQuery, |
3027 | 219 bool caseSensitivePN, |
220 bool mandatoryTag) | |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 ValueRepresentation vr = FromDcmtkBridge::LookupValueRepresentation(tag); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 if (vr == ValueRepresentation_Sequence) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 { |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 throw OrthancException(ErrorCode_ParameterOutOfRange); |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 /** |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 * DICOM specifies that searches must always be case sensitive, |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 * except for tags with a PN value representation. For PN, Orthanc |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 * uses the configuration option "CaseSensitivePN" to decide |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 * whether matching is case-sensitive or case-insensitive. |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 * Reference: DICOM PS 3.4 |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 * - C.2.2.2.1 ("Single Value Matching") |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 * - C.2.2.2.4 ("Wild Card Matching") |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 * http://medical.nema.org/Dicom/2011/11_04pu.pdf |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 * "Except for Attributes with a PN Value Representation, only |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 * entities with values which match exactly the value specified in the |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 * request shall match. This matching is case-sensitive, i.e., |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 * sensitive to the exact encoding of the key attribute value in |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 * character sets where a letter may have multiple encodings (e.g., |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 * based on its case, its position in a word, or whether it is |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 * accented) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 * For Attributes with a PN Value Representation (e.g., Patient Name |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 * (0010,0010)), an application may perform literal matching that is |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 * either case-sensitive, or that is insensitive to some or all |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 * aspects of case, position, accent, or other character encoding |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 * variants." |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 * |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 * (0008,0018) UI SOPInstanceUID => Case-sensitive |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 * (0008,0050) SH AccessionNumber => Case-sensitive |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 * (0010,0020) LO PatientID => Case-sensitive |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 * (0020,000D) UI StudyInstanceUID => Case-sensitive |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 * (0020,000E) UI SeriesInstanceUID => Case-sensitive |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 **/ |
3027 | 260 |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 if (vr == ValueRepresentation_PersonName) |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 { |
3027 | 263 AddDicomConstraintInternal(tag, vr, dicomQuery, caseSensitivePN, mandatoryTag); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 else |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 { |
3027 | 267 AddDicomConstraintInternal(tag, vr, dicomQuery, true /* case sensitive */, mandatoryTag); |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 } |
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 } |
3027 | 270 |
271 | |
272 void DatabaseLookup::AddRestConstraint(const DicomTag& tag, | |
273 const std::string& dicomQuery, | |
274 bool caseSensitive, | |
275 bool mandatoryTag) | |
276 { | |
277 AddDicomConstraintInternal(tag, FromDcmtkBridge::LookupValueRepresentation(tag), | |
278 dicomQuery, caseSensitive, mandatoryTag); | |
279 } | |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
280 |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
281 |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
282 bool DatabaseLookup::HasOnlyMainDicomTags() const |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
283 { |
5176 | 284 std::set<DicomTag> allMainTags; |
285 DicomMap::GetAllMainDicomTags(allMainTags); | |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
286 |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
287 for (size_t i = 0; i < constraints_.size(); i++) |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
288 { |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
289 assert(constraints_[i] != NULL); |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
290 |
4932
b7ce2bb6b881
refactored the list of MainDicomTags to be able to change it dynamicaly. Unit tests and Integration tests ok
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
291 if (allMainTags.find(constraints_[i]->GetTag()) == allMainTags.end()) |
3033
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
292 { |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
293 // This is not a main DICOM tag |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
294 return false; |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
295 } |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
296 } |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
297 |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
298 return true; |
5da6d1063d8f
effectively replacing LookupResource by DatabaseLookup in searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
299 } |
4196
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
300 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
301 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
302 std::string DatabaseLookup::Format() const |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
303 { |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
304 std::string s; |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
305 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
306 for (size_t i = 0; i < constraints_.size(); i++) |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
307 { |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
308 assert(constraints_[i] != NULL); |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
309 s += ("Contraint " + boost::lexical_cast<std::string>(i) + ": " + |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
310 constraints_[i]->Format() + "\n"); |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
311 } |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
312 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
313 return s; |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
314 } |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
315 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
316 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
317 bool DatabaseLookup::HasTag(const DicomTag& tag) const |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
318 { |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
319 for (size_t i = 0; i < constraints_.size(); i++) |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
320 { |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
321 assert(constraints_[i] != NULL); |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
322 if (constraints_[i]->GetTag() == tag) |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
323 { |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
324 return true; |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
325 } |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
326 } |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
327 |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
328 return false; |
37310bb1cd30
Fix handling of "ModalitiesInStudy" (0008,0061) in C-FIND and "/tools/find"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
329 } |
4977
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
330 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
331 bool DatabaseLookup::GetConstraint(const DicomTagConstraint*& constraint, const DicomTag& tag) const |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
332 { |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
333 for (size_t i = 0; i < constraints_.size(); i++) |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
334 { |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
335 assert(constraints_[i] != NULL); |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
336 if (constraints_[i]->GetTag() == tag) |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
337 { |
4981 | 338 constraint = constraints_[i]; |
4977
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
339 return true; |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
340 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
341 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
342 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
343 return false; |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
344 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
345 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
346 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
347 void DatabaseLookup::RemoveConstraint(const DicomTag& tag) |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
348 { |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
349 for (size_t i = 0; i < constraints_.size(); i++) |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
350 { |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
351 assert(constraints_[i] != NULL); |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
352 if (constraints_[i]->GetTag() == tag) |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
353 { |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
354 delete constraints_[i]; |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
355 constraints_.erase(constraints_.begin() + i); |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
356 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
357 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
358 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
359 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
360 DatabaseLookup* DatabaseLookup::Clone() const |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
361 { |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
362 std::unique_ptr<DatabaseLookup> clone(new DatabaseLookup()); |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
363 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
364 for (size_t i = 0; i < constraints_.size(); i++) |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
365 { |
4995 | 366 clone->AddConstraintInternal(new DicomTagConstraint(*constraints_[i])); |
4977
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
367 } |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
368 |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
369 return clone.release(); |
dad71e6da406
pre-filtering studies without ModalitiesInStudies first
Alain Mazy <am@osimis.io>
parents:
4932
diff
changeset
|
370 } |
5220
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
371 |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
372 |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
373 void DatabaseLookup::AddWithLabel(const std::string& label) |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
374 { |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
375 if (label.empty()) |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
376 { |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
377 throw OrthancException(ErrorCode_ParameterOutOfRange); |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
378 } |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
379 else |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
380 { |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
381 withLabels_.insert(label); |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
382 } |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
383 } |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
384 |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
385 |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
386 void DatabaseLookup::AddWithoutLabel(const std::string& label) |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
387 { |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
388 if (label.empty()) |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
389 { |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
390 throw OrthancException(ErrorCode_ParameterOutOfRange); |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
391 } |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
392 else |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
393 { |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
394 withoutLabels_.insert(label); |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
395 } |
df39c7583a49
preparing virtual methods for labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
396 } |
2892
ce310baccda6
DicomTagConstraint and DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 } |