// copy element from dataset to directory record static void copyElement(DcmItem& dataset, const DcmTagKey &key, DcmDirectoryRecord& record, const OFBool optional, const OFBool copyEmpty) { /* check whether tag exists in source dataset (if optional) */ if (!optional || (copyEmpty && dataset.tagExists(key)) || dataset.tagExistsWithValue(key)) { DcmElement *delem = NULL; /* get copy of element from source dataset */ OFCondition status = dataset.findAndGetElement(key, delem, OFFalse /*searchIntoSub*/, OFTrue /*createCopy*/); if (status.good()) { /* ... and insert it into the destination dataset (record) */ status = record.insert(delem, OFTrue /*replaceOld*/); if (status.good()) { DcmTag tag(key); /* check for correct VR in the dataset */ if (delem->getVR() != tag.getEVR()) { /* create warning message */ LOG(WARNING) << "DICOMDIR: possibly wrong VR: " << tag.getTagName() << " " << key << " with " << DcmVR(delem->getVR()).getVRName() << " found, expected " << tag.getVRName() << " instead"; } } else delete delem; } else if (status == EC_TagNotFound) status = record.insertEmptyElement(key); printAttributeErrorMessage(key, status, "insert"); } }
void test_element_from_odil( TInputType const & source_value, TInputType const & (odil::Element::*getter)() const) { odil::Tag const source_tag(0xdead, 0xbeef); DcmTagKey const destination_tag = odil::dcmtk::convert(source_tag); odil::Element const source(source_value, VVR); DcmElement * destination = odil::dcmtk::convert(source_tag, source); BOOST_CHECK_NE(destination, (DcmElement const *)(NULL)); BOOST_CHECK_EQUAL(destination->getVR(), VEVR); BOOST_CHECK_NE( dynamic_cast<TOutputType *>(destination), (TOutputType *)(NULL)); BOOST_CHECK_EQUAL(destination->getVM(), source.size()); for(std::size_t i=0; i<source.size(); ++i) { typedef typename odil::dcmtk::VRTraits<VEVR>::ValueType ValueType; if(typeid(TInputType) == typeid(odil::Value::Reals)) { compare<ValueType>( odil::dcmtk::ElementAccessor<ValueType>::element_get(*destination, i), (source.*getter)()[i]); } else { BOOST_CHECK_EQUAL( odil::dcmtk::ElementAccessor<ValueType>::element_get(*destination, i), (source.*getter)()[i]); } } }