Mercurial > hg > orthanc
annotate OrthancServer/Search/HierarchicalMatcher.cpp @ 3021:2cbafb5d5a62
renamed LookupResource::IVisitor as ServerContext::ILookupVisitor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 15 Dec 2018 16:29:50 +0100 |
parents | 4767d36679ed |
children | 4e43e67f8ecf |
rev | line source |
---|---|
1795 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1795 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2409
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1795 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeadersServer.h" | |
35 #include "HierarchicalMatcher.h" | |
36 | |
1890
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
37 #include "../../Core/Logging.h" |
1795 | 38 #include "../../Core/OrthancException.h" |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2283
diff
changeset
|
39 #include "../../Core/DicomParsing/FromDcmtkBridge.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2283
diff
changeset
|
40 #include "../../Core/DicomParsing/ToDcmtkBridge.h" |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
41 #include "../OrthancConfiguration.h" |
1795 | 42 |
43 #include <dcmtk/dcmdata/dcfilefo.h> | |
44 | |
45 namespace Orthanc | |
46 { | |
2256
de1ba22fd28a
simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
47 HierarchicalMatcher::HierarchicalMatcher(ParsedDicomFile& query) |
1795 | 48 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
49 bool caseSensitivePN; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
50 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
51 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
52 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
53 caseSensitivePN = lock.GetConfiguration().GetBooleanParameter("CaseSensitivePN", false); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
54 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
55 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
56 Setup(*query.GetDcmtkObject().getDataset(), caseSensitivePN, query.GetEncoding()); |
1795 | 57 } |
58 | |
59 | |
60 HierarchicalMatcher::~HierarchicalMatcher() | |
61 { | |
62 for (Constraints::iterator it = constraints_.begin(); | |
63 it != constraints_.end(); ++it) | |
64 { | |
65 if (it->second != NULL) | |
66 { | |
67 delete it->second; | |
68 } | |
69 } | |
70 | |
71 for (Sequences::iterator it = sequences_.begin(); | |
72 it != sequences_.end(); ++it) | |
73 { | |
74 if (it->second != NULL) | |
75 { | |
76 delete it->second; | |
77 } | |
78 } | |
79 } | |
80 | |
81 | |
82 void HierarchicalMatcher::Setup(DcmItem& dataset, | |
83 bool caseSensitivePN, | |
84 Encoding encoding) | |
85 { | |
86 for (unsigned long i = 0; i < dataset.card(); i++) | |
87 { | |
88 DcmElement* element = dataset.getElement(i); | |
89 if (element == NULL) | |
90 { | |
91 throw OrthancException(ErrorCode_InternalError); | |
92 } | |
93 | |
94 DicomTag tag(FromDcmtkBridge::Convert(element->getTag())); | |
2200
af60b784d2b8
Ignore "Group Length" tags in C-FIND queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2007
diff
changeset
|
95 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET || // Ignore encoding |
af60b784d2b8
Ignore "Group Length" tags in C-FIND queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2007
diff
changeset
|
96 tag.GetElement() == 0x0000) // Ignore all "Group Length" tags |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
97 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
98 continue; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
99 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
100 |
2006
6301bbcbcaed
more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
101 ValueRepresentation vr = FromDcmtkBridge::LookupValueRepresentation(tag); |
1795 | 102 |
103 if (constraints_.find(tag) != constraints_.end() || | |
104 sequences_.find(tag) != sequences_.end()) | |
105 { | |
106 throw OrthancException(ErrorCode_BadRequest); | |
107 } | |
108 | |
109 if (vr == ValueRepresentation_Sequence) | |
110 { | |
111 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element); | |
112 | |
113 if (sequence.card() == 0 || | |
114 (sequence.card() == 1 && sequence.getItem(0)->card() == 0)) | |
115 { | |
116 // Universal matching of a sequence | |
117 sequences_[tag] = NULL; | |
118 } | |
119 else if (sequence.card() == 1) | |
120 { | |
121 sequences_[tag] = new HierarchicalMatcher(*sequence.getItem(0), caseSensitivePN, encoding); | |
122 } | |
123 else | |
124 { | |
125 throw OrthancException(ErrorCode_BadRequest); | |
126 } | |
127 } | |
128 else | |
129 { | |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
130 std::set<DicomTag> ignoreTagLength; |
1795 | 131 std::auto_ptr<DicomValue> value(FromDcmtkBridge::ConvertLeafElement |
1929
cda5b0ab4ce5
ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
132 (*element, DicomToJsonFlags_None, |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
133 ORTHANC_MAXIMUM_TAG_LENGTH, encoding, ignoreTagLength)); |
1795 | 134 |
1867
769178f0ab2c
Fix modality worklists server if some fields are null
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1797
diff
changeset
|
135 if (value->IsBinary()) |
1795 | 136 { |
1890
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
137 if (!value->GetContent().empty()) |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
138 { |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
139 LOG(WARNING) << "This C-Find modality worklist query contains a non-empty tag (" |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
140 << tag.Format() << ") with UN (unknown) value representation. " |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
141 << "It will be ignored."; |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
142 } |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
143 |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
144 constraints_[tag] = NULL; |
1795 | 145 } |
1867
769178f0ab2c
Fix modality worklists server if some fields are null
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1797
diff
changeset
|
146 else if (value->IsNull() || |
769178f0ab2c
Fix modality worklists server if some fields are null
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1797
diff
changeset
|
147 value->GetContent().empty()) |
1795 | 148 { |
149 // This is an universal matcher | |
150 constraints_[tag] = NULL; | |
151 } | |
152 else | |
153 { | |
154 // DICOM specifies that searches must be case sensitive, except | |
155 // for tags with a PN value representation | |
156 bool sensitive = true; | |
2007
655489d9165d
DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2006
diff
changeset
|
157 if (vr == ValueRepresentation_PersonName) |
1795 | 158 { |
159 sensitive = caseSensitivePN; | |
160 } | |
161 | |
162 constraints_[tag] = IFindConstraint::ParseDicomConstraint(tag, value->GetContent(), sensitive); | |
163 } | |
164 } | |
165 } | |
166 } | |
167 | |
168 | |
169 std::string HierarchicalMatcher::Format(const std::string& prefix) const | |
170 { | |
171 std::string s; | |
172 | |
173 for (Constraints::const_iterator it = constraints_.begin(); | |
174 it != constraints_.end(); ++it) | |
175 { | |
176 s += prefix + it->first.Format() + " "; | |
177 | |
178 if (it->second == NULL) | |
179 { | |
180 s += "*\n"; | |
181 } | |
182 else | |
183 { | |
184 s += it->second->Format() + "\n"; | |
185 } | |
186 } | |
187 | |
188 for (Sequences::const_iterator it = sequences_.begin(); | |
189 it != sequences_.end(); ++it) | |
190 { | |
191 s += prefix + it->first.Format() + " "; | |
192 | |
193 if (it->second == NULL) | |
194 { | |
195 s += "*\n"; | |
196 } | |
197 else | |
198 { | |
199 s += "Sequence:\n" + it->second->Format(prefix + " "); | |
200 } | |
201 } | |
202 | |
203 return s; | |
204 } | |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
205 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
206 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
207 bool HierarchicalMatcher::Match(ParsedDicomFile& dicom) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
208 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
209 return MatchInternal(*dicom.GetDcmtkObject().getDataset(), |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
210 dicom.GetEncoding()); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
211 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
212 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
213 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
214 bool HierarchicalMatcher::MatchInternal(DcmItem& item, |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
215 Encoding encoding) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
216 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
217 for (Constraints::const_iterator it = constraints_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
218 it != constraints_.end(); ++it) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
219 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
220 if (it->second != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
221 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
222 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
223 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
224 DcmElement* element = NULL; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
225 if (!item.findAndGetElement(tag, element).good() || |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
226 element == NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
227 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
228 return false; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
229 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
230 |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
231 std::set<DicomTag> ignoreTagLength; |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
232 std::auto_ptr<DicomValue> value(FromDcmtkBridge::ConvertLeafElement |
1929
cda5b0ab4ce5
ORTHANC_MAXIMUM_TAG_LENGTH made explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
233 (*element, DicomToJsonFlags_None, |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
234 ORTHANC_MAXIMUM_TAG_LENGTH, encoding, ignoreTagLength)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
235 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
236 if (value->IsNull() || |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
237 value->IsBinary() || |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
238 !it->second->Match(value->GetContent())) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
239 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
240 return false; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
241 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
242 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
243 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
244 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
245 for (Sequences::const_iterator it = sequences_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
246 it != sequences_.end(); ++it) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
247 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
248 if (it->second != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
249 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
250 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
251 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
252 DcmSequenceOfItems* sequence = NULL; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
253 if (!item.findAndGetSequence(tag, sequence).good() || |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
254 sequence == NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
255 { |
1891 | 256 continue; |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
257 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
258 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
259 bool match = false; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
260 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
261 for (unsigned long i = 0; i < sequence->card(); i++) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
262 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
263 if (it->second->MatchInternal(*sequence->getItem(i), encoding)) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
264 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
265 match = true; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
266 break; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
267 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
268 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
269 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
270 if (!match) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
271 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
272 return false; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
273 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
274 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
275 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
276 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
277 return true; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
278 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
279 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
280 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
281 DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source, |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
282 Encoding encoding) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
283 { |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
284 std::auto_ptr<DcmDataset> target(new DcmDataset); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
285 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
286 for (Constraints::const_iterator it = constraints_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
287 it != constraints_.end(); ++it) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
288 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
289 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
290 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
291 DcmElement* element = NULL; |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
292 if (source.findAndGetElement(tag, element).good() && |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
293 element != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
294 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
295 std::auto_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(it->first)); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
296 cloned->copyFrom(*element); |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
297 target->insert(cloned.release()); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
298 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
299 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
300 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
301 for (Sequences::const_iterator it = sequences_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
302 it != sequences_.end(); ++it) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
303 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
304 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
305 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
306 DcmSequenceOfItems* sequence = NULL; |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
307 if (source.findAndGetSequence(tag, sequence).good() && |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
308 sequence != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
309 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
310 std::auto_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag)); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
311 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
312 for (unsigned long i = 0; i < sequence->card(); i++) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
313 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
314 if (it->second == NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
315 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
316 cloned->append(new DcmItem(*sequence->getItem(i))); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
317 } |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
318 else if (it->second->MatchInternal(*sequence->getItem(i), encoding)) // TODO Might be optimized |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
319 { |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
320 // It is necessary to encapsulate the child dataset into a |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
321 // "DcmItem" object before it can be included in a |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
322 // sequence. Otherwise, "dciodvfy" reports an error "Bad |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
323 // tag in sequence - Expecting Item or Sequence Delimiter." |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
324 std::auto_ptr<DcmDataset> child(it->second->ExtractInternal(*sequence->getItem(i), encoding)); |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
325 cloned->append(new DcmItem(*child)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
326 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
327 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
328 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
329 target->insert(cloned.release()); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
330 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
331 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
332 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
333 return target.release(); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
334 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
335 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
336 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
337 ParsedDicomFile* HierarchicalMatcher::Extract(ParsedDicomFile& dicom) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
338 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
339 std::auto_ptr<DcmDataset> dataset(ExtractInternal(*dicom.GetDcmtkObject().getDataset(), |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
340 dicom.GetEncoding())); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
341 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
342 std::auto_ptr<ParsedDicomFile> result(new ParsedDicomFile(*dataset)); |
2283
2a15186ca28a
more generic fix for issue 49
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2282
diff
changeset
|
343 result->SetEncoding(dicom.GetEncoding()); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
344 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
345 return result.release(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
346 } |
1795 | 347 } |