annotate OrthancServer/Search/HierarchicalMatcher.cpp @ 2791:d015fa861e3c

selective disabling of modules in the Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 26 Jul 2018 21:18:05 +0200
parents 878b59270859
children 4767d36679ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1891
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeadersServer.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "HierarchicalMatcher.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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"
2256
de1ba22fd28a simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
41 #include "../OrthancInitialization.h"
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <dcmtk/dcmdata/dcfilefo.h>
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
2256
de1ba22fd28a simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
47 HierarchicalMatcher::HierarchicalMatcher(ParsedDicomFile& query)
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 Setup(*query.GetDcmtkObject().getDataset(),
2256
de1ba22fd28a simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
50 Configuration::GetGlobalBoolParameter("CaseSensitivePN", false),
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 query.GetEncoding());
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 HierarchicalMatcher::~HierarchicalMatcher()
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 for (Constraints::iterator it = constraints_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 it != constraints_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (it->second != NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 delete it->second;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 for (Sequences::iterator it = sequences_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 it != sequences_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (it->second != NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 delete it->second;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 void HierarchicalMatcher::Setup(DcmItem& dataset,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 bool caseSensitivePN,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 Encoding encoding)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 for (unsigned long i = 0; i < dataset.card(); i++)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 DcmElement* element = dataset.getElement(i);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (element == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 throw OrthancException(ErrorCode_InternalError);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1929
diff changeset
96 ValueRepresentation vr = FromDcmtkBridge::LookupValueRepresentation(tag);
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 if (constraints_.find(tag) != constraints_.end() ||
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 sequences_.find(tag) != sequences_.end())
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 if (vr == ValueRepresentation_Sequence)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (sequence.card() == 0 ||
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 (sequence.card() == 1 && sequence.getItem(0)->card() == 0))
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 // Universal matching of a sequence
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 sequences_[tag] = NULL;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 else if (sequence.card() == 1)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 sequences_[tag] = new HierarchicalMatcher(*sequence.getItem(0), caseSensitivePN, encoding);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
125 std::set<DicomTag> ignoreTagLength;
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 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
127 (*element, DicomToJsonFlags_None,
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
128 ORTHANC_MAXIMUM_TAG_LENGTH, encoding, ignoreTagLength));
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
1867
769178f0ab2c Fix modality worklists server if some fields are null
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1797
diff changeset
130 if (value->IsBinary())
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
1890
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1867
diff changeset
132 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
133 {
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1867
diff changeset
134 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
135 << 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
136 << "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
137 }
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 constraints_[tag] = NULL;
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
1867
769178f0ab2c Fix modality worklists server if some fields are null
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1797
diff changeset
141 else if (value->IsNull() ||
769178f0ab2c Fix modality worklists server if some fields are null
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1797
diff changeset
142 value->GetContent().empty())
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 // This is an universal matcher
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 constraints_[tag] = NULL;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 // DICOM specifies that searches must be case sensitive, except
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 // for tags with a PN value representation
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 bool sensitive = true;
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
152 if (vr == ValueRepresentation_PersonName)
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 sensitive = caseSensitivePN;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 constraints_[tag] = IFindConstraint::ParseDicomConstraint(tag, value->GetContent(), sensitive);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 std::string HierarchicalMatcher::Format(const std::string& prefix) const
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 std::string s;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 for (Constraints::const_iterator it = constraints_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 it != constraints_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 s += prefix + it->first.Format() + " ";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 if (it->second == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 s += "*\n";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 s += it->second->Format() + "\n";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 for (Sequences::const_iterator it = sequences_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 it != sequences_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 s += prefix + it->first.Format() + " ";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 if (it->second == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 s += "*\n";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 s += "Sequence:\n" + it->second->Format(prefix + " ");
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 return s;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
204 return MatchInternal(*dicom.GetDcmtkObject().getDataset(),
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
205 dicom.GetEncoding());
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
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 bool HierarchicalMatcher::MatchInternal(DcmItem& item,
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
210 Encoding encoding) const
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 for (Constraints::const_iterator it = constraints_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
213 it != constraints_.end(); ++it)
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 if (it->second != NULL)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
218
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
219 DcmElement* element = NULL;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
220 if (!item.findAndGetElement(tag, element).good() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
221 element == NULL)
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 return false;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
224 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
225
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
226 std::set<DicomTag> ignoreTagLength;
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
227 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
228 (*element, DicomToJsonFlags_None,
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
229 ORTHANC_MAXIMUM_TAG_LENGTH, encoding, ignoreTagLength));
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
230
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
231 if (value->IsNull() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
232 value->IsBinary() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
233 !it->second->Match(value->GetContent()))
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 return 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 }
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 for (Sequences::const_iterator it = sequences_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
241 it != sequences_.end(); ++it)
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 if (it->second != NULL)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
246
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
247 DcmSequenceOfItems* sequence = NULL;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
248 if (!item.findAndGetSequence(tag, sequence).good() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
249 sequence == NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
250 {
1891
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
251 continue;
1796
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
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
254 bool match = false;
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 for (unsigned long i = 0; i < sequence->card(); i++)
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 if (it->second->MatchInternal(*sequence->getItem(i), encoding))
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
259 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
260 match = true;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
261 break;
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 }
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 if (!match)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
266 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
267 return false;
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 }
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 true;
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
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
276 DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source,
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
277 Encoding encoding) const
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
278 {
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
279 std::auto_ptr<DcmDataset> target(new DcmDataset);
1796
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 (Constraints::const_iterator it = constraints_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
282 it != constraints_.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 DcmElement* element = NULL;
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
287 if (source.findAndGetElement(tag, element).good() &&
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
288 element != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
289 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
290 std::auto_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(it->first));
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
291 cloned->copyFrom(*element);
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
292 target->insert(cloned.release());
1796
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 }
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 for (Sequences::const_iterator it = sequences_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
297 it != sequences_.end(); ++it)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
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 DcmSequenceOfItems* sequence = NULL;
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
302 if (source.findAndGetSequence(tag, sequence).good() &&
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
303 sequence != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
304 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
305 std::auto_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag));
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 for (unsigned long i = 0; i < sequence->card(); i++)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
308 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
309 if (it->second == NULL)
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 cloned->append(new DcmItem(*sequence->getItem(i)));
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 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
314 {
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
315 // It is necessary to encapsulate the child dataset into a
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
316 // "DcmItem" object before it can be included in a
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
317 // sequence. Otherwise, "dciodvfy" reports an error "Bad
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
318 // tag in sequence - Expecting Item or Sequence Delimiter."
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
319 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
320 cloned->append(new DcmItem(*child));
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
321 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
322 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
323
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
324 target->insert(cloned.release());
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
325 }
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
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
328 return target.release();
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
329 }
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 ParsedDicomFile* HierarchicalMatcher::Extract(ParsedDicomFile& dicom) const
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
333 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
334 std::auto_ptr<DcmDataset> dataset(ExtractInternal(*dicom.GetDcmtkObject().getDataset(),
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
335 dicom.GetEncoding()));
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 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
338 result->SetEncoding(dicom.GetEncoding());
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
339
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
340 return result.release();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
341 }
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }