Dov Grobgeld
Dov Grobgeld

Reputation: 4983

Convert a dicom tag to its string name in gdcm in C++

Given a gdcm tag, e.g. gdcm::Tag(0x0010,0x0010) how can it be convert to the corresponding tag name string, in this case "PatientsName" in C++?

Upvotes: 3

Views: 964

Answers (1)

drescherjm
drescherjm

Reputation: 10857

Here is what I do in a Qt based application with GDCM:

QString duDicomDictionary::getTagName( const gdcm::Tag & tag )
{
    QString retVal;

    const gdcm::Global& g = gdcm::Global::GetInstance();
    const gdcm::Dicts &dicts = g.GetDicts();
    const gdcm::Dict &pubdict = dicts.GetPublicDict();

    gdcm::DictEntry ent = pubdict.GetDictEntry(tag);

    if (ent.GetVR() != gdcm::VR::INVALID ) {
        retVal = QString::fromStdString(ent.GetName());
    }

    return retVal;
}

This code will only work for public groups.

To get the private groups I use (after I populated the private dictionary):

QString duDicomDictionary::getTagName( const gdcm::PrivateTag & tag )
{
    QString retVal;

    const gdcm::Global& g = gdcm::Global::GetInstance();
    const gdcm::Dicts &dicts = g.GetDicts();
    const gdcm::PrivateDict &privdict = dicts.GetPrivateDict();

    gdcm::DictEntry ent = privdict.GetDictEntry(tag);

    if (ent.GetVR() != gdcm::VR::INVALID ) {
        retVal = QString::fromStdString(ent.GetName());
    }
    else
    {
        ent = g_privateDict.GetDictEntry(tag);

        if (ent.GetVR() != gdcm::VR::INVALID ) {
            retVal = QString::fromStdString(ent.GetName());
        }

    }

    return retVal;
}

Upvotes: 3

Related Questions