Exemplo n.º 1
0
/* CreateStudyListWindow
**
** Purpose:
**	Creates a window that will display the list of studies
**	in the database.
**
** Parameter Dictionary:
**	None
**
** Return Values:
**	Handle to a widget
**
** Notes:
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
Widget
CreateStudyListWindow()
{
    Widget
	form,
	label;
    unsigned int
        i;

    if (GetStudyList() == FALSE) {
	printf("Fatal Error: GetStudyList failed\n");
	return 0;
    }
    shell = XtVaCreatePopupShell("Study List",
				 topLevelShellWidgetClass, toplevel, NULL);
    form = XtVaCreateManagedWidget("study_form", formWidgetClass,
				   shell, NULL);
    label = XtVaCreateManagedWidget("study_label", labelWidgetClass,
		      form, XtNlabel, "List of Studies:", XtNborderWidth, 0,
				    XtNresizable, FALSE, NULL);
    list = CreateSimpleList(form, label, NULL, 300, 120, selectStudy, NULL,
			  text_studylist, LST_Count(&lst_studylist), FALSE);
    if (list == 0) {
	printf("Could not create list widget\n");
	return 0;
    }
    for (i = 0; i < LST_Count(&lst_studylist); i++)
	printf("%s\n", text_studylist[i]);
    return (shell);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
static void selectArchive(llist entries)
{
  CONDITION cond;
  LST_HEAD *studyList;
  char dbKey[64];
  QUERY_LIST_ITEM *item;
  IDB_Limits limits;
  char password[64];
  int flag = 0;

  studyList = LST_Create();
  strcpy(dbKey, cgi_val(entries, "DBKey"));
  strcpy(password, cgi_val(entries, "password"));

  TBL_SetOption("OPEN_SPEEDUP");
  cond = listOfStudies(dbKey, studyList);
  orderStudyListByName(studyList);

  flag = passwordCompare(dbKey, password);
  if (flag == 0)
    strcpy(password, "READONLY");

  memset(&limits, 0, sizeof(limits));
  cond = dbLimits(dbKey, &limits);

  html_header();
  html_begin_body_options("CTN Archive: List of Studies", "bgcolor=#ffffff");

  if (flag == 0) {
    printf("Read only access granted <br>\n");
  }

  printf("CTN Archive: %s <br> \n", dbKey);
  { char *remoteUser;

    remoteUser = getenv("REMOTE_USER");
    if (remoteUser == NULL)
      remoteUser = "******";

    printf("Remote user: %s<br>\n", remoteUser);
  }

  printf("%d patients, %d studies, %d images <br>\n",
	 limits.PatientCount,
	 limits.StudyCount,
	 limits.ImageCount);
  printf("DB Size/Limits (MB): %d/%d<br>\n",
	 limits.DBSize/1000000,
	 limits.DBLimit);
#if 0
  printf("%d studies <br><br>\n", LST_Count(&studyList));
#endif

  printf("<pre>\n");
  item = LST_Dequeue(&studyList);
  while(item != NULL) {
    char tmp[1024];
    sprintf(tmp, "%-30s %8s (%2d series) %-32s",
	    item->query.patient.PatNam,
	    item->query.study.StuDat,
	    item->query.study.NumStuRelSer,
	    item->query.study.StuDes);

#if 0
    printf("<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&StudyUID=%s"">%s</a><br>\n",
#endif

    printf(
"<a href=""/cgi-bin/archive_agent.cgi?submitSearch=%s&DBKey=%s&\
password=%s&StudyUID=%s"">%s</a>\n",
	   "StudySelect",
	   dbKey,
	   password,
	   item->query.study.StuInsUID,
	   tmp);

    free(item);
    item = LST_Dequeue(&studyList);
  }
  printf("</pre>\n");

  LST_Destroy(&studyList);

  html_end();
}
Exemplo n.º 5
0
Arquivo: set.c Projeto: nagyistge/ctn
/* nsetImageBoxCallback
**
** Purpose:
**	Call back routine called by SRV_NSetResponse used to build the
**	N-SET response message.
**
** Parameter Dictionary:
**	nsetRequest	Pointer to N-SET Request message
**	nsetResponse	Pointer to N-SET Response message
**	ctx		Pointer to context for this command.
**	pc		Presentation context that describes this SOP Class
**
** Return Values:
**	SRV_NORMAL under error free conditions.
**
**	SRV_CALLBACKABORTEDSERVICE
**	SRV_NORMAL
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
static CONDITION
nsetImageBoxCallback(MSG_N_SET_REQ * nsetRequest,
		     MSG_N_SET_RESP * nsetResponse,
		     void *sendBack, DUL_PRESENTATIONCONTEXT * pc)
{

    CONDITION
    cond;			/* condition code returned by various
				 * facilities */
    int
        index;			/* loop index */
    char
       *flagNameList = NULL;	/* holds attribute names that gave errors
				 * during verification process */
    BIB_NODE
	* bibNode;		/* pointer to instance of Image Box */
    char
       *fileName;		/* filename holding attributes of image */
    GQ_ELEM
	gqElement;		/* The GQ element that is to be enqueued */
    PRN_BASICIMAGEBOX
	bibAttrib,		/* structure holding attributes of image box */
	*bibPtr;		/* pointer to the above structure */
    CTNBOOLEAN
	flag = FALSE;		/* to check if the image is present */

    /*
     * For Image Position, we do a runtime check depending on the value of
     * Image Display Format specified by the Film Box attribute.
     */

    /* Now define a table of all supported attributes */
    static SUPPORTEDATTRIBUTES supportedAttributeList[] = {
	{PRN_BIB_K_IMAGEPOSITION, "BIB Image Position ", NULL, 0},
	{PRN_BIB_K_IMAGEMODULE, "BIB Preformatted Image Sequence ",
	NULL, 0},
	{PRN_BIB_K_POLARITY, "BIB Polarity ", bibPolarity,
	(int) DIM_OF(bibPolarity)},
	{PRN_BIB_K_MAGNIFICATIONTYPE, "BIB Magnification type ",
	bibMagnificationType, (int) DIM_OF(bibMagnificationType)},
#ifdef ASG
	{PRN_BIB_K_SMOOTHINGTYPE, "BIB Smooothing Type ",
	bibSmoothingType, (int) DIM_OF(bibSmoothingType)},
	{PRN_BIB_K_REQUESTEDIMAGESIZE, "BIB Requested Image Size ",
	bibRequestedImageSize, (int) DIM_OF(bibRequestedImageSize)}
#endif
    };

    /* we now build up the response message */
    nsetResponse->type = MSG_K_N_SET_RESP;
    nsetResponse->messageIDRespondedTo = nsetRequest->messageID;
    strcpy(nsetResponse->classUID, nsetRequest->classUID);
    strcpy(nsetResponse->instanceUID, nsetRequest->instanceUID);

    /* default */
    nsetResponse->dataSetType = DCM_CMDDATANULL;
#ifdef ASG
    nsetResponse->dataSet = NULL;	/* no data set is sent */
#endif

    bibPtr = &bibAttrib;
    bibPtr->bibAttributeFlag = 0x0;
    (void) strcpy(bibPtr->imageBoxSOPClassUID, nsetRequest->classUID);
    (void) strcpy(bibPtr->imageBoxSOPInstanceUID, nsetRequest->instanceUID);
    /* Parse the data set sent by the SCU */
    cond = PRN_ParseObject(&nsetRequest->dataSet, PRN_K_BASICGREYSCALEIMAGEBOX,
			   (void **) &bibPtr);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetImageBoxCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
				  APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    /* PRN_DumpAttributes(bibPtr, stdout); */
    cond = supportedAttributes(MSG_K_N_SET_REQ, bibPtr, supportedAttributeList,
			(int) DIM_OF(supportedAttributeList), &flagNameList,
			       (void **) &nsetResponse);
    if (cond != APP_NORMAL) {
	switch (cond) {
	case APP_MISSINGREQUIREDATTRIBUTE:
	    nsetResponse->status = MSG_K_MISSINGATTRIBUTE;
	    break;
	case APP_UNSUPPORTEDMANDATORYATTRIBUTE:
	case APP_UNSUPPORTEDOPTIONALATTRIBUTE:
	    nsetResponse->status = MSG_K_NOSUCHATTRIBUTE;
	    break;
	case APP_UNSUPPORTEDATTRIBUTEVALUE:
	    nsetResponse->status = MSG_K_INVALIDATTRIBUTEVALUE;
	    break;
	}
	cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				  "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    /*
     * Now we update the hierarchy. We note here that attributes are set for
     * the image boxes belonging to the current BASIC FILM BOX instance which
     * is given by bfbInstance
     */
    bibNode = (BIB_NODE *) LST_Position(&bfbInstance->bibList,
					LST_Head(&bfbInstance->bibList));
    if (bibNode == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_MISSINGIMAGES),
				  "nsetImageBoxCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		      APP_ERROR(APP_MISSINGIMAGES), "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    flag = FALSE;
    /*
     * go thru the list of Image SOP instance UIDs maintained by the Film Box
     * instance
     */
    for (index = 0; index < (int) LST_Count(&bfbInstance->bibList)
	 && !flag; index++) {
	/* now see if the instance UID matches */
	if (strcmp(nsetRequest->instanceUID, bibNode->bibInstanceUID) == 0) {
	    flag = TRUE;
	}
	if (!flag)
	    bibNode = (BIB_NODE *) LST_Next(&bfbInstance->bibList);
    }
    if (flag == FALSE) {
	cond = COND_PushCondition(APP_ERROR(APP_NOSUCHINSTANCE),
			  nsetRequest->instanceUID, "nsetImageBoxCallback");
	nsetResponse->status = MSG_K_NOSUCHOBJECTINSTANCE;
	goto ERROR_RETURN;
    }
    /* we now store the attributes of the image box */
    /*
     * To avoid copying so much data, we just make a pointer point to the
     * dataSet
     */
    bibNode->bibAttrib = nsetRequest->dataSet;
    nsetRequest->dataSet = NULL;/* remove the data set from the request
				 * message */

    /*
     * If the server's terminal has x-capability and wishes to enqueue the
     * image in the GQueue
     */
    if (gqueueFlag) {
	gqElement.prnMessage = PRN_NEWIMAGEBOX;
	(void) strcpy(gqElement.instanceUID, bibNode->bibInstanceUID);
	/* get a new file name to store the object */
	fileName = getNewFileName();
	(void) strcpy(gqElement.objFile, fileName);

	/* now write the object into the file and enqueue it */
	cond = DCM_WriteFile(&bibNode->bibAttrib, DCM_ORDERLITTLEENDIAN,
			     fileName);
	if (cond != DCM_NORMAL) {
	    unlink(gqElement.objFile);	/* delete the file before exiting */
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				   "DCM_WriteFile", "nsetImageBoxCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "DCM_WriteFile",
				      "nsetImageBoxCallback");
	    goto ERROR_RETURN;
	}
	cond = GQ_Enqueue(gqID, (void *) &gqElement);
	if (cond != GQ_NORMAL) {
	    unlink(gqElement.objFile);
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetImageBoxCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
				      APP_ERROR(APP_FAILURE), "GQ_Enqueue",
				      "nsetImageBoxCallback");
	    goto ERROR_RETURN;
	}
    }
    /* send attributes back, but do not send back the image pixel data */
    /* temporarily we reset the FLAG for the pixel data */
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
    bibPtr->bibAttributeFlag ^= PRN_BIB_K_IMAGEMODULE;
    cond = PRN_BuildObject((void *) bibPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetImageBoxCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
				  APP_ERROR(APP_FAILURE), "PRN_BuildObject",
				  "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    /* set back the FLAG */
    bibPtr->bibAttributeFlag |= PRN_BIB_K_IMAGEMODULE;
    /* everything is successful */
    nsetResponse->status = MSG_K_SUCCESS;
    return SRV_NORMAL;

ERROR_RETURN:
    COND_DumpConditions();
    return SRV_CALLBACKABORTEDSERVICE;
}
Exemplo n.º 6
0
Arquivo: cget.c Projeto: nagyistge/ctn
static CONDITION
cgetCallback(MSG_C_GET_REQ * request, MSG_C_GET_RESP * response,
	   MSG_C_STORE_REQ * storeRequest, MSG_C_STORE_RESP * storeResponse,
	     int responseCount, char *SOPClass, char *queryLevel,
/*	     CGET_PARAMS * cgetParams) */
	     void *cgetParamsPtr)
{
    CONDITION cond;
    static LST_HEAD *imageList = NULL;
    IDB_HANDLE **handle;
    static QUERY_MAP
        map[] = {{"PATIENT", IDB_PATIENT_LEVEL},
    {"STUDY", IDB_STUDY_LEVEL},
    {"SERIES", IDB_SERIES_LEVEL},
    {"IMAGE", IDB_IMAGE_LEVEL},
    };
    int
        i,
        searchQueryEnd;
    CTNBOOLEAN
	done;
    long
        selectCount;

    IDB_Query
	queryStructure;
    QUERY_LIST_ITEM
	* queryItem;
    static LST_HEAD
    *   queryList = NULL,
       *failedList = NULL;
    static DUL_NETWORKKEY
    *   network;
    DUL_ASSOCIATESERVICEPARAMETERS
	* params;
    DCM_ELEMENT
	e = {
	DCM_IDFAILEDINSTANCEUIDLIST, DCM_UI, "", 1, 0, NULL
    };
    IDB_InstanceListElement
	* instance;
    MSG_STATUS_DESCRIPTION
	statusDescription;	/* to check the status returned by a
				 * StoreResponse */
/*  The following definition and cast operation allow us to satisfy prototypes
**  for get callbacks as defined in dicom_services.h.
*/
    CGET_PARAMS *cgetParams;
    cgetParams = (CGET_PARAMS *) cgetParamsPtr;

    network = *cgetParams->network;
    params = cgetParams->params;
    handle = cgetParams->handle;

    strcpy(response->classUID, request->classUID);
    response->conditionalFields = DCM_CMDDATANULL;
    response->dataSetType = DCM_CMDDATANULL;
    response->identifier = NULL;

    if (response->status == MSG_K_CANCEL) {
	if (!silent)
	    printf("CGet cancelled\n");
	if (queryList != NULL) {
	    while ((queryItem = LST_Dequeue(&queryList)) != NULL)
		free(queryItem);
	}
	response->conditionalFields |= MSG_K_C_GET_COMPLETED |
	    MSG_K_C_GET_FAILED | MSG_K_C_GET_WARNING;
	/* check if there is any failed UID list existing */
	if (failedList != NULL) {
	    response->dataSetType = DCM_CMDDATAIDENTIFIER;
	    response->identifier = failedList;
	}
	response->conditionalFields |= MSG_K_C_GET_REMAINING;
	return SRV_NORMAL;
    }
/*  Check if there was a store response from the previous store request.
**  If so, set various fields of the CGetResponse message.
**  The first time this callback is invoked, store response will be
**  NULL and response count will equal 0.
*/

    if (storeResponse != NULL) {
	if (!silent) {
	    printf("Store Response received\n");
	    MSG_DumpMessage(storeResponse, stdout);
	}
	cond = MSG_StatusLookup(storeResponse->status,
				MSG_K_C_STORE_RESP, &statusDescription);
	if (cond != MSG_NORMAL) {
	    fprintf(stderr, "Invalid status code in store response: %s\n",
		    storeResponse->status);
	    return 0;		/* repair */
	}
	switch (statusDescription.statusClass) {
	case MSG_K_CLASS_SUCCESS:
	    response->completedSubOperations++;
	    break;
	case MSG_K_CLASS_WARNING:
	    response->warningSubOperations++;
	    break;
	case MSG_K_CLASS_REFUSED:
	case MSG_K_CLASS_FAILURE:
	    response->failedSubOperations++;
	    break;
	default:
	    fprintf(stderr, "Invalid status code in store response: %s\n",
		    storeResponse->status);
	    break;
	}
/*
** A status of pending does not contain a failed UID list. Also, a
** pending status must contain the number of remaining, completed,
** failed and warning sub operations
*/
	response->dataSetType = DCM_CMDDATANULL;
	response->identifier = NULL;
	response->conditionalFields |= MSG_K_C_GET_REMAINING |
	    MSG_K_C_GET_COMPLETED | MSG_K_C_GET_FAILED |
	    MSG_K_C_GET_WARNING;
	/* we send a PENDING response */
	response->status = MSG_K_C_GET_SUBOPERATIONSCONTINUING;
    }
    if (imageList == NULL) {
	imageList = LST_Create();
	if (imageList == NULL)
	    return 0;
    }
    if (!silent) {
	printf("CGet callback\n");
	printf("SOP Class:      %s\n", SOPClass);
	printf("Query Level:    %s\n", queryLevel);
	printf("Response Count: %d\n", responseCount);
    }
    if (responseCount == 0) {
	if (!silent)
	    (void) DCM_DumpElements(&request->identifier, 0);
#ifdef CTN_MULTIBYTE
	cond = parseQueryMB(&request->identifier, &queryStructure);
#else
	cond = parseQuery(&request->identifier, &queryStructure);
#endif
	if (cond != APP_NORMAL)
	    return 0;
	for (i = 0, done = FALSE; !done && i < (int) DIM_OF(map); i++) {
	    if (strcmp(map[i].levelChar, queryLevel) == 0) {
		searchQueryEnd = map[i].levelInt;
		done = TRUE;
	    }
	}
	switch (searchQueryEnd) {
	case IDB_PATIENT_LEVEL:
	    queryStructure.study.StuInsUID[0] = '\0';
	    queryStructure.StudyQFlag = QF_STU_StuInsUID;
	    queryStructure.StudyNullFlag = QF_STU_StuInsUID;

	    queryStructure.series.SerInsUID[0] = '\0';
	    queryStructure.SeriesQFlag = QF_SER_SerInsUID;
	    queryStructure.SeriesNullFlag = QF_SER_SerInsUID;

	    queryStructure.image.SOPInsUID[0] = '\0';
	    queryStructure.ImageQFlag = QF_IMA_SOPInsUID;
	    queryStructure.ImageNullFlag = QF_IMA_SOPInsUID;
	    break;
	case IDB_STUDY_LEVEL:
	    queryStructure.series.SerInsUID[0] = '\0';
	    queryStructure.SeriesQFlag = QF_SER_SerInsUID;
	    queryStructure.SeriesNullFlag = QF_SER_SerInsUID;

	    queryStructure.image.SOPInsUID[0] = '\0';
	    queryStructure.ImageQFlag = QF_IMA_SOPInsUID;
	    queryStructure.ImageNullFlag = QF_IMA_SOPInsUID;
	    break;
	case IDB_SERIES_LEVEL:
	    queryStructure.image.SOPInsUID[0] = '\0';
	    queryStructure.ImageQFlag = QF_IMA_SOPInsUID;
	    queryStructure.ImageNullFlag = QF_IMA_SOPInsUID;
	    break;
	case IDB_IMAGE_LEVEL:
	    break;
	}

	if (strcmp(SOPClass, DICOM_SOPPATIENTQUERY_GET) == 0)
	    cond = IDB_Select(handle, PATIENT_ROOT, IDB_PATIENT_LEVEL,
			      IDB_IMAGE_LEVEL,
		  &queryStructure, &selectCount, selectCallback, imageList);
	else if (strcmp(SOPClass, DICOM_SOPPATIENTSTUDYQUERY_GET) == 0)
	    cond = IDB_Select(handle, PATIENTSTUDY_ONLY, IDB_PATIENT_LEVEL,
			      IDB_IMAGE_LEVEL,
		  &queryStructure, &selectCount, selectCallback, imageList);
	else if (strcmp(SOPClass, DICOM_SOPSTUDYQUERY_GET) == 0)
	    cond = IDB_Select(handle, STUDY_ROOT, IDB_PATIENT_LEVEL,
			      IDB_IMAGE_LEVEL,
		  &queryStructure, &selectCount, selectCallback, imageList);
	else
	    cond = 0;

	if ((cond != IDB_NORMAL) && (cond != IDB_NOMATCHES)) {
	    COND_DumpConditions();
	    return 0;
	}
	response->remainingSubOperations = LST_Count(&imageList);
	if (!silent)
	    printf("Total store requests: %d\n", response->remainingSubOperations);

	failedList = LST_Create();
	if (failedList == NULL)
	    return 0;
    }
    if (imageList != NULL)
	queryItem = LST_Dequeue(&imageList);
    else
	queryItem = NULL;

    if (queryItem != NULL) {
	instance = LST_Head(&queryItem->query.image.InstanceList);
	if (instance != NULL) {
	    storeRequest->dataSetType = DCM_CMDDATAOTHER;
	    strcpy(storeRequest->classUID, queryItem->query.image.SOPClaUID);
	    strcpy(storeRequest->instanceUID, queryItem->query.image.SOPInsUID);

	    if (!silent)
		printf("Image file name: %s\n", instance->Path);

	    if (strcmp(instance->Transfer, DICOM_TRANSFERLITTLEENDIAN) == 0) {
		cond = DCM_OpenFile(instance->Path,
				  DCM_ORDERLITTLEENDIAN | DCM_NOGROUPLENGTH,
				    &storeRequest->dataSet);
	    } else {
		cond = DCM_OpenFile(instance->Path,
				    DCM_PART10FILE | DCM_NOGROUPLENGTH,
				    &storeRequest->dataSet);
		(void) DCM_RemoveGroup(&storeRequest->dataSet, DCM_GROUPFILEMETA);
	    }

	    if (cond != DCM_NORMAL)
		return 0;	/* repair */
	} else
	    return 0;		/* repair */

	free(queryItem);	/* repair - memory leak */

	response->remainingSubOperations--;
	if (!silent)
	    MSG_DumpMessage(response, stdout);
    } else {			/* No more requests remain */

	storeRequest->dataSetType = DCM_CMDDATANULL;
	if ((response->failedSubOperations == 0) &&
	    (response->warningSubOperations == 0)) {

	    /* complete success */
	    response->status = MSG_K_SUCCESS;
	    response->dataSetType = DCM_CMDDATANULL;
	    response->identifier = NULL;
	    response->conditionalFields |= MSG_K_C_GET_COMPLETED |
		MSG_K_C_GET_FAILED | MSG_K_C_GET_WARNING;
	} else if ((response->warningSubOperations == 0) &&
		   (response->completedSubOperations == 0)) {
	    /* All sub operations failed */
	    response->status = MSG_K_C_GET_UNABLETOPROCESS;
	    response->dataSetType = DCM_CMDDATAIDENTIFIER;
	    response->identifier = failedList;
	    response->conditionalFields |= MSG_K_C_GET_COMPLETED |
		MSG_K_C_GET_FAILED | MSG_K_C_GET_WARNING;
	} else {
	    /* Some sub operations may have failed or had warnings */
	    response->status = MSG_K_C_GET_COMPLETEWITHFAILURES;
	    response->dataSetType = DCM_CMDDATAIDENTIFIER;
	    response->identifier = failedList;
	    response->conditionalFields |= MSG_K_C_GET_COMPLETED |
		MSG_K_C_GET_FAILED | MSG_K_C_GET_WARNING;
	}
    }

    return SRV_NORMAL;
}