1 /*
2  *
3  *  Copyright (C) 2003-2015, 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: DSRMammographyCadSRConstraintChecker
20  *
21  */
22 
23 
24 #include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
25 
26 #include "dcmtk/dcmsr/dsrmamcc.h"
27 
28 
DSRMammographyCadSRConstraintChecker()29 DSRMammographyCadSRConstraintChecker::DSRMammographyCadSRConstraintChecker()
30   : DSRIODConstraintChecker()
31 {
32 }
33 
34 
~DSRMammographyCadSRConstraintChecker()35 DSRMammographyCadSRConstraintChecker::~DSRMammographyCadSRConstraintChecker()
36 {
37 }
38 
39 
isByReferenceAllowed() const40 OFBool DSRMammographyCadSRConstraintChecker::isByReferenceAllowed() const
41 {
42     return OFTrue;
43 }
44 
45 
isTemplateSupportRequired() const46 OFBool DSRMammographyCadSRConstraintChecker::isTemplateSupportRequired() const
47 {
48     return OFTrue;
49 }
50 
51 
getRootTemplateIdentification(OFString & templateIdentifier,OFString & mappingResource) const52 OFCondition DSRMammographyCadSRConstraintChecker::getRootTemplateIdentification(OFString &templateIdentifier,
53                                                                                 OFString &mappingResource) const
54 {
55     templateIdentifier = "4000";
56     mappingResource = "DCMR";
57     return EC_Normal;
58 }
59 
60 
getDocumentType() const61 DSRTypes::E_DocumentType DSRMammographyCadSRConstraintChecker::getDocumentType() const
62 {
63     return DT_MammographyCadSR;
64 }
65 
66 
checkContentRelationship(const E_ValueType sourceValueType,const E_RelationshipType relationshipType,const E_ValueType targetValueType,const OFBool byReference) const67 OFBool DSRMammographyCadSRConstraintChecker::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.5-2 in DICOM PS3.3 */
73     OFBool result = OFFalse;
74     /* row 1 of the table */
75     if ((relationshipType == RT_contains) && !byReference && (sourceValueType == VT_Container))
76     {
77         result = (targetValueType == VT_Code) || (targetValueType == VT_Num) || (targetValueType == VT_SCoord) ||
78                  (targetValueType == VT_Image) || (targetValueType == VT_Container) ||
79                  (targetValueType == VT_Text) || (targetValueType == VT_Date);
80     }
81     /* row 2 of the table */
82     else if ((relationshipType == RT_hasObsContext) && !byReference && ((sourceValueType == VT_Container) ||
83         (sourceValueType == VT_Text) || (sourceValueType == VT_Code) || (sourceValueType == VT_Num)))
84     {
85         result = (targetValueType == VT_Text) || (targetValueType == VT_Code) || (targetValueType == VT_Num) ||
86                  (targetValueType == VT_Date) || (targetValueType == VT_Time) || (targetValueType == VT_PName) ||
87                  (targetValueType == VT_UIDRef) || (targetValueType == VT_Composite);
88     }
89     /* row 3 of the table */
90     else if ((relationshipType == RT_hasAcqContext) && !byReference && (sourceValueType == VT_Image))
91     {
92         result = (targetValueType == VT_Text) || (targetValueType == VT_Code) || (targetValueType == VT_Date) ||
93                  (targetValueType == VT_Time) || (targetValueType == VT_Num);
94     }
95     /* row 4 of the table */
96     else if ((relationshipType == RT_hasConceptMod) && !byReference &&
97         ((sourceValueType == VT_Container) || (sourceValueType == VT_Code) ||
98         (sourceValueType == VT_Num) || (sourceValueType == VT_Composite)))
99     {
100         result = (targetValueType == VT_Text) || (targetValueType == VT_Code);
101     }
102     /* row 5 the table */
103     else if ((relationshipType == RT_hasProperties) &&
104         ((sourceValueType == VT_Text) || (sourceValueType == VT_Code) || (sourceValueType == VT_Num)))
105     {
106         /* by-reference allowed */
107         result = (targetValueType == VT_Container) || (targetValueType == VT_Text) || (targetValueType == VT_Code) ||
108                  (targetValueType == VT_Num) || (targetValueType == VT_Date) || (targetValueType == VT_Image) ||
109                  (targetValueType == VT_SCoord) || (targetValueType == VT_UIDRef);
110     }
111     /* row 6 of the table */
112     else if ((relationshipType == RT_inferredFrom) && ((sourceValueType == VT_Code) || (sourceValueType == VT_Num)))
113     {
114         /* by-reference allowed */
115         result = (targetValueType == VT_Code) || (targetValueType == VT_Num) || (targetValueType == VT_SCoord) ||
116                  (targetValueType == VT_Container) || (targetValueType == VT_Text) ||
117                  (targetValueType == VT_Image);
118     }
119     /* row 7 of the table */
120     else if ((relationshipType == RT_selectedFrom) && (sourceValueType == VT_SCoord))
121     {
122         /* by-reference allowed */
123         result = (targetValueType == VT_Image);
124     }
125     return result;
126 }
127