Exemplo n.º 1
0
static int replaceData( gdcm::Tag const &t, gdcm::DataSet &ds, const gdcm::DictEntry &entry, char const *str, gdcm::VL::Type const size ) {
    gdcm::DataElement de ( t );
    de.SetVR( ds.FindDataElement(t) ? ds.GetDataElement(t).GetVR() : entry.GetVR() );
    de.SetByteValue( str, size );
    ds.Replace( de );
    return 1;
}
Exemplo n.º 2
0
static int basicProtection ( gdcm::Tag const &tag, const gdcm::Type type, gdcm::DataSet &ds ) {
    gdcm::DataElement de = ds.GetDataElement( tag );

    if ( canEmpty(tag, type) ) {
	de.Empty();
	ds.Replace( de );
	return 1;
    }

    gdcm::UIDGenerator uid;
    if ( isVRUI(tag) ) {
	const gdcm::ByteValue *bv;
	const char *oldUID = ( !de.IsEmpty() && (bv = de.GetByteValue()) ) ? bv->GetPointer() : "";
	// anonymize UID XXX
	const char *newUID = "DUMMY-UID"; //uid.Generate();
	de.SetByteValue( newUID, (uint32_t)strlen(newUID) );
    } else {
	const char *dummy = "DUMMY";
	//dummy = ( dummy = gdcm::DummyValueGenerator::Generate( "" ) )  "";
	// anonymize non-UID XXX
	de.SetByteValue( dummy, (uint32_t)strlen(dummy) );
    }
    ds.Replace( de );
    return 1;
}
Exemplo n.º 3
0
    static ::gdcmIO::container::DicomCodedAttribute readCodeSequence(const ::gdcm::DataSet & dataset)
    {
        ::gdcmIO::container::DicomCodedAttribute codedAttributes;

        if ( !dataset.FindDataElement(::gdcm::Tag(GROUP,ELEMENT)))
        {
            // Return empty coded attributes
            return codedAttributes;
        }

        ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence =
                dataset.GetDataElement(::gdcm::Tag(GROUP,ELEMENT)).GetValueAsSQ();
        if (sequence->GetNumberOfItems() == 0)  // One Item shall be permitted
        {
            // Return empty coded attributes
            return codedAttributes;
        }

        const ::gdcm::DataSet& itemDataset = sequence->GetItem(1).GetNestedDataSet();

        // Code value - Type 1
        codedAttributes.setCodeValue(DicomData::getTrimmedTagValue<0x0008,0x0100>(itemDataset));

        // Coding Scheme Designator - Type 1
        codedAttributes.setCodingSchemeDesignator(DicomData::getTrimmedTagValue<0x0008,0x0102>(itemDataset));

        // Coding Scheme Version - Type 1C
        codedAttributes.setCodingSchemeVersion(DicomData::getTrimmedTagValue<0x0008,0x0103>(itemDataset));

        // Code Meaning - Type 1
        codedAttributes.setCodeMeaning(DicomData::getTrimmedTagValue<0x0008,0x0104>(itemDataset));

        return codedAttributes;
    }
Exemplo n.º 4
0
static int lreplace( gdcm::Tag const &t, const char *value, gdcm::VL const & vl, gdcm::DataSet &ds ) {
    if ( t.GetGroup() < 0x0008 ) return 0;

    if ( t.IsPrivate() && vl == 0 && ds.FindDataElement( t ) ) {
	gdcm::DataElement de ( ds.GetDataElement( t ) );
	if ( de.GetVR() != gdcm::VR::INVALID ) {
	    if ( de.GetVR() == gdcm::VR::SQ && *value == 0 )
		{ return emptyData( t, ds ); } // Only allowed operation for a Private Tag
	    else { return 0; } //Trying to replace value of a Private Tag
	}
	de.SetByteValue( "", 0 );
	ds.Insert( de );
	return 1;
    } else {
	const gdcm::DictEntry &entry = dicts.GetDictEntry( t );

	if ( entry.GetVR() == gdcm::VR::INVALID || entry.GetVR() == gdcm::VR::UN )
	    { return 0; }

	if ( entry.GetVR() == gdcm::VR::SQ && vl == 0 && value && *value == 0 )
	    { return emptyData( t, ds ); }

	else if ( entry.GetVR() && gdcm::VR::VRBINARY && vl == 0 )
		{ return replaceData( t, ds, entry, "", 0 ); }

	else { // ASCII
	    if ( value ) {
		std::string padded( value, vl);
		if ( vl.IsOdd() && (entry.GetVR() != gdcm::VR::UI) ) { padded += " "; }
		return replaceData( t, ds, entry, padded.c_str(), (gdcm::VL::Type)padded.size() );
	    }
	}
    }

    return 0;
}