Example #1
0
int
p_parseSequence(DCM_OBJECT ** object)
{

    DCM_ELEMENT e;
    LST_HEAD *l;
    CONDITION cond;
    int index;
    SQ_TYPE type;
    SQ_REFVISITSOPINSTANCEUID *visit;
    SQ_REFSTUDYSOPINSTANCEUID *study;
    void *pointer;

    static DCM_MAP_SQ sequences[] = {
	{DCM_IDREFERENCEDVISITSEQ, SQ_K_REFVISITSOPINSTANCEUID,
	HIS_K_PATRVSEQUENCE},
	{DCM_IDREFERENCEDSTUDYSEQ, SQ_K_REFSTUDYSOPINSTANCEUID,
	HIS_K_PATRSSEQUENCE},
    };

    for (index = 0; index < (int) DIM_OF(sequences); index++) {
	e.tag = sequences[index].tag;
	cond = DCM_GetSequenceList(object, e.tag, &e.d.sq);
	if (cond != DCM_NORMAL) {
	    if (cond != DCM_ELEMENTNOTFOUND)
		return -1;
	} else {
	    cond = SQ_ParseSequence(&e, &type, &l);
	    if (cond != SQ_NORMAL || type != sequences[index].type)
		return -2;
	    p.Update_Flag |= sequences[index].his_field;
	    pointer = LST_Head(&l);
	    if (pointer != NULL)
		LST_Position(&l, pointer);
	    while (pointer != NULL) {
		switch (sequences[index].tag) {
		case DCM_IDREFERENCEDVISITSEQ:
		    visit = (SQ_REFVISITSOPINSTANCEUID *) pointer;
		    strcpy(p.RVSequence[p.RVSequenceCount],
			   visit->referencedSOPInstanceUID);
		    ++p.RVSequenceCount;
		    break;
		case DCM_IDREFERENCEDSTUDYSEQ:
		    study = (SQ_REFSTUDYSOPINSTANCEUID *) pointer;
		    strcpy(p.RSSequence[p.RSSequenceCount],
			   study->referencedSOPInstanceUID);
		    ++p.RSSequenceCount;
		    break;
		}
		pointer = LST_Next(&l);
	    }
	}
    }
    return 0;
/*
    e[0].tag = DCM_IDREFERENCEDVISITSEQ;
    e[1].tag = DCM_IDREFERENCEDSTUDYSEQ;

    for (index = 0; index < (int) DIM_OF(e); index++) {
	cond = DCM_GetSequenceList(object, e[index].tag, &e[index].d.sq);
	if (cond == DCM_ELEMENTNOTFOUND)
	    continue;
	else if (cond != DCM_NORMAL)
	    return -1;

	cond = SQ_ParseSequence(&e[index], &type, &l);
	if (cond != SQ_NORMAL)
	    return -2;

	if (type == SQ_K_REFVISITSOPINSTANCEUID) {
	    p.Update_Flag |= HIS_K_PATRVSEQUENCE;
	    visit = LST_Head(&l);
	    if (visit != NULL)
		LST_Position(&l, visit);
	    while (visit != NULL) {
		strcpy(p.RVSequence[p.RVSequenceCount],
		       visit->referencedSOPInstanceUID);
		++p.RVSequenceCount;
		visit = LST_Next(&l);
	    }
	}
	if (type == SQ_K_REFSTUDYSOPINSTANCEUID) {
	    p.Update_Flag |= HIS_K_PATRSSEQUENCE;
	    study = LST_Head(&l);
	    if (study != NULL)
		LST_Position(&l, study);
	    while (study != NULL) {
		strcpy(p.RSSequence[p.RSSequenceCount],
		       study->referencedSOPInstanceUID);
		++p.RSSequenceCount;
		study = LST_Next(&l);
	    }
	}
    }

    return 0;
*/
}
Example #2
0
File: set.c Project: 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;
}
Example #3
0
CONDITION
SRV_AcceptServiceClassWithOneXferSyntax(DUL_PRESENTATIONCONTEXT * requestedCtx,
		  DUL_SC_ROLE role, DUL_ASSOCIATESERVICEPARAMETERS * params,
		  const char* singleXferSyntax)
{
    int
        index;
    CTNBOOLEAN
	abstractFound = FALSE,
	transferFound = FALSE;

    CONDITION
	cond,
	rtnCond = SRV_NORMAL;
    DUL_PRESENTATIONCONTEXT
	* ctx;
    DUL_TRANSFERSYNTAX
	* transfer;

    if (params->acceptedPresentationContext == NULL) {
	params->acceptedPresentationContext = LST_Create();
	if (params->acceptedPresentationContext == NULL) {
	    return COND_PushCondition(SRV_LISTFAILURE,
		    SRV_Message(SRV_LISTFAILURE), "SRV_AcceptServiceClass");
	}
    }
    for (index = 0; index < (int) DIM_OF(syntaxList) && !abstractFound; index++) {
	if (strcmp(requestedCtx->abstractSyntax, syntaxList[index]) == 0) {
	    abstractFound = TRUE;
	}
    }
    if (abstractFound) {
#if 0
	char* xferSyntaxes[] =
	{ "1.2.840.10008.1.2.4.50",	/* JPEG Baseline Process 1 */
	"1.2.840.10008.1.2.4.51",	/* JPEG Extended Process 2 & 4 */
	"1.2.840.10008.1.2.1",		/* Explicit VR Little Endian */
	"1.2.840.10008.1.2.1.99",	/* Deflated Explicit VR Little Endian */
	"1.2.840.10008.1.2.2",		/* Explicit VR Big Endian Endian */
	DICOM_TRANSFERLITTLEENDIAN };
#endif

	transfer = matchProposedXferSyntax(requestedCtx,
			"ACCEPT/XFER", &singleXferSyntax, 1);
	if (transfer == NULL) {
	  cond = DUL_MakePresentationCtx(&ctx,
				       requestedCtx->proposedSCRole,
				       DUL_SC_ROLE_DEFAULT,
				       requestedCtx->presentationContextID,
				    DUL_PRESENTATION_REJECT_TRANSFER_SYNTAX,
				       requestedCtx->abstractSyntax,
	      DICOM_TRANSFERLITTLEENDIAN, DICOM_TRANSFERLITTLEENDIAN, NULL);
	  if (cond != DUL_NORMAL)
	    return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
				  SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
				      "SRV_AcceptServiceClass");
	  (void) COND_PushCondition(SRV_UNSUPPORTEDSERVICE,
				  SRV_Message(SRV_UNSUPPORTEDSERVICE),
		    requestedCtx->abstractSyntax, "SRV_AcceptServiceClass");
	  rtnCond = COND_PushCondition(SRV_PRESENTATIONCTXREJECTED,
				   SRV_Message(SRV_PRESENTATIONCTXREJECTED),
		    requestedCtx->abstractSyntax, "SRV_AcceptServiceClass");
	} else {
	    cond = DUL_MakePresentationCtx(&ctx,
					 requestedCtx->proposedSCRole, role,
					requestedCtx->presentationContextID,
					   DUL_PRESENTATION_ACCEPT,
					   requestedCtx->abstractSyntax,
					   transfer->transferSyntax,
					   transfer->transferSyntax,
					   NULL);
	    if (cond != DUL_NORMAL)
		return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
				  SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
					  "SRV_AcceptServiceClass");
	}
#if 0
	if ((transfer = LST_Head(&requestedCtx->proposedTransferSyntax)) == NULL)
	    return COND_PushCondition(SRV_LISTFAILURE,
		    SRV_Message(SRV_LISTFAILURE), "SRV_AcceptServiceClass");
	(void) LST_Position(&requestedCtx->proposedTransferSyntax, transfer);
	while (!transferFound && (transfer != NULL)) {
	    if (strcmp(transfer->transferSyntax, DICOM_TRANSFERLITTLEENDIAN) == 0)
		transferFound = TRUE;
	    else
		transfer = LST_Next(&requestedCtx->proposedTransferSyntax);
	}
	if (transferFound) {
	    cond = DUL_MakePresentationCtx(&ctx,
					 requestedCtx->proposedSCRole, role,
					requestedCtx->presentationContextID,
					   DUL_PRESENTATION_ACCEPT,
					   requestedCtx->abstractSyntax,
	      DICOM_TRANSFERLITTLEENDIAN, DICOM_TRANSFERLITTLEENDIAN, NULL);
	    if (cond != DUL_NORMAL)
		return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
				  SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
					  "SRV_AcceptServiceClass");
	} else {
	    cond = DUL_MakePresentationCtx(&ctx,
					   requestedCtx->proposedSCRole,
					   DUL_SC_ROLE_DEFAULT,
					requestedCtx->presentationContextID,
				    DUL_PRESENTATION_REJECT_TRANSFER_SYNTAX,
					   requestedCtx->abstractSyntax,
	      DICOM_TRANSFERLITTLEENDIAN, DICOM_TRANSFERLITTLEENDIAN, NULL);
	    if (cond != DUL_NORMAL)
		return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
				  SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
					  "SRV_AcceptServiceClass");

	    (void) COND_PushCondition(SRV_UNSUPPORTEDTRANSFERSYNTAX,
				 SRV_Message(SRV_UNSUPPORTEDTRANSFERSYNTAX),
		    requestedCtx->abstractSyntax, "SRV_AcceptServiceClass");
	    rtnCond = COND_PushCondition(SRV_PRESENTATIONCTXREJECTED,
				   SRV_Message(SRV_PRESENTATIONCTXREJECTED),
		    requestedCtx->abstractSyntax, "SRV_AcceptServiceClass");
	}
#endif
    } else {
	cond = DUL_MakePresentationCtx(&ctx,
				       requestedCtx->proposedSCRole,
				       DUL_SC_ROLE_DEFAULT,
				       requestedCtx->presentationContextID,
				    DUL_PRESENTATION_REJECT_ABSTRACT_SYNTAX,
				       requestedCtx->abstractSyntax,
	      DICOM_TRANSFERLITTLEENDIAN, DICOM_TRANSFERLITTLEENDIAN, NULL);
	if (cond != DUL_NORMAL)
	    return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
				  SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
				      "SRV_AcceptServiceClass");
	(void) COND_PushCondition(SRV_UNSUPPORTEDSERVICE,
				  SRV_Message(SRV_UNSUPPORTEDSERVICE),
		    requestedCtx->abstractSyntax, "SRV_AcceptServiceClass");
	rtnCond = COND_PushCondition(SRV_PRESENTATIONCTXREJECTED,
				   SRV_Message(SRV_PRESENTATIONCTXREJECTED),
		    requestedCtx->abstractSyntax, "SRV_AcceptServiceClass");
    }
    cond = LST_Enqueue(&params->acceptedPresentationContext, ctx);
    if (cond != LST_NORMAL)
	return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE),
				  "SRV_AcceptServiceClass");

/*    pdvList.count = 0; */

    return rtnCond;
}
Example #4
0
int
p_buildSequence(DCM_OBJECT ** object, SQ_TYPE type)
{

    int index = 0;
    int i;
    LST_HEAD *l;
    DCM_ELEMENT *e;
    CONDITION cond;
    SQ_REFVISITSOPINSTANCEUID *visit;
    SQ_REFSTUDYSOPINSTANCEUID *study;
    void *pointer;

    static SQ_MAP_SOP sops[] = {
	{SQ_K_REFVISITSOPINSTANCEUID,
	    DICOM_SOPCLASSDETACHEDVISITMGMT, &(p.RVSequenceCount),
	sizeof(SQ_REFVISITSOPINSTANCEUID)},
	{SQ_K_REFSTUDYSOPINSTANCEUID,
	    DICOM_SOPCLASSDETACHEDSTUDYMGMT, &(p.RSSequenceCount),
	sizeof(SQ_REFSTUDYSOPINSTANCEUID)},
    };

    l = LST_Create();
    if (l == NULL)
	return -1;

    for (i = 0; i < (int) DIM_OF(sops) && sops[i].type != type;
	 i++);
    if (i >= (int) DIM_OF(sops))
	return -1;
    while (index < *(sops[i].counter)) {
	if ((pointer = malloc(sops[i].size)) == NULL)
	    return -1;
	switch (type) {
	case SQ_K_REFVISITSOPINSTANCEUID:
	    visit = (SQ_REFVISITSOPINSTANCEUID *) pointer;
	    visit->type = type;
	    sprintf(visit->referencedSOPClassUID, "%s", sops[i].sopclass);
	    sprintf(visit->referencedSOPInstanceUID, "%s", p.RVSequence[index]);
	    break;
	case SQ_K_REFSTUDYSOPINSTANCEUID:
	    study = (SQ_REFSTUDYSOPINSTANCEUID *) pointer;
	    study->type = type;
	    sprintf(study->referencedSOPClassUID, "%s", sops[i].sopclass);
	    sprintf(study->referencedSOPInstanceUID, "%s", p.RSSequence[index]);
	    break;
	}
	if (LST_Enqueue(&l, pointer) != LST_NORMAL)
	    return -2;
	index++;
    }
    cond = SQ_BuildSequence(&l, sops[i].type, &e);
    if (cond != SQ_NORMAL) {
	COND_DumpConditions();
	fprintf(stderr, "SQ_BuildSequence failed \n");
	return -1;
    }
    cond = DCM_AddElement(object, e);
    if (cond != DCM_NORMAL) {
	COND_DumpConditions();
	fprintf(stderr, "DCM_AddElement failed \n");
	return -1;
    }
    return 0;
/*
    if (!strcmp(DICOM_SOPCLASSDETACHEDVISITMGMT, sopclass)) {
	while (index < p.RVSequenceCount) {
	    visit = malloc(sizeof(*visit));
	    if (visit == NULL)
		return -1;
	    visit->type = SQ_K_REFVISITSOPINSTANCEUID;
	    sprintf(visit->referencedSOPClassUID, "%s", sopclass);
	    sprintf(visit->referencedSOPInstanceUID, "%s", p.RVSequence[index]);
	    LST_Enqueue(&l, visit);
	    index++;
	}

	cond = SQ_BuildSequence(&l, SQ_K_REFVISITSOPINSTANCEUID, &e);
	if (cond != SQ_NORMAL) {
	    COND_DumpConditions();
	    fprintf(stderr, "SQ_BuildSequence failed \n");
	    return -1;
	}
	cond = DCM_AddElement(object, e);
	if (cond != DCM_NORMAL) {
	    COND_DumpConditions();
	    fprintf(stderr, "DCM_AddElement failed \n");
	    return -1;
	}
	return 1;
    }
    if (!strcmp(DICOM_SOPCLASSDETACHEDSTUDYMGMT, sopclass)) {
	while (index < p.RSSequenceCount) {
	    study = malloc(sizeof(*study));
	    if (study == NULL)
		return -1;
	    study->type = SQ_K_REFSTUDYSOPINSTANCEUID;
	    sprintf(study->referencedSOPClassUID, "%s", sopclass);
	    sprintf(study->referencedSOPInstanceUID, "%s", p.RSSequence[index]);
	    LST_Enqueue(&l, study);
	    index++;
	}

	cond = SQ_BuildSequence(&l, SQ_K_REFSTUDYSOPINSTANCEUID, &e);
	if (cond != SQ_NORMAL) {
	    COND_DumpConditions();
	    fprintf(stderr, "SQ_BuildSequence failed \n");
	    return -1;
	}
	cond = DCM_AddElement(object, e);
	if (cond != DCM_NORMAL) {
	    COND_DumpConditions();
	    fprintf(stderr, "DCM_AddElement failed \n");
	    return -1;
	}
	return 1;
    }
*/
}
Example #5
0
int
MDBImageManager::fillPatientStudyVector(const MPatientStudy& patientStudy,
					MPatientStudyVector& v)
{

  char* searchCriteria[] = {
    "patid",
    "nam",
    "datbir",
    "sex",
    "stuinsuid",
    // "studat",	// Comment this out; treat for date range
    "stutim",
    "accnum",
    "stuid",
    "modinstu"
  };

  int i;
  MCriteriaVector criteria;

  MString studyDate = patientStudy.studyDate();
  if (studyDate != "") {
    if (studyDate.containsCharacter('-')) {
      MString lower = studyDate.getToken('-', 0);
      MString upper = studyDate.getToken('-', 1);
      if (lower != "") {
	MCriteria p;
	p.attribute = "studat";
	p.oper = TBL_GREATER_EQUAL;
	p.value = lower;
	criteria.push_back(p);
      }
      if (upper != "") {
	MCriteria p;
	p.attribute = "studat";
	p.oper = TBL_LESS_EQUAL;
	p.value = upper;
	criteria.push_back(p);
      }
    } else {
      MCriteria p;
      p.attribute = "studat";
      p.oper = TBL_EQUAL;
      p.value = studyDate;
      criteria.push_back(p);
    }
  }


  const MDomainMap& m = patientStudy.map();
  for(i = 0; i < (int)DIM_OF(searchCriteria); i++) {
    MDomainMap::const_iterator iDomain = m.find(searchCriteria[i]);
    if (iDomain == m.end())   // added for testing -- does this need to be here?
      continue;
    MString s = (*iDomain).second;

    // MString s = m[searchCriteria[i]];

    if (s != "") {
      if ((*iDomain).first == "modinstu") {
	s = "*" + s + "*";
      }

      TBL_OPERATOR oper = TBL_EQUAL;
      if (s.find("*") != string::npos) {
	s.substitute('*', '%');
	oper = TBL_LIKE;
      }
      MCriteria c;
      c.attribute = searchCriteria[i];
      c.oper = oper;
      c.value = s;
      criteria.push_back(c);
    }
  }
  MPatientStudy p;
  mDBInterface->select(p, criteria, patientStudyCallback, &v);
#if 0
  MPatientVector::iterator patientIterator = mPatientVector.begin();
  for (; patientIterator != mPatientVector.end(); patientIterator++)
    v.push_back(*patientIterator);
#endif

  return 0;
}
Example #6
0
int
i_parseSequence(DCM_OBJECT ** object)
{

    DCM_ELEMENT e;
    LST_HEAD *l;
    CONDITION cond;
    int index;
    SQ_TYPE type;
    SQ_REFRESULTSSOPINSTANCEUID *results;
    SQ_REQINTERPRETATIONAPPROVER *approver;
    SQ_REQPROCEDURECODE *diagnosis;
    void *pointer;

    static DCM_MAP_SQ sequences[] = {
	{DCM_IDREFERENCEDRESULTSSEQ, SQ_K_REFRESULTSSOPINSTANCEUID,
	HIS_K_INTRRSEQUENCE},
	{DCM_RESINTERPAPPROVERSEQUENCE, SQ_K_REQINTERPRETATIONAPPROVER,
	HIS_K_INTIAPPSEQUENCE},
	{DCM_RESDIAGNOSISCODESEQ, SQ_K_REQDIAGNOSISCODE,
	HIS_K_INTIDCSEQUENCE},
    };

    for (index = 0; index < (int) DIM_OF(sequences); index++) {
	e.tag = sequences[index].tag;
	cond = DCM_GetSequenceList(object, e.tag, &e.d.sq);
	if (cond != DCM_NORMAL) {
	    if (cond != DCM_ELEMENTNOTFOUND)
		return -1;
	} else {
	    cond = SQ_ParseSequence(&e, &type, &l);
	    if (cond != SQ_NORMAL || type != sequences[index].type)
		return -2;
	    p.Update_Flag |= sequences[index].his_field;
	    pointer = LST_Head(&l);
	    if (pointer != NULL)
		LST_Position(&l, pointer);
	    while (pointer != NULL) {
		switch (sequences[index].tag) {
		case DCM_IDREFERENCEDRESULTSSEQ:
		    strcpy(p.RRSequence[p.RRSequenceCount],
			   ((SQ_REFRESULTSSOPINSTANCEUID *)
			    pointer)->referencedSOPInstanceUID);
		    p.RRSequenceCount++;
		    break;
		case DCM_RESINTERPAPPROVERSEQUENCE:
		    strcpy(p.IApprover[p.IApprovalSequenceCount],
			   ((SQ_REQINTERPRETATIONAPPROVER *)
			    pointer)->physiciansApproving);
		    strcpy(p.IADates[p.IApprovalSequenceCount],
			   ((SQ_REQINTERPRETATIONAPPROVER *)
			    pointer)->approvalDates);
		    strcpy(p.IATimes[p.IApprovalSequenceCount],
			   ((SQ_REQINTERPRETATIONAPPROVER *)
			    pointer)->approvalTimes);
		    p.IApprovalSequenceCount++;
		    break;
		case DCM_RESDIAGNOSISCODESEQ:
		    strcpy(p.IDCSequence[p.IDCSequenceCount].
			   CodeValue,
			   ((SQ_REQPROCEDURECODE *) pointer)->codeValue);
		    strcpy(p.IDCSequence[p.IDCSequenceCount].
			   CodingSchemeDesignator,
			   ((SQ_REQPROCEDURECODE *) pointer)->codingSchemeDesignator);
		    strcpy(p.IDCSequence[p.IDCSequenceCount].
			   CodeMeaning,
			   ((SQ_REQPROCEDURECODE *) pointer)->codeMeaning);
		    p.IDCSequenceCount++;
		    break;
		}
		pointer = LST_Next(&l);
	    }
	}
    }
    return 0;
/*
    e.tag = DCM_IDREFERENCEDRESULTSSEQ;

    cond = DCM_GetSequenceList(object, e.tag, &e.d.sq);
    if (cond == DCM_ELEMENTNOTFOUND)
	return 0;
    else if (cond != DCM_NORMAL)
	return -1;

    cond = SQ_ParseSequence(&e, &type, &l);
    if (cond != SQ_NORMAL)
	return -2;
    if (type == SQ_K_REFRESULTSSOPINSTANCEUID) {
	p.Update_Flag |= HIS_K_INTRRSEQUENCE;
	results = LST_Head(&l);
	if (results != NULL)
	    LST_Position(&l, results);
	while (results != NULL) {
	    strcpy(p.RRSequence[p.RRSequenceCount],
		   results->referencedSOPInstanceUID);
	    ++p.RRSequenceCount;
	    results = LST_Next(&l);
	}
    }
*/
}
OFCondition RetrieveDICOMFilesFromPACS::acceptSubAssociation(T_ASC_Network *associationNetwork, T_ASC_Association **association)
{
    const char *knownAbstractSyntaxes[] = { UID_VerificationSOPClass };
    const char *transferSyntaxes[] = { NULL, NULL, NULL, NULL };
    int numTransferSyntaxes;

    OFCondition condition = ASC_receiveAssociation(associationNetwork, association, ASC_DEFAULTMAXPDU);

    if (condition.good())
    {
#ifndef DISABLE_COMPRESSION_EXTENSION
        // Si disposem de compressió la demanem, i podrem accelerar el temps de descàrrega considerablement
        // De moment demanem la compressió lossless que tot PACS que suporti compressió ha
        // de proporcionar: JPEGLossless:Non-Hierarchical-1stOrderPrediction
        transferSyntaxes[0] = UID_JPEGProcess14SV1TransferSyntax;
        transferSyntaxes[1] = UID_LittleEndianExplicitTransferSyntax;
        transferSyntaxes[2] = UID_BigEndianExplicitTransferSyntax;
        transferSyntaxes[3] = UID_LittleEndianImplicitTransferSyntax;
        numTransferSyntaxes = 4;
#else
        // Defined in dcxfer.h
        if (gLocalByteOrder == EBO_LittleEndian)
        {
        transferSyntaxes[0] = UID_LittleEndianExplicitTransferSyntax;
        transferSyntaxes[1] = UID_BigEndianExplicitTransferSyntax;
        }
        else
        {
        transferSyntaxes[0] = UID_BigEndianExplicitTransferSyntax;
        transferSyntaxes[1] = UID_LittleEndianExplicitTransferSyntax;
        }
        transferSyntaxes[2] = UID_LittleEndianImplicitTransferSyntax;
        numTransferSyntaxes = 3;
#endif

        // Accept the Verification SOP Class if presented
        condition = ASC_acceptContextsWithPreferredTransferSyntaxes((*association)->params, knownAbstractSyntaxes, DIM_OF(knownAbstractSyntaxes),
                                                                    transferSyntaxes, numTransferSyntaxes);

        if (condition.good())
        {
            // The array of Storage SOP Class UIDs comes from dcuid.h
            condition = ASC_acceptContextsWithPreferredTransferSyntaxes((*association)->params, dcmAllStorageSOPClassUIDs, numberOfAllDcmStorageSOPClassUIDs,
                                                                        transferSyntaxes, numTransferSyntaxes);
        }
    }

    if (condition.good())
    {
        condition = ASC_acknowledgeAssociation(*association);
    }
    else
    {
        ASC_dropAssociation(*association);
        ASC_destroyAssociation(association);
    }
    return condition;
}
Example #8
0
CONDITION
MSG_ParseCMoveResponse(DCM_OBJECT ** object, MSG_C_MOVE_RESP * moveResponse)
{
    static MSG_C_MOVE_RESP	    response;
    static unsigned short       command, type;

    static DCM_ELEMENT elementList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDCOMMANDFIELD, DCM_US, "", 1, sizeof(command), (void *) &command},
    		{DCM_GROUPCOMMAND, DCM_CMDCLASSUID, DCM_UI, "", 1, sizeof(response.classUID), (void *) response.classUID},
    		{DCM_GROUPCOMMAND, DCM_CMDMSGIDRESPOND, DCM_US, "", 1, sizeof(response.messageIDRespondedTo), (void *) &response.messageIDRespondedTo},
    		{DCM_GROUPCOMMAND, DCM_CMDDATASETTYPE, DCM_US, "", 1, sizeof(type), (void *) &type},
    		{DCM_GROUPCOMMAND, DCM_CMDSTATUS, DCM_US, "", 1, sizeof(response.status), (void *) &response.status},
    };

    DCM_ELEMENT		e;			/* Used for conditional elements */

    static MSGPRV_CONDITIONAL conditionalList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDSUCCESSINSTANCEUIDLIST, DCM_UI, "", 1, 0, (void *) &response.successUIDs, &response.conditionalFields, MSG_K_C_MOVE_SUCCESSUID},
    		{DCM_GROUPCOMMAND, DCM_CMDFAILEDINSTANCEUIDLIST, DCM_UI, "", 1, 0, (void *) &response.failedUIDs, &response.conditionalFields, MSG_K_C_MOVE_FAILEDUID},
    		{DCM_GROUPCOMMAND, DCM_CMDWARNINGINSTANCEUIDLIST, DCM_UI, "", 1, 0, (void *) &response.warningUIDs, &response.conditionalFields, MSG_K_C_MOVE_WARNINGUID},
    		{DCM_GROUPCOMMAND, DCM_CMDREMAININGSUBOPERATIONS, DCM_US, "", 1, sizeof(response.remainingSubOperations), (void *) &response.remainingSubOperations, &response.conditionalFields, MSG_K_C_MOVE_REMAINING},
    		{DCM_GROUPCOMMAND, DCM_CMDCOMPLETEDSUBOPERATIONS, DCM_US, "", 1, sizeof(response.completedSubOperations), (void *) &response.completedSubOperations, &response.conditionalFields, MSG_K_C_MOVE_COMPLETED},
    		{DCM_GROUPCOMMAND, DCM_CMDFAILEDSUBOPERATIONS, DCM_US, "", 1, sizeof(response.failedSubOperations), (void *) &response.failedSubOperations, &response.conditionalFields, MSG_K_C_MOVE_FAILED},
    		{DCM_GROUPCOMMAND, DCM_CMDWARNINGSUBOPERATIONS, DCM_US, "", 1, sizeof(response.warningSubOperations), (void *) &response.warningSubOperations, &response.conditionalFields, MSG_K_C_MOVE_WARNING},
    };

    void		       *ctx;
    int			       index;
    unsigned long	   rtnLength;
    CONDITION		   cond;

    for (index = 0; index < (int) DIM_OF(elementList); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(object, &elementList[index], &rtnLength, &ctx);
    	if (cond != DCM_NORMAL) return COND_PushCondition(MSG_PARSEFAILED, MSG_Message(MSG_PARSEFAILED));
    }
    response.type = MSG_K_C_MOVE_RESP;

    for (index = 0; index < (int) DIM_OF(conditionalList); index++) {
    	cond = DCM_NORMAL;
    	e = conditionalList[index].e;
    	if (e.length == 0) {
    		cond = DCM_GetElementSize(object, DCM_MAKETAG(e.group, e.element), &rtnLength);
    		if (cond == DCM_NORMAL) {
    			e.length = rtnLength;
    			e.d.string = malloc(rtnLength + 1);
    			if (e.d.string == NULL) return 0;	/* repair */
    			*conditionalList[index].e.d.stringArray = e.d.string;
    		}else{
    			(void) COND_PopCondition(FALSE);
    		}
    	}
    	if (cond == DCM_NORMAL) {
    		ctx = NULL;
    		cond = DCM_GetElementValue(object, &e, &rtnLength, &ctx);
    		if (cond == DCM_NORMAL) {
    			*conditionalList[index].flag |= conditionalList[index].flagBit;
    			e.d.string[rtnLength] = '\0';
    		}
    	}
    }

    *moveResponse = response;
    return MSG_NORMAL;
}
Example #9
0
OFCondition PACSConnection::configureEcho()
{
    const char *transferSyntaxes[] = { UID_LittleEndianImplicitTransferSyntax };
    // PresentationContextID always has to be odd
    int presentationContextID = 1;

    return ASC_addPresentationContext(m_associationParameters, presentationContextID, UID_VerificationSOPClass, transferSyntaxes, DIM_OF(transferSyntaxes));
}
Example #10
0
CONDITION
nextAssociationRequest(char *node, DUL_NETWORKKEY ** network,
	     DUL_ASSOCIATESERVICEPARAMETERS * service, unsigned long maxPDU,
		  CTNBOOLEAN forgiveFlag, DUL_ASSOCIATIONKEY ** association)
{
    CTNBOOLEAN
	drop,
	acceptFlag,
	acceptPresentationContext,
	readAccess,
	writeAccess;
    CONDITION
	cond,
	rtnCond = APP_NORMAL;
    DUL_PRESENTATIONCONTEXT
	* requestedCtx;
    int
        classCount;
    DUL_SC_ROLE
	scRole = DUL_SC_ROLE_DEFAULT;
    DUL_ABORTITEMS
	abortItems;
    DMAN_HANDLE
	* manageHandle;

    (void) memset(service, 0, sizeof(*service));
    service->maxPDU = maxPDU;
    strcpy(service->calledImplementationClassUID,
	   MIR_IMPLEMENTATIONCLASSUID);
    strcpy(service->calledImplementationVersionName,
	   MIR_IMPLEMENTATIONVERSIONNAME);
    cond = DUL_ReceiveAssociationRQ(network, DUL_BLOCK,
				    service, association);
    if (cond != DUL_NORMAL)
	return COND_PushCondition(APP_ERROR(APP_ASSOCIATIONRQFAILED));

    acceptFlag = TRUE;
    drop = FALSE;

    cond = DMAN_Open(controlDatabase, service->callingAPTitle,
		     service->calledAPTitle, &manageHandle);
    if (cond != DMAN_NORMAL) {
	acceptFlag = FALSE;
	rtnCond = COND_PushCondition(APP_ERROR(APP_ASSOCIATIONRQFAILED));
    }
    if (acceptFlag) {

	cond = associationCheck(node, service, &manageHandle, forgiveFlag,
				&abortItems);
	if (CTN_ERROR(cond)) {
	    acceptFlag = FALSE;
	    fprintf(stderr, "Incorrect Association Request\n");
	    (void) DUL_RejectAssociationRQ(association, &abortItems);
	    rtnCond = COND_PushCondition(APP_ERROR(APP_ASSOCIATIONRQFAILED));
	} else if (!CTN_SUCCESS(cond)) {
	    COND_DumpConditions();
	}
    }
    if (acceptFlag) {
	if (verboseDUL)
	    DUL_DumpParams(service);

	requestedCtx = LST_Head(&service->requestedPresentationContext);
	if (requestedCtx != NULL)
	    (void) LST_Position(&service->requestedPresentationContext,
				requestedCtx);
	classCount = 0;
	while (requestedCtx != NULL) {
	    int i;

	    acceptPresentationContext = FALSE;
	    for (i = 0; i < DIM_OF(supportedSOPClasses); i++) {
		if (strcmp(supportedSOPClasses[i], requestedCtx->abstractSyntax) == 0)
		    acceptPresentationContext = TRUE;
	    }
	    if (acceptPresentationContext) {
		switch (requestedCtx->proposedSCRole) {
		case DUL_SC_ROLE_DEFAULT:
		    scRole = DUL_SC_ROLE_DEFAULT;
		    break;
		case DUL_SC_ROLE_SCU:
		    scRole = DUL_SC_ROLE_SCU;
		    break;
		case DUL_SC_ROLE_SCP:
		    acceptPresentationContext = FALSE;
		    break;
		case DUL_SC_ROLE_SCUSCP:
		    scRole = DUL_SC_ROLE_SCU;
		    break;
		default:
		    scRole = DUL_SC_ROLE_DEFAULT;
		    break;
		}
	    }
	    if (acceptPresentationContext) {
		cond = SRV_AcceptServiceClass(requestedCtx, scRole,
					      service);
		if (cond == SRV_NORMAL) {
		    classCount++;
		} else {
		    printf("SRV Facility rejected SOP Class: %s\n",
			   requestedCtx->abstractSyntax);
		    COND_DumpConditions();
		}
	    } else {
		printf("Simple server rejects: %s\n",
		       requestedCtx->abstractSyntax);
		cond = SRV_RejectServiceClass(requestedCtx,
				     DUL_PRESENTATION_REJECT_USER, service);
		if (cond != SRV_NORMAL) {
		    drop = TRUE;
		}
	    }
	    requestedCtx = LST_Next(&service->requestedPresentationContext);
	}
	printf("Supported classes: %d\n", classCount);

	if (drop) {
	    (void) DUL_DropAssociation(association);
	    rtnCond = COND_PushCondition(APP_ERROR(APP_ASSOCIATIONRQFAILED));
	} else {
/*	    cond = DUL_AcknowledgeAssociationRQ(association, service);
	    if (cond != DUL_NORMAL) {
		rtnCond = COND_PushCondition(APP_ERROR(APP_ASSOCIATIONRQFAILED));
	    }
	    if (verboseDUL)
		DUL_DumpParams(service);
*/
	}
    }
    (void) DMAN_Close(&manageHandle);
    return rtnCond;
}
Example #11
0
File: cget.c Project: 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;
}
Example #12
0
int
UID_IsStorageClass(const char* sopClassUID)
{
  char *classArray[] = {

  /* In order of PS 3.4, Table B.5-1 */
  DICOM_SOPCLASSCOMPUTEDRADIOGRAPHY,
  DICOM_SOPCLASSCT,
  DICOM_SOPCLASSENHANCEDCT,
  DICOM_SOPCLASSHARDCOPYCOLORIMAGE,
  DICOM_SOPCLASSHARDCOPYGRAYSCALEIMAGE,
  DICOM_SOPCLASSMR,
  DICOM_SOPCLASSENHANCEDMR,
  DICOM_SOPCLASSENCAPSULATEDPDF,
  DICOM_SOPCLASSNM,
  DICOM_SOPCLASSPET,
  DICOM_SOPRTDOSESTORAGE,
  DICOM_SOPRTIMAGESTORAGE,
  DICOM_SOPRTPLANSTORAGE,
  DICOM_SOPRTSTRUCTURESETSTORAGE,
  DICOM_SOPRTBREAMS,
  DICOM_SOPRTBRACHYTREATMENT,
  DICOM_SOPRTTREATMENTSUMMARY,
  DICOM_SOPCLASSSECONDARYCAPTURE,
  DICOM_SOPCLASSSTANDALONECURVE,
  DICOM_SOPCLASSSTANDALONEMODALITYLUT,
  DICOM_SOPCLASSSTANDALONEOVERLAY,
  DICOM_SOPCLASSSTANDALONEVOILUT,
  DICOM_SOPCLASSSTANDALONEPETCURVE,
  DICOM_SOPCLASSSTOREDPRINT,
  DICOM_SOPCLASSUS,
  DICOM_SOPCLASSUSMULTIFRAMEIMAGE,
  DICOM_SOPCLASSXRAYANGIO,
  DICOM_SOPCLASSXRAYFLUORO,
  DICOM_SOPCLASSDIGXRAYPRESENTATION,
  DICOM_SOPCLASSDIGXRAYPROCESSING,
  DICOM_SOPCLASSMAMMOXRPRESENTATION,
  DICOM_SOPCLASSMAMMOXRPROCESSING,
  DICOM_SOPCLASSINTRAORALPRESENTATION,
  DICOM_SOPCLASSINTRAORALPROCESSING,
  DICOM_SOPCLASSVLENDOSCOPIC,
  DICOM_SOPCLASSVLMICROSCOPIC,
  DICOM_SOPCLASSVLSLIDEMICROSCOPIC,
  DICOM_SOPCLASSVLPHOTOGRAPHIC,
  /* More storage SOP Classes */
  DICOM_SOPCLASSUSMULTIFRAMEIMAGE1993,
  DICOM_SOPCLASSNM1993,
  DICOM_SOPCLASSUS1993,
  DICOM_SOPCLASSWAVEFORMSTORAGE,
  DICOM_SOPCLASSECGWAVEFORMSTORAGE,
  DICOM_SOPCLASSXRAYANGIOBIPLANE_RET
  };
  int idx;

  if (sopClassUID == 0)
    return 0;

  for (idx = 0; idx < DIM_OF(classArray); idx++) {
    if (strcmp(sopClassUID, classArray[idx]) == 0)
      return 1;
  }

  return 0;
}
Example #13
0
static CONDITION
readUIDFile(UID_BLOCK * block)
{
    CONDITION
    cond;
    FILE
	* f;
    static UID_BLOCK
        b;
    int
        index;
    char
        buffer[120],
        keyWord[120];

    static BLOCK_MAP map[] = {
	{"PATIENT", &b.patient},
	{"VISIT", &b.visit},
	{"STUDY", &b.study},
	{"SERIES", &b.series},
	{"IMAGE", &b.image},
	{"RESULTS", &b.results},
	{"INTERPRETATION", &b.interpretation},
	{"PRINTER", &b.printer},
	{"DEVICE", &b.deviceType},
	{"SERIAL", &b.serialNumber},
	{"STUDYCOMPONENT", &b.studyComponent},
	{"STORAGECOMMITTRANSACTION", &b.storageCommitTransaction}
    };

    cond = getUIDFile();
    if (cond != UID_NORMAL)
	return cond;

    (void) memset(&b, 0, sizeof(b));

    f = fopen(uidFile, "r");
    if (f == NULL)
	return COND_PushCondition(UID_FILEOPENFAILURE,
				  UID_Message(UID_FILEOPENFAILURE), uidFile);

    while (fgets(buffer, sizeof(buffer), f) != NULL) {
	if (sscanf(buffer, "%s", keyWord) == 1) {
	    if (strcmp(keyWord, "ROOT") == 0) {
		if (sscanf(buffer, "%s %s", keyWord, b.root) != 2)
		    return COND_PushCondition(UID_ILLEGALROOT,
				      UID_Message(UID_ILLEGALROOT), buffer);
	    } else {
		for (index = 0; index < (int) DIM_OF(map); index++) {
		    if (strcmp(keyWord, map[index].keyWord) == 0) {
			if (sscanf(buffer, "%s %ld", keyWord, map[index].value) != 2)
			    return COND_PushCondition(UID_ILLEGALNUMERIC,
				   UID_Message(UID_ILLEGALNUMERIC), buffer);
		    }
		}
	    }
	}
    }

    (void) fclose(f);
    if (b.deviceType == 0)
	return COND_PushCondition(UID_NODEVICETYPE, UID_Message(UID_NODEVICETYPE),
				  uidFile);
    if (strlen(b.root) == 0)
	return COND_PushCondition(UID_NOROOT, UID_Message(UID_NOROOT),
				  uidFile);
    *block = b;
    return UID_NORMAL;
}
Example #14
0
File: set.c Project: nagyistge/ctn
/* nsetBFSCallback
**
** Purpose:
**	Callback function invoked by SRV_NSetResponse to set the attributes
**	of Basic Film Session
**
** Parameter Dictionary:
**	nsetRequest	Pointer to the set request
**	nsetResponse	Pointer to the set response
**	sendBack	Indicates whether attributes are to be sent back
**			to the requesting SCU
**	pc		Presentation context describes this SOP class
**
** Return Values:
**	SRV_NORMAL on success
**	SRV_CALLBACKABORTEDSERVICE on failure
**
** Notes:
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
static CONDITION
nsetBFSCallback(MSG_N_SET_REQ * nsetRequest,
		MSG_N_SET_RESP * nsetResponse,
		void *sendBack, DUL_PRESENTATIONCONTEXT * pc)
{
    CONDITION
    cond;			/* condition code returned by various
				 * facilities used by the callback */
    PRN_BASICFILMSESSION bfsAttrib,	/* holds attributes of the Basic Film
					 * Session received from the
					 * requesting SCU */
       *bfsPtr;			/* a pointer to the above structure */
    char
       *fileName;		/* filename holding attributes of Basic Film
				 * Session instance */
    GQ_ELEM
	gqElement;		/* The GQ element to be enqueued */
    char
       *flagNameList = NULL;	/* holds attribute names for which the
				 * verification service caused an error */

    /* define a table of all those attributes that need to be verified */
    static SUPPORTEDATTRIBUTES supportedAttributeList[] = {
	{PRN_BFS_K_COPIES, "BFS Copies ", bfsSupportedCopies,
	(int) DIM_OF(bfsSupportedCopies)},
	{PRN_BFS_K_PRIORITY, "BFS Priority ", bfsSupportedPriority,
	(int) DIM_OF(bfsSupportedPriority)},
	{PRN_BFS_K_MEDIUMTYPE, "BFS Medium type ", bfsSupportedMediumType,
	(int) DIM_OF(bfsSupportedMediumType)},
	{PRN_BFS_K_FILMDESTINATION, "BFS Film Destination ",
	bfsSupportedFilmDestination, (int) DIM_OF(bfsSupportedFilmDestination)},
	{PRN_BFS_K_FILMSESSIONLABEL, "BFS Film Session Label ",
	    bfsSupportedFilmSessionLabel,
	(int) DIM_OF(bfsSupportedFilmSessionLabel)},
#ifdef ASG
	{PRN_BFS_K_MEMORYALLOCATION, "BFS Memory Allocation ",
	NULL, 0}
#endif
    };

    /* we 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);
    nsetResponse->dataSetType = DCM_CMDDATANULL;
    nsetResponse->conditionalFields = 0;
#ifdef ASG
    nsetResponse->dataSet = NULL;
#endif

    /*
     * Verify that the instance UID specified in the Request message is valid
     */
    if (strcmp(bfsInstance.bfsInstanceUID, nsetRequest->instanceUID) != 0) {
	/* instance UID conflict */
	nsetResponse->status = MSG_K_CLASSINSTANCECONFLICT;
	strcpy(nsetResponse->requestedClassUID, nsetRequest->classUID);
	strcpy(nsetResponse->requestedInstanceUID, nsetRequest->instanceUID);
	nsetResponse->conditionalFields |= MSG_K_N_SETRESP_REQUESTEDCLASSUID |
	    MSG_K_N_SETRESP_REQUESTEDINSTANCEUID;
	goto ERROR_RETURN;
    }
    bfsPtr = &bfsAttrib;
    bfsPtr->bfsAttributeFlag = 0x0;
    (void) strcpy(bfsPtr->filmSessionSOPClassUID, nsetResponse->classUID);
    (void) strcpy(bfsPtr->filmSessionSOPInstanceUID,
		  nsetResponse->instanceUID);
    /* Parse the data set sent by SCU */
    cond = PRN_ParseObject(&nsetRequest->dataSet, PRN_K_BASICFILMSESSION,
			   (void **) &bfsPtr);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetBFSCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_ParseObject", "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    if (traceFlag) {
	printf("Film Session Attributes Specified by SCU (NSet Request):\n");
	PRN_DumpAttributes(bfsPtr, stdout);
    }
    /*
     * We verify if the performing SCU has provided all mandatory attributes
     * and the requesting SCU has specified values for the mandatory
     * attributes. Further, we also verify if the optional attributes
     * requested by the SCU are supported by the performing SCU. Finally, we
     * verify if the values supplied by the requesting SCU are supported by
     * the performing SCU.
     * 
     * At any point, the function finds a discrepancy, it returns the
     * appropriate error condition
     */
    cond = supportedAttributes(MSG_K_N_SET_REQ, bfsPtr,
	       supportedAttributeList, (int) DIM_OF(supportedAttributeList),
			       &flagNameList, (void **) &nsetResponse);
    if (cond != APP_NORMAL) {
	/*
	 * depending upon the condition returned, set the message status
	 * value
	 */
	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,
				  "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    /*
     * At this point the verification process is successful Proceed by
     * creating the Basic Film Session
     */
    /* UPDATE hierarchy */
    cond = PRN_BuildObject((void *) bfsPtr, &bfsInstance.bfsAttrib);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFSCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    strcpy(bfsInstance.bfsInstanceUID, nsetResponse->instanceUID);
    /*
     * If the server's terminal has x-capability and wishes to enqueue the
     * image in the GQueue
     */
    if (gqueueFlag) {
	gqElement.prnMessage = PRN_NEWFILMSESSION;	/* element type to be
							 * enqueued */
	(void) strcpy(gqElement.instanceUID, bfsInstance.bfsInstanceUID);
	/* 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(&bfsInstance.bfsAttrib, DCM_ORDERLITTLEENDIAN,
			     fileName);
	if (cond != DCM_NORMAL) {
	    unlink(gqElement.objFile);	/* delete the file before exiting */
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "DCM_WriteFile", "nsetBFSCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
		APP_ERROR(APP_FAILURE), "DCM_WriteFile", "nsetBFSCallback");
	    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", "nsetBFSCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
		   APP_ERROR(APP_FAILURE), "GQ_Enqueue", "nsetBFSCallback");
	    goto ERROR_RETURN;
	}
    }
    /* Attributes need to be sent back */
    cond = PRN_BuildObject((void *) bfsPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFSCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
    /* everything is successful */
    nsetResponse->status = MSG_K_SUCCESS;
    return SRV_NORMAL;

    /*
     * This is the exit point for all errors that may have occurred in the
     * callback routine
     */
ERROR_RETURN:
    COND_DumpConditions();
    return SRV_CALLBACKABORTEDSERVICE;
}
Example #15
0
CONDITION
HAP_ObjectToQuery(DCM_OBJECT ** object, char *SOPClass, Query * query,
		  int *elementCount)
{
    CONDITION
	cond,
	returnCondition;
    int
        index;
    void
       *ctx;
    unsigned long
        l;
    long
        flag;
    static char
        queryLevelString[48];
    DCM_ELEMENT
	queryLevelElement =
    {
	DCM_IDQUERYLEVEL, DCM_CS, "", 1,
	    sizeof(queryLevelString), (void *) queryLevelString
    };

    *elementCount = 0;
    q.QueryState = 0;
    q.Patient.Query_Flag = 0;
    q.Study.Query_Flag = 0;
    q.Series.Query_Flag = 0;
    q.Image.Query_Flag = 0;

    ctx = NULL;
    returnCondition = HAP_NORMAL;

    cond = DCM_GetElementValue(object, &queryLevelElement, &l, &ctx);
    if (cond != DCM_NORMAL) {
	if (cond == DCM_ILLEGALOBJECT)
	    return COND_PushCondition(HAP_ILLEGALOBJECT, "");
	else {
	    (void) COND_PopCondition(FALSE);
	    (void) COND_PushCondition(HAP_QUERYLEVELMISSING, "");
	    returnCondition = HAP_INCOMPLETEOBJECT;
	}
    } else {
	queryLevelString[l] = '\0';
	if (queryLevelString[l - 1] == ' ')
	    queryLevelString[l - 1] = '\0';

	for (index = 0; index < DIM_OF(levelMap); index++) {
	    if (strcmp(levelMap[index].queryLevel, queryLevelString) == 0)
		q.QueryState |= levelMap[index].flag;
	}
    }

    flag = 0;
    for (index = 0; index < DIM_OF(classMap); index++) {
	if (strcmp(classMap[index].SOPClass, SOPClass) == 0)
	    flag |= classMap[index].flag;
    }
    if (flag == 0)
	return HAP_ILLEGALSOPCLASS;

    q.QueryState |= flag;

    for (index = 0; index < (int) DIM_OF(list); index++) {
	ctx = NULL;
	cond = DCM_GetElementValue(object, &list[index].e, &l, &ctx);
	if (cond == DCM_NORMAL) {
	    (*elementCount)++;
	    list[index].e.d.string[l] = '\0';
	    *list[index].flagAddress |= list[index].flag;
	} else
	    (void) COND_PopCondition(FALSE);
    }
    *query = q;
    return returnCondition;
}
Example #16
0
File: set.c Project: nagyistge/ctn
/* nsetBFBCallback
**
** Purpose:
**	Describe the purpose of the function
**
** Parameter Dictionary:
**	Define the parameters to the function
**
** Return Values:
**
** Notes:
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
static CONDITION
nsetBFBCallback(MSG_N_SET_REQ * nsetRequest,
		MSG_N_SET_RESP * nsetResponse,
		void *sendBack, DUL_PRESENTATIONCONTEXT * pc)
{
#ifdef ASG
    CONDITION
    cond;			/* various condition codes returned by the
				 * facilities */

    PRN_BASICFILMBOX bfbAttrib,	/* structure to hold the attributes of BASIC
				 * FILM BOX */
       *bfbPtr = NULL;		/* pointer to the above structure */
    int
        index;			/* loop indices */
    int
        index2;
    char
       *fileName;		/* filename holding attributes of Basic Film
				 * Box instance that is to be enqueued */
    GQ_ELEM
	gqElement;		/* A GQ element that shall hold the instance
				 * of the Basic Film Box */
    char
       *flagNameList = NULL;	/* holds values and names of attributes that
				 * cause any error during verification */

    static APP_BFBIMAGEDISPLAYFORMAT
        bfbImageDisplayFormat;	/* this structure gets filled by the
				 * verification service as a side-effect */

    /* define the table of all attributes that need to be verified */
    static SUPPORTEDATTRIBUTES supportedAttributeList[] = {
	{PRN_BFB_K_MAGNIFICATIONTYPE, "BFB Magnification Type ",
	bfbMagnificationType, (int) DIM_OF(bfbMagnificationType)},
	{PRN_BFB_K_MAXDENSITY, "BFB Max Density ", NULL, 0},
	{PRN_BFB_K_CONFIGURATIONINFO, "BFB Configuration Information ",
	bfbConfigurationInfo, (int) DIM_OF(bfbConfigurationInfo)},
	{PRN_BFB_K_SMOOTHINGTYPE, "BFB Smoothing Type", NULL, 0},
	{PRN_BFB_K_BORDERDENSITY, "BFB Border Density ",
	bfbBorderDensity, (int) DIM_OF(bfbBorderDensity)},
	{PRN_BFB_K_EMPTYIMAGEDENSITY, "BFB Empty Image Density ",
	bfbEmptyImageDensity, (int) DIM_OF(bfbEmptyImageDensity)},
	{PRN_BFB_K_MINDENSITY, "BFB Min Density ", NULL, 0},
	{PRN_BFB_K_TRIM, "BFB Trim ", bfbTrim, (int) DIM_OF(bfbTrim)}
    };

    /* we build up the response message */
    nsetResponse->type = MSG_K_N_SET_RESP;
    nsetResponse->status = MSG_K_SUCCESS;
    nsetResponse->messageIDRespondedTo = nsetRequest->messageID;
    nsetResponse->dataSetType = DCM_CMDDATANULL;
    nsetResponse->conditionalFields = 0;
    strcpy(nsetResponse->classUID, nsetRequest->classUID);
#ifdef ASG
    nsetResponse->dataSet = NULL;
#endif
    /*
     * verify that the arriving NSet request for the Basic Film Box is for
     * the last created film box instance
     */

    /* Parse the received data set */
    bfbPtr = &bfbAttrib;
    bfbPtr->bfbAttributeFlag = 0x0;
    (void) strcpy(bfbPtr->filmBoxSOPClassUID, nsetRequest->classUID);
    (void) strcpy(bfbPtr->filmBoxSOPInstanceUID, nsetResponse->instanceUID);
    cond = PRN_ParseObject(&nsetRequest->dataSet, PRN_K_BASICFILMBOX,
			   (void **) &bfbPtr);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_ParseObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    if (traceFlag) {
	printf("Basic Film Box Attributes specified by SCU:\n");
	PRN_DumpAttributes(bfbPtr, stdout);
    }
    /*
     * We verify if the performing SCU has provided all mandatory attributes
     * and the requesting SCU has specified values for the mandatory
     * attributes. Further, we also verify if the optional attributes
     * requested by the SCU are supported by the performing SCU. Finally, we
     * verify if the values supplied by the requesting SCU are supported by
     * the performing SCU.
     * 
     * At any point, the function finds a discrepancy, it returns the
     * appropriate error condition
     */
    cond = supportedAttributes(MSG_K_N_CREATE_REQ, bfbPtr,
	       supportedAttributeList, (int) DIM_OF(supportedAttributeList),
			       &flagNameList, (void **) &nsetResponse);
    if (cond != APP_NORMAL) {
	/*
	 * depending upon the condition returned, set the message status
	 * value
	 */
	switch (cond) {
	case APP_MISSINGREQUIREDATTRIBUTE:
	    nsetResponse->status = MSG_K_MISSINGATTRIBUTE;
	    cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				      "nsetBFBCallback");
	    goto ERROR_RETURN;
	    break;
	case APP_UNSUPPORTEDMANDATORYATTRIBUTE:
	    cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				      "nsetBFBCallback");
	    goto ERROR_RETURN;
	    break;
	case APP_UNSUPPORTEDOPTIONALATTRIBUTE:
	    /* nsetResponse->status = MSG_K_NOSUCHATTRIBUTE; */
	    nsetResponse->status = MSG_K_SUCCESS;
	    break;
	case APP_UNSUPPORTEDATTRIBUTEVALUE:
	    /* nsetResponse->status = MSG_K_INVALIDATTRIBUTEVALUE; */
	    nsetResponse->status = MSG_K_SUCCESS;
	    break;
	}
    }
    /*
     * we need to build the referenced image box sequence to be included in
     * the data set. We do not support sequence of annotation boxes.
     */
    bfbPtr->referencedBABSeq = NULL;	/* no seq of annotation boxes */
    bfbPtr->referencedBIBSeq = LST_Create();
    if (bfbPtr->referencedBIBSeq == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "LST_Create", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		   APP_ERROR(APP_FAILURE), "LST_Create", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /*
     * We also update the hierarchy. Create a copy of the BFB instance
     */
    if ((bfbInstance = malloc(sizeof(*bfbInstance))) == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_MALLOCFAILURE),
				  "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
			   APP_ERROR(APP_MALLOCFAILURE), "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    (void) strcpy(bfbInstance->bfbInstanceUID, nsetResponse->instanceUID);
    bfbInstance->bfbAttrib = NULL;

    /* now acquire space to store the list of image boxes */
    bfbInstance->babList = NULL;/* we do not have an annotation box */
    bfbInstance->bibList = LST_Create();
    if (bfbInstance->bibList == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "LST_Create", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		   APP_ERROR(APP_FAILURE), "LST_Create", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /*
     * The SCP now creates instances of the BASIC IMAGE BOX SOP class
     * depending on the attribute value viz. imageDisplayFormat
     * 
     */
    switch (bfbImageDisplayFormat.type) {
    case STANDARD_FORMAT:
	/* images are stored in row-major order */
	for (index = 0; index < bfbImageDisplayFormat.format.standard.numRows;
	     index++) {
	    for (index2 = 0; index2 <
	       bfbImageDisplayFormat.format.standard.numColumns; index2++) {
		cond = createBIBList(bfbPtr);
		if (cond != APP_NORMAL) {
		    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
					"createBIBList", "nsetBFBCallback");
		    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "createBIBList",
					      "nsetBFBCallback");
		    goto ERROR_RETURN;
		}
	    }
	}
	break;
    case ROW_FORMAT:
	for (index = 0; index < bfbImageDisplayFormat.format.row.numRows;
	     index++) {
	    for (index2 = 0; index2 <
		 bfbImageDisplayFormat.format.row.imagesPerRow[index];
		 index2++) {
		cond = createBIBList(bfbPtr);
		if (cond != APP_NORMAL) {
		    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
					"createBIBList", "nsetBFBCallback");
		    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "createBIBList",
					      "nsetBFBCallback");
		    goto ERROR_RETURN;
		}
	    }
	}
	break;
    case COL_FORMAT:
	for (index = 0; index < bfbImageDisplayFormat.format.standard.numRows;
	     index++) {
	    for (index2 = 0; index2 <
		 bfbImageDisplayFormat.format.col.imagesPerColumn[index];
		 index2++) {
		cond = createBIBList(bfbPtr);
		if (cond != APP_NORMAL) {
		    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
					"createBIBList", "nsetBFBCallback");
		    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "createBIBList",
					      "nsetBFBCallback");
		    goto ERROR_RETURN;
		}
	    }
	}
	break;
    }
    /*
     * We need to update the following flag since, the SCP provides this
     * attribute.
     */
    bfbPtr->bfbAttributeFlag |= PRN_BFB_K_REFERENCEDBASICIMAGEBOXSEQ;
    /* we now build the response data set */
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
    cond = PRN_BuildObject((void *) bfbPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /* also add this to the hierarchy */
    cond = PRN_BuildObject((void *) bfbPtr, &bfbInstance->bfbAttrib);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /*
     * If the server's terminal has x-capability and wishes to enqueue the
     * film box instance in the GQueue
     */
    if (gqueueFlag) {
	gqElement.prnMessage = PRN_NEWFILMBOX;
	(void) strcpy(gqElement.instanceUID, bfbInstance->bfbInstanceUID);
	/* 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(&bfbInstance->bfbAttrib, DCM_ORDERLITTLEENDIAN,
			     fileName);
	if (cond != DCM_NORMAL) {
	    unlink(gqElement.objFile);	/* delete the file before exiting */
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "DCM_WriteFile", "nsetBFBCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
		APP_ERROR(APP_FAILURE), "DCM_WriteFile", "nsetBFBCallback");
	    goto ERROR_RETURN;
	}
	cond = GQ_Enqueue((void *) &gqElement);
	if (cond != GQ_NORMAL) {
	    unlink(gqElement.objFile);
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetBFBCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
				      APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetBFBCallback");
	    goto ERROR_RETURN;
	}
    }
    /*
     * add this bfbInstance to the list of basic film boxes maintained by the
     * the parent Basic Film Session instance
     */
    cond = LST_Enqueue(&bfsInstance.bfbList, bfbInstance);
    if (cond != LST_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "LST_Enqueue", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		  APP_ERROR(APP_FAILURE), "LST_Enqueue", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /* Attributes need to be sent back */
    cond = PRN_BuildObject((void *) bfbPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /* everything is successful (may have warnings) */
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
#ifdef ASG
    nsetResponse->status = MSG_K_SUCCESS;
#endif
    if (traceFlag) {
	printf("Returning SRV_NORMAL in nsetBFBCallback\n");
	MSG_DumpMessage(nsetResponse, stdout);
    }
    return SRV_NORMAL;

ERROR_RETURN:
    COND_DumpConditions();
    if (traceFlag) {
	printf("Returning SRV_CALLBACKABORTEDSERVICE in nsetBFBCallback\n");
	MSG_DumpMessage(nsetResponse, stdout);
    }
    return SRV_CALLBACKABORTEDSERVICE;
#endif
    return SRV_NORMAL;
}
Example #17
0
CONDITION
HAP_QueryToObject(Query * query, DCM_OBJECT ** object, char *SOPClass,
		  int *elementCount)
{
    CONDITION
	cond,
	returnCondition;
    int
        index;
    DCM_ELEMENT
	e;
    long
        flag;
    static char
        queryLevelString[48];
    DCM_ELEMENT
	queryLevelElement =
    {
	DCM_IDQUERYLEVEL, DCM_CS, "", 1,
	    sizeof(queryLevelString), (void *) queryLevelString
    };

    q = *query;
    *elementCount = 0;

    if (*object == NULL) {
	cond = DCM_CreateObject(object);
	if (cond != DCM_NORMAL)
	    return HAP_OBJECTCREATEFAILED;
    }
    returnCondition = HAP_NORMAL;
    flag = q.QueryState &
	(DB_K_LEVELPAT | DB_K_LEVELSTUDY | DB_K_LEVELSERIES | DB_K_LEVELIMAGE);
    if (flag == 0)
	returnCondition = COND_PushCondition(HAP_INCOMPLETEQUERY, "");
    else {
	for (index = 0; index < DIM_OF(levelMap); index++) {
	    if ((q.QueryState & levelMap[index].flag) != 0) {
		(void) strcpy(queryLevelString, levelMap[index].queryLevel);
		queryLevelElement.length = strlen(queryLevelElement.d.string);
		cond = DCM_ModifyElements(object, &queryLevelElement,
					  1, NULL, 0, NULL);
		if (cond != DCM_NORMAL)
		    return cond;
	    }
	}
    }


    flag = q.QueryState &
	(DB_K_CLASSPAT | DB_K_CLASSSTUDY | DB_K_CLASSPATSTUDY);
    if (flag == 0)
	returnCondition = COND_PushCondition(HAP_INCOMPLETEQUERY, "");
    else {
	for (index = 0; index < DIM_OF(classMap); index++) {
	    if ((q.QueryState & classMap[index].flag) != 0) {
		(void) strcpy(SOPClass, classMap[index].SOPClass);
		cond = DCM_NORMAL;
	    }
	}
    }

    for (index = 0; index < (int) DIM_OF(list); index++) {
	flag = *list[index].flagAddress;
	if ((flag & list[index].flag) != 0) {
	    e = list[index].e;
	    e.length = strlen(e.d.string);
	    cond = DCM_AddElement(object, &e);
	    if (cond != DCM_NORMAL)
		return cond;
	    (*elementCount)++;
	}
    }
    return returnCondition;
}
Example #18
0
int
MDBImageManager::fillStudyVector(const MStudy& study, MStudyVector& v)
{
  char* searchCriteria[] = {
    "stuinsuid",
    // "studat",		// Comment out as we treat this for date range
    "stutim",
    "accnum",
    "stuid"
  };

  MCriteriaVector criteria;

  MString studyDate = study.studyDate();
  if (studyDate != "") {
    if (studyDate.containsCharacter('-')) {
      MString lower = studyDate.getToken('-', 0);
      MString upper = studyDate.getToken('-', 1);
      if (lower != "") {
	MCriteria p;
	p.attribute = "studat";
	p.oper = TBL_GREATER_EQUAL;
	p.value = lower;
	criteria.push_back(p);
      }
      if (upper != "") {
	MCriteria p;
	p.attribute = "studat";
	p.oper = TBL_LESS_EQUAL;
	p.value = upper;
	criteria.push_back(p);
      }
    } else {
      MCriteria p;
      p.attribute = "studat";
      p.oper = TBL_EQUAL;
      p.value = studyDate;
      criteria.push_back(p);
    }
  }


  int i;

  const MDomainMap& m = study.map();
  for(i = 0; i < (int)DIM_OF(searchCriteria); i++) {
    MDomainMap::const_iterator iDomain = m.find(searchCriteria[i]);
    if (iDomain == m.end())
      continue;

    MString s = (*iDomain).second;

    if (s != "") {
      TBL_OPERATOR oper = TBL_EQUAL;
      if (s.find("*") != string::npos) {
	s.substitute('*', '%');
	oper = TBL_LIKE;
      }
      MCriteria c;
      c.attribute = searchCriteria[i];
      c.oper = oper;
      c.value = s;
      criteria.push_back(c);
    }
  }
  MStudy s;
  mDBInterface->select(s, criteria, studyCallback, this);
  MStudyVector::iterator studyIterator = mStudyVector.begin();
  for (; studyIterator != mStudyVector.end(); studyIterator++)
    v.push_back(*studyIterator);

  return 0;
}
Example #19
0
CONDITION
SRV_RequestServiceClass(const char *SOPClass, DUL_SC_ROLE role,
			DUL_ASSOCIATESERVICEPARAMETERS * params)
{
    DUL_PRESENTATIONCONTEXTID
	contextID = 1;
    int
        index;
    CTNBOOLEAN
	found = FALSE;
    CONDITION
	cond;
    DUL_PRESENTATIONCONTEXT
	* ctx;

    if (params->requestedPresentationContext == NULL) {
	params->requestedPresentationContext = LST_Create();
	if (params->requestedPresentationContext == NULL) {
	    return COND_PushCondition(SRV_LISTFAILURE,
		   SRV_Message(SRV_LISTFAILURE), "SRV_RequestServiceClass");
	}
    }
    ctx = LST_Head(&params->requestedPresentationContext);
    if (ctx != NULL)
	(void) LST_Position(&params->requestedPresentationContext, ctx);
    while (ctx != NULL) {
	contextID += 2;
	if (strcmp(SOPClass, ctx->abstractSyntax) == 0)
	    return SRV_NORMAL;

	ctx = LST_Next(&params->requestedPresentationContext);
    }

    for (index = 0; index < (int) DIM_OF(syntaxList) && !found; index++) {
	if (strcmp(SOPClass, syntaxList[index]) == 0) {
	    found = TRUE;
	}
    }
    if (found) {
	char **xferSyntaxes;

	int singleMode = 1;
	int xferSyntaxCount = 0;

	xferSyntaxes = mapProposedSOPToXferSyntax(SOPClass,
		"PROPOSE/XFER", &xferSyntaxCount, &singleMode);

	if (singleMode == 1) {
	    cond = DUL_AddSinglePresentationCtx(params,
			role, DUL_SC_ROLE_DEFAULT, contextID,
			0, SOPClass, (const char**)xferSyntaxes,
			xferSyntaxCount);
	} else {
	    cond = DUL_AddMultiplePresentationCtx(params,
			role, DUL_SC_ROLE_DEFAULT, contextID,
			0, SOPClass, (const char**)xferSyntaxes,
			xferSyntaxCount);
	}
	if (cond != DUL_NORMAL) {
	    return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
			SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
			"SRV_RequestServiceClass");
	}
/* Legacy version removed 1/3/2001, smm
	    cond = DUL_MakePresentationCtx(&ctx, role, DUL_SC_ROLE_DEFAULT,
				       contextID, 0, SOPClass, "",
				       DICOM_TRANSFERLITTLEENDIAN, NULL);
	if (cond != DUL_NORMAL)
	    return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR,
				  SRV_Message(SRV_PRESENTATIONCONTEXTERROR),
				      "SRV_RequestServiceClass");
	else {
	    cond = LST_Enqueue(&params->requestedPresentationContext, ctx);
	    if (cond != LST_NORMAL)
		return COND_PushCondition(SRV_LISTFAILURE,
		   SRV_Message(SRV_LISTFAILURE), "SRV_RequestServiceClass");

	    contextID += 2;
	}
*/

    } else
	return COND_PushCondition(SRV_UNSUPPORTEDSERVICE,
			      SRV_Message(SRV_UNSUPPORTEDSERVICE), SOPClass,
				  "SRV_RequestServiceClass");

    return SRV_NORMAL;
}
Example #20
0
CONDITION
HAP_BuildVisit(DCM_OBJECT ** object,
	       HIS_VisitLevel * xl, HAP_VISIT_EVENT event)
{

    int index,
        x;

    CONDITION
	cond;

    CTNBOOLEAN
	eventFound = FALSE;

    static unsigned long his_flags[] =
    {HIS_K_VISRPSEQUENCE, HIS_K_VISRSSEQUENCE,
    HIS_K_VISADCSEQUENCE, HIS_K_VISDDCSEQUENCE};
    static SQ_TYPE types[] =
    {SQ_K_REFPATIENTSOPINSTANCEUID, SQ_K_REFSTUDYSOPINSTANCEUID,
    SQ_K_ADMITDIAGNOSISCODE, SQ_K_DISCHARGEDIAGNOSISCODE};

    p = *xl;

    if (event != 0) {
	for (index = 0; index < (int) DIM_OF(array) && !eventFound; index++) {
	    if (event == array[index].event) {
		eventFound = TRUE;
		if ((event & HAP_X_VARIABLE_EVENT) != 0) {
		    if ((p.Update_Flag & array[index].required_event_attrib) !=
			array[index].required_event_attrib)
			return HAP_INCOMPLETEEVENT;
		} else {
		    if (p.Update_Flag != array[index].required_event_attrib)
			return HAP_INCOMPLETEEVENT;
		}
	    }
	}

	if (!eventFound)
	    return HAP_ILLEGALEVENT;
    }
    cond = DCM_ModifyElements(object, NULL, 0, list, (int) DIM_OF(list),
			      NULL);
    if (cond != DCM_NORMAL)
	return HAP_ILLEGALOBJECT;

    for (index = 0; index < (int) DIM_OF(his_flags); index++)
	if (p.Update_Flag & his_flags[index]) {
	    x = v_buildSequence(object, types[index]);
	    if (x < 0)
		return 0;	/* needs repair */
	}
/*
    if (p.Update_Flag & HIS_K_VISRPSEQUENCE) {
	x = v_buildSequence(object, SQ_K_REFPATIENTSOPINSTANCEUID);
	if (x < 0)
	    return 0;
    }
    if (p.Update_Flag & HIS_K_VISRSSEQUENCE) {
	x = v_buildSequence(object, SQ_K_REFSTUDYSOPINSTANCEUID);
	if (x < 0)
	    return 0;
    }
*/
    return HAP_NORMAL;
}
Example #21
0
int
i_buildSequence(DCM_OBJECT ** object, SQ_TYPE type)
{

    int index = 0;
    int i;
    LST_HEAD *l;
    DCM_ELEMENT *e;
    CONDITION cond;
    SQ_REFRESULTSSOPINSTANCEUID *results;
    SQ_REQINTERPRETATIONAPPROVER *approver;
    SQ_REQPROCEDURECODE *diagnosis;
    void *pointer;

    static SQ_MAP_SOP sops[] = {
	{SQ_K_REFRESULTSSOPINSTANCEUID,
	    DICOM_SOPCLASSDETACHEDRESULTSMGMT, &(p.RRSequenceCount),
	sizeof(SQ_REFRESULTSSOPINSTANCEUID)},
	{SQ_K_REQINTERPRETATIONAPPROVER,
	    "", &(p.IApprovalSequenceCount),
	sizeof(SQ_REQINTERPRETATIONAPPROVER)},
	{SQ_K_REQDIAGNOSISCODE,
	    "", &(p.IApprovalSequenceCount),
	sizeof(SQ_REQPROCEDURECODE)},
    };

    l = LST_Create();
    if (l == NULL)
	return -1;

    for (i = 0; i < (int) DIM_OF(sops) && sops[i].type != type; i++);
    if (i >= (int) DIM_OF(sops))
	return -1;

    while (index < *(sops[i].counter)) {
	if ((pointer = malloc(sops[i].size)) == NULL)
	    return -1;
	switch (type) {
	case SQ_K_REFRESULTSSOPINSTANCEUID:
	    results = (SQ_REFRESULTSSOPINSTANCEUID *) pointer;
	    results->type = type;
	    sprintf(results->referencedSOPClassUID, "%s",
		    DICOM_SOPCLASSDETACHEDRESULTSMGMT);
	    sprintf(results->referencedSOPInstanceUID, "%s",
		    p.RRSequence[index]);
	    break;
	case SQ_K_REQINTERPRETATIONAPPROVER:
	    approver = (SQ_REQINTERPRETATIONAPPROVER *) pointer;
	    approver->type = type;
	    sprintf(approver->physiciansApproving, "%s",
		    p.IApprover[index]);
	    sprintf(approver->approvalDates, "%s",
		    p.IADates[index]);
	    sprintf(approver->approvalTimes, "%s",
		    p.IATimes[index]);
	    break;
	case SQ_K_REQDIAGNOSISCODE:
	    diagnosis = (SQ_REQPROCEDURECODE *) pointer;
	    diagnosis->type = type;
	    sprintf(diagnosis->codeValue, "%s",
		    p.IDCSequence[index].CodeValue);
	    sprintf(diagnosis->codingSchemeDesignator, "%s",
		    p.IDCSequence[index].CodingSchemeDesignator);
	    sprintf(diagnosis->codeMeaning, "%s",
		    p.IDCSequence[index].CodeMeaning);
	    break;
	}
	LST_Enqueue(&l, pointer);
	index++;
    }
    cond = SQ_BuildSequence(&l, sops[i].type, &e);
    if (cond != SQ_NORMAL) {
	COND_DumpConditions();
	fprintf(stderr, "SQ_BuildSequence failed \n");
	return -1;
    }
    cond = DCM_AddElement(object, e);
    if (cond != DCM_NORMAL) {
	COND_DumpConditions();
	fprintf(stderr, "DCM_AddElement failed \n");
	return -1;
    }
    return 0;
}