static void addString(DCM_OBJECT* obj, DCM_TAG tag, char* s) { DCM_ELEMENT e; CONDITION cond; if (s == 0) return; memset(&e, 0, sizeof(e)); e.tag = tag; cond = DCM_LookupElement(&e); if (cond != DCM_NORMAL) { COND_DumpConditions(); exit(1); } e.d.string = s; e.length = strlen(s); cond = DCM_ModifyElements(&obj, &e, 1, 0, 0, 0); if (cond != DCM_NORMAL) { COND_DumpConditions(); exit(1); } }
DCM_OBJECT * createQueryObject(const char *fileName) { DCM_OBJECT *obj; CONDITION cond; DCM_ELEMENT e; char txt[1024] = ""; int group = 0; int element = 0; char textValue[1024]; if (fileName != NULL) { cond = DCM_OpenFile(fileName, DCM_ORDERLITTLEENDIAN, &obj); if (cond != DCM_NORMAL) { COND_DumpConditions(); exit(1); } return obj; } cond = DCM_CreateObject(&obj, 0); if (cond != DCM_NORMAL) { COND_DumpConditions(); exit(1); } while (fgets(txt, sizeof(txt), stdin) != NULL) { if (txt[0] == '#' || txt[0] == '\0') continue; if (txt[0] == '\n' || txt[0] == '\r') continue; if (sscanf(txt, "%x %x %[^\n]", &group, &element, textValue) != 3) continue; e.tag = DCM_MAKETAG(group, element); DCM_LookupElement(&e); if (strncmp(textValue, "#", 1) == 0) { e.length = 0; e.d.string = NULL; } else { e.length = strlen(textValue); e.d.string = textValue; } cond = DCM_AddElement(&obj, &e); if (cond != DCM_NORMAL) { COND_DumpConditions(); exit(1); } } return obj; }
CTNBOOLEAN DCM_IsSequence(DCM_TAG tag) { CTNBOOLEAN flag = FALSE; DCM_ELEMENT e; CONDITION cond; memset(&e, 0, sizeof(e)); e.tag = tag; cond = DCM_LookupElement(&e); if (cond != DCM_NORMAL) { return FALSE; } if (e.representation == DCM_SQ) { flag = TRUE; } return flag; }
/* extractAccessionNumber ** ** Purpose: ** Extract the Accession number from a DICOM image file. ** ** Parameter Dictionary: ** file Name of the file ** ** Return Values: ** Accession number if found, else NULL ** ** Notes: ** ** Algorithm: ** Description of the algorithm (optional) and any other notes. */ static char * extractAccessionNumber(char *file) { DCM_OBJECT * object = NULL; DCM_ELEMENT element; CONDITION cond; cond = DCM_OpenFile(file, DCM_ORDERLITTLEENDIAN, &object); if (cond != DCM_NORMAL) { printf("DCM_Openfile failed on %s\n", file); if (verbose == TRUE) COND_DumpConditions(); return (NULL); } element.tag = DCM_IDACCESSIONNUMBER; element.d.string = (char *) malloc(DICOM_CS_LENGTH + 1); element.length = DICOM_CS_LENGTH + 1; cond = DCM_LookupElement(&element); if (cond != DCM_NORMAL) { printf("DCM_LookupElement failed\n"); if (verbose == TRUE) COND_DumpConditions(); return (NULL); } cond = DCM_ParseObject(&object, &element, 1, NULL, 0, NULL); if (cond != DCM_NORMAL) { printf("DCM Parse Object failed\n"); if (verbose == TRUE) COND_DumpConditions(); return (NULL); } return (element.d.string); }
int main(int argc, char **argv) { CONDITION cond; /* Return value from DUL and ACR routines */ DCM_OBJECT * object; /* Handle to the information object */ DCM_ELEMENT element; /* Handle to the DCM_ELEMENT */ IE_OBJECT * ieObject; /* Handle to the IE_OBJECT object */ IE_INFORMATIONENTITY * ieIE, *ie_node; /* Handle to IE_INFORMATIONENTITY */ LST_HEAD * ie_head, *mod_head, *attr_head; /* Handle to the LST_HEAD */ IE_MODULE * ieModule, *mod_node; /* Handle to IE_MODULE */ IE_ATTRIBUTE * attr_node; /* Handle to IE_ATTRIBUTE */ CTNBOOLEAN verbose = FALSE; /* For debugging purpose */ CTNBOOLEAN flag; /* Return value from findElement routine */ unsigned long options = DCM_ORDERLITTLEENDIAN; /* Byte order in data streams */ char *file; /* The image file name */ char UID[90]; /* The SOP Class UID of the image file */ U32 length; /* Length of the data field of DCM_ELEMENT */ int ie_loop, mod_loop, attr_loop, j, k, i;/* Iteration variables */ while (--argc > 0 && (*++argv)[0] == '-') { switch (*(argv[0] + 1)) { case 'v': verbose = TRUE; break; case 'b': options &= ~DCM_ORDERMASK; options |= DCM_ORDERBIGENDIAN; break; case 't': options &= ~DCM_FILEFORMATMASK; options |= DCM_PART10FILE; break; default: break; } } if (argc < 1) usageerror(); file = *argv; THR_Init(); DCM_Debug(verbose); /* Open a DICOM object file and put the contents into the memory represented by the information object. */ cond = DCM_OpenFile(file, options, &object); if (cond != DCM_NORMAL && ((options & DCM_PART10FILE) == 0)) { COND_DumpConditions(); (void) DCM_CloseObject(&object); (void) COND_PopCondition(TRUE); fprintf(stderr, "Could not open %s as expected. Trying Part 10 format.\n", file); cond = DCM_OpenFile(file, options | DCM_PART10FILE, &object); } if (cond != DCM_NORMAL) { COND_DumpConditions(); THR_Shutdown(); return 1; }else{ printf("file is successfully opened!\n"); /* Call IE_ExamineObject to examine this DCM object. */ cond = IE_ExamineObject(&object, &ieObject); if (cond == IE_ILLEGALDCMOBJECT || cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE){ COND_DumpConditions(); }else{ /* Print the IE_OBJECT object. */ strcpy(UID, ieObject->classUID); printObject(ieObject); /* Examine each IE on the list. */ ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE); /* Print each IE_IE. */ printIE(ieIE); /* Examine each module on the list. */ mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); cond = IE_ExamineModule(&object, ieIE->ieType, mod_node->moduleType, &ieModule); printModule(ieModule); /* Print each IE_ATTRIBUTE. */ attr_head = ieModule->attributeList; attr_loop = LST_Count(&attr_head); for (j = 0; j < attr_loop; j++) { attr_node = LST_Pop(&attr_head); printIEAttribute(attr_node); free(attr_node); } free(mod_node); cond = IE_Free((void **) &ieModule); } free(ie_node); cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); /* Check to see the status of the Information Entities. */ cond = IE_ExamineObject(&object, &ieObject); printf("\n%s requirements:\n", ieObject->objectDescription); ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); if (ie_node->requirement == IE_K_REQUIRED) printIE(ie_node); free(ie_node); } cond = IE_Free((void **) &ieObject); /* Check to see the status of the Information Entity and status of the Modules within them. */ cond = IE_ExamineObject(&object, &ieObject); printf("\n%s requirements:\n", ieObject->objectDescription); ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE); if (ie_node->requirement == IE_K_REQUIRED) { printf("\n"); printIE(ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); if (mod_node->requirement == IE_K_REQUIRED) printModule(mod_node); free(mod_node); } } free(ie_node); cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); /* Check to see the missing attributes if there is any. */ cond = IE_ObjectRequirements(UID, &ieObject); printf("\n Missing required(type1 and type2) attributes: \n"); ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); cond = IE_IERequirements(UID, ie_node->ieType, &ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); cond = IE_ModuleRequirements(UID, ie_node->ieType, mod_node->moduleType, &ieModule); printf(" %s\n", ieModule->moduleDescription); attr_head = ieModule->attributeList; attr_loop = LST_Count(&attr_head); for (j = 0; j < attr_loop; j++) { attr_node = LST_Pop(&attr_head); flag = findElement(object, attr_node->element.tag, &element); cond = DCM_LookupElement(&element); if (cond != DCM_NORMAL) cond = COND_PopCondition(FALSE); if (!flag) { if (attr_node->requirement == IE_K_TYPE1){ printf(" %08x, %s\n", element.tag, element.description); }else if (attr_node->requirement == IE_K_TYPE2){ cond = DCM_GetElementSize(&object, attr_node->element.tag, &length); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); printf(" %08x, %s\n", element.tag, element.description); } } } } /* finish one module */ free(mod_node); cond = IE_Free((void **) &ieModule); } free(ie_node); cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); } } /* Free the memory and remove the object handle. */ cond = DCM_CloseObject(&object); if (cond != DCM_NORMAL){ COND_DumpConditions(); }else{ printf("The object is closed successfully.\n"); } THR_Shutdown(); return 0; }
static CTNBOOLEAN findElement(DCM_OBJECT * object, DCM_TAG tag, DCM_ELEMENT * element) { CONDITION cond; /* Return value from DUL and ACR routines */ DCM_ELEMENT dcm_element; /* Handle to the dicom data element */ void *ctx; /* Context variable used by DCM_GetElementValue */ CTNBOOLEAN flag = TRUE; /* See Return Values in the header */ CTNBOOLEAN isString = FALSE; /* Flag indicates if value is of string type */ /* Find the group and element fields in the tag. */ dcm_element.tag = tag; element->tag = dcm_element.tag; /* Find the representation of the data in the element. */ cond = DCM_LookupElement(&dcm_element); if (cond != DCM_NORMAL) { cond = COND_PopCondition(FALSE); return FALSE; } /* Fill the length field and assign the memory for the data. */ switch (dcm_element.representation) { case DCM_LO: /* Long string */ case DCM_UI: /* UID */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_DA: /* Date */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_CS: /* Control string */ case DCM_TM: /* Time */ case DCM_SH: /* Short string */ case DCM_DS: /* Decimal string */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_IS: /* Integer string */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_ST: /* Short text */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_LT: /* Long text */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_PN: /* Person name */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_AS: /* Age string */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char)); isString = TRUE; } break; case DCM_SS: /* Signed short */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.ss = malloc((dcm_element.length + 1) * sizeof(char)); } break; case DCM_SL: /* signed long */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.sl = malloc((dcm_element.length + 1) * sizeof(char)); } break; case DCM_US: /* unsigned short */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.us = malloc((dcm_element.length + 1) * sizeof(char)); } break; case DCM_UL: /* unsigned long */ cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); return FALSE; }else{ dcm_element.d.ul = malloc((dcm_element.length + 1) * sizeof(char)); } break; case DCM_SQ: /* Sequence of items */ break; default: cond = DCM_GetElementSize(&object, tag, &(dcm_element.length)); if (cond == DCM_NORMAL){ return flag; }else{ cond = COND_PopCondition(FALSE); return FALSE; } } /* The following is necessary when made the first call to DCM_GetElementValue(). */ ctx = NULL; cond = DCM_GetElementValue(&object, &dcm_element, &(dcm_element.length), &ctx); if (cond != DCM_NORMAL) { /* check for error */ /* the attribute is not found */ flag = FALSE; cond = COND_PopCondition(FALSE); }else{ if (isString) dcm_element.d.string[dcm_element.length] = '\0'; *element = dcm_element; } return flag; }
int main(int argc, char **argv) { CONDITION /* Return value from DUL and ACR routines */ cond; IE_OBJECT /* Handle to the IE_OBJECT object */ * ieObject; IE_INFORMATIONENTITY /* Handle to IE_INFORMATIONENTITY */ * ieIE, *ie_node; LST_HEAD /* Handle to the LST_HEAD */ * ie_head, *mod_head, *attr_head; IE_MODULE /* Handle to IE_MODULE */ * ieModule, *mod_node; IE_ATTRIBUTE /* Handle to IE_ATTRIBUTE */ * attr_node; CTNBOOLEAN /* For debugging purpose */ verbose = FALSE; char /* The UID of the image file */ *UID, *SOPClassName; int /* Iteration variables */ ie_loop, mod_loop, attr_loop, i, k, j; if (argc < 1) usageerror(); THR_Init(); DCM_Debug(verbose); while (--argc > 0 && (*++argv)[0] == '-') { switch (*(argv[0] + 1)) { case 'v': verbose = TRUE; break; default: break; } } while (argc-- > 0) { SOPClassName = *argv; (void) *argv++; /* * Find the SOP Class UID according to the SOP Class name. */ UID = lookupUID(SOPClassName); if (UID != NULL) { /* The SOP Class name is legal */ printf("\nRequired IEs and Modules for %s image file:\n", SOPClassName); /* * Find the required IEs. */ cond = IE_ObjectRequirements(UID, &ieObject); if (cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE || cond == IE_ILLEGALDCMOBJECT) { COND_DumpConditions(); THR_Shutdown(); return (2); } ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { /* * Find all the required Modules. */ ie_node = LST_Pop(&ie_head); printf("%s\n", ie_node->ieDescription); cond = IE_IERequirements(UID, ie_node->ieType, &ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); printf(" %s\n", mod_node->moduleDescription); } cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); printf("\n"); printf("Required Modules and Attributes for %s image file:\n", SOPClassName); /* * Find all the required IEs. */ cond = IE_ObjectRequirements(UID, &ieObject); if (cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE || cond == IE_ILLEGALDCMOBJECT) { COND_DumpConditions(); THR_Shutdown(); return (2); } ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { /* * Find all the required Modules. */ ie_node = LST_Pop(&ie_head); cond = IE_IERequirements(UID, ie_node->ieType, &ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); cond = IE_ModuleRequirements(UID, ie_node->ieType, mod_node->moduleType, &ieModule); printf("%s\n", mod_node->moduleDescription); attr_head = ieModule->attributeList; attr_loop = LST_Count(&attr_head); for (j = 0; j < attr_loop; j++) { /* * Find all the mandatory attributes. */ attr_node = LST_Pop(&attr_head); cond = DCM_LookupElement (&(attr_node->element)); printf(" %s\n", attr_node->element.description); } } } } else /* Illegal SOP Class entered by the user */ printf("Illegal SOP Class.\n"); } THR_Shutdown(); return (0); }
static void browseSelectionCB_scrolledList3( Widget wgt, XtPointer cd, XtPointer cb) { Widget UxWidget = wgt; XtPointer UxClientData = cd; XtPointer UxCallbackArg = cb; { /* * scrolledList3 * * * Purpose: * This subroutine lists the description of the selected * attribute * in the text widgets. * * * Parameter Dictinary: * cbs input, pointer to the * selected attribute * * * Return Value: * Description of the element * * * Notes: * * * Algorithm: * Description of the algorithm (optional) and any * other notes. * * */ XmListCallbackStruct *cbs; char *atname; int i; char buf2[64], buf1[64]; CONDITION cond; unsigned short gg, ee; cbs = (XmListCallbackStruct *) UxCallbackArg; if ((atname = (char *) malloc(64)) == NULL) printf(" malloc atname failed\n"); XmStringGetLtoR(cbs->item, XmSTRING_DEFAULT_CHARSET, &atname); if (strlen(XmTextGetString(text1)) != 0) XmTextSetString(text1, NULL); if (strlen(XmTextGetString(text2)) != 0) XmTextSetString(text2, NULL); ieAttr = LST_Head(&attr_head); (void) LST_Position(&attr_head, ieAttr); for (i = 2; i <= cbs->item_position; i++) ieAttr = LST_Next(&attr_head); cond = DCM_LookupElement(&ieAttr->element); if (cond != DCM_NORMAL) { (void) COND_ExtractConditions(errorstackP); copyWtext(info); (void) COND_PopCondition(clearStack); free(info); } sprintf(buf1, " %s", atname); XmTextSetString(text1, buf1); if (ieAttr->element.length == 0) { strcpy(buf2, "<None>"); XmTextSetString(text2, buf2); } else { switch (ieAttr->element.representation) { case DCM_AS: /* Age String */ case DCM_CS: /* control string */ case DCM_DA: /* date */ case DCM_DS: /* decimal string */ case DCM_IS: /* integer string */ case DCM_LO: /* long string */ case DCM_LT: /* long text */ case DCM_ST: /* short text */ case DCM_SH: /* short string */ case DCM_TM: /* time */ case DCM_UI: /* uid */ case DCM_PN: /* person name */ gg = DCM_TAG_GROUP(ieAttr->element.tag); ee = DCM_TAG_ELEMENT(ieAttr->element.tag); sprintf(buf2, "%04x, %04x, %s", gg, ee, ieAttr->element.d.string); XmTextSetString(text2, buf2); break; case DCM_SS: /* signed short */ gg = DCM_TAG_GROUP(ieAttr->element.tag); ee = DCM_TAG_ELEMENT(ieAttr->element.tag); sprintf(buf2, "%04x, %04x, %d", gg, ee, *(ieAttr->element.d.us)); XmTextSetString(text2, buf2); break; case DCM_SL: /* signed long */ gg = DCM_TAG_GROUP(ieAttr->element.tag); ee = DCM_TAG_ELEMENT(ieAttr->element.tag); sprintf(buf2, " %04x, %04x, %d", gg, ee, *(ieAttr->element.d.sl)); XmTextSetString(text2, buf2); break; case DCM_US: /* unsigned short */ gg = DCM_TAG_GROUP(ieAttr->element.tag); ee = DCM_TAG_ELEMENT(ieAttr->element.tag); sprintf(buf2, " %04x, %04x, %d", gg, ee, *(ieAttr->element.d.us)); XmTextSetString(text2, buf2); break; case DCM_UL: /* unsigned long */ gg = DCM_TAG_GROUP(ieAttr->element.tag); ee = DCM_TAG_ELEMENT(ieAttr->element.tag); sprintf(buf2, " %04x, %04x, %d", gg, ee, *(ieAttr->element.d.ul)); XmTextSetString(text2, buf2); break; default: break; } } free(atname); } }