Skip to content

Instantly share code, notes, and snippets.

@JulesGorny
Last active August 29, 2015 14:06
Show Gist options
  • Save JulesGorny/55d445270e3cfddad17f to your computer and use it in GitHub Desktop.
Save JulesGorny/55d445270e3cfddad17f to your computer and use it in GitHub Desktop.
char *file = "C:/Folder1/Folder2/dicomfile";
//Open the DICOM file
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(file);
DcmDataset *dictionary;
//If the loading worked
if( status.good() )
dictionary = fileformat.getDataset();
else
std::cout << "Data dictionary can't be found, file corrupted." << std::endl;
OFString tagValue;
//Retrieve tag value from tag (here the patient name)
//If the tag exists
if( dictionary->findAndGetOFString(DcmTagKey(0x0010, 0x0010), tagValueOF) )
std::cout << "The tag exists" << std::endl;
//Browse all the attributes in the DICOM file metadata
for(unsigned long i = 0; i<dictionary->card(); i++)
{
//Get the element
DcmElement *element = dictionary->getElement(i);
//Get the element tag
DcmTag tag = element->getTag();
//Get the element tag key
DcmTagKey tagKey = DcmTagKey(element->getGTag(), element->getETag());
//Get the element tag name
const char *tagName = tag.getTagName();
//Get the tag value for this element
OFString val;
element->getOFString(val, 0);
}
//Delete a tag
dictionary->remove(DcmTagKey(0x0010, 0x0010));
//Replace the value of a tag
OFString previousValue;
const char *newValue = "aValue";
//If the tag exists
if( dictionary->findAndGetOFString(tag, previousValue).good() )
//Replace the value
dictionary->putAndInsertString(tag, newValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment