1 /*
2  *
3  *  Copyright (C) 2015-2017, J. Riesmeier, Oldenburg, Germany
4  *  All rights reserved.  See COPYRIGHT file for details.
5  *
6  *  This software and supporting documentation are maintained by
7  *
8  *    OFFIS e.V.
9  *    R&D Division Health
10  *    Escherweg 2
11  *    D-26121 Oldenburg, Germany
12  *
13  *
14  *  Module: dcmsr
15  *
16  *  Author: Joerg Riesmeier
17  *
18  *  Purpose:
19  *    classes: DSRRootTemplate
20  *
21  */
22 
23 
24 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
25 
26 #include "dcmtk/dcmsr/dsrrtpl.h"
27 #include "dcmtk/dcmsr/dsrstpl.h"
28 #include "dcmtk/dcmsr/dsrxmld.h"
29 
30 
DSRRootTemplate(const E_DocumentType documentType,const OFString & templateIdentifier,const OFString & mappingResource,const OFString & mappingResourceUID)31 DSRRootTemplate::DSRRootTemplate(const E_DocumentType documentType,
32                                  const OFString &templateIdentifier,
33                                  const OFString &mappingResource,
34                                  const OFString &mappingResourceUID)
35   : DSRDocumentTree(documentType),
36     DSRTemplateCommon(templateIdentifier, mappingResource, mappingResourceUID)
37 {
38 }
39 
40 
DSRRootTemplate(const DSRRootTemplate & rootTemplate)41 DSRRootTemplate::DSRRootTemplate(const DSRRootTemplate &rootTemplate)
42   : DSRDocumentTree(rootTemplate),
43     DSRTemplateCommon(rootTemplate)
44 {
45 }
46 
47 
~DSRRootTemplate()48 DSRRootTemplate::~DSRRootTemplate()
49 {
50 }
51 
52 
clone() const53 DSRRootTemplate *DSRRootTemplate::clone() const
54 {
55     return new DSRRootTemplate(*this);
56 }
57 
58 
cloneTree() const59 DSRDocumentTree *DSRRootTemplate::cloneTree() const
60 {
61     DSRDocumentTree *tree = DSRDocumentTree::clone();
62     if (tree != NULL)
63     {
64         /* mark root CONTAINER with template identification */
65         tree->setTemplateIdentification(getTemplateIdentifier(), getMappingResource(), getMappingResourceUID());
66     }
67     return tree;
68 }
69 
70 
clear()71 void DSRRootTemplate::clear()
72 {
73     /* call clear() method of base classes */
74     DSRDocumentTree::clear();
75     DSRTemplateCommon::clear();
76 }
77 
78 
isValid() const79 OFBool DSRRootTemplate::isValid() const
80 {
81     /* check whether both base classes are valid */
82     return DSRDocumentTree::isValid() && DSRTemplateCommon::isTemplateIdentificationValid();
83 }
84 
85 
getTree()86 const DSRDocumentTree &DSRRootTemplate::getTree()
87 {
88     /* update the document tree for output (if needed) */
89     updateTreeForOutput();
90     return *this;
91 }
92 
93 
addExtraContentItem(const E_RelationshipType relationshipType,const E_ValueType valueType,const E_AddMode addMode)94 OFCondition DSRRootTemplate::addExtraContentItem(const E_RelationshipType relationshipType,
95                                                  const E_ValueType valueType,
96                                                  const E_AddMode addMode)
97 {
98     OFCondition result = SR_EC_NonExtensibleTemplate;
99     /* check whether this template is extensible */
100     if (isExtensible())
101     {
102         /* call the function doing the real work */
103         if (addContentItem(relationshipType, valueType, addMode) > 0)
104             result = EC_Normal;
105         else
106             result = SR_EC_CannotAddContentItem;
107     }
108     return result;
109 }
110 
111 
112 
insertExtraTemplate(const DSRSubTemplate & subTemplate,const E_AddMode addMode,const E_RelationshipType defaultRelType)113 OFCondition DSRRootTemplate::insertExtraTemplate(const DSRSubTemplate &subTemplate,
114                                                  const E_AddMode addMode,
115                                                  const E_RelationshipType defaultRelType)
116 {
117     OFCondition result = SR_EC_NonExtensibleTemplate;
118     /* check whether this template is extensible */
119     if (isExtensible())
120     {
121         /* call the function doing the real work */
122         result = insertSubTree(subTemplate.cloneTree(), addMode, defaultRelType, OFTrue /*deleteIfFail*/);
123     }
124     return result;
125 }
126 
127 
128 // protected methods
129 
read(DcmItem &,const E_DocumentType,const size_t)130 OFCondition DSRRootTemplate::read(DcmItem & /*dataset*/,
131                                   const E_DocumentType /*documentType*/,
132                                   const size_t /*flags*/)
133 {
134     /* not implemented (yet) */
135     return EC_IllegalCall;
136 }
137 
138 
readXML(const DSRXMLDocument &,DSRXMLCursor,const size_t)139 OFCondition DSRRootTemplate::readXML(const DSRXMLDocument & /*doc*/,
140                                      DSRXMLCursor /*cursor*/,
141                                      const size_t /*flags*/)
142 {
143     /* not implemented (yet) */
144     return EC_IllegalCall;
145 }
146 
147 
updateTreeForOutput()148 void DSRRootTemplate::updateTreeForOutput()
149 {
150     /* mark root CONTAINER with template identification (if applicable) */
151     OFCondition result = setTemplateIdentification(getTemplateIdentifier(), getMappingResource(), getMappingResourceUID());
152     /* in case of error, output some useful debug information */
153     if (result.bad())
154     {
155         DCMSR_DEBUG("DSRRootTemplate::updateTreeForOutput() Problem with setting TID "
156             << getTemplateIdentifier() << " (" << getMappingResource() << "): " << result.text());
157     }
158 }
159