I would like to check if a given element (LO) has valid characters. I'm receiving a study description with a \n in it. As per DICOM this is not valid. The standard says:
"Long String
A character string that may be padded with leading and/or trailing spaces. The character code 5CH (the BACKSLASH “\” in ISO-IR 6) shall not be present, as it is used as the delimiter between values in multiple valued
Default Character Repertoire and/or as defined by (0008,0005).
64 chars maximum (see NOTE in 6.2) PS 3.5-2000
Page 17 - Final Draft - data elements. The string shall not have
Control Characters except for ESC."
Is there code in dcmtk that will check for that character set? I would like to re-use the code rather than re-inventing the wheel.
The toolkit contains code for VR value checks, although not currently in any of the libraries. The tool "dcmpschk" (in dcmpstat/apps) uses regular expressions (a Lex scanner) to check string VRs. Look at the functions checkelem() and checkitem() in dcmpstat/apps/dcmpschk.cc - these should be exactly what you need.
Thanks for the reply. Looking at the code it does a lot more than what I want at this moment in time. I'll try to cook my own simpler version for a simpler test.
As a side note, though, I got the file with the newline in the study description and passed it through your dcmpschk:
Warning: Attribute value uses retired form.
Affected attribute: PerformingPhysiciansName (0008,1050), Type PN
Attribute value : [HARRIS]
Error: Attribute value does not conform to data type definition.
Affected attribute: Exposure (0018,1152), Type IS
Attribute value : [2.8]
Expected format for each value: [\+\-]?[0-9]+ in the range -2^31 .. 2^31-1
Test failed - one or more errors.
Notice that it doesn't say anything about the newline in the study description.
/** check whether given value conforms to value representation CS (Code String).
* Valid characters are: A-Z, 0-9, _ and ' ' (space). The maximum length is 16.
* @param value string value to be checked
* @param pos returns index of first invalid character (0..n-1) if not NULL.
* Points to trailing zero byte (eos) if value is valid.
* @param checkLength check maximum length if OFTrue, ignore length if OFFalse
* @return OFTrue if value is valid, OFFalse otherwise
*/
static OFBool checkVR(const OFString &value,
size_t *pos = NULL,
const OFBool checkLength = OFTrue);
Checking routines for other VRs will be added when needed.