1 /*
2 *
3 * Copyright (C) 1994-2002, OFFIS
4 *
5 * This software and supporting documentation were developed by
6 *
7 * Kuratorium OFFIS e.V.
8 * Healthcare Information and Communication Systems
9 * Escherweg 2
10 * D-26121 Oldenburg, Germany
11 *
12 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY
13 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR
14 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR
15 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
16 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
17 *
18 * Module: dcmdata
19 *
20 * Author: Gerd Ehlers, Andreas Barth
21 *
22 * Purpose: Implementation of class DcmUniqueIdentifier
23 *
24 */
25
26
27 #include "osconfig.h"
28 #include "ofstream.h"
29 #include "ofstring.h"
30 #include "ofstd.h"
31 #include "dcvrui.h"
32 #include "dcuid.h"
33
34 #define INCLUDE_CSTRING
35 #define INCLUDE_CCTYPE
36 #include "ofstdinc.h"
37
38
39 // ********************************
40
41
DcmUniqueIdentifier(const DcmTag & tag,const Uint32 len)42 DcmUniqueIdentifier::DcmUniqueIdentifier(const DcmTag &tag,
43 const Uint32 len)
44 : DcmByteString(tag, len)
45 {
46 /* padding character is NULL not a space! */
47 paddingChar = '\0';
48 maxLength = 64;
49 }
50
51
DcmUniqueIdentifier(const DcmUniqueIdentifier & old)52 DcmUniqueIdentifier::DcmUniqueIdentifier(const DcmUniqueIdentifier &old)
53 : DcmByteString(old)
54 {
55 }
56
57
~DcmUniqueIdentifier()58 DcmUniqueIdentifier::~DcmUniqueIdentifier()
59 {
60 }
61
62
operator =(const DcmUniqueIdentifier & obj)63 DcmUniqueIdentifier &DcmUniqueIdentifier::operator=(const DcmUniqueIdentifier &obj)
64 {
65 DcmByteString::operator=(obj);
66 return *this;
67 }
68
69
70 // ********************************
71
72
ident() const73 DcmEVR DcmUniqueIdentifier::ident() const
74 {
75 return EVR_UI;
76 }
77
78
79 // ********************************
80
81
print(ostream & out,const size_t flags,const int level,const char *,size_t *)82 void DcmUniqueIdentifier::print(ostream &out,
83 const size_t flags,
84 const int level,
85 const char * /*pixelFileName*/,
86 size_t * /*pixelCounter*/)
87 {
88 if (valueLoaded())
89 {
90 /* get string data (possibly multi-valued) */
91 char *string = NULL;
92 getString(string);
93 if (string != NULL)
94 {
95 /* check whether UID number can be mapped to a UID name */
96 const char *symbol = dcmFindNameOfUID(string);
97 if ((symbol != NULL) && (strlen(symbol) > 0))
98 {
99 const size_t bufSize = strlen(symbol) + 1 /* for "=" */ + 1;
100 char *buffer = new char[bufSize];
101 if (buffer != NULL)
102 {
103 /* concatenate "=" and the UID name */
104 OFStandard::strlcpy(buffer, "=", bufSize);
105 OFStandard::strlcat(buffer, symbol, bufSize);
106 printInfoLine(out, flags, level, buffer);
107 /* delete temporary character buffer */
108 delete[] buffer;
109 } else /* could not allocate buffer */
110 DcmByteString::print(out, flags, level);
111 } else /* no symbol (UID name) found */
112 DcmByteString::print(out, flags, level);
113 } else
114 printInfoLine(out, flags, level, "(no value available)" );
115 } else
116 printInfoLine(out, flags, level, "(not loaded)" );
117 }
118
119
120 // ********************************
121
122
putString(const char * stringVal)123 OFCondition DcmUniqueIdentifier::putString(const char *stringVal)
124 {
125 const char *uid = stringVal;
126 /* check whether parameter contains a UID name instead of a UID number */
127 if ((stringVal != NULL) && (stringVal[0] == '='))
128 uid = dcmFindUIDFromName(stringVal + 1);
129 /* call inherited method to set the UID string */
130 return DcmByteString::putString(uid);
131 }
132
133
134 // ********************************
135
136
makeMachineByteString()137 OFCondition DcmUniqueIdentifier::makeMachineByteString()
138 {
139 /* get string data */
140 char *value = (char *)getValue();
141 /* check whether automatic input data correction is enabled */
142 if ((value != NULL) && dcmEnableAutomaticInputDataCorrection.get())
143 {
144 const int len = strlen(value);
145 /*
146 ** Remove any leading, embedded, or trailing white space.
147 ** This manipulation attempts to correct problems with
148 ** incorrectly encoded UIDs which have been observed in
149 ** some images.
150 */
151 int k = 0;
152 for (int i = 0; i < len; i++)
153 {
154 if (!isspace(value[i]))
155 {
156 value[k] = value[i];
157 k++;
158 }
159 }
160 value[k] = '\0';
161 }
162 /* call inherited method: re-computes the string length, etc. */
163 return DcmByteString::makeMachineByteString();
164 }
165