Mercurial > hg > orthanc
annotate OrthancServer/Sources/Search/HierarchicalMatcher.cpp @ 5654:b89439c14916
back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2024 17:53:00 +0200 |
parents | f7adfb22e20e |
children |
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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5294
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1795 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "../PrecompiledHeadersServer.h" | |
25 #include "HierarchicalMatcher.h" | |
26 | |
4045 | 27 #include "../../../OrthancFramework/Sources/Logging.h" |
28 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
29 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
30 #include "../../../OrthancFramework/Sources/DicomParsing/ToDcmtkBridge.h" | |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
31 #include "../OrthancConfiguration.h" |
1795 | 32 |
33 #include <dcmtk/dcmdata/dcfilefo.h> | |
34 | |
35 namespace Orthanc | |
36 { | |
2256
de1ba22fd28a
simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
37 HierarchicalMatcher::HierarchicalMatcher(ParsedDicomFile& query) |
1795 | 38 { |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
39 bool caseSensitivePN; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
40 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
41 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
42 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
43 caseSensitivePN = lock.GetConfiguration().GetBooleanParameter("CaseSensitivePN", false); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
44 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
45 |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
46 bool hasCodeExtensions; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
47 Encoding encoding = query.DetectEncoding(hasCodeExtensions); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
48 Setup(*query.GetDcmtkObject().getDataset(), caseSensitivePN, encoding, hasCodeExtensions); |
1795 | 49 } |
50 | |
51 | |
52 HierarchicalMatcher::~HierarchicalMatcher() | |
53 { | |
54 for (Sequences::iterator it = sequences_.begin(); | |
55 it != sequences_.end(); ++it) | |
56 { | |
57 if (it->second != NULL) | |
58 { | |
59 delete it->second; | |
60 } | |
61 } | |
62 } | |
63 | |
64 | |
65 void HierarchicalMatcher::Setup(DcmItem& dataset, | |
66 bool caseSensitivePN, | |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
67 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
68 bool hasCodeExtensions) |
1795 | 69 { |
70 for (unsigned long i = 0; i < dataset.card(); i++) | |
71 { | |
72 DcmElement* element = dataset.getElement(i); | |
73 if (element == NULL) | |
74 { | |
75 throw OrthancException(ErrorCode_InternalError); | |
76 } | |
77 | |
78 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
|
79 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
|
80 tag.GetElement() == 0x0000) // Ignore all "Group Length" tags |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
81 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
82 continue; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
83 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
84 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
85 if (flatTags_.find(tag) != flatTags_.end() || |
1795 | 86 sequences_.find(tag) != sequences_.end()) |
87 { | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
88 // A constraint already exists on this tag |
1795 | 89 throw OrthancException(ErrorCode_BadRequest); |
90 } | |
91 | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
92 if (FromDcmtkBridge::LookupValueRepresentation(tag) == ValueRepresentation_Sequence) |
1795 | 93 { |
94 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element); | |
95 | |
96 if (sequence.card() == 0 || | |
97 (sequence.card() == 1 && sequence.getItem(0)->card() == 0)) | |
98 { | |
99 // Universal matching of a sequence | |
100 sequences_[tag] = NULL; | |
101 } | |
102 else if (sequence.card() == 1) | |
103 { | |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
104 sequences_[tag] = new HierarchicalMatcher(*sequence.getItem(0), caseSensitivePN, encoding, hasCodeExtensions); |
1795 | 105 } |
106 else | |
107 { | |
108 throw OrthancException(ErrorCode_BadRequest); | |
109 } | |
110 } | |
111 else | |
112 { | |
3072 | 113 flatTags_.insert(tag); |
114 | |
2409
e4045b3c9772
ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
115 std::set<DicomTag> ignoreTagLength; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
116 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
|
117 (*element, DicomToJsonFlags_None, |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
118 0, encoding, hasCodeExtensions, ignoreTagLength)); |
1795 | 119 |
3072 | 120 // WARNING: Also modify "DatabaseLookup::IsMatch()" if modifying this code |
121 if (value.get() == NULL || | |
122 value->IsNull()) | |
123 { | |
124 // This is an universal constraint | |
125 } | |
126 else if (value->IsBinary()) | |
1795 | 127 { |
1890
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
128 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
|
129 { |
74dc6b764ff0
Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1867
diff
changeset
|
130 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
|
131 << 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
|
132 << "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
|
133 } |
1795 | 134 } |
3072 | 135 else if (value->GetContent().empty()) |
1795 | 136 { |
137 // This is an universal matcher | |
138 } | |
139 else | |
140 { | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
141 flatConstraints_.AddDicomConstraint |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
142 (tag, value->GetContent(), caseSensitivePN, true /* mandatory */); |
1795 | 143 } |
144 } | |
145 } | |
146 } | |
147 | |
148 | |
149 std::string HierarchicalMatcher::Format(const std::string& prefix) const | |
150 { | |
151 std::string s; | |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
152 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
153 std::set<DicomTag> tags; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
154 for (size_t i = 0; i < flatConstraints_.GetConstraintsCount(); i++) |
1795 | 155 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
156 const DicomTagConstraint& c = flatConstraints_.GetConstraint(i); |
1795 | 157 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
158 s += c.Format() + "\n"; |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
159 tags.insert(c.GetTag()); |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
160 } |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
161 |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
162 // Loop over the universal constraints |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
163 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
|
164 it != flatTags_.end(); ++it) |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
165 { |
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
166 if (tags.find(*it) == tags.end()) |
1795 | 167 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
168 s += prefix + it->Format() + " == *\n"; |
1795 | 169 } |
170 } | |
171 | |
172 for (Sequences::const_iterator it = sequences_.begin(); | |
173 it != sequences_.end(); ++it) | |
174 { | |
175 s += prefix + it->first.Format() + " "; | |
176 | |
177 if (it->second == NULL) | |
178 { | |
179 s += "*\n"; | |
180 } | |
181 else | |
182 { | |
183 s += "Sequence:\n" + it->second->Format(prefix + " "); | |
184 } | |
185 } | |
186 | |
187 return s; | |
188 } | |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
189 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
190 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
191 bool HierarchicalMatcher::Match(ParsedDicomFile& dicom) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
192 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
193 bool hasCodeExtensions; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
194 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
195 |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
196 return MatchInternal(*dicom.GetDcmtkObject().getDataset(), |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
197 encoding, hasCodeExtensions); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
198 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
199 |
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 bool HierarchicalMatcher::MatchInternal(DcmItem& item, |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
202 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
203 bool hasCodeExtensions) const |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
204 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
205 if (!flatConstraints_.IsMatch(item, encoding, hasCodeExtensions)) |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
206 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
207 return false; |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
208 } |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
209 |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
210 for (Sequences::const_iterator it = sequences_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
211 it != sequences_.end(); ++it) |
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 if (it->second != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
214 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
215 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
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 DcmSequenceOfItems* sequence = NULL; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
218 if (!item.findAndGetSequence(tag, sequence).good() || |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
219 sequence == NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
220 { |
1891 | 221 continue; |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
222 } |
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 bool match = false; |
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 for (unsigned long i = 0; i < sequence->card(); i++) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
227 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
228 if (it->second->MatchInternal(*sequence->getItem(i), encoding, hasCodeExtensions)) |
1796
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 match = true; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
231 break; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
232 } |
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 if (!match) |
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 return false; |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
238 } |
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 } |
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 return true; |
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 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
246 DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source, |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
247 Encoding encoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
248 bool hasCodeExtensions) const |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
249 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
250 std::unique_ptr<DcmDataset> target(new DcmDataset); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
251 |
5294
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
252 std::string currentPrivateCreator = ""; |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
253 |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
254 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
|
255 it != flatTags_.end(); ++it) |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
256 { |
3071
2df061cf2fec
getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
257 DcmTagKey tag = ToDcmtkBridge::Convert(*it); |
1796
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 DcmElement* element = NULL; |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
260 if (source.findAndGetElement(tag, element).good() && |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
261 element != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
262 { |
5294
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
263 if (tag.isPrivateReservation()) |
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
|
264 { |
5294
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
265 OFString privateCreator; |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
266 element->getOFString(privateCreator, 0, false); |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
267 currentPrivateCreator = privateCreator.c_str(); |
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
|
268 } |
5294
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
269 else if (!it->IsPrivate()) |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
270 { |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
271 // reset the private creator as soon as we reach the end of the current private block |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
272 currentPrivateCreator = ""; |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
273 } |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
274 |
e0e2aee4453e
Modality worklists plugin: allow searching on private tags (exact match only)
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
275 std::unique_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(*it, currentPrivateCreator.c_str())); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
276 cloned->copyFrom(*element); |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
277 target->insert(cloned.release()); |
1796
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 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
281 for (Sequences::const_iterator it = sequences_.begin(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
282 it != sequences_.end(); ++it) |
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first); |
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 DcmSequenceOfItems* sequence = NULL; |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
287 if (source.findAndGetSequence(tag, sequence).good() && |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
288 sequence != NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
289 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
290 std::unique_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
291 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
292 for (unsigned long i = 0; i < sequence->card(); i++) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
293 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
294 if (it->second == NULL) |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
295 { |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
296 cloned->append(new DcmItem(*sequence->getItem(i))); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
297 } |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
298 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
|
299 { |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
300 // It is necessary to encapsulate the child dataset into a |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
301 // "DcmItem" object before it can be included in a |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
302 // sequence. Otherwise, "dciodvfy" reports an error "Bad |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
303 // 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
|
304 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
|
305 cloned->append(new DcmItem(*child)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
306 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
307 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
308 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
309 target->insert(cloned.release()); |
1796
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 } |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
312 |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1796
diff
changeset
|
313 return target.release(); |
1796
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 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
316 |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
317 ParsedDicomFile* HierarchicalMatcher::Extract(ParsedDicomFile& dicom) const |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
318 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
319 bool hasCodeExtensions; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
320 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
321 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3691
diff
changeset
|
322 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
|
323 encoding, hasCodeExtensions)); |
1796
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
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<ParsedDicomFile> result(new ParsedDicomFile(*dataset)); |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3072
diff
changeset
|
326 result->SetEncoding(encoding); |
1796
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 return result.release(); |
5e08a5fe6b27
HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1795
diff
changeset
|
329 } |
1795 | 330 } |