-
Notifications
You must be signed in to change notification settings - Fork 494
/
ctkDICOMDisplayedFieldGenerator.cpp
206 lines (165 loc) · 7.5 KB
/
ctkDICOMDisplayedFieldGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*=========================================================================
Library: CTK
Copyright (c) PerkLab 2013
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
// Qt includes
#include <QStringList>
// ctkDICOM includes
#include "ctkLogger.h"
#include "ctkDICOMDatabase.h"
#include "ctkDICOMDisplayedFieldGenerator.h"
#include "ctkDICOMDisplayedFieldGenerator_p.h"
#include "ctkDICOMDisplayedFieldGeneratorAbstractRule.h"
#include "ctkDICOMDisplayedFieldGeneratorRuleFactory.h"
//------------------------------------------------------------------------------
static ctkLogger logger("org.commontk.dicom.DICOMDisplayedFieldGenerator" );
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// ctkDICOMDisplayedFieldGeneratorPrivate methods
//------------------------------------------------------------------------------
ctkDICOMDisplayedFieldGeneratorPrivate::ctkDICOMDisplayedFieldGeneratorPrivate(ctkDICOMDisplayedFieldGenerator& o)
: q_ptr(&o)
, Database(nullptr)
{
}
//------------------------------------------------------------------------------
ctkDICOMDisplayedFieldGeneratorPrivate::~ctkDICOMDisplayedFieldGeneratorPrivate()
{
}
//------------------------------------------------------------------------------
void ctkDICOMDisplayedFieldGeneratorPrivate::setupEnabledDisplayedFieldGeneratorRules()
{
if (!this->Database)
{
qCritical() << Q_FUNC_INFO << " failed: DICOM database needs to be set";
return;
}
if (!this->GeneratorRules.isEmpty())
{
qWarning() << Q_FUNC_INFO << " : Generator rules have not been cleared before new update session";
this->clearDisplayedFieldGeneratorRules();
}
// Instantiate enabled rules registered in factory
this->GeneratorRules =
ctkDICOMDisplayedFieldGeneratorRuleFactory::instance()->copyEnabledDisplayedFieldGeneratorRules(this->Database);
// Setup generator rules used in this update session
foreach(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule, this->GeneratorRules)
{
// Set database
rule->setDatabase(this->Database);
// Register empty field names
rule->registerEmptyFieldNames(
this->EmptyFieldNamesSeries, this->EmptyFieldNamesStudies, this->EmptyFieldNamesPatients );
}
//TODO: Process Options field in DisplayedFieldGeneratorRules table when has a concrete use.
}
//------------------------------------------------------------------------------
void ctkDICOMDisplayedFieldGeneratorPrivate::clearDisplayedFieldGeneratorRules()
{
// Delete generator rules and clear container
foreach(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule, this->GeneratorRules)
{
delete rule;
}
this->GeneratorRules.clear();
// Clear empty field names registered previously by the rules
this->EmptyFieldNamesSeries.clear();
this->EmptyFieldNamesStudies.clear();
this->EmptyFieldNamesPatients.clear();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// ctkDICOMDisplayedFieldGenerator methods
//------------------------------------------------------------------------------
ctkDICOMDisplayedFieldGenerator::ctkDICOMDisplayedFieldGenerator(QObject *parent)
: d_ptr(new ctkDICOMDisplayedFieldGeneratorPrivate(*this))
{
Q_UNUSED(parent);
}
//------------------------------------------------------------------------------
ctkDICOMDisplayedFieldGenerator::~ctkDICOMDisplayedFieldGenerator()
{
Q_D(ctkDICOMDisplayedFieldGenerator);
d->clearDisplayedFieldGeneratorRules();
}
//------------------------------------------------------------------------------
QStringList ctkDICOMDisplayedFieldGenerator::getRequiredTags()
{
Q_D(ctkDICOMDisplayedFieldGenerator);
QStringList requiredTags;
foreach(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule, d->GeneratorRules)
{
requiredTags << rule->getRequiredDICOMTags();
}
requiredTags.removeDuplicates();
return requiredTags;
}
//------------------------------------------------------------------------------
void ctkDICOMDisplayedFieldGenerator::updateDisplayedFieldsForInstance(
const QString& sopInstanceUID, const QMap<QString, QString> &cachedTagsForInstance,
QMap<QString, QString> &displayedFieldsForCurrentSeries,
QMap<QString, QString> &displayedFieldsForCurrentStudy,
QMap<QString, QString> &displayedFieldsForCurrentPatient )
{
Q_D(ctkDICOMDisplayedFieldGenerator);
Q_UNUSED(sopInstanceUID);
QMap<QString, QString> newFieldsSeries;
QMap<QString, QString> newFieldsStudy;
QMap<QString, QString> newFieldsPatient;
foreach(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule, d->GeneratorRules)
{
QMap<QString, QString> initialFieldsSeries = displayedFieldsForCurrentSeries;
QMap<QString, QString> initialFieldsStudy = displayedFieldsForCurrentStudy;
QMap<QString, QString> initialFieldsPatient = displayedFieldsForCurrentPatient;
rule->getDisplayedFieldsForInstance(cachedTagsForInstance, newFieldsSeries, newFieldsStudy, newFieldsPatient);
rule->mergeDisplayedFieldsForInstance(
initialFieldsSeries, initialFieldsStudy, initialFieldsPatient, // original DB contents
newFieldsSeries, newFieldsStudy, newFieldsPatient, // new value
displayedFieldsForCurrentSeries, displayedFieldsForCurrentStudy, displayedFieldsForCurrentPatient, // new DB contents
d->EmptyFieldNamesSeries, d->EmptyFieldNamesStudies, d->EmptyFieldNamesPatients // empty field names defined by all the rules
);
}
}
//------------------------------------------------------------------------------
void ctkDICOMDisplayedFieldGenerator::startUpdate()
{
Q_D(ctkDICOMDisplayedFieldGenerator);
// Re-initialize generator rules in case new ones have been registered or the rule options changed in the database
d->clearDisplayedFieldGeneratorRules();
d->setupEnabledDisplayedFieldGeneratorRules();
foreach(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule, d->GeneratorRules)
{
rule->startUpdate();
}
}
//------------------------------------------------------------------------------
void ctkDICOMDisplayedFieldGenerator::endUpdate(QMap<QString, QMap<QString, QString> > &displayedFieldsMapSeries,
QMap<QString, QMap<QString, QString> > &displayedFieldsMapStudy,
QMap<QString, QMap<QString, QString> > &displayedFieldsMapPatient)
{
Q_D(ctkDICOMDisplayedFieldGenerator);
foreach(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule, d->GeneratorRules)
{
rule->endUpdate(displayedFieldsMapSeries, displayedFieldsMapStudy, displayedFieldsMapPatient);
}
}
//------------------------------------------------------------------------------
void ctkDICOMDisplayedFieldGenerator::setDatabase(ctkDICOMDatabase* database)
{
Q_D(ctkDICOMDisplayedFieldGenerator);
if (d->Database == database)
{
return;
}
d->Database = database;
d->setupEnabledDisplayedFieldGeneratorRules();
}