L_DicomGetCharValue
#include "Ltdic.h"
L_CHAR * EXT_FUNCTION L_DicomGetCharValue(hDS, pElement, nIndex, nCount)
HDICOMDS hDS; |
/* a DICOM handle */ |
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 |
hDS |
A DICOM handle. |
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(HWND hDlg, HDICOMDS hDS, 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 = L_DicomGetCountValue(hDS, 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 = L_DicomGetCharValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%02X", (L_UCHAR)pChar[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_SS: // Signed Short
pShort = L_DicomGetShortValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%d", pShort[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_US: // Unsigned Short
case VR_OW: // Other Word String
pShort = L_DicomGetShortValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%u", (L_UINT16)pShort[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_SL: // Signed Long
case VR_IS: // Integer String
pLong = L_DicomGetLongValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%ld", pLong[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_UL: // Unsigned Long
pLong = L_DicomGetLongValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%lu", (L_UINT32)pLong[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_AT: // Attribute Tag
pLong = L_DicomGetLongValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%04X:%04X", GETGROUP((L_UINT32)pLong[i]),
GETELEMENT((L_UINT32)pLong[i]));
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_FL: // Floating Point Single
pFloat = L_DicomGetFloatValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%f", pFloat[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_FD: // Floating Point Double
case VR_DS: // Decimal String
pDouble = L_DicomGetDoubleValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%f", pDouble[i]);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)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 = L_DicomGetStringValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)pChar);
pChar = pChar + strlen(pChar) + 1;
}
break;
case VR_AS: // Age String
pAge = L_DicomGetAgeValue(hDS, 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;
}
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_DA: // Date
pDate = L_DicomGetDateValue(hDS, pElement, 0, nCount);
for (i = 0; i < nCount; i++)
{
wsprintf(szText, "%02u/%02u/%u", pDate[i].nMonth, pDate[i].nDay, pDate[i].nYear);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_TM: // Time
pTime = L_DicomGetTimeValue(hDS, 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);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
case VR_DT: // Date Time
pDateTime = L_DicomGetDateTimeValue(hDS, 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);
SendMessage(hDlg, LB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)szText);
}
break;
}
L_DicomFreeValue(hDS, pElement);
}
L_VOID Test(HWND hDlg)
{
HDICOMDS hDS;
pDICOMELEMENT pElement;
hDS = L_DicomCreateDS(NULL);
L_DicomLoadDS(hDS, "c:\\ltwin14\\images\\image1.dic", 0);
pElement = L_DicomFindFirstElement(hDS, NULL, TAG_PATIENT_NAME, FALSE);
if (pElement != NULL)
{
ShowValue(hDlg, hDS, pElement);
}
L_DicomFreeDS(hDS);
}