1 /*
2  *
3  *  Copyright (C) 2003-2016, OFFIS e.V.
4  *  All rights reserved.  See COPYRIGHT file for details.
5  *
6  *  This software and supporting documentation were developed 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: DSRComprehensiveSRConstraintChecker
20  *
21  */
22 
23 
24 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
25 
26 #include "dcmtk/dcmsr/dsrcomcc.h"
27 
28 
DSRComprehensiveSRConstraintChecker()29 DSRComprehensiveSRConstraintChecker::DSRComprehensiveSRConstraintChecker()
30   : DSRIODConstraintChecker()
31 {
32 }
33 
34 
~DSRComprehensiveSRConstraintChecker()35 DSRComprehensiveSRConstraintChecker::~DSRComprehensiveSRConstraintChecker()
36 {
37 }
38 
39 
isByReferenceAllowed() const40 OFBool DSRComprehensiveSRConstraintChecker::isByReferenceAllowed() const
41 {
42     return OFTrue;
43 }
44 
45 
isTemplateSupportRequired() const46 OFBool DSRComprehensiveSRConstraintChecker::isTemplateSupportRequired() const
47 {
48     return OFFalse;
49 }
50 
51 
getRootTemplateIdentification(OFString & templateIdentifier,OFString & mappingResource) const52 OFCondition DSRComprehensiveSRConstraintChecker::getRootTemplateIdentification(OFString &templateIdentifier,
53                                                                                OFString &mappingResource) const
54 {
55     templateIdentifier.clear();
56     mappingResource.clear();
57     return EC_Normal;
58 }
59 
60 
getDocumentType() const61 DSRTypes::E_DocumentType DSRComprehensiveSRConstraintChecker::getDocumentType() const
62 {
63     return DT_ComprehensiveSR;
64 }
65 
66 
checkContentRelationship(const E_ValueType sourceValueType,const E_RelationshipType relationshipType,const E_ValueType targetValueType,const OFBool byReference) const67 OFBool DSRComprehensiveSRConstraintChecker::checkContentRelationship(const E_ValueType sourceValueType,
68                                                                      const E_RelationshipType relationshipType,
69                                                                      const E_ValueType targetValueType,
70                                                                      const OFBool byReference) const
71 {
72     /* the following code implements the constraints of table A.35.3-2 in DICOM PS3.3 */
73     OFBool result = OFFalse;
74     /* row 1 of the table */
75     if ((relationshipType == RT_contains) && (sourceValueType == VT_Container))
76     {
77         result = (targetValueType == VT_Text)     || (targetValueType == VT_Code)      || (targetValueType == VT_Num)    ||
78                  (targetValueType == VT_DateTime) || (targetValueType == VT_Date)      || (targetValueType == VT_Time)   ||
79                  (targetValueType == VT_UIDRef)   || (targetValueType == VT_PName)     || (targetValueType == VT_SCoord) ||
80                  (targetValueType == VT_TCoord)   || (targetValueType == VT_Composite) || (targetValueType == VT_Image)  ||
81                  (targetValueType == VT_Waveform) || ((targetValueType == VT_Container) && !byReference /* only by-value */);
82     }
83     /* row 2 of the table */
84     else if ((relationshipType == RT_hasObsContext) && ((sourceValueType == VT_Container) ||
85         (sourceValueType == VT_Text) || (sourceValueType == VT_Code) || (sourceValueType == VT_Num)))
86     {
87         result = (targetValueType == VT_Text)     || (targetValueType == VT_Code)  || (targetValueType == VT_Num)  ||
88                  (targetValueType == VT_DateTime) || (targetValueType == VT_Date)  || (targetValueType == VT_Time) ||
89                  (targetValueType == VT_UIDRef)   || (targetValueType == VT_PName) || (targetValueType == VT_Composite);
90     }
91     /* row 3 of the table */
92     else if ((relationshipType == RT_hasAcqContext) && ((sourceValueType == VT_Container) || (sourceValueType == VT_Image) ||
93         (sourceValueType == VT_Waveform) || (sourceValueType == VT_Composite) || (sourceValueType == VT_Num)))
94     {
95         result = (targetValueType == VT_Text)     || (targetValueType == VT_Code)  || (targetValueType == VT_Num)  ||
96                  (targetValueType == VT_DateTime) || (targetValueType == VT_Date)  || (targetValueType == VT_Time) ||
97                  (targetValueType == VT_UIDRef)   || (targetValueType == VT_PName) || (targetValueType == VT_Container);
98     }
99     /* row 4 of the table */
100     else if ((relationshipType == RT_hasConceptMod) && !byReference /* only by-value */)
101     {
102         result = (targetValueType == VT_Text) || (targetValueType == VT_Code);
103     }
104     /* row 5 of the table */
105     else if ((relationshipType == RT_hasProperties) &&
106         ((sourceValueType == VT_Text) || (sourceValueType == VT_Code) || (sourceValueType == VT_Num)))
107     {
108         result = (targetValueType == VT_Text)     || (targetValueType == VT_Code)      || (targetValueType == VT_Num)    ||
109                  (targetValueType == VT_DateTime) || (targetValueType == VT_Date)      || (targetValueType == VT_Time)   ||
110                  (targetValueType == VT_UIDRef)   || (targetValueType == VT_PName)     || (targetValueType == VT_Image)  ||
111                  (targetValueType == VT_Waveform) || (targetValueType == VT_Composite) || (targetValueType == VT_SCoord) ||
112                  (targetValueType == VT_TCoord)   || (targetValueType == VT_Container);
113     }
114     /* row 6 of the table - introduced with CP-1076 */
115     else if ((relationshipType == RT_hasProperties) && (sourceValueType == VT_PName))
116     {
117         result = (targetValueType == VT_Text) || (targetValueType == VT_Code) || (targetValueType == VT_DateTime) ||
118                  (targetValueType == VT_Date) || (targetValueType == VT_Time) || (targetValueType == VT_UIDRef)   ||
119                  (targetValueType == VT_PName);
120     }
121     /* row 7 of the table */
122     else if ((relationshipType == RT_inferredFrom) &&
123         ((sourceValueType == VT_Text) || (sourceValueType == VT_Code) || (sourceValueType == VT_Num)))
124     {
125         result = (targetValueType == VT_Text)     || (targetValueType == VT_Code)      || (targetValueType == VT_Num)    ||
126                  (targetValueType == VT_DateTime) || (targetValueType == VT_Date)      || (targetValueType == VT_Time)   ||
127                  (targetValueType == VT_UIDRef)   || (targetValueType == VT_PName)     || (targetValueType == VT_Image)  ||
128                  (targetValueType == VT_Waveform) || (targetValueType == VT_Composite) || (targetValueType == VT_SCoord) ||
129                  (targetValueType == VT_TCoord)   || (targetValueType == VT_Container);
130     }
131     /* row 8 of the table */
132     else if ((relationshipType == RT_selectedFrom) && (sourceValueType == VT_SCoord))
133     {
134         result = (targetValueType == VT_Image);
135     }
136     /* row 9 of the table */
137     else if ((relationshipType == RT_selectedFrom) && (sourceValueType == VT_TCoord))
138     {
139         result = (targetValueType == VT_SCoord) || (targetValueType == VT_Image) || (targetValueType == VT_Waveform);
140     }
141     return result;
142 }
143