forked from DCMTK/dcmtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsrcontn.cc
260 lines (220 loc) · 8.54 KB
/
dsrcontn.cc
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
*
* Copyright (C) 2000-2018, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmsr
*
* Author: Joerg Riesmeier
*
* Purpose:
* classes: DSRContainerTreeNode
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmsr/dsrtypes.h"
#include "dcmtk/dcmsr/dsrcontn.h"
#include "dcmtk/dcmsr/dsrxmld.h"
#include "dcmtk/dcmdata/dcdeftag.h"
DSRContainerTreeNode::DSRContainerTreeNode(const E_RelationshipType relationshipType,
const E_ContinuityOfContent continuityOfContent)
: DSRDocumentTreeNode(relationshipType, VT_Container),
ContinuityOfContent(continuityOfContent)
{
}
DSRContainerTreeNode::DSRContainerTreeNode(const DSRContainerTreeNode &node)
: DSRDocumentTreeNode(node),
ContinuityOfContent(node.ContinuityOfContent)
{
}
DSRContainerTreeNode::~DSRContainerTreeNode()
{
}
OFBool DSRContainerTreeNode::operator==(const DSRDocumentTreeNode &node) const
{
/* call comparison operator of base class (includes check of value type) */
OFBool result = DSRDocumentTreeNode::operator==(node);
if (result)
{
/* it's safe to cast the type since the value type has already been checked */
result = (ContinuityOfContent == OFstatic_cast(const DSRContainerTreeNode &, node).ContinuityOfContent);
}
return result;
}
OFBool DSRContainerTreeNode::operator!=(const DSRDocumentTreeNode &node) const
{
/* call comparison operator of base class (includes check of value type) */
OFBool result = DSRDocumentTreeNode::operator!=(node);
if (!result)
{
/* it's safe to cast the type since the value type has already been checked */
result = (ContinuityOfContent != OFstatic_cast(const DSRContainerTreeNode &, node).ContinuityOfContent);
}
return result;
}
DSRContainerTreeNode *DSRContainerTreeNode::clone() const
{
return new DSRContainerTreeNode(*this);
}
void DSRContainerTreeNode::clear()
{
ContinuityOfContent = COC_Separate; // this is more useful that COC_invalid
}
OFBool DSRContainerTreeNode::isValid() const
{
/* ConceptNameCodeSequence required for root node container */
return DSRDocumentTreeNode::isValid() && hasValidValue() &&
((getRelationshipType() != RT_isRoot) || getConceptName().isValid());
}
OFBool DSRContainerTreeNode::hasValidValue() const
{
return (ContinuityOfContent != COC_invalid);
}
OFBool DSRContainerTreeNode::isShort(const size_t /*flags*/) const
{
return OFFalse;
}
OFCondition DSRContainerTreeNode::print(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
OFCondition result = DSRDocumentTreeNode::print(stream, flags);
if (result.good())
{
DCMSR_PRINT_ANSI_ESCAPE_CODE(DCMSR_ANSI_ESCAPE_CODE_DELIMITER)
stream << "=";
DCMSR_PRINT_ANSI_ESCAPE_CODE(DCMSR_ANSI_ESCAPE_CODE_ITEM_VALUE)
stream << continuityOfContentToEnumeratedValue(ContinuityOfContent);
}
return result;
}
OFCondition DSRContainerTreeNode::readContentItem(DcmItem &dataset,
const size_t /*flags*/)
{
OFString tmpString;
/* read ContinuityOfContent */
OFCondition result = getAndCheckStringValueFromDataset(dataset, DCM_ContinuityOfContent, tmpString, "1", "1", "CONTAINER content item");
if (result.good())
{
ContinuityOfContent = enumeratedValueToContinuityOfContent(tmpString);
/* check ContinuityOfContent value */
if (ContinuityOfContent == COC_invalid)
{
printUnknownValueWarningMessage("ContinuityOfContent value", tmpString.c_str());
result = SR_EC_InvalidValue;
}
}
return result;
}
OFCondition DSRContainerTreeNode::writeContentItem(DcmItem &dataset) const
{
/* write ContinuityOfContent */
return putStringValueToDataset(dataset, DCM_ContinuityOfContent, continuityOfContentToEnumeratedValue(ContinuityOfContent));
}
OFCondition DSRContainerTreeNode::readXMLContentItem(const DSRXMLDocument &doc,
DSRXMLCursor cursor,
const size_t /*flags*/)
{
OFCondition result = SR_EC_CorruptedXMLStructure;
if (cursor.valid())
{
OFString tmpString;
/* read 'flag' and check validity */
ContinuityOfContent = enumeratedValueToContinuityOfContent(doc.getStringFromAttribute(cursor, tmpString, "flag"));
if (ContinuityOfContent == COC_invalid)
{
printUnknownValueWarningMessage("CONTAINER flag", tmpString.c_str());
result = SR_EC_InvalidValue;
} else
result = EC_Normal;
}
return result;
}
OFCondition DSRContainerTreeNode::writeXML(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
OFCondition result = EC_Normal;
writeXMLItemStart(stream, flags, OFFalse /*closingBracket*/);
stream << " flag=\"" << continuityOfContentToEnumeratedValue(ContinuityOfContent) << "\"";
stream << ">" << OFendl;
result = DSRDocumentTreeNode::writeXML(stream, flags);
writeXMLItemEnd(stream, flags);
return result;
}
OFCondition DSRContainerTreeNode::renderHTMLContentItem(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream & /*annexStream*/,
const size_t nestingLevel,
size_t & /*annexNumber*/,
const size_t flags) const
{
/* section heading (optional) */
if (nestingLevel > 0)
{
/* render ConceptName & Code (if valid) */
if (!getConceptName().getCodeMeaning().empty())
{
const size_t section = (nestingLevel > 6) ? 6 : nestingLevel;
docStream << "<h" << section << ">";
getConceptName().renderHTML(docStream, flags, (flags & HF_renderConceptNameCodes) && getConceptName().isValid() /*fullCode*/);
docStream << "</h" << section << ">" << OFendl;
}
/* render optional observation date/time */
if (!getObservationDateTime().empty())
{
OFString tmpString;
docStream << "<p>" << OFendl;
if (flags & HF_XHTML11Compatibility)
docStream << "<span class=\"observe\">";
else
docStream << "<small>";
docStream << "(observed: " << dicomToReadableDateTime(getObservationDateTime(), tmpString) << ")";
if (flags & HF_XHTML11Compatibility)
docStream << "</span>" << OFendl;
else
docStream << "</small>" << OFendl;
docStream << "</p>" << OFendl;
}
}
return EC_Normal;
}
OFCondition DSRContainerTreeNode::renderHTML(STD_NAMESPACE ostream &docStream,
STD_NAMESPACE ostream &annexStream,
const size_t nestingLevel,
size_t &annexNumber,
const size_t flags) const
{
/* check for validity */
if (!isValid())
printInvalidContentItemMessage("Rendering", this);
/* render content item */
OFCondition result = renderHTMLContentItem(docStream, annexStream, nestingLevel, annexNumber, flags);
if (result.good())
{
/* section body: render child nodes */
if (ContinuityOfContent == COC_Continuous)
result = renderHTMLChildNodes(docStream, annexStream, nestingLevel, annexNumber, flags & ~HF_renderItemsSeparately);
else // might be invalid
result = renderHTMLChildNodes(docStream, annexStream, nestingLevel, annexNumber, flags | HF_renderItemsSeparately);
} else
printContentItemErrorMessage("Rendering", result, this);
return result;
}
OFCondition DSRContainerTreeNode::setContinuityOfContent(const E_ContinuityOfContent continuityOfContent,
const OFBool /*check*/)
{
OFCondition result = EC_IllegalParameter;
/* check whether the passed value is valid */
if (continuityOfContent != COC_invalid)
{
ContinuityOfContent = continuityOfContent;
result = EC_Normal;
}
return result;
}