LDicomDS::InsertKey

#include "ltdic.h"

pDICOMELEMENT LDicomDS::InsertKey(pParent, pszKey, bOptional)

Inserts a new key element in the Dicom Dir Data Set.

Parameters

pDICOMELEMENT 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.

L_TCHAR * 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
"SPECTROSCOPY" Spectroscopy key element
"RAW DATA" Raw Data key element
"REGISTRATION" Registration key element
"FIDUCIAL" Fiducial key element
"HANGING PROTOCOL" Hanging key element
"ENCAP DOC" Encapsulated Document key element
"HL7 STRUC DOC" HL7 Structured Document key element
"VALUE MAP" Real World Value Mapping key element
"STEREOMETRIC" Stereometric Relationship key element

L_BOOL 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

Value Meaning
!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

Platforms

Win32, x64

See Also

Functions

Topics

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(TEXT("Root Key[%s]\n"), strRootKey); 
 
   //move to child KEY (STUDY) 
   pDICOMELEMENT pStudyKey  = pDicomDS->GetChildKey(pRootKey);  
   CString strStudyKey = pDicomDS->GetValueKey(pStudyKey); 
   strTmp.Format(TEXT("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, TEXT("SERIES"), TRUE); 
   pElement = pDicomDS->GetChildElement(pElement, TRUE); 
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE); 
   strTmp.Format(TEXT("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(TEXT("Next Series[%s]\n"), pDicomDS->GetStringValue(pElement, 0, 1) ); 
   strMsg = strMsg + strTmp; 
 
   //find last SERIES key 
   pElement = pDicomDS->FindLastKey(pElement, TEXT("SERIES"), TRUE); 
   pElement = pDicomDS->GetChildElement(pElement, TRUE); 
   pElement = pDicomDS->FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE); 
   strTmp.Format(TEXT("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(TEXT("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(TEXT("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(TEXT("Root Key[%s]\n"), strRootKey); 
 
   //move to child KEY (STUDY) 
   pDICOMELEMENT pStudyKey  = pDicomDS->GetChildKey(pRootKey);  
   CString strStudyKey = pDicomDS->GetValueKey(pStudyKey); 
   strTmp.Format(TEXT("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(TEXT("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(TEXT("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(TEXT("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(TEXT("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(TEXT("Root Key[%s]\n"), strRootKey); 
   strMsg = strMsg + strTmp; 
 
   AfxMessageBox(strMsg); 
} 
 
 
L_INT LDicomDS_InsertKeyExample() 
{ 
   L_INT          nRet; 
   CString        strMsg; 
   CString        strTmp; 
   LDicomDS       DicomDS; 
   pDICOMELEMENT  pElement, pKey; 
 
   DicomDS.InitDS(CLASS_BASIC_DIRECTORY, 0); 
 
   //insert some keys 
   pKey = DicomDS.InsertKey(NULL, TEXT("PATIENT"), TRUE); //insert PATIENT level key 
   pKey = DicomDS.InsertKey(pKey, TEXT("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, TEXT("SERIES"), TRUE); 
      pElement = DicomDS.GetChildElement(pKey, FALSE); 
      pElement = DicomDS.FindFirstElement(pElement, TAG_REFERENCED_FILE_ID, TRUE); 
      strTmp.Format(TEXT("%d"), i); 
      DicomDS.SetStringValue(pElement, (L_TCHAR*) (LPCTSTR)strTmp, 1, DICOM_CHARACTER_SET_DEFAULT); 
      pKey = DicomDS.GetParentKey(pKey);  
   } 
 
   //DisplayKeyInfo1 displays the information in the tree 
   DisplayKeyInfo1(&DicomDS); 
   nRet = DicomDS.SaveDS(MAKE_IMAGE_PATH(TEXT("one.dcm")), 0); 
   if(nRet != DICOM_SUCCESS) 
      return nRet; 
 
   //find last SERIES and delete it 
   pElement = DicomDS.GetChildKey(pKey); 
   pKey = DicomDS.FindLastKey(pElement, TEXT("SERIES"), TRUE); 
   DicomDS.DeleteKey(pKey); 
   AfxMessageBox(TEXT("Deleting Last Series Key...")); 
 
   //DisplayKeyInfo2 displays the same information as DisplayKeyInfo1 using different functions 
   DisplayKeyInfo2(&DicomDS); 
   nRet = DicomDS.SaveDS(MAKE_IMAGE_PATH(TEXT("two.dcm")), 0); 
   if(nRet != DICOM_SUCCESS) 
      return nRet; 
 
   return DICOM_SUCCESS; 
} 
Help Version 22.0.2021.9.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.