Using API to check valid characters in an LO element

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
anibal
Posts: 16
Joined: Fri, 2004-12-24, 05:30

Using API to check valid characters in an LO element

#1 Post by anibal »

Hi,

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.

Thanks,

-Anibal

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1462
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg »

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.

anibal
Posts: 16
Joined: Fri, 2004-12-24, 05:30

#3 Post by anibal »

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:
(anibal262.dyn.intelerad) [admin@imstest1] {admin} dcmpschk file.dcm
Testing: file.dcm


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.

This is what it has:

Code: Select all

(anibal262.dyn.intelerad) [admin@imstest1] {admin} dcmdump file.dcm | grep -i studyd
(0008,0020) DA [20041222]                               #   8, 1 StudyDate
]                          #  14, 1 StudyDescription
Not sure if this is of interest to you or someone in your team.

Thanks again.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#4 Post by Jörg Riesmeier »

anibal wrote:I'll try to cook my own simpler version for a simpler test.
There is also some code in the toolkit that checks CS values (see dcmdata/include/dcvrcs.h):

Code: Select all

    /** 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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests