Returns a pointer to a char value, stored in the value field, of the specified element.
#include "Ltdic.h"
L_UCHAR * LDicomDS::GetCharValue(pElement, nIndex, nCount)
Pointer to a DICOMELEMENT structure within the Data Set.
Index value that indicates which value to retrieve when more than one value is stored in the Value Field. The index is zero-based.
Value that indicates the number of values to retrieve when more than one value is stored in the Value Field. In most instances you will only retrieve one value so this parameter will be one.
| Value | Meaning |
|---|---|
| !NULL | A pointer to a char stored in the Value Field of the specified Data Element. |
| NULL | The length of the Value Field is 0, the function was called for the incorrect VR type, or the function was called for a folder (sequence) element. |
If you have more than one value stored in the Value Field of the specified Data Element, you can retrieve one or more than one of those elements. For example, if the Value Field of the specified Data Element contains three character values, and you are only interested in retrieving the last two character values, set nIndex to 1 and nCount to 2. This tells the function to retrieve the character values starting at position 1 (the index is zero based) and retrieve two values. Therefore you would retrieve the values in positions 1 and 2 in the Value Field.
This function can be called only if the Value Representation of the Data Element is VR_OB, VR_SQ, or VR_UN. For more information about Value Representations, refer to Default Value Representation Table.
Win32, x64
This example gets the value for an element.
L_VOID ShowValue(CListBox *pDlg, LDicomDS *pDS, pDICOMELEMENT pElement){L_INT32 i;L_INT32 nCount;L_TCHAR szText[256];L_TCHAR *pStringValue;L_UCHAR *pChar;L_INT16 *pShort;L_INT32 *pLong;L_FLOAT *pFloat;L_DOUBLE *pDouble;pVALUEAGE pAge;pVALUEDATE pDate;pVALUETIME pTime;pVALUEDATETIME pDateTime;nCount = pDS->GetCountValue(pElement);if (((pElement->nLength == ELEMENT_LENGTH_MAX)) ||(pElement->nLength > 1024) ||(nCount == 0)){return;}switch (pElement->nVR){case VR_OB: // Other Byte Stringcase VR_UN: // UnknownpChar = pDS->GetCharValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%02X"), (L_UCHAR)pChar[i]);pDlg->AddString(szText);}break;case VR_SS: // Signed ShortpShort = pDS->GetShortValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%d"), pShort[i]);pDlg->AddString(szText);}break;case VR_US: // Unsigned Shortcase VR_OW: // Other Word StringpShort = pDS->GetShortValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%u"), (L_UINT16)pShort[i]);pDlg->AddString(szText);}break;case VR_SL: // Signed Longcase VR_IS: // Integer StringpLong = pDS->GetLongValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%ld"), pLong[i]);pDlg->AddString(szText);}break;case VR_UL: // Unsigned LongpLong = pDS->GetLongValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%lu"), (L_UINT32)pLong[i]);pDlg->AddString(szText);}break;case VR_AT: // Attribute TagpLong = pDS->GetLongValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%04X:%04X"), GETGROUP((L_UINT32)pLong[i]),GETELEMENT((L_UINT32)pLong[i]));pDlg->AddString(szText);}break;case VR_FL: // Floating Point SinglepFloat = pDS->GetFloatValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%f"), pFloat[i]);pDlg->AddString(szText);}break;case VR_FD: // Floating Point Doublecase VR_DS: // Decimal StringpDouble = pDS->GetDoubleValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%f"), pDouble[i]);pDlg->AddString(szText);}break;case VR_CS: // Code Stringcase VR_SH: // Short Stringcase VR_LO: // Long Stringcase VR_AE: // Application Entitycase VR_LT: // Long Textcase VR_ST: // Short Textcase VR_UI: // Unique Identifiercase VR_UT: // Unlimited Textcase VR_PN: // Person NamepStringValue = pDS->GetStringValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){pDlg->AddString(pStringValue);pStringValue = pStringValue + wcslen(pStringValue) + 1;}break;case VR_AS: // Age StringpAge = pDS->GetAgeValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%u "), pAge[i].nNumber);switch (pAge[i].nReference){case VALUE_AGE_DAYS:wcscat_s(szText, 256, TEXT("days"));break;case VALUE_AGE_WEEKS:wcscat_s(szText, 256, TEXT("weeks"));break;case VALUE_AGE_MONTHS:wcscat_s(szText, 256, TEXT("months"));break;case VALUE_AGE_YEARS:wcscat_s(szText, 256, TEXT("years"));break;}pDlg->AddString(szText);}break;case VR_DA: // DatepDate = pDS->GetDateValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%02u/%02u/%u"), pDate[i].nMonth, pDate[i].nDay, pDate[i].nYear);pDlg->AddString(szText);}break;case VR_TM: // TimepTime = pDS->GetTimeValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%02u:%02u:%u.%lu"), pTime[i].nHours, pTime[i].nMinutes,pTime[i].nSeconds, pTime[i].nFractions);pDlg->AddString(szText);}break;case VR_DT: // Date TimepDateTime = pDS->GetDateTimeValue(pElement, 0, nCount);for (i = 0; i < nCount; i++){wsprintf(szText, TEXT("%d %02u/%02u/%u %02u:%02u:%u.%lu&%lu"),pDateTime[i].nMonth, pDateTime[i].nDay,pDateTime[i].nYear, pDateTime[i].nHours, pDateTime[i].nMinutes,pDateTime[i].nSeconds, pDateTime[i].nFractions,pDateTime[i].nOffset);pDlg->AddString(szText);}break;}pDS->FreeValue(pElement);}L_INT LDicomDS_GetCharValueExample(CListBox *pDlg){L_INT nRet;LDicomDS *pDS;pDICOMELEMENT pElement;pDS = new LDicomDS(NULL);nRet = pDS->LoadDS(MAKE_IMAGE_PATH(TEXT("image1.dcm")), 0);if(nRet != DICOM_SUCCESS)return nRet;pElement = pDS->FindFirstElement(NULL, TAG_PATIENT_NAME, FALSE);if (pElement != NULL){ShowValue(pDlg, pDS, pElement);}delete pDS;return DICOM_SUCCESS;}