LDicomDS::GetCharValue
#include "Ltdic.h"
L_CHAR * LDicomDS::GetCharValue(pElement, nIndex, nCount)
pDICOMELEMENT pElement; |
/* pointer to a DICOMELEMENT structure */ |
L_UINT32 nIndex; |
/* index used when multiple values are stored */ |
L_UINT32 nCount; |
/* the number of values to retrieve */ |
Returns a pointer to a char value, stored in the value field, of the specified element.
Parameter |
Description |
pElement |
Pointer to a DICOMELEMENT structure within the Data Set. |
nIndex |
Index value that indicates which value to retrieve when more than one value is stored in the Value Field. The index is zero-based. |
nCount |
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. |
Returns
!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. |
Comments
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 funtion 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.
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
/* This example gets the value for an element */
L_VOID ShowValue(CListBox *pDlg, LDicomDS *pDS, pDICOMELEMENT pElement)
{
L_INT32 i;
L_INT32 nCount;
L_CHAR szText[256];
L_CHAR *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, "%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, "%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, "%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, "%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, "%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, "%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, "%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, "%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
pChar = pDS->GetStringValue(pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
pDlg->AddString(pChar);
pChar = pChar + strlen(pChar) + 1;
}
break;
case VR_AS: // Age String
pAge = pDS->GetAgeValue(pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%u ", pAge[i].nNumber);
switch (pAge[i].nReference)
{
case VALUE_AGE_DAYS:
strcat(szText, "days");
break;
case VALUE_AGE_WEEKS:
strcat(szText, "weeks");
break;
case VALUE_AGE_MONTHS:
strcat(szText, "months");
break;
case VALUE_AGE_YEARS:
strcat(szText, "years");
break;
}
pDlg->AddString(szText);
}
break;
case VR_DA: // Date
pDate = pDS->GetDateValue(pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%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, "%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, "%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_VOID Test(CListBox *pDlg)
{
LDicomDS *pDS;
pDICOMELEMENT pElement;
pDS = new LDicomDS(NULL);
pDS->LoadDS("c:\\ltwin13\\images\\image1.dic", 0);
pElement = pDS->FindFirstElement(NULL, TAG_PATIENT_NAME, FALSE);
if (pElement != NULL)
{
ShowValue(pDlg, pDS, pElement);
}
delete pDS;
}