Mercurial > hg > orthanc
annotate OrthancServer/Sources/Search/HierarchicalMatcher.cpp @ 4870:43e613a7756b
upgrade to year 2022
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 11:15:42 +0100 |
parents | 7053502fbf97 |
children | 6eff25f70121 |
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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1795 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * In addition, as a special exception, the copyright holders of this | |
14 * program give permission to link the code of its release with the | |
15 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
16 * that use the same license as the "OpenSSL" library), and distribute | |
17 * the linked executables. You must obey the GNU General Public License | |
18 * in all respects for all of the code used other than "OpenSSL". If you | |
19 * modify file(s) with this exception, you may extend this exception to | |
20 * your version of the file(s), but you are not obligated to do so. If | |
21 * you do not wish to do so, delete this exception statement from your | |
22 * version. If you delete this exception statement from all source files | |
23 * in the program, then also delete it here. | |
24 * | |
25 * This program is distributed in the hope that it will be useful, but | |
26 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
28 * General Public License for more details. | |
29 * | |
30 * You should have received a copy of the GNU General Public License | |
31 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
32 **/ | |
33 | |
34 | |
35 #include "../PrecompiledHeadersServer.h" | |
36 #include "HierarchicalMatcher.h" | |
37 | |
4045 | 38 #include "../../../OrthancFramework/Sources/Logging.h" |
39 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
40 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
41 #include "../../../OrthancFramework/Sources/DicomParsing/ToDcmtkBridge.h" | |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
42 #include "../OrthancConfiguration.h" |
1795 | 43 |
44 #include <dcmtk/dcmdata/dcfilefo.h> | |
45 | |
46 namespace Orthanc | |
47 { | |
2256
de1ba22fd28a
simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
48 HierarchicalMatcher::HierarchicalMatcher(ParsedDicomFile& query) |
1795 | 49 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
50 bool caseSensitivePN; |
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 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
53 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
54 caseSensitivePN = lock.GetConfiguration().GetBooleanParameter("CaseSensitivePN", false); |
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 |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
57 bool hasCodeExtensions; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
58 Encoding encoding = query.DetectEncoding(hasCodeExtensions); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
59 Setup(*query.GetDcmtkObject().getDataset(), caseSensitivePN, encoding, hasCodeExtensions); |
1795 | 60 } |
61 | |
62 | |
63 HierarchicalMatcher::~HierarchicalMatcher() | |
64 { | |
65 for (Sequences::iterator it = sequences_.begin(); | |
66 it != sequences_.end(); ++it) | |
67 { | |
68 if (it->second != NULL) | |
69 { | |
70 delete it->second; | |
71 } | |
72 } | |
73 } | |
74 | |
75 | |
76 void HierarchicalMatcher::Setup(DcmItem& dataset, | |
77 bool caseSensitivePN, | |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
78 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
79 bool hasCodeExtensions) |
1795 | 80 { |
81 for (unsigned long i = 0; i < dataset.card(); i++) | |
82 { | |
83 DcmElement* element = dataset.getElement(i); | |
84 if (element == NULL) | |
85 { | |
86 throw OrthancException(ErrorCode_InternalError); | |
87 } | |
88 | |
89 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
|
90 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
|
91 tag.GetElement() == 0x0000) // Ignore all "Group Length" tags |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
92 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
93 continue; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
94 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
95 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
96 if (flatTags_.find(tag) != flatTags_.end() || |
1795 | 97 sequences_.find(tag) != sequences_.end()) |
98 { | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
99 // A constraint already exists on this tag |
1795 | 100 throw OrthancException(ErrorCode_BadRequest); |
101 } | |
102 | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
103 if (FromDcmtkBridge::LookupValueRepresentation(tag) == ValueRepresentation_Sequence) |
1795 | 104 { |
105 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element); | |
106 | |
107 if (sequence.card() == 0 || | |
108 (sequence.card() == 1 && sequence.getItem(0)->card() == 0)) | |
109 { | |
110 // Universal matching of a sequence | |
111 sequences_[tag] = NULL; | |
112 } | |
113 else if (sequence.card() == 1) | |
114 { | |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
115 sequences_[tag] = new HierarchicalMatcher(*sequence.getItem(0), caseSensitivePN, encoding, hasCodeExtensions); |
1795 | 116 } |
117 else | |
118 { | |
119 throw OrthancException(ErrorCode_BadRequest); | |
120 } | |
121 } | |
122 else | |
123 { | |
3072 | 124 flatTags_.insert(tag); |
125 | |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
126 std::set<DicomTag> ignoreTagLength; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
127 std::unique_ptr<DicomValue> value(FromDcmtkBridge::ConvertLeafElement |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
128 (*element, DicomToJsonFlags_None, |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
129 0, encoding, hasCodeExtensions, ignoreTagLength)); |
1795 | 130 |
3072 | 131 // WARNING: Also modify "DatabaseLookup::IsMatch()" if modifying this code |
132 if (value.get() == NULL || | |
133 value->IsNull()) | |
134 { | |
135 // This is an universal constraint | |
136 } | |
137 else if (value->IsBinary()) | |
1795 | 138 { |
1890
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
139 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
|
140 { |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
141 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
|
142 << 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
|
143 << "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
|
144 } |
1795 | 145 } |
3072 | 146 else if (value->GetContent().empty()) |
1795 | 147 { |
148 // This is an universal matcher | |
149 } | |
150 else | |
151 { | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
152 flatConstraints_.AddDicomConstraint |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
153 (tag, value->GetContent(), caseSensitivePN, true /* mandatory */); |
1795 | 154 } |
155 } | |
156 } | |
157 } | |
158 | |
159 | |
160 std::string HierarchicalMatcher::Format(const std::string& prefix) const | |
161 { | |
162 std::string s; | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
163 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
164 std::set<DicomTag> tags; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
165 for (size_t i = 0; i < flatConstraints_.GetConstraintsCount(); i++) |
1795 | 166 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
167 const DicomTagConstraint& c = flatConstraints_.GetConstraint(i); |
1795 | 168 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
169 s += c.Format() + "\n"; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
170 tags.insert(c.GetTag()); |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
171 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
172 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
173 // Loop over the universal constraints |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
174 for (std::set<DicomTag>::const_iterator it = flatTags_.begin(); |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
175 it != flatTags_.end(); ++it) |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
176 { |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
177 if (tags.find(*it) == tags.end()) |
1795 | 178 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
179 s += prefix + it->Format() + " == *\n"; |
1795 | 180 } |
181 } | |
182 | |
183 for (Sequences::const_iterator it = sequences_.begin(); | |
184 it != sequences_.end(); ++it) | |
185 { | |
186 s += prefix + it->first.Format() + " "; | |
187 | |
188 if (it->second == NULL) | |
189 { | |
190 s += "*\n"; | |
191 } | |
192 else | |
193 { | |
194 s += "Sequence:\n" + it->second->Format(prefix + " "); | |
195 } | |
196 } | |
197 | |
198 return s; | |
199 } | |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
200 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
201 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
202 bool HierarchicalMatcher::Match(ParsedDicomFile& dicom) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
203 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
204 bool hasCodeExtensions; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
205 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
206 |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
207 return MatchInternal(*dicom.GetDcmtkObject().getDataset(), |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
208 encoding, hasCodeExtensions); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
209 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
210 |
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 bool HierarchicalMatcher::MatchInternal(DcmItem& item, |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
213 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
214 bool hasCodeExtensions) const |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
215 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
216 if (!flatConstraints_.IsMatch(item, encoding, hasCodeExtensions)) |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
217 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
218 return false; |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
219 } |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
220 |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
221 for (Sequences::const_iterator it = sequences_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
222 it != sequences_.end(); ++it) |
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 if (it->second != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
225 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
226 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
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 DcmSequenceOfItems* sequence = NULL; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
229 if (!item.findAndGetSequence(tag, sequence).good() || |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
230 sequence == NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
231 { |
1891 | 232 continue; |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
233 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
234 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
235 bool match = false; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
236 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
237 for (unsigned long i = 0; i < sequence->card(); i++) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
238 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
239 if (it->second->MatchInternal(*sequence->getItem(i), encoding, hasCodeExtensions)) |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
240 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
241 match = true; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
242 break; |
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 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
246 if (!match) |
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 return false; |
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 } |
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 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
253 return true; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
254 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
255 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
256 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
257 DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source, |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
258 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
259 bool hasCodeExtensions) const |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
260 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
261 std::unique_ptr<DcmDataset> target(new DcmDataset); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
262 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
263 for (std::set<DicomTag>::const_iterator it = flatTags_.begin(); |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
264 it != flatTags_.end(); ++it) |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
265 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
266 DcmTagKey tag = ToDcmtkBridge::Convert(*it); |
1796
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 DcmElement* element = NULL; |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
269 if (source.findAndGetElement(tag, element).good() && |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
270 element != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
271 { |
3691
4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
272 if (it->IsPrivate()) |
4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
273 { |
4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
274 throw OrthancException(ErrorCode_NotImplemented, |
4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
275 "Not applicable to private tags: " + it->Format()); |
4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
276 } |
4922bdd046dd
Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
277 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
278 std::unique_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(*it, "" /* no private creator */)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
279 cloned->copyFrom(*element); |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
280 target->insert(cloned.release()); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
281 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
282 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
283 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
284 for (Sequences::const_iterator it = sequences_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
285 it != sequences_.end(); ++it) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
286 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
287 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
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 DcmSequenceOfItems* sequence = NULL; |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
290 if (source.findAndGetSequence(tag, sequence).good() && |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
291 sequence != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
292 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
293 std::unique_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag)); |
1796
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 for (unsigned long i = 0; i < sequence->card(); i++) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
296 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
297 if (it->second == NULL) |
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 cloned->append(new DcmItem(*sequence->getItem(i))); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
300 } |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
301 else if (it->second->MatchInternal(*sequence->getItem(i), encoding, hasCodeExtensions)) // TODO Might be optimized |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
302 { |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
303 // It is necessary to encapsulate the child dataset into a |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
304 // "DcmItem" object before it can be included in a |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
305 // sequence. Otherwise, "dciodvfy" reports an error "Bad |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
306 // tag in sequence - Expecting Item or Sequence Delimiter." |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
307 std::unique_ptr<DcmDataset> child(it->second->ExtractInternal(*sequence->getItem(i), encoding, hasCodeExtensions)); |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
308 cloned->append(new DcmItem(*child)); |
1796
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 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
311 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
312 target->insert(cloned.release()); |
1796
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 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
315 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
316 return target.release(); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
317 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
318 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
319 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
320 ParsedDicomFile* HierarchicalMatcher::Extract(ParsedDicomFile& dicom) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
321 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
322 bool hasCodeExtensions; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
323 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
324 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
325 std::unique_ptr<DcmDataset> dataset(ExtractInternal(*dicom.GetDcmtkObject().getDataset(), |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
326 encoding, hasCodeExtensions)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
327 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
328 std::unique_ptr<ParsedDicomFile> result(new ParsedDicomFile(*dataset)); |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
329 result->SetEncoding(encoding); |
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 return result.release(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
332 } |
1795 | 333 } |