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 String
case VR_UN: // Unknown
pChar = 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 Short
pShort = 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 Short
case VR_OW: // Other Word String
pShort = 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 Long
case VR_IS: // Integer String
pLong = 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 Long
pLong = 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 Tag
pLong = 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 Single
pFloat = 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 Double
case VR_DS: // Decimal String
pDouble = 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 String
case VR_SH: // Short String
case VR_LO: // Long String
case VR_AE: // Application Entity
case VR_LT: // Long Text
case VR_ST: // Short Text
case VR_UI: // Unique Identifier
case VR_UT: // Unlimited Text
case VR_PN: // Person Name
pStringValue = pDS->GetStringValue(pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
pDlg->AddString(pStringValue);
pStringValue = pStringValue + wcslen(pStringValue) + 1;
}
break;
case VR_AS: // Age String
pAge = 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: // Date
pDate = 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: // Time
pTime = 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 Time
pDateTime = 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;
}