InsertKey Example for C++ 6.0 or later
void CDicomDlg::DisplayKeyInfo1()
{
CString strMsg;
CString strTmp;
//move to root KEY (PATIENT)
m_pLEADDicomDS->MoveFirstKey(FALSE);
BSTR bstr = m_pLEADDicomDS->GetKeyValue();
CString cs = bstr;
SysFreeString(bstr);
strMsg.Format("Root Key[%s]\n", cs );
//move to child KEY (STUDY)
m_pLEADDicomDS->MoveChildKey ();
//move to child KEY (SERIES)
m_pLEADDicomDS->MoveChildKey ();
//find first SERIES
m_pLEADDicomDS->FindFirstKey ("SERIES", TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
bstr = m_pLEADDicomDS->GetStringValues (0);
cs = bstr;
SysFreeString(bstr);
strTmp.Format("First Series Key[%s]\n", cs);
strMsg = strMsg + strTmp;
//find next series
m_pLEADDicomDS->FindNextKey(TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
bstr = m_pLEADDicomDS->GetStringValues (0);
cs = bstr;
SysFreeString(bstr);
strTmp.Format("Next Series Key[%s]\n", cs );
strMsg = strMsg + strTmp;
//find last SERIES
m_pLEADDicomDS->FindLastKey("SERIES", TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
bstr = m_pLEADDicomDS->GetStringValues (0);
cs = bstr;
SysFreeString(bstr);
strTmp.Format("Last Series Key[%s]\n", cs );
strMsg = strMsg + strTmp;
//find previous SERIES
m_pLEADDicomDS->FindPrevKey(TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
bstr = m_pLEADDicomDS->GetStringValues (0);
cs = bstr;
SysFreeString(bstr);
strTmp.Format("Previous Series Key[%s]\n", cs );
strMsg = strMsg + strTmp;
AfxMessageBox(strMsg);
}
void CDicomDlg::DisplayKeyInfo2()
{
CString strMsg;
CString strTmp;
//move to root KEY (PATIENT)
m_pLEADDicomDS->MoveFirstKey(FALSE);
strMsg.Format("Root Key[%s]\n", m_pLEADDicomDS->GetKeyValue() );
//move to child KEY (STUDY)
m_pLEADDicomDS->MoveChildKey ();
//move to child KEY (SERIES)
m_pLEADDicomDS->MoveChildKey ();
//find first SERIES
m_pLEADDicomDS->MoveFirstKey(TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
strTmp.Format("First Series Key[%s]\n", m_pLEADDicomDS->GetStringValues (0));
strMsg = strMsg + strTmp;
//find next series
m_pLEADDicomDS->MoveNextKey(TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
strTmp.Format("Next Series Key[%s]\n", m_pLEADDicomDS->GetStringValues (0) );
strMsg = strMsg + strTmp;
//find last SERIES
m_pLEADDicomDS->MoveLastKey(TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
strTmp.Format("Last Series Key[%s]\n", m_pLEADDicomDS->GetStringValues (0) );
strMsg = strMsg + strTmp;
//find previous SERIES
m_pLEADDicomDS->MovePrevKey(TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
m_pLEADDicomDS->GetStringValue (0, 1);
strTmp.Format("Previous Series Key[%s]\n", m_pLEADDicomDS->GetStringValues (0) );
strMsg = strMsg + strTmp;
AfxMessageBox(strMsg);
}
void CDicomDlg::TestInsertKey()
{
CString strMsg;
CString strTmp;
long hTemp=0;
m_pLEADDicomDS->ResetDS ();
m_pLEADDicomDS->InitDS (DICOM_CLASS_BASIC_DIRECTORY, 0);
//insert some keys
m_pLEADDicomDS->InsertKey ("PATIENT", TRUE); //insert PATIENT level key
m_pLEADDicomDS->InsertKey ("STUDY", TRUE); //insert STUDY level key
//insert 5 SERIES level keys and some data
for (int i=0; i<5; i++)
{
m_pLEADDicomDS->StringValueCount = 1;
m_pLEADDicomDS->InsertKey ("SERIES", TRUE);
m_pLEADDicomDS->MoveChildElement ();
m_pLEADDicomDS->FindFirstElement (TAG_REFERENCED_FILE_ID, TRUE);
strTmp.Format("%d", i);
BSTR bstr = strTmp.AllocSysString();
m_pLEADDicomDS->StringValues [0] = bstr;
SysFreeString(bstr);
m_pLEADDicomDS->SetStringValue (1);
m_pLEADDicomDS->MoveParentElement ();
m_pLEADDicomDS->MoveParentKey (); //move back up one level
}
//DisplayKeyInfo1 displays the information in the tree
DisplayKeyInfo1();
//find last SERIES and delete it
m_pLEADDicomDS->MoveRootKey ();
m_pLEADDicomDS->MoveChildKey ();
m_pLEADDicomDS->MoveChildKey ();
m_pLEADDicomDS->FindLastKey ("SERIES", TRUE);
m_pLEADDicomDS->DeleteKey ();
AfxMessageBox("Deleting Last Series Key...");
//DisplayKeyInfo2 displays the same information as DisplayKeyInfo1 using different functions
DisplayKeyInfo1();
}