annotate OrthancServer/Search/HierarchicalMatcher.cpp @ 1797:23722a191e4e worklists

worklists are working
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Nov 2015 11:37:58 +0100
parents 5e08a5fe6b27
children 769178f0ab2c
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
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * modify file(s) with this exception, you may extend this exception to
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * 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
19 * you do not wish to do so, delete this exception statement from your
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
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 #include "../PrecompiledHeadersServer.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "HierarchicalMatcher.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../../Core/OrthancException.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../FromDcmtkBridge.h"
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
38 #include "../ToDcmtkBridge.h"
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <dcmtk/dcmdata/dcfilefo.h>
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace Orthanc
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 HierarchicalMatcher::HierarchicalMatcher(ParsedDicomFile& query,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 bool caseSensitivePN)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 Setup(*query.GetDcmtkObject().getDataset(),
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 caseSensitivePN,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 query.GetEncoding());
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 HierarchicalMatcher::~HierarchicalMatcher()
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 for (Constraints::iterator it = constraints_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 it != constraints_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 if (it->second != NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 delete it->second;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 for (Sequences::iterator it = sequences_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 it != sequences_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (it->second != NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 delete it->second;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
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 void HierarchicalMatcher::Setup(DcmItem& dataset,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 bool caseSensitivePN,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 Encoding encoding)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 for (unsigned long i = 0; i < dataset.card(); i++)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 DcmElement* element = dataset.getElement(i);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 if (element == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 throw OrthancException(ErrorCode_InternalError);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 DicomTag tag(FromDcmtkBridge::Convert(element->getTag()));
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
88 if (tag == DICOM_TAG_SPECIFIC_CHARACTER_SET)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
89 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
90 // Ignore this specific tag
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
91 continue;
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
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ValueRepresentation vr = FromDcmtkBridge::GetValueRepresentation(tag);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 if (constraints_.find(tag) != constraints_.end() ||
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 sequences_.find(tag) != sequences_.end())
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 if (vr == ValueRepresentation_Sequence)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (sequence.card() == 0 ||
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 (sequence.card() == 1 && sequence.getItem(0)->card() == 0))
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 // Universal matching of a sequence
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 sequences_[tag] = NULL;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 else if (sequence.card() == 1)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 sequences_[tag] = new HierarchicalMatcher(*sequence.getItem(0), caseSensitivePN, encoding);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 std::auto_ptr<DicomValue> value(FromDcmtkBridge::ConvertLeafElement
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 (*element, DicomToJsonFlags_None, encoding));
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 if (value->IsBinary() ||
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 value->IsNull())
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 else if (value->GetContent().empty())
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 // This is an universal matcher
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 constraints_[tag] = NULL;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 // DICOM specifies that searches must be case sensitive, except
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 // for tags with a PN value representation
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 bool sensitive = true;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 if (vr == ValueRepresentation_PatientName)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 sensitive = caseSensitivePN;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 constraints_[tag] = IFindConstraint::ParseDicomConstraint(tag, value->GetContent(), sensitive);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 std::string HierarchicalMatcher::Format(const std::string& prefix) const
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 std::string s;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 for (Constraints::const_iterator it = constraints_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 it != constraints_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 s += prefix + it->first.Format() + " ";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 if (it->second == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 s += "*\n";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 s += it->second->Format() + "\n";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 for (Sequences::const_iterator it = sequences_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 it != sequences_.end(); ++it)
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 += prefix + it->first.Format() + " ";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 if (it->second == NULL)
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 += "*\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 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 s += "Sequence:\n" + it->second->Format(prefix + " ");
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 return s;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
193 return MatchInternal(*dicom.GetDcmtkObject().getDataset(),
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
194 dicom.GetEncoding());
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
195 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
196
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
197
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
198 bool HierarchicalMatcher::MatchInternal(DcmItem& item,
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
199 Encoding encoding) const
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 for (Constraints::const_iterator it = constraints_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
202 it != constraints_.end(); ++it)
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 if (it->second != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
205 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
206 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
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 DcmElement* element = NULL;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
209 if (!item.findAndGetElement(tag, element).good() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
210 element == NULL)
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 return false;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
213 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
214
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
215 std::auto_ptr<DicomValue> value(FromDcmtkBridge::ConvertLeafElement
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
216 (*element, DicomToJsonFlags_None, encoding));
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
217
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
218 if (value->IsNull() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
219 value->IsBinary() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
220 !it->second->Match(value->GetContent()))
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
221 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
222 return false;
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 }
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
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
227 for (Sequences::const_iterator it = sequences_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
228 it != sequences_.end(); ++it)
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 if (it->second != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
231 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
232 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
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 DcmSequenceOfItems* sequence = NULL;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
235 if (!item.findAndGetSequence(tag, sequence).good() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
236 sequence == NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
237 {
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
238 return true;
1796
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 bool match = false;
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 for (unsigned long i = 0; i < sequence->card(); i++)
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 if (it->second->MatchInternal(*sequence->getItem(i), encoding))
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 match = true;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
248 break;
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 if (!match)
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 return 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 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
257 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
258
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
259 return true;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
260 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
261
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
262
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
263 DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source,
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
264 Encoding encoding) const
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
265 {
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
266 std::auto_ptr<DcmDataset> target(new DcmDataset);
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 for (Constraints::const_iterator it = constraints_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
269 it != constraints_.end(); ++it)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
272
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
273 DcmElement* element = NULL;
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
274 if (source.findAndGetElement(tag, element).good() &&
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
275 element != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
276 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
277 std::auto_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(it->first));
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
278 cloned->copyFrom(*element);
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
279 target->insert(cloned.release());
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 }
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 for (Sequences::const_iterator it = sequences_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
284 it != sequences_.end(); ++it)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
287
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
288 DcmSequenceOfItems* sequence = NULL;
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
289 if (source.findAndGetSequence(tag, sequence).good() &&
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
290 sequence != NULL)
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 std::auto_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag));
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 for (unsigned long i = 0; i < sequence->card(); i++)
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 if (it->second == NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
297 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
298 cloned->append(new DcmItem(*sequence->getItem(i)));
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 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
301 {
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
302 // It is necessary to encapsulate the child dataset into a
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
303 // "DcmItem" object before it can be included in a
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
304 // sequence. Otherwise, "dciodvfy" reports an error "Bad
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
305 // tag in sequence - Expecting Item or Sequence Delimiter."
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
306 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
307 cloned->append(new DcmItem(*child));
1796
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 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
310
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
311 target->insert(cloned.release());
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
312 }
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
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
315 return target.release();
1796
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
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 ParsedDicomFile* HierarchicalMatcher::Extract(ParsedDicomFile& dicom) const
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
320 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
321 std::auto_ptr<DcmDataset> dataset(ExtractInternal(*dicom.GetDcmtkObject().getDataset(),
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
322 dicom.GetEncoding()));
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
323
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
324 std::auto_ptr<ParsedDicomFile> result(new ParsedDicomFile(*dataset));
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
325 result->SetEncoding(Encoding_Utf8);
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 return result.release();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
328 }
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }