LDicomDS::InsertKey
#include "ltdic.h"
pDICOMELEMENT LDicomDS::InsertKey(pParent, pszKey, bOptional)
| 
   pDICOMELEMENT pParent;  | 
  
   /* pointer to a DICOMELEMENT structure */  | 
| 
   L_CHAR * pszKey;  | 
  
   /* type of key element to insert */  | 
| 
   L_BOOL bOptional;  | 
  
   /* flag that indicates which elements to insert */  | 
Inserts a new key element in the Dicom Dir Data Set.
| 
   Parameter  | 
  
   Description  | |
| 
   pParent  | 
  
   Pointer to a DICOMELEMENT structure that contains a key element in the Data Set. The new key element will be inserted as a child of this key element.  | |
| 
   pszKey  | 
  
   Character string that contains the type of key element to find. Possible values are:  | |
| 
   
  | 
  
   Value  | 
  
   Meaning  | 
| 
   
  | 
  
   "PATIENT"  | 
  
   Patient key element  | 
| 
   
  | 
  
   "STUDY"  | 
  
   Study key element  | 
| 
   
  | 
  
   "SERIES"  | 
  
   Series key element  | 
| 
   
  | 
  
   "IMAGE"  | 
  
   Image key element  | 
| 
   
  | 
  
   "OVERLAY"  | 
  
   Overlay key element  | 
| 
   
  | 
  
   "MODALITY LUT"  | 
  
   Modality-LUT key element  | 
| 
   
  | 
  
   "VOI LUT"  | 
  
   VOI-LUT key element  | 
| 
   
  | 
  
   "CURVE"  | 
  
   Curve key element  | 
| 
   
  | 
  
   "STORED PRINT"  | 
  
   Stored print key element  | 
| 
   
  | 
  
   "RT DOSE"  | 
  
   RT dose key element  | 
| 
   
  | 
  
   "RT STRUCTURE SET"  | 
  
   RT structure set key element  | 
| 
   
  | 
  
   "RT PLAN"  | 
  
   RT plan key element  | 
| 
   
  | 
  
   "RT TREAT RECORD"  | 
  
   RT treatment record key element  | 
| 
   
  | 
  
   "TOPIC"  | 
  
   Topic key element  | 
| 
   
  | 
  
   "VISIT"  | 
  
   Visit key element  | 
| 
   
  | 
  
   "RESULTS"  | 
  
   Results key element  | 
| 
   
  | 
  
   "INTERPRETATION"  | 
  
   Interpretation key element  | 
| 
   
  | 
  
   "STUDY COMPONENT"  | 
  
   Study Component key element  | 
| 
   
  | 
  
   "PRESENTATION"  | 
  
   Presentation key element  | 
| 
   
  | 
  
   "WAVEFORM"  | 
  
   Waveform key element  | 
| 
   
  | 
  
   "SR DOCUMENT"  | 
  
   Structured Reporting Document key element  | 
| 
   
  | 
  
   "PRIVATE"  | 
  
   Private key element  | 
| 
   
  | 
  
   "KEY OBJECT DOC"  | 
  
   Key Object Document key element  | 
| 
   bOptional  | 
  
   Flag that indicates which parts of the key element to insert. Possible values are:  | |
| 
   
  | 
  
   Value  | 
  
   Meaning  | 
| 
   
  | 
  
   TRUE  | 
  
   Insert all parts of the specified key element.  | 
| 
   
  | 
  
   FALSE  | 
  
   Insert only the mandatory parts of the specified key element.  | 
Returns
| 
   !NULL  | 
  
   A pointer to a DICOMELEMENT structure containing the newly inserted item.  | 
| 
   NULL  | 
  
   Not enough memory to insert the item.  | 
Comments
The newly inserted key element is inserted as a child of pParent.
Required DLLs and Libraries
| 
   LTDIC For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application  | 
See Also
Example
void DisplayKeyInfo1(LDicomDS *pDicomDS)
{
   CString strMsg;
   CString strTmp;
   LDicomDS DicomDS;
   
   //move to root KEY (PATIENT)
   pDICOMELEMENT pRootKey = pDicomDS->GetFirstKey(NULL, FALSE);
   CString strRootKey = pDicomDS->GetValueKey(pRootKey);
   strMsg.Format("Root Key[%s]\n", strRootKey);
         
   //move to child KEY (STUDY)
   pDICOMELEMENT pStudyKey  = pDicomDS->GetChildKey(pRootKey); 
   CString strStudyKey = pDicomDS->GetValueKey(pStudyKey);
   strTmp.Format("Root Key[%s]\n", strStudyKey);
   strMsg = strMsg + strTmp;
   //move to child KEY (SERIES)
   pDICOMELEMENT pSeriesKey = pDicomDS->GetChildKey(pStudyKey);
   
   //find first SERIES key
   pDICOMELEMENT pElement = pDicomDS->FindFirstKey(pSeriesKey, "SERIES", TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("First Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   
   //find next series key
   pElement = pDicomDS->FindNextKey(pElement,  TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("Next Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   
   //find last SERIES key
   pElement = pDicomDS->FindLastKey(pElement, "SERIES", TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("Last Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   
   //find previous SERIES key
   pElement = pDicomDS->FindPrevKey(pElement, TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("Previous Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   //Find root KEY another way
   pRootKey = pDicomDS->GetRootKey(pElement);
   strRootKey = pDicomDS->GetValueKey(pRootKey);
   strTmp.Format("Root Key[%s]\n", strRootKey);
   strMsg = strMsg + strTmp;
 
   AfxMessageBox(strMsg);
}
void DisplayKeyInfo2(LDicomDS *pDicomDS)
{
   CString strMsg;
   CString strTmp;
   LDicomDS DicomDS;
   
   //move to root KEY (PATIENT)
   pDICOMELEMENT pRootKey = pDicomDS->GetFirstKey(NULL, FALSE);
   CString strRootKey = pDicomDS->GetValueKey(pRootKey);
   strMsg.Format("Root Key[%s]\n", strRootKey);
   
   //move to child KEY (STUDY)
   pDICOMELEMENT pStudyKey  = pDicomDS->GetChildKey(pRootKey); 
   CString strStudyKey = pDicomDS->GetValueKey(pStudyKey);
   strTmp.Format("Root Key[%s]\n", strStudyKey);
   strMsg = strMsg + strTmp;
   //move to child KEY (SERIES)
   pDICOMELEMENT pSeriesKey = pDicomDS->GetChildKey(pStudyKey);
   
   //find first SERIES key
   pDICOMELEMENT pElement = pDicomDS->GetFirstKey(pSeriesKey, TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("First Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   
   //find next series key
   pElement = pDicomDS->GetNextKey(pElement,  TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("Next Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   
   //find last SERIES key
   pElement = pDicomDS->GetLastKey(pElement, TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("Last Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   
   //find previous SERIES key
   pElement = pDicomDS->GetPrevKey(pElement, TRUE);
   pElement = pDicomDS->GetChildElement(pElement, TRUE);
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
   strTmp.Format("Previous Series[%s]\n", pDicomDS->GetStringValue(pElement, 0, 1) );
   strMsg = strMsg + strTmp;
   //Find root KEY another way
   pRootKey = pDicomDS->GetRootKey(pElement);
   strRootKey = pDicomDS->GetValueKey(pRootKey);
   strTmp.Format("Root Key[%s]\n", strRootKey);
   strMsg = strMsg + strTmp;
 
   AfxMessageBox(strMsg);
}
void Sample () 
{
   CString strMsg;
   CString strTmp;
   LDicomDS DicomDS;
   pDICOMELEMENT pElement, pKey;
   
   DicomDS.InitDS(CLASS_BASIC_DIRECTORY, 0);
   
   //insert some keys
   pKey = DicomDS.InsertKey(NULL, "PATIENT", TRUE); //insert PATIENT level key
   pKey = DicomDS.InsertKey(pKey, "STUDY", TRUE);   //insert STUDY level key
   
   //insert 5 SERIES level keys and some data
   for (int i=0; i<5; i++)
   {
      pKey = DicomDS.InsertKey(pKey, "SERIES", TRUE);
      pElement = DicomDS.GetChildElement(pKey, FALSE);
      pElement = DicomDS.FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE);
      strTmp.Format("%d", i);
      DicomDS.SetStringValue(pElement, (L_CHAR *)(LPCTSTR)strTmp, 1);
      pKey = DicomDS.GetParentKey(pKey); 
   }
   
   //DisplayKeyInfo1 displays the information in the tree
   DisplayKeyInfo1(&DicomDS);
   DicomDS.SaveDS("d:\\temp\\one.dic", 0);
   
   //find last SERIES and delete it
   pElement = DicomDS.GetChildKey(pKey);
   pKey = DicomDS.FindLastKey(pElement, "SERIES", TRUE);
   DicomDS.DeleteKey(pKey);
   AfxMessageBox("Deleting Last Series Key...");
   
   //DisplayKeyInfo2 displays the same information as DisplayKeyInfo1 using different functions
   DisplayKeyInfo2(&DicomDS);
   DicomDS.SaveDS("d:\\temp\\two.dic", 0);
}