예제 #1
0
파일: anonymizer.cpp 프로젝트: CAAP/Lua
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;
}
예제 #2
0
파일: anonymizer.cpp 프로젝트: CAAP/Lua
static int recurseDataSet ( gdcm::DataSet &ds, gdcm::File &F ) {
    if ( ds.IsEmpty() ) {return 0;}

    static const gdcm::Tag *start = BasicApplicationLevelConfidentialityProfileAttributes;
    static const gdcm::Tag *ptr,*end = start + nIDs;
    const gdcm::IOD& iod = defs.GetIODFromFile( F );

    for(ptr = start; ptr != end; ++ptr) {
	const gdcm::Tag &tag = *ptr;
	if ( ds.FindDataElement( tag ) ) {
	    basicProtection( tag, iod.GetTypeFromTag(defs, tag), ds );
	}
    }

    gdcm::DataSet::ConstIterator it = ds.Begin();
    for (; it != ds.End() ;) {
	gdcm::DataElement de = *it++;
	gdcm::VR vr = gdcm::DataSetHelper::ComputeVR( F, ds, de.GetTag() );
	gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = 0;

	if ( vr == gdcm::VR::SQ && (sqi = de.GetValueAsSQ()) ) {
	    de.SetValue( *sqi );
	    de.SetVLToUndefined();
	    gdcm::SequenceOfItems::SizeType i;
	    for (i = 1; i <= sqi->GetNumberOfItems(); i++ ) {
		gdcm::Item &item = sqi->GetItem( i );
		gdcm::DataSet &nested = item.GetNestedDataSet();
		recurseDataSet( nested, F );
	    }
	}

	ds.Replace( de ); // REPLACE
    }
    return 1;
}
예제 #3
0
파일: anonymizer.cpp 프로젝트: CAAP/Lua
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;
}
예제 #4
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;
    }
예제 #5
0
파일: anonymizer.cpp 프로젝트: CAAP/Lua
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;
}
예제 #6
0
파일: anonymizer.cpp 프로젝트: CAAP/Lua
static int emptyData( gdcm::Tag const &t, gdcm::DataSet &ds ) {
    gdcm::DataElement de( t );
    de.SetVR( gdcm::VR::SQ );
    ds.Replace( de );
    return 1;
}