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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
/*
*
* Copyright (C) 2015-2018, J. Riesmeier, Oldenburg, Germany
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation are maintained by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmsr
*
* Author: Joerg Riesmeier
*
* Purpose:
* classes: DSRIncludedTemplateTreeNode
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmsr/dsrtypes.h"
#include "dcmtk/dcmsr/dsrtpltn.h"
#include "dcmtk/dcmsr/dsrstpl.h"
#include "dcmtk/dcmsr/dsrxmld.h"
DSRIncludedTemplateTreeNode::DSRIncludedTemplateTreeNode(const DSRSharedSubTemplate &referencedTemplate,
const E_RelationshipType defaultRelType)
: DSRDocumentTreeNode(defaultRelType, VT_includedTemplate),
ReferencedTemplate(referencedTemplate)
{
if (ReferencedTemplate)
{
/* store template identification of the referenced template */
DSRDocumentTreeNode::setTemplateIdentification(ReferencedTemplate->getTemplateIdentifier(),
ReferencedTemplate->getMappingResource(),
ReferencedTemplate->getMappingResourceUID());
}
}
DSRIncludedTemplateTreeNode::DSRIncludedTemplateTreeNode(const DSRIncludedTemplateTreeNode &node)
: DSRDocumentTreeNode(node),
ReferencedTemplate(node.ReferencedTemplate)
{
}
DSRIncludedTemplateTreeNode::~DSRIncludedTemplateTreeNode()
{
}
DSRIncludedTemplateTreeNode *DSRIncludedTemplateTreeNode::clone() const
{
return new DSRIncludedTemplateTreeNode(*this);
}
void DSRIncludedTemplateTreeNode::clear()
{
DSRDocumentTreeNode::clear();
ReferencedTemplate.reset();
}
OFBool DSRIncludedTemplateTreeNode::isEqual(const DSRDocumentTreeNode &node) const
{
/* call comparison operator of base class (includes check of value type) */
OFBool result = DSRDocumentTreeNode::isEqual(node);
if (result)
{
/* it's safe to cast the type since the value type has already been checked */
result = (ReferencedTemplate.get() == OFstatic_cast(const DSRIncludedTemplateTreeNode &, node).ReferencedTemplate.get());
}
return result;
}
OFBool DSRIncludedTemplateTreeNode::isNotEqual(const DSRDocumentTreeNode &node) const
{
/* call comparison operator of base class (includes check of value type) */
OFBool result = DSRDocumentTreeNode::isNotEqual(node);
if (!result)
{
/* it's safe to cast the type since the value type has already been checked */
result = (ReferencedTemplate.get() != OFstatic_cast(const DSRIncludedTemplateTreeNode &, node).ReferencedTemplate.get());
}
return result;
}
OFBool DSRIncludedTemplateTreeNode::isValid() const
{
return DSRDocumentTreeNode::isValid() && hasValidValue();
}
OFBool DSRIncludedTemplateTreeNode::hasValidValue() const
{
/* check whether the reference to the included template is valid */
return ReferencedTemplate ? OFTrue : OFFalse;
}
OFBool DSRIncludedTemplateTreeNode::isShort(const size_t /*flags*/) const
{
return !hasValidValue();
}
OFCondition DSRIncludedTemplateTreeNode::print(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
stream << "# INCLUDE ";
/* check whether template identification is set */
if (hasTemplateIdentification())
{
OFString templateIdentifier, mappingResource;
getTemplateIdentification(templateIdentifier, mappingResource);
stream << "TID " << templateIdentifier << " (" << mappingResource << ")";
} else {
/* no details on the template available */
stream << "<unknown template>";
}
/* check whether default relationship type is specified */
if (getRelationshipType() != RT_unknown)
stream << " with default relationship type " << relationshipTypeToDefinedTerm(getRelationshipType());
/* print annotation (optional) */
if (hasAnnotation() && (flags & PF_printAnnotation))
stream << " \"" << getAnnotation().getText() << "\"";
return EC_Normal;
}
OFCondition DSRIncludedTemplateTreeNode::writeXML(STD_NAMESPACE ostream &stream,
const size_t flags) const
{
OFCondition result = EC_Normal;
/* write content of included template in XML format (if non-empty) */
if (hasValidValue() && !ReferencedTemplate->isEmpty())
{
OFString templateIdentifier, mappingResource;
/* output details on beginning of included template (if enabled) */
if (hasTemplateIdentification() && (flags & XF_addCommentsForIncludedTemplate))
{
getTemplateIdentification(templateIdentifier, mappingResource);
stream << "<!-- BEGIN: included template TID " << templateIdentifier << " (" << mappingResource << ") -->" << OFendl;
}
/* write content of referenced document subtree */
result = ReferencedTemplate->writeXML(stream, flags);
/* output details on end of included template (if available, see above) */
if (!templateIdentifier.empty() && !mappingResource.empty())
stream << "<!-- END: included template TID " << templateIdentifier << " (" << mappingResource << ") -->" << OFendl;
}
return result;
}
OFCondition DSRIncludedTemplateTreeNode::setValue(const DSRSharedSubTemplate &referencedTemplate)
{
ReferencedTemplate = referencedTemplate;
/* currently, no checks are performed */
return EC_Normal;
}
// protected methods
OFCondition DSRIncludedTemplateTreeNode::read(DcmItem & /*dataset*/,
const DSRIODConstraintChecker * /*constraintChecker*/,
const size_t /*flags*/)
{
/* invalid: cannot read document with included templates */
return SR_EC_CannotProcessIncludedTemplates;
}
OFCondition DSRIncludedTemplateTreeNode::write(DcmItem & /*dataset*/,
DcmStack * /*markedItems*/)
{
/* invalid: cannot write document with included templates */
return SR_EC_CannotProcessIncludedTemplates;
}
OFCondition DSRIncludedTemplateTreeNode::readXML(const DSRXMLDocument & /*doc*/,
DSRXMLCursor /*cursor*/,
const E_DocumentType /*documentType*/,
const size_t /*flags*/)
{
/* invalid: cannot read document with included templates */
return SR_EC_CannotProcessIncludedTemplates;
}
OFCondition DSRIncludedTemplateTreeNode::renderHTML(STD_NAMESPACE ostream & /*docStream*/,
STD_NAMESPACE ostream & /*annexStream*/,
const size_t /*nestingLevel*/,
size_t & /*annexNumber*/,
const size_t /*flags*/,
const char * /*urlPrefix*/) const
{
/* invalid: cannot render document with included templates */
return SR_EC_CannotProcessIncludedTemplates;
}
OFCondition DSRIncludedTemplateTreeNode::setConceptName(const DSRCodedEntryValue & /*conceptName*/,
const OFBool /*check*/)
{
/* invalid: no concept name allowed */
return EC_IllegalCall;
}
OFCondition DSRIncludedTemplateTreeNode::setObservationDateTime(const OFString & /*observationDateTime*/,
const OFBool /*check*/)
{
/* invalid: no observation date/time allowed */
return EC_IllegalCall;
}
OFCondition DSRIncludedTemplateTreeNode::setObservationDateTime(const DcmElement & /*delem*/,
const unsigned long /*pos*/,
const OFBool /*check*/)
{
/* invalid: no observation date/time allowed */
return EC_IllegalCall;
}
OFCondition DSRIncludedTemplateTreeNode::setObservationDateTime(DcmItem & /*dataset*/,
const DcmTagKey & /*tagKey*/,
const unsigned long /*pos*/,
const OFBool /*check*/)
{
/* invalid: no observation date/time allowed */
return EC_IllegalCall;
}
OFCondition DSRIncludedTemplateTreeNode::setObservationUID(const OFString & /*observationUID*/,
const OFBool /*check*/)
{
/* invalid: no observation unique identifier allowed */
return EC_IllegalCall;
}
OFCondition DSRIncludedTemplateTreeNode::setTemplateIdentification(const OFString & /*templateIdentifier*/,
const OFString & /*mappingResource*/,
const OFString & /*mappingResourceUID*/,
const OFBool /*check*/)
{
/* invalid: no manual setting of template identification allowed */
return EC_IllegalCall;
}
// comparison operators
OFBool operator==(const DSRIncludedTemplateTreeNode &lhs,
const DSRIncludedTemplateTreeNode &rhs)
{
return lhs.isEqual(rhs);
}
OFBool operator!=(const DSRIncludedTemplateTreeNode &lhs,
const DSRIncludedTemplateTreeNode &rhs)
{
return lhs.isNotEqual(rhs);
}
|