InsertIOD Example for C#
//LEADDICOM1 is a DICOM Dataset defined outside this method
private void TestInsertIOD( bool bChild )
{
try
{
bool bInsert = false;
int lCode = 0;
short nType = 0;
int hIOD = 0;
int hTemp = 0;
short nRet = 0;
bInsert = false;
LEADDICOM1.EnableMethodErrors
= true;
lCode = 1048593;
nType = (short)LTDICLib.DicomIODTypeConstants.DICOM_IOD_TYPE_CLASS;
//store current
IOD hIOD = LEADDICOM1.get_CurrentIOD().hIOD;
LEADDICOM1.EnableMethodErrors
= false;
//does an IOD already exist on the
target level?
if (bChild == true)
{
//if the current
IOD has a child, move to that child's level
nRet = LEADDICOM1.MoveChildIOD();
if (nRet != 0) //no
children, so insert is OK
{
bInsert
= true;
LEADDICOM1.SetCurrentIOD(hIOD);
}
else //check
the child's level to see if target IOD already exists
{
hTemp
= LEADDICOM1.get_CurrentIOD().hIOD;
LEADDICOM1.MoveFirstIOD(true);
nRet
= LEADDICOM1.FindIOD(lCode,
nType, true);
if
(nRet != 0)
bInsert = true;
//move
back to parent level
LEADDICOM1.SetCurrentIOD(hTemp);
LEADDICOM1.MoveParentIOD();
}
}
else
{
//check the current
IOD's level LEADDICOM1.MoveFirstIOD(true);
nRet = LEADDICOM1.FindIOD(lCode, nType, true);
if (nRet != 0) bInsert
= true;
LEADDICOM1.SetCurrentIOD(hIOD);
}
LEADDICOM1.EnableMethodErrors
= true;
//allow user to insert item at the
same level as the current or as child
if (bInsert == true)
LEADDICOM1.InsertIOD(bChild,
nType, lCode, "My Test IOD", 5, "Test Description");
else
MessageBox.Show("Already
exists");
return;
}
catch
{
MessageBox.Show("Error");
LEADDICOM1.EnableMethodErrors
= true;
}
}