annotate OrthancServer/Sources/Search/HierarchicalMatcher.cpp @ 5111:7547c7dfd017

/tools/metrics-prometheus: added orthanc_last_change and orthanc_up_time_s
author Alain Mazy <am@osimis.io>
date Tue, 22 Nov 2022 18:01:23 +0100
parents 6eff25f70121
children 0ea402b4d901
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
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeadersServer.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "HierarchicalMatcher.h"
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
26 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
27 #include "../../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
28 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
29 #include "../../../OrthancFramework/Sources/DicomParsing/ToDcmtkBridge.h"
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
30 #include "../OrthancConfiguration.h"
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <dcmtk/dcmdata/dcfilefo.h>
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace Orthanc
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
2256
de1ba22fd28a simplification wrt. modality manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
36 HierarchicalMatcher::HierarchicalMatcher(ParsedDicomFile& query)
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
38 bool caseSensitivePN;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
39
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 OrthancConfiguration::ReaderLock lock;
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
42 caseSensitivePN = lock.GetConfiguration().GetBooleanParameter("CaseSensitivePN", false);
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
43 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
44
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
45 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
46 Encoding encoding = query.DetectEncoding(hasCodeExtensions);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
47 Setup(*query.GetDcmtkObject().getDataset(), caseSensitivePN, encoding, hasCodeExtensions);
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
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 HierarchicalMatcher::~HierarchicalMatcher()
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 for (Sequences::iterator it = sequences_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 it != sequences_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (it->second != NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 delete it->second;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
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 void HierarchicalMatcher::Setup(DcmItem& dataset,
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 bool caseSensitivePN,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
66 Encoding encoding,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
67 bool hasCodeExtensions)
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 for (unsigned long i = 0; i < dataset.card(); i++)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 DcmElement* element = dataset.getElement(i);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if (element == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 throw OrthancException(ErrorCode_InternalError);
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 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
78 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
79 tag.GetElement() == 0x0000) // Ignore all "Group Length" tags
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
80 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
81 continue;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
82 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
83
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
84 if (flatTags_.find(tag) != flatTags_.end() ||
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 sequences_.find(tag) != sequences_.end())
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
87 // A constraint already exists on this tag
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
91 if (FromDcmtkBridge::LookupValueRepresentation(tag) == ValueRepresentation_Sequence)
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 if (sequence.card() == 0 ||
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 (sequence.card() == 1 && sequence.getItem(0)->card() == 0))
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // Universal matching of a sequence
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 sequences_[tag] = NULL;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 else if (sequence.card() == 1)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
103 sequences_[tag] = new HierarchicalMatcher(*sequence.getItem(0), caseSensitivePN, encoding, hasCodeExtensions);
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 throw OrthancException(ErrorCode_BadRequest);
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
3072
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
112 flatTags_.insert(tag);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
113
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
114 std::set<DicomTag> ignoreTagLength;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
115 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
116 (*element, DicomToJsonFlags_None,
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
117 0, encoding, hasCodeExtensions, ignoreTagLength));
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
3072
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
119 // WARNING: Also modify "DatabaseLookup::IsMatch()" if modifying this code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
120 if (value.get() == NULL ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
121 value->IsNull())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
122 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
123 // This is an universal constraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
124 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
125 else if (value->IsBinary())
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
1890
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1867
diff changeset
127 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
128 {
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1867
diff changeset
129 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
130 << 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
131 << "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
132 }
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
3072
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3071
diff changeset
134 else if (value->GetContent().empty())
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 // This is an universal matcher
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
140 flatConstraints_.AddDicomConstraint
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
141 (tag, value->GetContent(), caseSensitivePN, true /* mandatory */);
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
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
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 std::string HierarchicalMatcher::Format(const std::string& prefix) const
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 std::string s;
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
151
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
152 std::set<DicomTag> tags;
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
153 for (size_t i = 0; i < flatConstraints_.GetConstraintsCount(); i++)
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
155 const DicomTagConstraint& c = flatConstraints_.GetConstraint(i);
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
157 s += c.Format() + "\n";
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
158 tags.insert(c.GetTag());
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
159 }
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 // Loop over the universal constraints
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
162 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
163 it != flatTags_.end(); ++it)
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
164 {
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
165 if (tags.find(*it) == tags.end())
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
167 s += prefix + it->Format() + " == *\n";
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
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 for (Sequences::const_iterator it = sequences_.begin();
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 it != sequences_.end(); ++it)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 s += prefix + it->first.Format() + " ";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (it->second == NULL)
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 s += "*\n";
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 else
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 s += "Sequence:\n" + it->second->Format(prefix + " ");
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
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 return s;
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
188
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 bool HierarchicalMatcher::Match(ParsedDicomFile& dicom) const
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
191 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
192 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
193 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
194
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
195 return MatchInternal(*dicom.GetDcmtkObject().getDataset(),
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
196 encoding, hasCodeExtensions);
1796
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
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 bool HierarchicalMatcher::MatchInternal(DcmItem& item,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
201 Encoding encoding,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
202 bool hasCodeExtensions) const
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
203 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
204 if (!flatConstraints_.IsMatch(item, encoding, hasCodeExtensions))
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
205 {
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
206 return false;
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
207 }
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
208
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
209 for (Sequences::const_iterator it = sequences_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
210 it != sequences_.end(); ++it)
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 if (it->second != NULL)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
215
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
216 DcmSequenceOfItems* sequence = NULL;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
217 if (!item.findAndGetSequence(tag, sequence).good() ||
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
218 sequence == NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
219 {
1891
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
220 continue;
1796
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
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
223 bool match = 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 for (unsigned long i = 0; i < sequence->card(); i++)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
226 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
227 if (it->second->MatchInternal(*sequence->getItem(i), encoding, hasCodeExtensions))
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
228 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
229 match = true;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
230 break;
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 }
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 if (!match)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
235 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
236 return false;
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
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
241 return true;
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
242 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
243
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
244
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
245 DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
246 Encoding encoding,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
247 bool hasCodeExtensions) const
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
248 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
249 std::unique_ptr<DcmDataset> target(new DcmDataset);
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
250
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
251 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
252 it != flatTags_.end(); ++it)
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
253 {
3071
2df061cf2fec getting rid of IFindConstraint hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
254 DcmTagKey tag = ToDcmtkBridge::Convert(*it);
1796
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 DcmElement* element = NULL;
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
257 if (source.findAndGetElement(tag, element).good() &&
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
258 element != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
259 {
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
260 if (it->IsPrivate())
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
261 {
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
262 throw OrthancException(ErrorCode_NotImplemented,
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
263 "Not applicable to private tags: " + it->Format());
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
264 }
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
265
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
266 std::unique_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(*it, "" /* no private creator */));
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
267 cloned->copyFrom(*element);
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
268 target->insert(cloned.release());
1796
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 for (Sequences::const_iterator it = sequences_.begin();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
273 it != sequences_.end(); ++it)
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 DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
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 DcmSequenceOfItems* sequence = NULL;
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
278 if (source.findAndGetSequence(tag, sequence).good() &&
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
279 sequence != NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
280 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
281 std::unique_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag));
1796
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 (unsigned long i = 0; i < sequence->card(); i++)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
284 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
285 if (it->second == NULL)
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
286 {
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
287 cloned->append(new DcmItem(*sequence->getItem(i)));
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
288 }
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
289 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
290 {
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
291 // It is necessary to encapsulate the child dataset into a
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
292 // "DcmItem" object before it can be included in a
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
293 // sequence. Otherwise, "dciodvfy" reports an error "Bad
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
294 // 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
295 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
296 cloned->append(new DcmItem(*child));
1796
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 }
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 target->insert(cloned.release());
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
301 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
302 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
303
1797
23722a191e4e worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1796
diff changeset
304 return target.release();
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
305 }
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
306
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 ParsedDicomFile* HierarchicalMatcher::Extract(ParsedDicomFile& dicom) const
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
309 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
310 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
311 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3072
diff changeset
312
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
313 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
314 encoding, hasCodeExtensions));
1796
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
315
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
316 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
317 result->SetEncoding(encoding);
1796
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 return result.release();
5e08a5fe6b27 HierarchicalMatcher - extracting tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1795
diff changeset
320 }
1795
af6840eb23ee HierarchicalMatcher
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }